Ejemplo n.º 1
0
void printRawResponseCb(XBeeResponse& response, uintptr_t data) {
	Print *p = (Print*)data;
	p->print("Response received: ");
	// Reconstruct the original packet
	uint8_t header[] = {START_BYTE, response.getMsbLength(), response.getLsbLength(), response.getApiId()};
	printHex(*p, header, sizeof(header), F(" "), NULL);
	p->write(' ');
	printHex(*p, response.getFrameData(), response.getFrameDataLength(), F(" "), NULL);
	p->println();
}
void ConnectOneAdapter::handleXBeeDiscovery(XBeeResponse &aResponse)
{
  uint8_t *frame = aResponse.getFrameData();
  XBeeAddress64 addr(ntohl(*((uint32_t*) (frame + 0))),
                     ntohl(*((uint32_t*) (frame + 4))));
  
  getOrCreateDevice(addr);
}
Ejemplo n.º 3
0
// copy common fields from xbee response to target response
void XBeeResponse::setCommon(XBeeResponse &target) {
	target.setApiId(getApiId());
	target.setAvailable(isAvailable());
	target.setChecksum(getChecksum());
	target.setErrorCode(getErrorCode());
	target.setFrameLength(getFrameDataLength());
	target.setMsbLength(getMsbLength());
	target.setLsbLength(getLsbLength());
}
Ejemplo n.º 4
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);
	}
}
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);
}
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);
}
void ConnectOneAdapter::handleXBeeTxStatus(XBeeResponse &aResponse)
{
  ZBTxStatusResponse status;
  aResponse.getZBTxStatusResponse(status);
  if (!status.isSuccess())
  {
    gLogger->info("Could not transmit frame: %d", status.getFrameId());

    for (size_t i = 0; i < mDevices.size(); i++) 
    {
      ConnectOneDevice *dev = mDevices[i];
      if (dev->mAvailable && dev->hasFrame(status.getFrameId()))
      {
        unavailable(dev);
        break;
      }
    }
  }
}
Ejemplo n.º 8
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);
	}
}