/* Main application */ int main(void) { // initialize the device SYSTEM_Initialize(); uint16_t portValue; char introduction[]="Here are some messages from PIC. \r\n"; char append[4][3]; uint8_t appendCount = 0; uint8_t uartBuffer[128]; uint8_t i = 0; char currentCountAscii[16]; uint8_t sLength = 0; uint8_t uartBytesWritten = 0; uint8_t* tempPtr; uint16_t tmrValue; //UART2_TRANSFER_STATUS status ; //intialize the Board Power VDD_Board IO_RB2_SetLow(); // //Testing UART code // while(name[i] != '\0') // { // uartBuffer[i] = (uint8_t)name[i]; // i++; // } // uartBuffer[i] = (uint8_t)name[i]; /* IO_RB15_SetHigh(); for(j = 0;j<10;j++) { while(!TMR2_GetElapsedThenClear()) { //IO_RB8_SetHigh(); IO_RB15_SetHigh(); } while(!TMR2_GetElapsedThenClear()) { //IO_RB8_SetLow(); IO_RB15_SetLow(); } TMR3_delay_ms(_XTAL_FREQ, 500); } IO_RB15_SetHigh(); */ memcpy((void*)append[0], (void*)"th",3); memcpy((void*)append[1], (void*)"st",3); memcpy((void*)append[2], (void*)"nd",3); memcpy((void*)append[3], (void*)"rd",3); while (1) { //IO_RB15_SetLow(); // Add your application code // Read RB7 //portValue = IO_RB7_GetValue(); //if(portValue == 1) if(i == 0) { strcpy(uartBuffer, introduction); sLength = strlen(uartBuffer); i++; }else{ appendCount = i%10; if(appendCount > 3) appendCount = 0; sLength = sprintf(uartBuffer, "PIC %d%s Transmission\r\n", i,append[appendCount]); i++; } uartBytesWritten = 0; while(uartBytesWritten < sLength) { //status = UART2_TransferStatusGet ( ) ; if (!UART2_TransmitBufferIsFull()) { tempPtr = uartBuffer + uartBytesWritten; uartBytesWritten += UART2_WriteBuffer(uartBuffer+uartBytesWritten, UART2_TransmitBufferSizeGet()); } UART2_TasksTransmit(); } if(i==1) TMR3_delay_ms(_XTAL_FREQ, 3000); //delay just so I can see the first message //else // TMR3_delay_ms(_XTAL_FREQ, 10); } return -1; }
/** bool DRV_UART2_TransmitBufferIsFull(void) */ bool DRV_UART2_TransmitBufferIsFull(void) { return(UART2_TransmitBufferIsFull()); }
/** * Relays data from Radio to USB/Bluetooth */ void relayFromRadio() { /* UART1 - FTDI USB * UART2 - Bluetooth * UART3 - Radio */ if(!UART3_ReceiveBufferIsEmpty()) //New data on UART3 (Radio) { uint8_t rxByte = UART3_Read(); //Read byte from U3 if(relayUSBConneted()) { // if(!UART1_TransmitBufferIsFull()) //There is free space in U1 tx buffer //commented this out to avoid random loss of connection -D Cironi 2015-05-11 // { UART1_Write(rxByte); //Send to U1 // } } else { if(!UART2_TransmitBufferIsFull()) //There is free space in U2 tx buffer { UART2_Write(rxByte); //Read byte from U3 and send to U2 } } LandChannel = CheckRCLoop(rxByte); //check to see if data from radio is RC_Channel info if(LandChannel != 0 && LandChannel < 1500 && MissionInjectStage == 0 && LandInjected == 0) //Valid reading and the mode we want for landing { MissionInjectStage = 1; } else if (LandChannel != 0 && LandChannel > 1500) //valid reading but not the mode we want { MissionInjectStage = 0; LandInjected = 0; Nop(); } switch(MissionInjectStage) //inject a packet on each cycle { case 0: //do nothing break; case 1: InjectCount(4); break; case 2: InjectWaypoint('h'); break; case 3: InjectWaypoint('1'); break; case 4: InjectWaypoint('2'); break; case 5: InjectWaypoint('3'); break; case 6: InjectAcknowledge(); break; } } }