Other Parts Discussed in Thread: MSP430F1611,
I am currently using TelosB which is based on MSP430f1611 with Radio chip cc2420
My laptop is Mac OS Sierra.
Here I am trying to achieve a couple of things:
1. I am trying to modify this code to read raw bytes of data packets from IEEE 802.15.4 printed on terminal but I am struggling to do.
2. How do I filter frames that I can only receive wanted packets?
The source code is attached in this post
Thank you
Kind regards
Yong Kim
#include "stdint.h" #include "string.h" #include "board.h" #include "radio.h" #include "leds.h" #include "uart.h" #include "sctimer.h" //=========================== defines ========================================= #define LENGTH_PACKET 125+LENGTH_CRC ///< maximum length is 127 bytes #define CHANNEL 11 ///< 11 = 2.405GHz #define LENGTH_SERIAL_FRAME 8 ///< length of the serial frame //=========================== variables ======================================= typedef struct { uint8_t num_radioTimerCompare; uint8_t num_startFrame; uint8_t num_endFrame; } app_dbg_t; app_dbg_t app_dbg; typedef struct { // rx packet volatile uint8_t rxpk_done; uint8_t rxpk_buf[LENGTH_PACKET]; uint8_t rxpk_len; uint8_t rxpk_num; int8_t rxpk_rssi; uint8_t rxpk_lqi; bool rxpk_crc; // uart uint8_t uart_txFrame[LENGTH_SERIAL_FRAME]; uint8_t uart_lastTxByte; volatile uint8_t uart_done; } app_vars_t; app_vars_t app_vars; //=========================== prototypes ====================================== // radiotimer void cb_radioTimerOverflows(void); // radio void cb_startFrame(PORT_TIMER_WIDTH timestamp); void cb_endFrame(PORT_TIMER_WIDTH timestamp); // uart void cb_uartTxDone(void); void cb_uartRxCb(void); //=========================== main ============================================ /** \brief The program starts executing here. */ int mote_main(void) { // clear local variables memset(&app_vars,0,sizeof(app_vars_t)); // initialize board board_init(); // add callback functions radio sctimer_setStartFrameCb(cb_startFrame); sctimer_setEndFrameCb(cb_endFrame); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); // prepare radio radio_rfOn(); radio_setFrequency(CHANNEL); // switch in RX radio_rxEnable(); while (1) { // sleep while waiting for at least one of the rxpk_done to be set app_vars.rxpk_done = 0; while (app_vars.rxpk_done==0) { board_sleep(); } // if I get here, I just received a packet //===== send notification over serial port // led leds_error_on(); // format frame to send over serial port app_vars.uart_txFrame[0] = app_vars.rxpk_len; // packet length app_vars.uart_txFrame[1] = app_vars.rxpk_num; // packet number app_vars.uart_txFrame[2] = app_vars.rxpk_rssi; // RSSI app_vars.uart_txFrame[3] = app_vars.rxpk_lqi; // LQI app_vars.uart_txFrame[4] = app_vars.rxpk_crc; // CRC app_vars.uart_txFrame[5] = 0xff; // closing flag app_vars.uart_txFrame[6] = 0xff; // closing flag app_vars.uart_txFrame[7] = 0xff; // closing flag app_vars.uart_done = 0; app_vars.uart_lastTxByte = 0; // send app_vars.uart_txFrame over UART uart_clearTxInterrupts(); uart_clearRxInterrupts(); uart_enableInterrupts(); uart_writeByte(app_vars.uart_txFrame[app_vars.uart_lastTxByte]); while (app_vars.uart_done==0); // busy wait to finish uart_disableInterrupts(); // led leds_error_off(); } } //=========================== callbacks ======================================= //===== radio void cb_startFrame(PORT_TIMER_WIDTH timestamp) { // update debug stats app_dbg.num_startFrame++; } void cb_endFrame(PORT_TIMER_WIDTH timestamp) { // update debug stats app_dbg.num_endFrame++; // indicate I just received a packet app_vars.rxpk_done = 1; leds_sync_on(); // get packet from radio radio_getReceivedFrame( app_vars.rxpk_buf, &app_vars.rxpk_len, sizeof(app_vars.rxpk_buf), &app_vars.rxpk_rssi, &app_vars.rxpk_lqi, &app_vars.rxpk_crc ); // read the packet number app_vars.rxpk_num = app_vars.rxpk_buf[0]; // led leds_sync_off(); } //===== uart void cb_uartTxDone(void) { uart_clearTxInterrupts(); // prepare to send the next byte app_vars.uart_lastTxByte++; if (app_vars.uart_lastTxByte<sizeof(app_vars.uart_txFrame)) { uart_writeByte(app_vars.uart_txFrame[app_vars.uart_lastTxByte]); } else { app_vars.uart_done=1; } } void cb_uartRxCb(void) { // uint8_t byte; uart_clearRxInterrupts(); // toggle LED leds_debug_toggle(); }