void startSweep(void){ char mystring[100] = ""; sprintf(mystring, "\nsweep_start;"); sendUART(mystring); sprintf(mystring, "\nsweep_size;%d;", samplespersweep); sendUART(mystring); sprintf(mystring, "\nscan_range;%d;", sweepstoppos-sweepstartpos); sendUART(mystring); }
//Handle an AT response packet and pass it to the sendUART function void xbeeHandleATR(unsigned char frame_id, WordVal command, unsigned char *data, unsigned char length) { unsigned char frame_header[5]; frame_header[RX_API_POS] = AT_RESPONSE; frame_header[ATR_FRAME_ID_POS] = frame_id; frame_header[ATR_COMMAND_HB_POS] = command.byte.HB; frame_header[ATR_COMMAND_LB_POS] = command.byte.LB; frame_header[ATR_STATUS_POS] = 0x00; CRITICAL_SECTION_START //Start Byte while(BusyUART1()); WriteUART1(RX_START); //Length High Byte while(BusyUART1()); WriteUART1(0x00); //Length Low Byte while(BusyUART1()); WriteUART1(length+FRAME_HEADER_LEN); sendUART(frame_header, data, length); CRITICAL_SECTION_END }
static void sendSpeed(unsigned char speed){ char buff[10]; buff[0] = 'D'; decToAsc(speed,3,&buff[1]); buff[4] = '\n'; buff[5] = '\r'; sendUART(6,buff); }
static void sendFlags(timeFlags * flags){ char buff[8]; buff[0] = 'F'; buff[1] = 'P'; buff[2] = '0' + flags->gosleep; buff[3] = 'W'; buff[4] = '0' + flags->wakeup; buff[5] = '\n'; buff[6] = '\r'; sendUART(7,buff); }
static void sendTime(rtcTimeWDay * time, char tmp){ char buff[12]; buff[0] = tmp; decToAsc(time->hour,2,&buff[1]); decToAsc(time->minute,2,&buff[3]); decToAsc(time->second,2,&buff[5]); decToAsc(time->wday,1,&buff[7]); buff[8] = '\n'; buff[9] = '\r'; sendUART(10,buff); }
int _write(int file, char *ptr, int len) { if (len == 0) return 0; if (file == 0 || file == 1) { usbSend(ptr, len); return len; } else if (file < 10) { unsigned int port = UART_FD[file]; if (port) { int totalSent = 0; while (len > 0) { int sent = sendUART(port, ptr, len); len -= sent; ptr += sent; totalSent += sent; } return totalSent; } else { return -1; } } else { int fd = file-10; if (fd < fatFilesOpen) { unsigned int res; if (fatFiles[fd].append) { _lseek(file, 0, SEEK_END); } FRESULT rr = f_write(&fatFiles[fd].fil, ptr, len, &res); if (rr) { fiprintf(stderr, "Failed to write FAT file %d (bytes: %d): %d\n\r", fd, len, rr); errno = EINVAL; return -1; } else { errno = 0; return res; } } } errno = EINVAL; return -1; }
/* Main ----------------------------------------------------------------------*/ int main(void){ inits( ); //while(1){;;} while(1){ // Runs in 1000Hz. if(runRegulator){ runRegulator = false; regulator( ); } // Reset if line is lost. /* if(stopTimer >= 3000){ stopTimer = 0; isFindingLine = false; runState = false; drive_total_stop( ); }*/ // Runs when all ADC are read, to calculate speed. if(adcDMA){ adcDMA = false; spokesCounter( ); } // Runs when data has been received. if(handleUsart){ handleUsart = false; usartHandler( ); } // Runs when data has been requested. if(usartRequested){ usartRequested = false; sendUART( ); } } }
void sendScanData(double sample){ char mystring[100] = ""; sprintf(mystring, "\nsample;%f;", sample); sendUART(mystring); }