//removes the first message from the queue void removeFirstMessageFromQueue(uint8_t qNumber) { if (channelQueuesArray[qNumber].numMessagesOnQueue == 0) { blinkRed(17); blinkGreen(15); blinkOrange(11); return; } uint8_t i = 0; for (i = 0; i < channelQueuesArray[qNumber].numMessagesOnQueue - 1; i++) { channelQueuesArray[qNumber].packetList[i] = channelQueuesArray[qNumber].packetList[i + 1]; } channelQueuesArray[qNumber].numMessagesOnQueue--; //one less message on the queue }
//removes the next message from the queue of messages pending processing //and returns it //decrements numPacketsPendingProcessing ReceiveMessagePacket removeProcessPendingMsg() { if (numPacketsPendingProcessing == 0) { while (1) { blinkRed(25); blinkGreen(50);} } ReceiveMessagePacket returnMsg = receivedQueue[0]; uint8_t i = 0; for (i = 0; i < numPacketsPendingProcessing - 1; i++) { receivedQueue[i] = receivedQueue[i + 1]; } numPacketsPendingProcessing--; return returnMsg; }
//This does the actual sending of the message //modifies: nothing //effects: send message in the Q_tx_msg_buff on the channel //NOTE: This method does NOT mess with or consider anything having to do with the channelQueuesArray at all uint8_t rbSendMessageHelper(uint8_t channel, uint8_t message[], uint8_t messageLength) { if (channel <= 0 || channel > MAX_CHANNELS) { //putstring("\nINVALID CHANNEL PASSED TO rbSendMessageHelper: "); putnum_uh(channel); while (1) { blinkRed(14); blinkOrange(14); } } disableRTC2(); if (pollClockLine(channel) == 0) { //putstring("\n about to ATTEMPT TO RECEIVE BEFORE SENDING on channel: "); putnum_ud(channel); ReceiveMessagePacket incomingPacket = receiveMessage(channel); if (incomingPacket.messageLength != 0) { //valid message, but it in the pending processing buffer //putstring("\nReceived Message before sending on channel "); putnum_ud(channel); //putstring(" Adding message to process pending queue"); addProcessPendingMsg(incomingPacket); } } uint8_t i; uint8_t good_tx = TRUE; for (i = 0; i < messageLength; i++) { if (sendByte(message[i], channel) == FALSE) { //the message was not received. //putstring("failed to send a byte"); good_tx = FALSE; break; } else good_tx = TRUE; refreshChannel(channel); //able to send at least 1 byte } /*if (channel == 1 && !good_tx) { putstring("\nch1 send failure\n"); }*/ enableRTC2(); return good_tx; }
void CheckBluetoothValues(void) { if (!firstRun) { // Reset the UART RX buffer to clear it UART1_ResetBuffer(); DataMatch = true; // Check RTC value UART1_WriteString((unsigned char *) "SHR,0018"); __delay_ms(5); // check if a recevied command is in the buffer if (uart1_rxLength > 11) { // check if the date in the Bluetooth module matches the LastDate variable. If not then the date has been updated by a client for (x = 0; x < 10; x++) { if (DateTimeResponse[x + 9] != uart1_rxBuffer[x]) { DataMatch = false; } } if (DataMatch == false) { if ((uart1_rxBuffer[0] == '1' || uart1_rxBuffer[0] == '2') && ((uart1_rxBuffer[1] >= '0') && (uart1_rxBuffer[1] <= '9'))){ Time.tm_year = CharToInt(uart1_rxBuffer[0], uart1_rxBuffer[1]); Time.tm_mon = CharToInt(uart1_rxBuffer[2], uart1_rxBuffer[3]); Time.tm_mday = CharToInt(uart1_rxBuffer[4], uart1_rxBuffer[5]); Time.tm_hour = CharToInt(uart1_rxBuffer[6], uart1_rxBuffer[7]); Time.tm_min = CharToInt(uart1_rxBuffer[8], uart1_rxBuffer[9]); Time.tm_sec = CharToInt(uart1_rxBuffer[10], uart1_rxBuffer[11]); Time.tm_wday = 1; // weekday RTCC_TimeSet(&Time); blinkRed(); } } } } // Check Alert Status }
void FSM::evalState() { switch (currentState) { case Start: case Standby: process->driveStop(); process->lightGreenOff(); process->lightRedOff(); process->lightYellowOff(); process->turnLEDQ1Off(); process->turnLEDQ2Off(); process->turnLEDResetOff(); process->turnLEDStartOn(); break; case Ready: process->driveStop(); process->lightGreenOn(); process->lightRedOff(); process->lightYellowOff(); process->turnLEDStartOn(); break; case Transport: process->driveRight(); process->lightGreenOn(); process->lightRedOff(); process->lightYellowOff(); process->turnLEDStartOff(); break; case MetalDetection: process->driveStop(); process->lightGreenOn(); process->lightRedOff(); process->lightYellowOff(); break; case NonMetalic: process->driveRight(); process->lightGreenOn(); process->lightRedOff(); process->lightYellowOff(); process->turnLEDStartOff(); process->openJunction(); break; case EndReached: process->driveStop(); process->lightRedOff(); process->lightYellowOff(); process->turnLEDStartOff(); process->closeJunction(); process->turnLEDStartOn(); blinkGreen(); break; case Metalic: process->driveRight(); process->lightGreenOff(); process->lightRedOff(); process->lightYellowOn(); break; case SlideReached: process->driveStop(); process->lightGreenOn(); process->lightRedOff(); process->lightYellowOff(); process->turnLEDStartOn(); break; case Error: process->driveStop(); process->lightGreenOff(); process->lightYellowOff(); process->turnLEDStartOn(); process->closeJunction(); blinkRed(); break; case TransportBack: process->driveLeft(); blinkRed(); process->lightGreenOff(); break; case StartReached: process->driveStop(); blinkRed(); break; } }