void openserial_stop() { uint16_t temp_openserial_input_buffer_fill_level; INTERRUPT_DECLARATION(); DISABLE_INTERRUPTS(); temp_openserial_input_buffer_fill_level = openserial_vars.input_buffer_fill_level; ENABLE_INTERRUPTS(); uart_disableInterrupts(); // disable USCI_A1 TX & RX interrupt DISABLE_INTERRUPTS(); openserial_vars.mode=MODE_OFF; ENABLE_INTERRUPTS(); if (temp_openserial_input_buffer_fill_level>0) { uint8_t temp_openserial_received_command; DISABLE_INTERRUPTS(); temp_openserial_received_command = openserial_vars.received_command; ENABLE_INTERRUPTS(); switch (temp_openserial_received_command) { case 'R': //Trigger IDManager about isRoot idmanager_triggerAboutRoot(); break; case 'B': //Trigger IDManager about isBridge idmanager_triggerAboutBridge(); break; case 'T': //Trigger TCPInject tcpinject_trigger(); break; case 'U': //Trigger UDPInject udpinject_trigger(); break; case 'E': //Trigger ICMPv6Echo icmpv6echo_trigger(); break; case 'O': //Trigger ICMPv6Router icmpv6router_trigger(); break; case 'P': //Trigger ICMPv6RPL icmpv6rpl_trigger(); break; case 'D': //Trigger OpenBridge (called only by moteProbe) openbridge_trigger(); break; default: openserial_printError(COMPONENT_OPENSERIAL,ERR_UNSUPPORTED_COMMAND, (errorparameter_t)temp_openserial_received_command, (errorparameter_t)0); DISABLE_INTERRUPTS(); openserial_vars.input_buffer_fill_level = 0; ENABLE_INTERRUPTS(); break; } } }
void openserial_stop() { uint8_t inputBufFill; uint8_t cmdByte; bool busyReceiving; INTERRUPT_DECLARATION(); DISABLE_INTERRUPTS(); busyReceiving = openserial_vars.busyReceiving; inputBufFill = openserial_vars.inputBufFill; ENABLE_INTERRUPTS(); // disable USCI_A1 TX & RX interrupt uart_disableInterrupts(); DISABLE_INTERRUPTS(); openserial_vars.mode=MODE_OFF; ENABLE_INTERRUPTS(); //the inputBuffer has to be reset if it is not reset where the data is read. //or the function openserial_getInputBuffer is called (which resets the buffer) if (busyReceiving==TRUE){ openserial_printError(COMPONENT_OPENSERIAL,ERR_BUSY_RECEIVING, (errorparameter_t)0, (errorparameter_t)inputBufFill); } if (busyReceiving == FALSE && inputBufFill>0) { DISABLE_INTERRUPTS(); cmdByte = openserial_vars.inputBuf[0]; ENABLE_INTERRUPTS(); switch (cmdByte) { case SERFRAME_PC2MOTE_SETROOTBRIDGE: idmanager_triggerAboutRoot(); idmanager_triggerAboutBridge(); break; case SERFRAME_PC2MOTE_SETROOT: idmanager_triggerAboutRoot(); break; case SERFRAME_PC2MOTE_SETBRIDGE: idmanager_triggerAboutBridge(); break; case SERFRAME_PC2MOTE_DATA: openbridge_triggerData(); break; case SERFRAME_PC2MOTE_TRIGGERSERIALECHO: //echo function must reset input buffer after reading the data. openserial_echo(&openserial_vars.inputBuf[1],inputBufFill-1); break; default: openserial_printError(COMPONENT_OPENSERIAL,ERR_UNSUPPORTED_COMMAND, (errorparameter_t)cmdByte, (errorparameter_t)0); //reset here as it is not being reset in any other callback DISABLE_INTERRUPTS(); openserial_vars.inputBufFill = 0; ENABLE_INTERRUPTS(); break; } } DISABLE_INTERRUPTS(); openserial_vars.inputBufFill = 0; openserial_vars.busyReceiving = FALSE; ENABLE_INTERRUPTS(); }