void openserial_init() { uint16_t crc; // reset variable memset(&openserial_vars,0,sizeof(openserial_vars_t)); // admin openserial_vars.mode = MODE_OFF; openserial_vars.debugPrintCounter = 0; // input openserial_vars.reqFrame[0] = HDLC_FLAG; openserial_vars.reqFrame[1] = SERFRAME_MOTE2PC_REQUEST; crc = HDLC_CRCINIT; crc = crcIteration(crc,openserial_vars.reqFrame[1]); crc = ~crc; openserial_vars.reqFrame[2] = (crc>>0)&0xff; openserial_vars.reqFrame[3] = (crc>>8)&0xff; openserial_vars.reqFrame[4] = HDLC_FLAG; openserial_vars.reqFrameIdx = 0; openserial_vars.lastRxByte = HDLC_FLAG; openserial_vars.busyReceiving = FALSE; openserial_vars.inputEscaping = FALSE; openserial_vars.inputBufFill = 0; // ouput openserial_vars.outputBufFilled = FALSE; openserial_vars.outputBufIdxR = 0; openserial_vars.outputBufIdxW = 0; // set callbacks uart_setCallbacks(isr_openserial_tx, isr_openserial_rx); }
/** \brief The program starts executing here. */ int mote_main(void) { // clear local variable memset(&app_vars,0,sizeof(app_vars_t)); // initialize the board board_init(); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); uart_enableInterrupts(); // setup BSP timer bsp_timer_set_callback(cb_compare); bsp_timer_scheduleIn(BSP_TIMER_PERIOD); while(1) { // wait for timer to elapse while (app_vars.uartSendNow==0); app_vars.uartSendNow = 0; // send string over UART app_vars.uartDone = 0; app_vars.uart_lastTxByteIndex = 0; uart_writeByte(stringToSend[app_vars.uart_lastTxByteIndex]); while(app_vars.uartDone==0); } }
/** \brief The program starts executing here. */ int mote_main(void) { board_init(); // clear local variable memset(&app_vars,0,sizeof(app_vars_t)); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); uart_enableInterrupts(); // send stringToSend over UART app_vars.uart_lastTxByteIndex = 0; uart_writeByte(stringToSend[app_vars.uart_lastTxByteIndex]); while(1) { board_sleep(); } }
void openserial_init() { //initialize variables openserial_vars.input_command[0] = (uint8_t)'^'; openserial_vars.input_command[1] = (uint8_t)'^'; openserial_vars.input_command[2] = (uint8_t)'^'; openserial_vars.input_command[3] = (uint8_t)'R'; openserial_vars.input_command[4] = 0;//to be filled out later openserial_vars.input_command[5] = (uint8_t)'$'; openserial_vars.input_command[6] = (uint8_t)'$'; openserial_vars.input_command[7] = (uint8_t)'$'; openserial_vars.output_buffer_index_read = 0; openserial_vars.output_buffer_index_write = 0; openserial_vars.somethingInOutputBuffer = FALSE; openserial_vars.mode = MODE_OFF; // set callbacks uart_setCallbacks(isr_openserial_tx, isr_openserial_rx); }
/** \brief The program starts executing here. */ int mote_main(void) { uint8_t i; uint8_t j; // initialize the board board_init(); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); uart_enableInterrupts(); while(1) { // clear local variable memset(app_vars.eui,0,sizeof(app_vars.eui)); memset(app_vars.eui_string,'-',sizeof(app_vars.eui_string)-2); app_vars.eui_string[23] = '\r'; app_vars.eui_string[24] = '\n'; // read EUI64 eui64_get(app_vars.eui); // format EUI64 j = 0; for (i=0;i<8;i++) { app_vars.eui_string[j] = lookup[app_vars.eui[i]>>4 & 0x0f]; j++; app_vars.eui_string[j] = lookup[app_vars.eui[i]>>0 & 0x0f]; j++; j++; } // send string over UART app_vars.uartDone = 0; app_vars.uart_lastTxByteIndex = 0; uart_writeByte(app_vars.eui_string[app_vars.uart_lastTxByteIndex]); while(app_vars.uartDone==0); } }
void openserial_init(void) { // reset variable memset(&openserial_vars,0,sizeof(openserial_vars_t)); // admin openserial_vars.fInhibited = FALSE; openserial_vars.ctsStateChanged = FALSE; openserial_vars.debugPrintCounter = 0; // input openserial_vars.hdlcBusyReceiving = FALSE; openserial_vars.hdlcInputEscaping = FALSE; openserial_vars.inputBufFillLevel = 0; // ouput openserial_vars.outputBufIdxR = 0; openserial_vars.outputBufIdxW = 0; openserial_vars.fBusyFlushing = FALSE; openserial_vars.reset_timerId = opentimers_create(TIMER_GENERAL_PURPOSE, TASKPRIO_OPENSERIAL); openserial_vars.debugPrint_timerId = opentimers_create(TIMER_GENERAL_PURPOSE, TASKPRIO_OPENSERIAL); opentimers_scheduleIn( openserial_vars.debugPrint_timerId, DEBUGPRINT_PERIOD, TIME_MS, TIMER_PERIODIC, openserial_debugPrint_timer_cb ); // UART uart_setCallbacks( isr_openserial_tx, isr_openserial_rx ); uart_enableInterrupts(); }
/** \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 radio_setOverflowCb(cb_radioTimerOverflows); radio_setCompareCb(cb_radioTimerCompare); radio_setStartFrameCb(cb_startFrame); radio_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 //===== get packet from radio // led 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(); //===== 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(); } }
/** \brief The program starts executing here. */ int mote_main() { // needed since we are disabling/enabling interrupts below INTERRUPT_DECLARATION(); // clear local variables memset(&app_vars,0,sizeof(app_vars_t)); // initialize board board_init(); // add callback functions radio radio_setOverflowCb(cb_radioTimerOverflows); radio_setCompareCb(cb_radioTimerCompare); radio_setStartFrameCb(cb_startFrame); radio_setEndFrameCb(cb_endFrame); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); app_vars.uart_end=FALSE; // prepare radio radio_rfOn(); radio_setFrequency(CHANNEL); // switch in RX by default radio_rxEnable(); app_vars.flags=0x00; //wait for rx while (1) { // sleep while waiting for at least one of the flags to be set while (app_vars.flags==0x00) { board_sleep(); } // handle and clear every flag while(app_vars.flags) { DISABLE_INTERRUPTS(); leds_sync_on(); // done receiving a packet // get packet from radio radio_getReceivedFrame(app_vars.packet, &app_vars.packet_len, sizeof(app_vars.packet), &app_vars.rxpk_rssi, &app_vars.rxpk_lqi, &app_vars.rxpk_crc); app_vars.packet_num=app_vars.packet[0];//packet number leds_error_off(); stringToSend[0]=app_vars.packet_num; stringToSend[1]=app_vars.rxpk_rssi; stringToSend[2]=app_vars.rxpk_lqi; stringToSend[3]=app_vars.rxpk_crc; stringToSend[4]= 0xFF; //clear this interrupt. app_vars.flags = 0x00; app_vars.uart_end=FALSE; app_vars.uart_lastTxByte = 0; ENABLE_INTERRUPTS(); // send stringToSend over UART uart_clearTxInterrupts(); uart_clearRxInterrupts(); uart_enableInterrupts(); uart_writeByte(stringToSend[app_vars.uart_lastTxByte]); while (app_vars.uart_end==FALSE);//wait to finish uart_disableInterrupts(); // clear flag leds_sync_off(); } } }