コード例 #1
0
ファイル: transmit.cpp プロジェクト: kfujiapples/Team-Quasar
/* Transmission Code */
void Transmit_Packet(void)
{   
    /* Create Xbee object */
    XBee xbee = XBee();

    /* Packet to be transmitted */
    uint8_t payload[MAX_SIZE];

    /* Obtain address of receiving end */
    XBeeAddress64 addr64 = XBeeAddress64(0x0, 0x0);
    ZBTxStatusResponse txStatus = ZBTxStatusResponse();

    /* Clear the payload */
    memset(payload, '\0', sizeof(payload));

    /* Debug Packet */
    //payload[0] = '1';
    //payload[1] = '5';

    /* Transfer information into payload */
    memcpy(payload, &G_packet, sizeof(payload));

    for(int i = 0; i < MAX_SIZE; i++)
    { Serial.write(payload[i]);}

    ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
  
    /* Transfer the payload */
    xbee.send(zbTx); //!!Prints packet to serial monitor

    /* delay */
    delay(1000);
}
コード例 #2
0
byte Radio::send_byte(byte byte_to_be_sent){
   uint8_t to_be_sent[] = {byte_to_be_sent};
   _tx = ZBTxRequest(_addr64,to_be_sent,1);
   xbee.send(_tx);
   
// Wait for a status response.
   if(xbee.readPacket(5000)){
      if(xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE)
      {
         xbee.getResponse().getZBTxStatusResponse(_txStatus);
         if(_txStatus.getDeliveryStatus() == 0){
            DEBUG("Successfully delivered byte");
            delay(_WAITING_delay);
            return 1;
         }
         else{
            DEBUG("Not delivered successfully");
            return 0;
         }
      }
      else {
        DEBUG("Incorrect API ID");
        // Serial.println(xbee.getResponse().getApiId(),HEX);
        clear_serial();
        return 0;
      }
   }
   else {
      DEBUG("Did not respond");
      return 0;
   }
}
コード例 #3
0
void gd_dev_xbee_write(uint8_t *data, int data_len)
{
    XBeeAddress64 addr64 = XBeeAddress64(0, 0);
    ZBTxRequest zbtx = ZBTxRequest(addr64, data, data_len);

    xbee.send(zbtx);
}
コード例 #4
0
byte Radio::send_bytes(uint8_t *to_be_sent, int n) {
   // while(!send_byte(n));
   _tx = ZBTxRequest(_addr64,to_be_sent,n);
   xbee.send(_tx);
   DEBUG("Sent packet");
   // Wait for a status response.
   if(xbee.readPacket(5000)){
     if(xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE){
       xbee.getResponse().getZBTxStatusResponse(_txStatus);
       if(_txStatus.getDeliveryStatus() == 0){
         DEBUG("Successfully delivered bytes");
         return 1;
       }
       else{
         DEBUG("Not successfully delivered");
         return 0; 
       }
     }
     else{
        DEBUG("Not the correct packet");
        return 0;
     }
   }
   else{
      DEBUG("Never recieved status response");
      return 0;
   } 
}
コード例 #5
0
ファイル: XBeePlus.cpp プロジェクト: Deamiter/Bee
bool XBeePlus::send(uint8_t * arrayPointer, uint8_t arrayLength, uint32_t addr64_MSB, uint32_t addr64_LSB){
	addr64.setMsb(addr64_MSB);
	addr64.setLsb(addr64_LSB);
	
	ZBTxRequest zbTx = ZBTxRequest(addr64, arrayPointer, arrayLength);
	//zbTx.setOption(0xAAAA);	
	//Serial.print("Option: ");	
	//Serial.println(zbTx.getOption());
	_xbee.send(zbTx);	

  	if (_xbee.readPacket(5000)){
		uint8_t API_ID = _xbee.getResponse().getApiId();
    		if (API_ID == 89 || API_ID==139) {
      			_xbee.getResponse().getZBTxStatusResponse(txStatus);
	        	// get the delivery status, the fifth byte
      			if (txStatus.getDeliveryStatus() == SUCCESS) {
				#ifdef DEBUG
				Serial.println("success");
				Serial.println("---------------------------------------------------------------");
				#endif	
				// success.  time to celebrate			
				return true;
        			
        			
      			} else {
        			//the remote XBee did not receive our packet. is it powered on?
				#ifdef DEBUG				
				Serial.println("fail");
				#endif
				return false;        			

      			}
    		}
		else{
			Serial.print("Wrong API_ID: ");
			Serial.println(API_ID);
			return false;
		}
		
  	} else if (_xbee.getResponse().isError()) {
		#ifdef DEBUG
		Serial.print("Error reading packet.  Error code: ");  
		#endif
		Serial.println(_xbee.getResponse().getErrorCode());
		return false;
  	} else { // time elapsed with no answer
    	#ifdef DEBUG
		Serial.println("untimely response");
		#endif
		return false;
  	}	
}
コード例 #6
0
ファイル: firenest.cpp プロジェクト: davidlgj/firecrow
    void setupold() {
      
      //mySerial.begin(4800);
      //mySerial.println("Hello world");
      
      for (int i= 0; i<CHANNELS; i++) {
        pinMode(channels[i].button_pin,INPUT);
        digitalWrite(channels[i].button_pin,HIGH); //enable internal 20K pullup
        
        pinMode(channels[i].led_pin,OUTPUT);
        //blink leds a bit
        digitalWrite(channels[i].led_pin,HIGH);
        delay(200);
        digitalWrite(channels[i].led_pin,LOW);
      }
      
      //debug led
      //pinMode(13,OUTPUT);
      //digitalWrite(13,HIGH);
      //delay(500);
      //digitalWrite(13,LOW);
      
      xbee.begin(XBEE_BAUD);

      //discover the other XBEE's address
      discover();
      zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
      
      //send a no-op packet so that the xbees can do their magic and find each other
      payload[0] = 254;
      xbee.send(zbTx);
      
      //Flash all leds once so the user knows
      flashAll(500);

      //mySerial.println("Discovered address");
      //mySerial.print("MSB: ");
      //mySerial.println(addr64.getMsb());
      //mySerial.println(addr64.getMsb()==0x0013a200?"Yes!":"NO");
      //mySerial.print("LSB: ");
      //mySerial.println(addr64.getLsb());
      //mySerial.println(addr64.getLsb()==0x403141DA?"Yes!":"NO");
    }
コード例 #7
0
Radio::Radio(): xbee(){
   _read_wait = 300;  // millis
   _max_read_waits = 10;
   _WAITING_delay = 100;
   _max_connect_tries = 10;
   _show_debug = 1;
   _connected = 0;

   //RECIEVING
   _response = XBeeResponse();
   // Packet to be recieved
   _rx = ZBRxResponse();

   // TRANSMITTING
   // DH and DL of the recieving Xbee - default is coordinator
   _addr64 = XBeeAddress64(0x00000000, 0x00000000);
   _tx = ZBTxRequest(_addr64, payload,sizeof(payload));
   _txStatus = ZBTxStatusResponse();
}
コード例 #8
0
/** EXPERT FUNCTION - DON'T CALL UNLESS YOU KNOW WHAT YOU ARE DOING!
	Transmits the message in the argument and consequently read the	response from the XBee.	
	Message * message: Message to be transmitted.
**/
bool LithneClass::sendMessage( Message * message )
{
	bool willSend = true;
	/* Place the total payload in the local payload array
	uint8_t payload[message->getPayloadSize()];
	for (int i = 0; i < sizeof(payload); i++)
	{
		payload[i] = message->getPayloadByte(i);
	}*/

  	/* Retrieve the 64-bit address from the message*/
	XBeeAddress64 addr64 	=	message->getRecipient64();
	uint16_t	  addr16	=	message->getRecipient16();

	/*	We always supply the 64-bit and 16-bit address. In case the
		16-bit address is NOT known, the ZBTxRequest will automatically
		use the 64-bit address.
	*/
	// zbTx = ZBTxRequest( addr64,  message->getPayload(), message->getPayloadSize() );
	zbTx = ZBTxRequest( addr64, addr16, 0, 0, message->getPayload(), message->getPayloadSize(), 0x01 );
	// zbTx = ZBTxRequest( addr64, addr16, 0, 0, payload, sizeof(payload), 0x01 );

	// Send exceptions in the broadcasting mode
	if ( addr64.getMsb() == 0x0 && 
		 addr64.getLsb() == 0xFFFF )
	{
		zbTx.setFrameId(NO_RESPONSE_FRAME_ID); //disable TX_STATUS_RESPONSE for Broadcast which speeds up the transmission rate
		// Check for sending speed
		if ( millis() - _lastSend < SEND_DELAY_BROADCAST)
		{
			willSend = false;
		}
		// No broadcasting is allowed in the programming scope
		if( message->getScope() == Lithne.PROGRAMMING_SCOPE )
		{
			willSend = false;	
		}
	}
	// In case of non-broadcast messages
	else
	{
		// Check for sending speed
		if ( millis() - _lastSend < SEND_DELAY_UNICAST)
		{
			willSend = false;
		}
	}
	/* We check if the user is not transmitting too fast and flooding the network */
	if ( willSend )
	{
		/* The complete ZBTxRequest is transmitted */
		_lastSend = millis();
		/* Store the addresses we transmit to */	
		last16B	=	addr16;
		last64B	=	addr64;

		xbee.send(zbTx);

		/* After transmitting, read any possible status response */
		readXbee();
	}
}
コード例 #9
0
size_t XbeeApiStream::write(const uint8_t* buf, size_t len) {
  if (len == 0) return 0;
  ZBTxRequest txResponse = ZBTxRequest(coordAddr64, (uint8_t*)buf, len);
  xbee.send(txResponse);
  return len;
}
コード例 #10
0
ファイル: joystick.c プロジェクト: sachinio/homeautomation

#include <XBee.h>
XBee xbee = XBee();

unsigned char payload[] = { 0,0,0,0,0,0,0,0,0,0};

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40bf8a68);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));

#define JX A0
#define JY A1

int SPIN = 13;

int centerX = 0;
int centerY = 0;
int lastx = 0;
int lasty = 0;
int lasts = LOW;

int x;
int y;
int s;

void setup() {
  Serial.begin(9600);
  xbee.setSerial(Serial);
  centerX = analogRead(JX);
  centerY = analogRead(JY);
コード例 #11
0
ファイル: XBeeMenu.cpp プロジェクト: XBeeModule/XBee
long XBee_Addr64_LS_tmp = 0;                    //
int XBee_Addr16;                            //16-разрядный адрес
int Len_XBee = 0;
unsigned char info_XBee_data[96];
unsigned char info_XBee_data1[96];
char* simbol_ascii[2];
char   cmd;

XBeeResponse response = XBeeResponse();               //Это создает экземпляр объекта "response" "ответ" обрабатывать пакеты Xbee
ZBRxResponse rx = ZBRxResponse();                     //Это создает экземпляр объекта "rx" на процесс Xbee Series 2 API пакеты
ModemStatusResponse msr = ModemStatusResponse();      //Это создает экземпляр объекта "msr" процесс associate/disassociate packets (PAN membership)
ZBRxIoSampleResponse ioSample = ZBRxIoSampleResponse();


XBeeAddress64 addr64 = XBeeAddress64(XBee_Addr64_MS, XBee_Addr64_LS);                                     // SH + SL Address of receiving XBee
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));                                         // Формирует пакет  zbTx с адресом отправителя и данными
ZBTxStatusResponse txStatus = ZBTxStatusResponse();                                                       // Это создает экземпляр объекта "txStatus" процесс благодарности прислал Xbee Series 2 API пакеты
AtCommandRequest atRequest = AtCommandRequest(shCmd);                                                     // XBeeAddress64 remoteAddress = XBeeAddress64(XBee_Addr64_MS, XBee_Addr64_LS);
AtCommandRequest arRequestMod = AtCommandRequest(command, commandValue, commandValueLength);
AtCommandResponse atResponse = AtCommandResponse();
RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(addr64, irCmd, irValue, sizeof(irValue)); // Create a remote AT request with the IR command
RemoteAtCommandResponse remoteAtResponse = RemoteAtCommandResponse();                                     // Create a Remote AT response object

XBeeActive RealXBeeMenu;

void XBeeActive::setup()
{
	xbee.begin(Serial1);
	DEBAG.println("\nXBee setup");
}
void XBeeActive::sendAtCommand()