C++ Wrapper around the IBM LMiC LoRaWAN implementation

Dependencies:   LMiC SX1276Lib

Committer:
Sille Van Landschoot
Date:
Sun Oct 16 09:57:58 2016 +0200
Revision:
9:cfe697b53d71
Parent:
8:8ce065f8c62f
Child:
10:9bf05e9b4cde
add linkcheck control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 1:7cfc59ba0797 1 /* The MIT License (MIT)
sillevl 1:7cfc59ba0797 2 *
sillevl 1:7cfc59ba0797 3 * Copyright (c) 2016 Sille Van Landschoot
sillevl 1:7cfc59ba0797 4 *
sillevl 1:7cfc59ba0797 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
sillevl 1:7cfc59ba0797 6 * of this software and associated documentation files (the "Software"), to deal
sillevl 1:7cfc59ba0797 7 * in the Software without restriction, including without limitation the rights
sillevl 1:7cfc59ba0797 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
sillevl 1:7cfc59ba0797 9 * copies of the Software, and to permit persons to whom the Software is
sillevl 1:7cfc59ba0797 10 * furnished to do so, subject to the following conditions:
sillevl 1:7cfc59ba0797 11 *
sillevl 1:7cfc59ba0797 12 * The above copyright notice and this permission notice shall be included in all
sillevl 1:7cfc59ba0797 13 * copies or substantial portions of the Software.
sillevl 1:7cfc59ba0797 14 *
sillevl 1:7cfc59ba0797 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
sillevl 1:7cfc59ba0797 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
sillevl 1:7cfc59ba0797 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
sillevl 1:7cfc59ba0797 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
sillevl 1:7cfc59ba0797 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
sillevl 1:7cfc59ba0797 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
sillevl 1:7cfc59ba0797 21 * SOFTWARE.
sillevl 1:7cfc59ba0797 22 */
sillevl 1:7cfc59ba0797 23
sillevl 1:7cfc59ba0797 24
sillevl 1:7cfc59ba0797 25 #include <Node.h>
sillevl 1:7cfc59ba0797 26 #include <stdio.h>
sillevl 1:7cfc59ba0797 27 #include <stdlib.h>
sillevl 1:7cfc59ba0797 28
sillevl 1:7cfc59ba0797 29 void onEvent(ev_t ev)
sillevl 1:7cfc59ba0797 30 {
sillevl 1:7cfc59ba0797 31 SimpleLoRaWAN::Node::onEvent(ev);
sillevl 1:7cfc59ba0797 32 }
sillevl 1:7cfc59ba0797 33
sillevl 1:7cfc59ba0797 34
sillevl 2:6fac10decfb3 35
sillevl 1:7cfc59ba0797 36
sillevl 1:7cfc59ba0797 37 namespace SimpleLoRaWAN
sillevl 1:7cfc59ba0797 38 {
sillevl 1:7cfc59ba0797 39
sillevl 1:7cfc59ba0797 40 Node::Node()
sillevl 1:7cfc59ba0797 41 {
sillevl 2:6fac10decfb3 42 init();
sillevl 1:7cfc59ba0797 43 }
sillevl 1:7cfc59ba0797 44
sillevl 1:7cfc59ba0797 45 Node::~Node()
sillevl 1:7cfc59ba0797 46 {
sillevl 1:7cfc59ba0797 47
sillevl 1:7cfc59ba0797 48 }
sillevl 1:7cfc59ba0797 49
sillevl 2:6fac10decfb3 50 void Node::init()
sillevl 2:6fac10decfb3 51 {
sillevl 2:6fac10decfb3 52 os_init();
sillevl 2:6fac10decfb3 53
sillevl 2:6fac10decfb3 54 // reset MAC state
sillevl 2:6fac10decfb3 55 LMIC_reset();
sillevl 7:c5eb71a7c94f 56 LMIC_setDrTxpow(DR_SF7, 14);
sillevl 2:6fac10decfb3 57 }
sillevl 2:6fac10decfb3 58
sillevl 1:7cfc59ba0797 59
sillevl 1:7cfc59ba0797 60 void Node::send(char* data, int size)
sillevl 1:7cfc59ba0797 61 {
sillevl 1:7cfc59ba0797 62 memcpy (LMIC.frame, data, size);
sillevl 1:7cfc59ba0797 63 LMIC_setTxData2(15, LMIC.frame, size, 0);
sillevl 1:7cfc59ba0797 64 }
sillevl 1:7cfc59ba0797 65
sillevl 1:7cfc59ba0797 66
sillevl 1:7cfc59ba0797 67 void Node::onEvent(ev_t ev)
sillevl 1:7cfc59ba0797 68 {
sillevl 1:7cfc59ba0797 69 printf("Event (%d)!!!\r\n", ev);
sillevl 1:7cfc59ba0797 70 switch(ev) {
sillevl 1:7cfc59ba0797 71 case EV_JOINED:
sillevl 1:7cfc59ba0797 72 printf("JOINED\n\r");
sillevl 1:7cfc59ba0797 73 LMIC_setLinkCheckMode(0); // Link check is currently not implemented for TTN, so just disable it
sillevl 1:7cfc59ba0797 74 break;
sillevl 1:7cfc59ba0797 75 case EV_TXCOMPLETE:
sillevl 1:7cfc59ba0797 76 printf("TXCOMPLETE\n\r");
sillevl 1:7cfc59ba0797 77 break;
sillevl 1:7cfc59ba0797 78 default:
sillevl 1:7cfc59ba0797 79 break;
sillevl 1:7cfc59ba0797 80 }
sillevl 1:7cfc59ba0797 81 }
sillevl 1:7cfc59ba0797 82
sillevl 1:7cfc59ba0797 83 void Node::process()
sillevl 1:7cfc59ba0797 84 {
sillevl 1:7cfc59ba0797 85 os_runloop_once();
sillevl 1:7cfc59ba0797 86 }
sillevl 1:7cfc59ba0797 87
Sille Van Landschoot 9:cfe697b53d71 88 void Node::enableLinkCheck()
Sille Van Landschoot 9:cfe697b53d71 89 {
Sille Van Landschoot 9:cfe697b53d71 90 setLinkCheck(true);
Sille Van Landschoot 9:cfe697b53d71 91 }
Sille Van Landschoot 9:cfe697b53d71 92
Sille Van Landschoot 9:cfe697b53d71 93 void Node::disableLinkCheck()
Sille Van Landschoot 9:cfe697b53d71 94 {
Sille Van Landschoot 9:cfe697b53d71 95 setLinkCheck(false);
Sille Van Landschoot 9:cfe697b53d71 96 }
Sille Van Landschoot 9:cfe697b53d71 97
Sille Van Landschoot 9:cfe697b53d71 98 void Node::setLinkCheck(int state)
Sille Van Landschoot 9:cfe697b53d71 99 {
Sille Van Landschoot 9:cfe697b53d71 100 LMIC_setLinkCheckMode(state);
Sille Van Landschoot 9:cfe697b53d71 101 }
Sille Van Landschoot 9:cfe697b53d71 102
sillevl 2:6fac10decfb3 103
sillevl 1:7cfc59ba0797 104 } /* namespace SimpleLoRaWAN */