transmit example for LMIC_MOTE_L152RC
Dependencies: lmic_MOTE_L152RC mbed-src
Revision 0:cf8cd2f1ab24, committed 2015-06-02
- Comitter:
- dudmuck
- Date:
- Tue Jun 02 19:06:00 2015 +0000
- Child:
- 1:1ff358d55507
- Commit message:
- transmit example for LMIC
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.h Tue Jun 02 19:06:00 2015 +0000 @@ -0,0 +1,3 @@ +#define CFG_us915 + +#define CFG_sx1272_radio \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hello_main.cpp Tue Jun 02 19:06:00 2015 +0000 @@ -0,0 +1,114 @@ +#if 0 + +/******************************************************************************* + * Copyright (c) 2014-2015 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Zurich Research Lab - initial API, implementation and documentation + *******************************************************************************/ + +#include "lmic.h" +#include "debug.h" +#include "mbed.h" + +/*#include "gps.h" +#include "sx9500.h" +#include "mma8451q.h" +#include "mpl3115a2.h" + +GPS gps; +I2C i2c(I2C_SDA, I2C_SCL); +SX9500 sx9500(i2c, PA_9); +MMA8451Q mma8451q(i2c); +MPL3115A2 mpl3115a2(i2c);*/ + +// LMIC application callbacks not used in his example +void os_getArtEui (u1_t* buf) { +} + +void os_getDevEui (u1_t* buf) { +} + +void os_getDevKey (u1_t* buf) { +} + +void onEvent (ev_t ev) { +} + +/*static u1_t readReg (u1_t addr) { + hal_pin_nss(0); + hal_spi(addr & 0x7F); + u1_t val = hal_spi(0x00); + hal_pin_nss(1); + return val; +} + +void print_gpio() +{ + printf("GPIOA->MODER:%08x\r\n", GPIOA->MODER); + printf("GPIOA->IDR:%04x\r\n", GPIOA->IDR); + printf("GPIOA->ODR:%04x\r\n", GPIOA->ODR); + printf("GPIOA->AFR:%x %x\r\n", GPIOA->AFR[0], GPIOA->AFR[1]); // 0x40020020 0x40020024 + + printf("GPIOB->MODER:%08x\r\n", GPIOB->MODER); + printf("GPIOB->IDR:%04x\r\n", GPIOB->IDR); + printf("GPIOB->ODR:%04x\r\n", GPIOB->ODR); + printf("GPIOB->AFR:%x %x\r\n", GPIOB->AFR[0], GPIOB->AFR[1]); + + printf("GPIOC->MODER:%08x\r\n", GPIOC->MODER); + printf("GPIOC->IDR:%04x\r\n", GPIOC->IDR); + printf("GPIOC->ODR:%04x\r\n", GPIOC->ODR); + printf("GPIOC->AFR:%x %x\r\n", GPIOC->AFR[0], GPIOC->AFR[1]); + printf("opmode:%02x\r\n", readReg(0x01)); +}*/ + +// counter +static int cnt = 0; + +// log text to USART and toggle LED +static void initfunc (osjob_t* job) { + //int ms = rand() & 0x7ff; // 0 to 2sec + //int ms = rand() & 0x7f; // + //int ms = 1000; + //int ms_ticks = ms2osticks(ms); + // say hello + //debug_str("Hello World!\r\n"); + // log counter + debug_val("cnt = ", cnt); + //print_gpio(); + //debug("%d cnt = %d\r\n", ms_ticks, cnt); + // toggle LED + debug_led(++cnt & 1); + // reschedule job every second + os_setTimedCallback(job, os_getTime()+sec2osticks(1), initfunc); + //os_setTimedCallback(job, os_getTime()+ms_ticks, initfunc); + //os_setTimedCallback(job, os_getTime()+sec2osticks(10), initfunc); + //os_setTimedCallback(job, os_getTime()+ms2osticks(50), initfunc); +} + +// application entry point +int main () { + osjob_t initjob; + + /*gps.init(); + sx9500.standby(); + mpl3115a2.SetModeStandby(); + mma8451q.set_active(0); + gps.enable(false); */ + + // initialize runtime env + os_init(); + // initialize debug library + debug_init(); + // setup initial job + os_setCallback(&initjob, initfunc); + // execute scheduled jobs and events + os_runloop(); + // (not reached) + return 0; +} +#endif /* #if 0 */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lmic.lib Tue Jun 02 19:06:00 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/dudmuck/code/lmic/#f2716e543d97
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Tue Jun 02 19:06:00 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/mbed_official/code/mbed-src/#edd95c0879f8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/transmit_main.cpp Tue Jun 02 19:06:00 2015 +0000 @@ -0,0 +1,109 @@ +//#if 0 +/******************************************************************************* + * Copyright (c) 2014-2015 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Zurich Research Lab - initial API, implementation and documentation + *******************************************************************************/ + +#include "lmic.h" +#include "debug.h" + +////////////////////////////////////////////////// +// CONFIGURATION (FOR APPLICATION CALLBACKS BELOW) +////////////////////////////////////////////////// + +// application router ID (LSBF) +static const u1_t APPEUI[8] = { 0x01, 0x00, 0x01, 0x00, 0x00, 0x0c, 0x25, 0x00 }; + +// unique device ID (LSBF) +static const u1_t DEVEUI[8] = { 0x0f, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x25, 0x00 }; + +// device-specific AES key (derived from device EUI) +static const u1_t DEVKEY[16] = { 0xe4, 0x72, 0x71, 0xc5, 0xf5, 0x30, 0xa9, 0x9f, 0xcf, 0xc4, 0x0e, 0xab, 0xea, 0xd7, 0x19, 0x42, }; + // E4 -72 -71 -C5 -F5 -30 -A9 -9F -CF -C4 -0E -AB -EA -D7 -19 -42 + +////////////////////////////////////////////////// +// APPLICATION CALLBACKS +////////////////////////////////////////////////// + +// provide application router ID (8 bytes, LSBF) +void os_getArtEui (u1_t* buf) { + memcpy(buf, APPEUI, 8); +} + +// provide device ID (8 bytes, LSBF) +void os_getDevEui (u1_t* buf) { + memcpy(buf, DEVEUI, 8); +} + +// provide device key (16 bytes) +void os_getDevKey (u1_t* buf) { + memcpy(buf, DEVKEY, 16); +} + + +////////////////////////////////////////////////// +// MAIN - INITIALIZATION AND STARTUP +////////////////////////////////////////////////// + +// initial job +static void initfunc (osjob_t* j) { + // reset MAC state + LMIC_reset(); + // start joining + LMIC_startJoining(); + // init done - onEvent() callback will be invoked... +} + + +// application entry point +int main () { + osjob_t initjob; + + // initialize runtime env + os_init(); + // initialize debug library + debug_init(); + // setup initial job + os_setCallback(&initjob, initfunc); + // execute scheduled jobs and events + os_runloop(); + // (not reached) + return 0; +} + + +////////////////////////////////////////////////// +// LMIC EVENT CALLBACK +////////////////////////////////////////////////// + +void onEvent (ev_t ev) { + debug_event(ev); + + switch(ev) { + + // network joined, session established + case EV_JOINED: + debug_val("netid = ", LMIC.netid); + goto tx; + + // scheduled data sent (optionally data received) + case EV_TXCOMPLETE: + if(LMIC.dataLen) { // data received in rx slot after tx + debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen); + } + tx: + // immediately prepare next transmission + LMIC.frame[0] = LMIC.snr; + // schedule transmission (port 1, datalen 1, no ack requested) + LMIC_setTxData2(1, LMIC.frame, 1, 0); + // (will be sent as soon as duty cycle permits) + break; + } +} +//#endif /* #if 0 */