/****************************************************************************** * Wireless Hub * * Wixel Pin Usage * P0_0 Connected to RESET on ARDUINO * P0_1 - P0_5 Unused * P1_0 - P1_5 Unused * P1_6 WIXEL TX * P1_7 WIXEL RX * P2_1 Red LED * P2_2 Yellow LED and bootloader activate * * PACKET FORMAT * Array Description * [0] Length - atm is constant 9 * [1] SerialNumber 1 * [2] SerialNumber 2 * [3] SerialNumber 3 * [4] SerialNumber 4 * [5] Data 1 - Temperature * [6] Data 2 - Temperature Setpoint * [7] Data 3 - Status * [8] Data 4 - State * ******************************************************************************/ /*- Dependencies ------------------------------------------------------------*/ #include #include #include #include #include #include /*- Parameters --------------------------------------------------------------*/ /*- Definitions--------------------------------------------------------------*/ typedef struct Report { uint8 length; uint8 serialNumber[4]; uint8 readings[4]; } Report; /*- Global Variables -------------------------------------------------------*/ /*- Function Declarations ---------------------------------------------------*/ void updateLeds(); void putchar(char); void RadioService(); /*- Main Program ------------------------------------------------------------*/ void main(void) { systemInit(); usbInit(); radioQueueInit(); uart1Init(); uart1SetBaudRate(9600); while(1) { updateLeds(); boardService(); usbComService(); RadioService(); } } /*- Functions ---------------------------------------------------------------*/ void updateLeds() { usbShowStatusWithGreenLed(); LED_RED(0); LED_YELLOW(0); } void putchar(char c) { usbComTxSendByte(c); } void RadioService() { Report XDATA * rxPacket; static uint8 XDATA * txBuf; static uint32 XDATA lastTx; //check to see if any new data has been sent wirelessly if ((rxPacket = (Report XDATA *)radioQueueRxCurrentPacket()) && usbComTxAvailable() >= 64) { // We received a packet from a Wixel uint8 i; // Print the Serial Number to usb for debugging printf("%02X-%02X-%02X-%02X %5u", rxPacket->serialNumber[3], rxPacket->serialNumber[2], rxPacket->serialNumber[1], rxPacket->serialNumber[0], (uint16)getMs() ); // Print the Data Received to usb for debugging for(i = 0; i < 4; i++) { printf(" %5d", rxPacket->readings[i]); } printf(" %5d", rxPacket->length); putchar('\r'); putchar('\n'); //Send the Data received over radio to the arduino serialy if(uart1TxAvailable() > 8) { uart1TxSendByte(rxPacket->length); uart1TxSendByte(rxPacket->serialNumber[0]); uart1TxSendByte(rxPacket->serialNumber[1]); uart1TxSendByte(rxPacket->serialNumber[2]); uart1TxSendByte(rxPacket->serialNumber[3]); uart1TxSendByte(rxPacket->readings[0]); uart1TxSendByte(rxPacket->readings[1]); uart1TxSendByte(rxPacket->readings[2]); uart1TxSendByte(rxPacket->readings[3]); radioQueueRxDoneWithPacket(); } //radioQueueRxDoneWithPacket(); //since the uart isn't working we never get rid of this packet keep printing } //check to see if the arduino has sent a packet serially and if the radio buffer has room if ((uart1RxAvailable() > 8) && (txBuf = radioQueueTxCurrentPacket())) { //We received a packet from the arduino uint8 i; //retrieve the packet form the buffer for(i = 0; i <= 8; i++) { txBuf[i] = uart1RxReceiveByte(); } //Send the packet over usb for debugging printf("%02X-%02X-%02X-%02X %5u", txBuf[4], txBuf[3], txBuf[2], txBuf[1], (uint16)getMs() ); for(i = 5; i <= 8; i++) { printf(" %5d", txBuf[i]); } printf(" %5d", txBuf[0]); putchar('\r'); putchar('\n'); //Transmit the packet over radio to other wixel radioQueueTxSendPacket(); } }