int main(void) { char buffer[MINLENGTH]; int status = 0; while (status != -1) { status = readbuff(buffer); if (status == 1) status = copyline(buffer); } return 0; }
int get_next_line(int const fd, char ** line) { int ret_readbuff; int ret_read; ret_read = 1; *line = ft_strnew(BUFF_SIZE + 1); while ((ret_readbuff = readbuff(line)) == 0 && ret_read != 0) { *line = ft_strnew(BUFF_SIZE + 1); ret_read = read (fd, *line, BUFF_SIZE); } if (ret_read > 0) return (1); return (ret_read); }
void buffer_parse() { int8_t temp[8]; int i; if(buffer[0] == 0xFF) { switch(buffer[1]) { case 0x20: //set pid x readbuff(temp, buffer, 5, 2); pid[0].p = ((float)hascii2dec(temp, 5)/100); readbuff(temp, buffer, 5, 7); pid[0].i = ((float)hascii2dec(temp, 5)/100); readbuff(temp, buffer, 5, 12); pid[0].d = ((float)hascii2dec(temp, 5)/100); usart_put(0xFF); usart_put(0x20); dec2hascii((int)(pid[0].p*100), 5); dec2hascii((int)(pid[0].i*100), 5); dec2hascii((int)(pid[0].d*100), 5); usart_put(0x0A); break; case 0x21: //set pid y readbuff(temp, buffer, 5, 2); pid[1].p = ((float)hascii2dec(temp, 5)/100); readbuff(temp, buffer, 5, 7); pid[1].i = ((float)hascii2dec(temp, 5)/100); readbuff(temp, buffer, 5, 12); pid[1].d = ((float)hascii2dec(temp, 5)/100); usart_put(0xFF); usart_put(0x21); dec2hascii((int)(pid[1].p*100), 5); dec2hascii((int)(pid[1].i*100), 5); dec2hascii((int)(pid[1].d*100), 5); usart_put(0x0A); break; case 0x22: //set power readbuff(temp, buffer, 5, 2); iPower = hascii2dec(temp, 5); usart_put(0xFF); usart_put(0x22); dec2hascii(iPower, 5); usart_put(0x0A); break; case 0x23: //set angle readbuff(temp, buffer, 8, 2); dest_angle.x = ((float)hascii2dec(temp, 8)/100); readbuff(temp, buffer, 8, 10); dest_angle.y = ((float)hascii2dec(temp, 8)/100); readbuff(temp, buffer, 8, 18); dest_angle.z = ((float)hascii2dec(temp, 8)/100); usart_put(0xFF); usart_put(0x23); dec2hascii((int)(dest_angle.x*100), 8); dec2hascii((int)(dest_angle.y*100), 8); dec2hascii((int)(dest_angle.z*100), 8); usart_put(0x0A); break; case 0x25: usart_put(0xFF); usart_put(0x25); dec2hascii((int)(pid[0].p*100), 5); dec2hascii((int)(pid[0].i*100), 5); dec2hascii((int)(pid[0].d*100), 5); dec2hascii((int)(pid[1].p*100), 5); dec2hascii((int)(pid[1].i*100), 5); dec2hascii((int)(pid[1].d*100), 5); dec2hascii(iPower, 5); dec2hascii(ADCVal[0], 5); dec2hascii(ADCVal[1], 5); dec2hascii((int)(dest_angle.x*100), 8); dec2hascii((int)(dest_angle.y*100), 8); dec2hascii((int)(dest_angle.z*100), 8); usart_put(0x0A); break; case 0x26: usart_put(0xFF); usart_put(0x26); dec2hascii(ADCVal[0], 5); dec2hascii(ADCVal[1], 5); usart_put(0x0A); break; } } buffer_pos = 0; }