コード例 #1
0
/*******************************************************************************
 * @fn     uint8_t send_sync_message()
 * @brief  TODO
 * ****************************************************************************/
uint8_t send_sync_message()
{
  // Send sync message
  radio_tx( tx_buffer, sizeof(packet_header_t) );
  led2_toggle();
  
  return 1;
}
コード例 #2
0
ファイル: ccrl.c プロジェクト: KryoStoffer/sensemote
uint8_t radio_cmd (void) {
	uint16_t delay_count=0;
	uint8_t retry=10;
	rf_ack=0;
	while (retry && !rf_ack) {
		if (delay_count==0) {
			radio_tx(cmd);
			//cons_puts("Sending cmd\r\n");
			delay_count=5000;
			retry--;
		}
		delay_count--;
		radio_tick();
	}
	if (retry) {
		return 1;
	} else {
		cons_putc(1);
		return 0;
	}
}
コード例 #3
0
ファイル: mac_coord.c プロジェクト: Georgisim/sensemote
void radio_received(__xdata uint8_t *inpkt)
{
    uint8_t i;
    uint8_t local_seq = 0x00;
    __xdata uint8_t *txpkt = NULL;

    // make a copy as the radio buffer is volatile, is this neccessary?
    memcpy(tmpbuf, inpkt, inpkt[0]+1);

    timer_delayMS(MAC_TURNAROUND_DELAY_MS);   // give other end time to turnaround

    // check header length
    if (tmpbuf[0] < 9)  // type + eui64
        return;

    //cons_puts("****************** radio_rx:");
    //cons_dump(inpkt, inpkt[0]+1);

    if (tmpbuf[1] & MAC_TYPE_POLLACK)    // this packet is a response from another hub, drop it
        return;

    // find a stored packet for poller
    if (tmpbuf[1] & MAC_TYPE_POLL)    // type field 
    {
        // find a stored packet for poller
        //BOOLEAN allEmpty = TRUE;
        for (i=0;i<NUM_SLOTS;i++)
        {
            if (slottbl[i].length > 0)  // non-empty
            {
                //allEmpty = FALSE;
                if (0==memcmp(slottbl[i].dst_eui64, tmpbuf+2, 8))   // do we have a packet for poller?
                {
                    //cons_puts("Got pkt for poller\r\n");
                    slottbl[i].poll_seq = tmpbuf[10]; // echo back the poller's sequence number
                    txpkt = &(slottbl[i].length);
                    local_seq = slottbl[i].local_seq;
                    break;
                }
                else
                {
                    //cons_puts("No pkt for poller\r\n");
                }
            }
        }
        //if (allEmpty)
        //    cons_puts("********** ALL SLOTS EMPTY\r\n");

    }
    else
    {
        //cons_puts("******** NOT A POLL!\r\n");
    }

#ifdef SEND_EMPTY_PACKET
    // it's a poll, but we have no data pending
    if (tmpbuf[1] & MAC_TYPE_POLL && (txpkt == NULL))
    {   // ready the empty packet
        txpkt = emptypkt;
        txpkt[0] = 11;
        txpkt[1] = MAC_TYPE_POLLACK | MAC_TYPE_PLAINTEXT;   // type
        memcpy(txpkt+2, tmpbuf+2, 8);   // node's eui64
        txpkt[10] = tmpbuf[10]; // echo back the poller's sequence number
        txpkt[11] = 0;  // empty payload
    }
#endif

    if (txpkt != NULL && txpkt[0] != 0) // if there's something to send
    {
        radio_tx(txpkt);
        //cons_puts("RADIOTX: ");
        //cons_dump(txpkt, txpkt[0]+1);
        while(!radio_txComplete());     // spin until sent

        if (txpkt != emptypkt)  // not sent empty packet
        {
            mac_tx_cb(txpkt+2, txpkt + 11, TRUE, local_seq);  // callback to user
            txpkt[0] = 0;   // mark this slot as empty (slottbl[i].length=0)
        }
    }

    if (*(tmpbuf+11) > 0)   // empty poll is an empty packet
        mac_rx_cb(tmpbuf+2, tmpbuf+11, tmpbuf[1] & MAC_TYPE_ENCRYPTED);  // tell user about packet received
}