void checkSerialAPI(){ xbee.readPacket(); if (xbee.getResponse().isAvailable()) { if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { xbee.getResponse().getZBRxResponse(rx); if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) { } else {} int len = rx.getDataLength(); char m[len+1]; for(int i=0;i<len;i++){ m[i]=rx.getData(i); } m[len]='\0'; splitString(m, CMD,DEL,BRI, R, G ,B, TOUT); t=millis() + TOUT * 1000; } else if (xbee.getResponse().getApiId() == MODEM_STATUS_RESPONSE) { xbee.getResponse().getModemStatusResponse(msr); if (msr.getStatus() == ASSOCIATED) {} else if (msr.getStatus() == DISASSOCIATED) {} else {} } else {} } else if (xbee.getResponse().isError()) {} }
// Wait for the response to the join message uint8_t EndDevice::joiningWaitResponse() { DEBUG_MSG("[JOINING WAIT RESPONSE]"); if (hasTimedOut()) { // Timed out waiting for a response to the join message disableTimeout(); State = EndDeviceError; return TICK_JOIN_TIMEOUT; } else if (xbee.getResponse().isAvailable()) { if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { ZBRxResponse zbrr; xbee.getResponse().getZBRxResponse(zbrr); if (zbrr.getDataLength() == 1 && zbrr.getData()[0] == 'K') { // Got a correct response disableTimeout(); State = EndDeviceIdle; return TICK_JOIN_OK; } else { // TODO: Got wrong response, ignore it? State = EndDeviceError; return TICK_JOIN_BAD_MSG; // XXX: Not sure if this check/return value is needed really } } else { // TODO: Other type of message } } return TICK_OK; }
// Recieve data from the base station. uint8_t EndDevice::requestWait() { DEBUG_MSG("[REQUEST WAIT]"); if (hasTimedOut()) { // Timed out waiting for more data disableTimeout(); // Discard the partially received data dataEnd = data; // Retry the update 4 times. timesTimeout++; if (timesTimeout > 3) { State = EndDeviceError; timesTimeout = 0; return TICK_UPDATE_TIMEOUT; } else { State = EndDeviceRequestSend; } } else if (xbee.getResponse().isAvailable()) { if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { DEBUG_MSG(" GOT PACKET"); // Has a data packet disableTimeout(); ZBRxResponse zbrr; xbee.getResponse().getZBRxResponse(zbrr); // Copy the data into the buffer memcpy(dataEnd, zbrr.getData(), zbrr.getDataLength()); dataEnd += zbrr.getDataLength(); // Test if this was the final data packet for this message if (zbrr.getData()[zbrr.getDataLength()-1] == 0) { timesTimeout = 0; // Reset timeout counter as we got a complete message DEBUG_MSG(" GOT MSG"); DEBUG_MSG((char *) data); State = EndDeviceIdle; dataEnd = data; return TICK_NEW_MSG; } else { setTimeout(5000); } } else { // TODO: Other type of message } } return TICK_OK; }
void processRxPacket(ZBRxResponse & rx, uintptr_t) { DebugSerial.println(F("Message received")); Buffer b(rx.getData(), rx.getDataLength()); XBeeAddress64 addr = rx.getRemoteAddress64(); // DebugSerial.println(addr,HEX); if (b.len() == 4 ) { if (addr == 0x0013A20041629B6C) { // DebugSerial.println(F("0013A20041629B6C")); publish(F("0013A20041629B6C"), b.remove < float > ()); return; } else if (addr == 0x0013A20041629B76) { // DebugSerial.println(F("0013A20041629B76")); publish(F("0013A20041629B76"), b.remove < float > ()); return; }else if (addr == 0x0013A20040D7B896) { // DebugSerial.println(F("0013A20040D7B896")); publish(F("0013A20040D7B896"), b.remove < float > ()); return; }else if (addr == 0x0013A20041629B72) { // DebugSerial.println(F("0013A20041629B72")); publish(F("0013A20041629B72"), b.remove < float > ()); return; }else if (addr == 0x0013A20041629B77) { // DebugSerial.println(F("0013A20041629B77")); publish(F("0013A20041629B77"), b.remove < float > ()); return; } else if (addr == 0x0013A20041629B6A) { // DebugSerial.println(F("0013A20041629B6A")); publish(F("0013A20041629B6A"), b.remove < float > ()); return; } else if (addr == 0x0013A20040D7B872) { // DebugSerial.println(F("0013A20040D7B872")); publish(F("0013A20040D7B872"), b.remove < float > ()); return; } else if (addr == 0x0013A20040B09A44) { // DebugSerial.println(F("0013A20040B09A44")); publish(F("0013A20040B09A44"), b.remove < float > ()); return; } // // else if (addr == 0x0013A20040D7B885) { // DebugSerial.println(F("0013A20040D7B885")); // publish(F("0013A20040D7B885"), b.remove < float > ()); // return; // } // DebugSerial.println(b.remove<float>()); } // this should get extended for all the xbee's DebugSerial.println(F("Unknown or invalid packet")); printResponse(rx, DebugSerial); }
void ConnectOneAdapter::handleRxResponse(XBeeResponse &aResponse) { ZBRxResponse rx; aResponse.getZBRxResponse(rx); string data((const char*) rx.getData(), rx.getDataLength()); XBeeAddress64& addr = rx.getRemoteAddress64(); // Prefix data items... ConnectOneDevice *dev = getOrCreateDevice(addr); if (data[0] == '*') handleMTConnectCommand(dev, data); else handleMTConnectSamples(dev, data); }
int main() { pi.cls(); //clear lcd xbee.begin(9600); //same baud rate as xbees while(true) { xbee.readPacket(); //check for packet if (xbee.getResponse().isAvailable()) { //got a packet if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { // got a ZBRx packet xbee.getResponse().getZBRxResponse(rx); pi.locate(0,0); pi.printf("+"); pi.locate(0,1); // string c=""; string data=""; for(int i=0; i< rx.getDataLength(); i++) { //c=rx.getData(i); data+=rx.getData(i); // pc.printf("%s\n",c); } pc.printf("%s\n",data); char *str; strcpy(str, data.c_str()); char speed1[32], speed2[32]; strcpy(speed1, strtok(str , "/")); strcpy(speed2, strtok(NULL, "/")); float lspeed=atof(speed1); float rspeed=atof(speed2); pi.left_motor(lspeed); pi.right_motor(rspeed); } } else if (xbee.getResponse().isError()) { pi.locate(0,0); pi.printf("Error"); } } }