Beispiel #1
0
void printResponseCb(XBeeResponse& r, uintptr_t data) {
	uint8_t id = r.getApiId();
	// Figure out the API type and call the corresonding function
	if (id == ZB_TX_STATUS_RESPONSE) {
		ZBTxStatusResponse response;
		r.getZBTxStatusResponse(response);
		printResponseCb(response, data);
	} else if (id == ZB_RX_RESPONSE) {
		ZBRxResponse response;
		r.getZBRxResponse(response);
		printResponseCb(response, data);
	} else if (id == ZB_EXPLICIT_RX_RESPONSE) {
		ZBExplicitRxResponse response;
		r.getZBExplicitRxResponse(response);
		printResponseCb(response, data);
	} else if (id == ZB_IO_SAMPLE_RESPONSE) {
		ZBRxIoSampleResponse response;
		r.getZBRxIoSampleResponse(response);
		printResponseCb(response, data);
	} else if (id == TX_STATUS_RESPONSE) {
		TxStatusResponse response;
		r.getTxStatusResponse(response);
		printResponseCb(response, data);
	} else if (id == RX_16_RESPONSE) {
		Rx16Response response;
		r.getRx16Response(response);
		printResponseCb(response, data);
	} else if (id == RX_64_RESPONSE) {
		Rx64Response response;
		r.getRx64Response(response);
		printResponseCb(response, data);
	} else if (id == RX_16_IO_RESPONSE) {
		Rx16IoSampleResponse response;
		r.getRx16IoSampleResponse(response);
		printResponseCb(response, data);
	} else if (id == RX_64_IO_RESPONSE) {
		Rx64IoSampleResponse response;
		r.getRx64IoSampleResponse(response);
		printResponseCb(response, data);
	} else if (id == MODEM_STATUS_RESPONSE) {
		ModemStatusResponse response;
		r.getModemStatusResponse(response);
		printResponseCb(response, data);
	} else if (id == AT_COMMAND_RESPONSE) {
		AtCommandResponse response;
		r.getAtCommandResponse(response);
		printResponseCb(response, data);
	} else if (id == REMOTE_AT_COMMAND_RESPONSE) {
		RemoteAtCommandResponse response;
		r.getRemoteAtCommandResponse(response);
		printResponseCb(response, data);
	}
}
void ConnectOneAdapter::handleAtCommand(XBeeResponse &aResponse)
{
  LOCK(sSendLock);
  
  AtCommandResponse cmd;
  aResponse.getAtCommandResponse(cmd);
  if (cmd.isOk())
  {
    uint8_t *cp = cmd.getCommand();
    if (cp[0] == 'N' && cp[1] == 'P')
    {
      uint16_t v = ntohs(*((uint16_t*) cmd.getValue()));
      mXBee.setMaxSize(v);

      gLogger->debug("Maximum payload = %d", v);

      // Set the PAN ID
      {
        uint8_t command[] = { 'I', 'D' };
        uint8_t value[] = { 0x11, 0x11 };
        
        AtCommandRequest request(command, value, sizeof(value));
        mXBee.send(request);
      }
    }
    else if (cp[0] == 'I' && cp[1] == 'D')
    {
      // Send a discovery request
      uint8_t command[] = { 'N', 'D' };
      uint8_t value[] = { 0 };
      
      AtCommandRequest request(command, value, 0);
      mXBee.send(request);
    }        
    else if (cp[0] == 'N' && cp[1] == 'D')
    {
      uint8_t *response = cmd.getValue();
      XBeeAddress64 addr(ntohl(*((uint32_t*) (response + 2))),
                         ntohl(*((uint32_t*) (response + 6))));
      
      getOrCreateDevice(addr);
    }
  }

  UNLOCK(sSendLock);
}
Beispiel #3
0
void printErrorCb(XBeeResponse& r, uintptr_t data) {
	uint8_t id = r.getApiId();
	// Figure out the API type and call the corresonding function
	if (id == ZB_TX_STATUS_RESPONSE) {
		ZBTxStatusResponse response;
		r.getZBTxStatusResponse(response);
		printErrorCb(response, data);
	} else if (id == TX_STATUS_RESPONSE) {
		TxStatusResponse response;
		r.getTxStatusResponse(response);
		printErrorCb(response, data);
	} else if (id == AT_COMMAND_RESPONSE) {
		AtCommandResponse response;
		r.getAtCommandResponse(response);
		printErrorCb(response, data);
	} else if (id == REMOTE_AT_COMMAND_RESPONSE) {
		RemoteAtCommandResponse response;
		r.getRemoteAtCommandResponse(response);
		printErrorCb(response, data);
	}
}