// 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; }
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()) {} }
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 XBeeResponse::getZBRxResponse(XBeeResponse &rxResponse) { ZBRxResponse* zb = static_cast<ZBRxResponse*>(&rxResponse); //TODO verify response api id matches this api for this response // pass pointer array to subclass zb->setFrameData(getFrameData()); setCommon(rxResponse); zb->getRemoteAddress64().setMsb((uint32_t(getFrameData()[0]) << 24) + (uint32_t(getFrameData()[1]) << 16) + (uint16_t(getFrameData()[2]) << 8) + getFrameData()[3]); zb->getRemoteAddress64().setLsb((uint32_t(getFrameData()[4]) << 24) + (uint32_t(getFrameData()[5]) << 16) + (uint16_t(getFrameData()[6]) << 8) + (getFrameData()[7])); }
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); }
bool XBeeMACLayer::receive(uip_lladdr_t* lladdr_src, uip_lladdr_t* lladdr_dest, uint8_t* data, uint16_t* length){ xbee.readPacket(); if (xbee.getResponse().isAvailable()) { // got something if (xbee.getResponse().getApiId() == RX_16_RESPONSE || xbee.getResponse().getApiId() == RX_64_RESPONSE) { // got a rx packet if (xbee.getResponse().getApiId() == RX_16_RESPONSE) { if (UIP_LLADDR_LEN == UIP_802154_SHORTADDR_LEN){ Rx16Response rx16 = Rx16Response(); xbee.getResponse().getRx16Response(rx16); memcpy(data, rx16.getData(), rx16.getDataLength()); *length = rx16.getDataLength(); //get the src and destination addresses if(rx16.getOption() == ZB_BROADCAST_PACKET){ //Then packet was a broadcast.. destination address is 0xFFFF, we use an all-zeroes address to represent broadcast lladdr_dest->addr[0] = 0; // Copy all-zeroes address to lladdr_dest lladdr_dest->addr[1] = 0; //lladdr_dest = NULL; }else{ //get dest address (it is my own) //lladdr_dest = &my_mac; lladdr_dest->addr[0] = my_mac.addr[0]; // Copy my_mac address to lladdr_dest lladdr_dest->addr[1] = my_mac.addr[1]; } lladdr_src->addr[0] = rxResp.getRemoteAddress16() >> 8; lladdr_src->addr[1] = rxResp.getRemoteAddress16() & 0x00FF; }else return false; } else { if (UIP_LLADDR_LEN == UIP_802154_LONGADDR_LEN){
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"); } } }
void printResponseCb(ZBRxResponse& rx, uintptr_t data) { Print *p = (Print*)data; p->println(F("ZBRxResponse received:")); printField(p, F(" From: 0x"), rx.getRemoteAddress64()); printField(p, F(" From: 0x"), rx.getRemoteAddress16()); printField(p, F(" Receive options: 0x"), rx.getOption()); if (rx.getDataLength() > 8) p->print(" Payload:\r\n "); else p->print(" Payload: "); printHex(*p, rx.getFrameData() + rx.getDataOffset(), rx.getDataLength(), F(" "), F("\r\n "), 8); p->println(); }
// 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; }