Commit edbcb027 authored by Guillaume Gonnet's avatar Guillaume Gonnet
Browse files

Fix a lot of compilation errors.

parent b85232d0
......@@ -11,7 +11,7 @@ APPLICATION = cubsat
BOARD ?= im880b
DRIVER ?= sx1272
# Riot submodule is in `RIOT` module.
# Riot submodule is in `RIOT` directory.
RIOTBASE ?= $(CURDIR)/RIOT
......@@ -22,16 +22,25 @@ DEVELHELP ?= 1
# Change this to 0 show compiler invocation lines by default.
QUIET ?= 1
# We use "IMAG" region in LoRaMAC-node.
REGION ?= EU868
CFLAGS += -DREGION_$(REGION)
# All modules defined in this application.
USEMODULE += cubsat-app
USEMODULE += cubsat-app-providers
USEMODULE += cubsat-app-benchmark
# USEMODULE += cubsat-app-benchmark
USEMODULE += lorariot-ctrl
USEMODULE += lorariot-adapter
USEMODULE += lorariot-region
USEMODULE += loramac-mac
USEMODULE += loramac-region
USEMODULE += loramac-crypto
# Application dependencies.
USEMODULE += $(DRIVER)
USEMODULE += random
USEMODULE += periph_uart
......
......@@ -19,10 +19,14 @@ export LORAMAC_INC := \
# Directory containing LoRaRIOT.
export LORAMAC_DIR := LoRaRIO$(CURDIR)/lorariot
export LORARIOT_DIR := $(CURDIR)/lorariot
# Include folders for LoRaRIOT.
export LORAMAC_INC := -I$(LORAMAC_DIR)
export LORARIOT_INC := -I$(LORARIOT_DIR)
# Include this directory for getting keys.
INCLUDES += -I$(CURDIR)
# Add source directories.
......
......@@ -8,4 +8,6 @@ MODULE := cubsat-app
DIRS += providers
INCLUDES += $(LORARIOT_INC) -I$(CURDIR)
include $(RIOTBASE)/Makefile.base
......@@ -7,6 +7,11 @@ This project is under the MIT license
*/
#include <mutex.h>
#include <stdint.h>
#include <stdbool.h>
// Stop the application on an error.
#define PANIC(msg) core_panic(PANIC_GENERAL_ERROR, msg)
......@@ -15,6 +20,8 @@ This project is under the MIT license
typedef struct {
mutex_t mutex;
bool is_parsing;
uint8_t line_length;
char line[127];
} gps_isr_info_t;
extern gps_isr_info_t gps_isr_info;
......@@ -7,11 +7,15 @@ This project is under the MIT license
*/
#include "app.h"
gps_isr_info_t gps_isr_info = { MUTEX_INIT };
gps_isr_info_t gps_isr_info = { MUTEX_INIT, 0, 0, "\0" };
uint8_t gps_parse_data()
uint8_t gps_parse_data(void)
{
// TODO.
return 0;
}
......@@ -7,6 +7,8 @@ This project is under the MIT license
*/
#include "lorariot.h"
#include <stdio.h>
......
......@@ -7,23 +7,28 @@ This project is under the MIT license
*/
#include "providers"
#include "providers.h"
#include "app.h"
// Configure LoRaMAC driver with provider information.
void pvd_otaa_configure(provider_t *)
void pvd_otaa_configure(provider_t *pvd)
{
// TODO: read join response and frame counter from EEPROM.
(void)pvd;
}
// Force (re)joining the network.
void pvd_otaa_join(provider_t *);
void pvd_otaa_join(provider_t *pvd)
{
// TODO: set app keys.
if (loramac_join_otaa() != OK)
PANIC("Can't join Orange network.");
// if (loramac_join_otaa() != OK)
// PANIC("Can't join Orange network.");
// TODO: save join response.
(void)pvd;
}
......@@ -7,13 +7,13 @@ This project is under the MIT license
*/
#include "providers"
#include "providers.h"
#include "lorakeys.h"
// Orange provider for benchmark.
static pvd_otta_t orange_bm_otta = {
EEPROM_ORANGE_BM,
0 /* EEPROM_ORANGE_BM */,
ORANGE_BM_DEVEUI,
ORANGE_BM_APPEUI,
ORANGE_BM_APPKEY
......@@ -24,25 +24,10 @@ provider_t pvd_orange_bm = PVD_IMPLEM_OTAA(orange_bm_otta);
// Orange provider for commands.
static pvd_otta_t orange_cmd_otta = {
EEPROM_ORANGE_BM,
0 /* EEPROM_ORANGE_BM */,
ORANGE_BM_DEVEUI,
ORANGE_BM_APPEUI,
ORANGE_BM_APPKEY
};
provider_t pvd_orange_cmd = PVD_IMPLEM_OTAA(orange_cmd_otta);
// The current provider.
static provider_t *current_pvd;
// Change the current LoRaWAN provider.
void change_provider(provider_t *pvd)
{
if (pvd == current_pvd) return;
if (current_pvd) current_pvd->disable();
pvd->enable(pvd);
current_pvd = pvd;
}
......@@ -9,15 +9,18 @@ This project is under the MIT license
#pragma once
#include "lorariot.h"
typedef (*pvd_configure_t)(struct provider_t *);
typedef (*pvd_join_t)(struct provider_t *);
struct provider_t;
typedef void (*pvd_enable_t)(struct provider_t *);
typedef void (*pvd_join_t)(struct provider_t *);
typedef struct provider_t {
void *data; // Provider specific data.
pvd_configure_t enable;
pvd_configure_t disable;
pvd_join_t reset;
pvd_enable_t enable;
pvd_join_t join;
} provider_t;
......@@ -30,8 +33,8 @@ typedef struct pvd_otta_t {
} pvd_otta_t;
// OTAA provider implementation.
void pvd_otaa_configure(provider_t *);
void pvd_otaa_join(provider_t *);
void pvd_otaa_configure(provider_t *pvd);
void pvd_otaa_join(provider_t *pvd);
// Feed a provider using default OTAA implementation.
#define PVD_IMPLEM_OTAA(otaa_info) \
......@@ -46,10 +49,6 @@ extern provider_t pvd_orange_cmd;
extern provider_t pvd_ttn_bm;
// Change the current LoRaWAN provider.
void change_provider(provider_t *pvd);
/**
* @brief Send some data using the specified provider.
* @param pvd the provider to use.
......
......@@ -9,6 +9,8 @@ This project is under the MIT license
#include "providers.h"
#include <mutex.h>
// Current loaded provider.
static provider_t *current_pvd;
......@@ -21,6 +23,10 @@ static mutex_t send_mutex = MUTEX_INIT;
static void change_provider(provider_t *pvd)
{
// TODO.
// pvd->enable(pvd);
(void)pvd;
}
......
......@@ -7,11 +7,11 @@ This project is under the MIT license
*/
#include <mutex.h>
#include "app.h"
#include <periph/uart.h>
#include <stdio.h>
#include <stdbool.h>
// UART configuration.
......@@ -28,12 +28,12 @@ static void gps_isr(gps_isr_info_t *info, char c)
if (info->is_parsing)
return; // Ignore new GPS data while parsing an old one.
if ((c == '$') || (c->line_length >= 127))
c->line_length = 0;
if ((c == '$') || (info->line_length >= 127))
info->line_length = 0;
c->line[c->line_length++] = c;
info->line[info->line_length++] = c;
if (c == '\n') {
c->line[c->line_length++] = '\0';
info->line[info->line_length++] = '\0';
mutex_unlock(&info->mutex);
}
}
......
......@@ -1684,6 +1684,10 @@ typedef enum eLoRaMacRegion_t
* North american band on 915MHz with a maximum of 16 channels
*/
LORAMAC_REGION_US915_HYBRID,
/*!
* IMAG region (band on 868MHz, with custom parameters)
*/
LORAMAC_REGION_IMAG,
}LoRaMacRegion_t;
/*!
......
#
# RIOT adapter.
# RIOT adapter for LoRaMAC-node.
#
# Copyright (C) 2019, ENSIMAG students
# This project is under the MIT license
MODULE := midway-src
DIRS += mac
DIRS += region
DIRS += crypto
DIRS += riot-adapt
DIRS += controller
INCLUDES += $(LORAMAC_INC)
INCLUDES += $(LORAMAC_INC) $(LORARIOT_INC)
include $(RIOTBASE)/Makefile.base
#
# LoRaRIOT controller module.
#
# Copyright (C) 2019, ENSIMAG students
# This project is under the MIT license
MODULE := lorariot-ctrl
include $(RIOTBASE)/Makefile.base
......@@ -9,21 +9,33 @@ LGPLv2.1 license.
#include "controller.h"
#include <debug.h>
#include <net/netdev/lora.h>
#include <net/loramac.h>
#include <sx127x.h>
#include <sx127x_params.h>
#include <sx127x_netdev.h>
// Message queue of event loop.
#define LORARIOT_MSG_QUEUE (16U)
static msg_t _lorariot_msg_queue[LORARIOT_MSG_QUEUE];
static msg_t msg_queue[LORARIOT_MSG_QUEUE];
// LoRaRIOT event loop.
#define LORARIOT_LORAMAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
static char _lorariot_stack[LORARIOT_LORAMAC_STACKSIZE];
static char lorariot_stack[LORARIOT_LORAMAC_STACKSIZE];
//
// LoRaMAC-node objects.
sx127x_t sx127x;
RadioEvents_t semtech_loramac_radio_events;
LoRaMacPrimitives_t semtech_loramac_primitives;
LoRaMacCallback_t semtech_loramac_callbacks;
RadioEvents_t lorariot_radio_ev;
LoRaMacPrimitives_t lorariot_primitives;
LoRaMacCallback_t lorariot_callbacks;
// PID of LoRaRIOT event loop.
kernel_pid_t lorariot_pid;
// Unique instance of `lorariot_ctrl_t`.
lorariot_ctrl_t lorariot;
......@@ -40,6 +52,7 @@ extern void lorariot_mlme_indication(MlmeIndication_t *indication);
// Main event loop for LoRaRIOT.
void *lorariot_event_loop(void *arg)
{
(void)arg;
msg_init_queue(msg_queue, LORARIOT_MSG_QUEUE);
while (true) {
......@@ -47,53 +60,53 @@ void *lorariot_event_loop(void *arg)
msg_receive(&msg);
switch (msg.type) {
case MSG_TYPE_ISR: {
case LORARIOT_TYPE_ISR: {
netdev_t *dev = msg.content.ptr;
dev->driver->isr(dev);
} break;
case MSG_TYPE_RX_TIMEOUT: {
lorariot_radio_events.RxTimeout();
case LORARIOT_TYPE_RX_TIMEOUT: {
lorariot_radio_ev.RxTimeout();
} break;
case MSG_TYPE_TX_TIMEOUT: {
lorariot_radio_events.TxTimeout();
case LORARIOT_TYPE_TX_TIMEOUT: {
lorariot_radio_ev.TxTimeout();
} break;
case MSG_TYPE_MAC_TIMEOUT: {
case LORARIOT_TYPE_MAC_TIMEOUT: {
void (*callback)(void) = msg.content.ptr;
callback();
} break;
case MSG_TYPE_LORAMAC_CMD: {
case LORARIOT_TYPE_CALL: {
msg_t msg_resp;
lorariot_call_t *call = msg.content.ptr;
call->func(mac, call->arg);
call->func(call->arg);
msg_reply(&msg, &msg_resp);
} break;
case MSG_TYPE_LORAMAC_JOIN: {
case LORARIOT_TYPE_LORAMAC_JOIN: {
msg_t msg_ret;
msg_ret.content.value = msg.content.value;
msg_send(&msg_ret, mac->caller_pid);
msg_send(&msg_ret, lorariot.caller_pid);
} break;
case MSG_TYPE_LORAMAC_LINK_CHECK: {
MlmeConfirm_t *confirm = (MlmeConfirm_t *)msg.content.ptr;
mac->link_chk.demod_margin = confirm->DemodMargin;
mac->link_chk.nb_gateways = confirm->NbGateways;
mac->link_chk.available = true;
case LORARIOT_TYPE_LORAMAC_LINK_CHECK: {
// MlmeConfirm_t *confirm = (MlmeConfirm_t *)msg.content.ptr;
// mac->link_chk.demod_margin = confirm->DemodMargin;
// mac->link_chk.nb_gateways = confirm->NbGateways;
// mac->link_chk.available = true;
} break;
case MSG_TYPE_LORAMAC_TX_STATUS: {
case LORARIOT_TYPE_LORAMAC_TX_STATUS: {
DEBUG("[lorariot] received TX status\n");
msg_t msg_ret;
msg_ret.type = msg.type;
msg_ret.content.value = msg.content.value;
msg_send(&msg_ret, mac->caller_pid);
msg_send(&msg_ret, lorariot.caller_pid);
} break;
case MSG_TYPE_LORAMAC_RX: {
case LORARIOT_TYPE_LORAMAC_RX: {
// TODO: call receive thread.
} break;
......@@ -111,24 +124,24 @@ void lorariot_call(lorariot_func_t func, void *arg)
msg_t msg, msg_resp;
lorariot_call_t call = { func, arg };
msg.type = MSG_TYPE_LORAMAC_CMD;
msg.type = LORARIOT_TYPE_CALL;
msg.content.ptr = &call;
msg_send_receive(&msg, &msg_resp, lorariot_pid);
}
// Initialize LoRaRIOT and LoRaMAC-node.
int lorariot_init()
int lorariot_init(void)
{
DEBUG("[lorariot] initializing LoRaRIOT and LoRaMAC-node\n");
// Initialize Radio module.
sx127x_setup(&sx127x, &sx127x_params[0]);
sx127x.netdev.driver = &sx127x_driver;
sx127x.netdev.event_callback = _semtech_loramac_event_cb;
sx127x.netdev.event_callback = lorariot_event_cb;
// Create event loop thread.
lorariot_pid = thread_create(_lorariot_stack, sizeof(_lorariot_stack),
lorariot_pid = thread_create(lorariot_stack, sizeof(lorariot_stack),
THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
lorariot_event_loop, NULL, "lorariot-evloop");
......@@ -138,12 +151,12 @@ int lorariot_init()
}
// Initialize LoRaMAC-node module.
primitives->MacMcpsConfirm = mcps_confirm;
primitives->MacMcpsIndication = mcps_indication;
primitives->MacMlmeConfirm = mlme_confirm;
primitives->MacMlmeIndication = mlme_indication;
LoRaMacInitialization(&lorariot_radio_events, primitives, callbacks,
REGION_IMAG);
lorariot_primitives.MacMcpsConfirm = lorariot_mcps_confirm;
lorariot_primitives.MacMcpsIndication = lorariot_mcps_indication;
lorariot_primitives.MacMlmeConfirm = lorariot_mlme_confirm;
lorariot_primitives.MacMlmeIndication = lorariot_mlme_indication;
LoRaMacInitialization(&lorariot_radio_ev, &lorariot_primitives,
&lorariot_callbacks, LORAMAC_REGION_IMAG);
return 0;
}
......@@ -8,25 +8,35 @@ LGPLv2.1 license.
*/
#include "lorariot.h"
#include "LoRaMac.h"
#include <msg.h>
#include <net/netdev.h>
#define ENABLE_DEBUG (1)
#include <debug.h>
// All message types for LoRaRIOT event loop.
#define LORARIOT_TYPE_ISR (0x3456) // radio device ISR */
#define LORARIOT_TYPE_RX_TIMEOUT (0x3457) /**< radio driver RX timeout */
#define LORARIOT_TYPE_TX_TIMEOUT (0x3458) /**< radio driver TX timeout */
#define LORARIOT_TYPE_MAC_TIMEOUT (0x3459) /**< MAC timers timeout */
#define LORARIOT_TYPE_CALL (0x3460) /**< Command sent to the MAC */
#define LORARIOT_TYPE_LORAMAC_JOIN (0x3461) /**< MAC join event */
#define LORARIOT_TYPE_LORAMAC_TX_STATUS (0x3462) /**< MAC TX status */
#define LORARIOT_TYPE_LORAMAC_RX (0x3463) /**< Some data received */
#define LORARIOT_TYPE_LORAMAC_LINK_CHECK (0x3464) /**< Link check info received */
#define LORARIOT_TYPE_ISR (0x3456) // radio device ISR
#define LORARIOT_TYPE_RX_TIMEOUT (0x3457) // radio driver RX timeout
#define LORARIOT_TYPE_TX_TIMEOUT (0x3458) // radio driver TX timeout
#define LORARIOT_TYPE_MAC_TIMEOUT (0x3459) // MAC timers timeout
#define LORARIOT_TYPE_CALL (0x3460) // Command sent to the MAC
#define LORARIOT_TYPE_LORAMAC_JOIN (0x3461) // MAC join event
#define LORARIOT_TYPE_LORAMAC_TX_STATUS (0x3462) // MAC TX status
#define LORARIOT_TYPE_LORAMAC_RX (0x3463) // Some data received
#define LORARIOT_TYPE_LORAMAC_LINK_CHECK (0x3464) // Link check info received
// PID of LoRaRIOT event loop.
extern kernel_pid_t lorariot_pid;
// LoRaMAC-node objects.
extern RadioEvents_t lorariot_radio_ev;
extern LoRaMacPrimitives_t lorariot_primitives;
extern LoRaMacCallback_t lorariot_callbacks;
// Store data of LoRaRIOT controller.
typedef struct {
......@@ -37,12 +47,17 @@ typedef struct {
extern lorariot_ctrl_t lorariot;
// Handle a NetDev event.
void lorariot_event_cb(netdev_t *dev, netdev_event_t event);
// LoRaRIOT debug functions.
#ifdef NDEBUG
#if ENABLE_DEBUG
void lorariot_debug_status(const char *name, LoRaMacStatus_t status);
void lorariot_debug_status_ev(const char *name, LoRaMacEventInfoStatus_t status);
void lorariot_debug_mcps(Mcps_t code);
#else
#define lorariot_debug_status(id, status) ((void)0)
#define lorariot_debug_status(name, status) ((void)0)
#define lorariot_debug_status_ev(name, status) ((void)0)
#define lorariot_debug_mcps(code) ((void)0)
#endif
......@@ -9,7 +9,7 @@ LGPLv2.1 license.
#include "controller.h"
#ifndef NDEBUG
#if ENABLE_DEBUG
// Debug a LoRAMAC status code.
......@@ -84,4 +84,4 @@ void lorariot_debug_mcps(Mcps_t code)
}
#endif // !NDEBUG
#endif // ENABLE_DEBUG
......@@ -7,6 +7,15 @@ LGPLv2.1 license.
*/
#include "controller.h"
#include <net/netdev/lora.h>
#include <net/loramac.h>
#include <sx127x.h>
#include <sx127x_params.h>
#include <sx127x_netdev.h>
// Handle a NetDev event.
void lorariot_event_cb(netdev_t *dev, netdev_event_t event)
......@@ -18,23 +27,21 @@ void lorariot_event_cb(netdev_t *dev, netdev_event_t event)
switch (event) {
case NETDEV_EVENT_ISR:
msg.type = MSG_TYPE_ISR;
if (msg_send(&msg, semtech_loramac_pid) <= 0) {
msg.type = LORARIOT_TYPE_ISR;
if (msg_send(&msg, lorariot_pid) <= 0)
DEBUG("[lorariot] possibly lost interrupt.\n");
}
break;
case NETDEV_EVENT_TX_COMPLETE:
sx127x_set_sleep((sx127x_t *)dev);
semtech_loramac_radio_events.TxDone();
lorariot_radio_ev.TxDone();
DEBUG("[lorariot] Transmission completed\n");
break;
case NETDEV_EVENT_TX_TIMEOUT:
msg.type = MSG_TYPE_TX_TIMEOUT;
if (msg_send(&msg, semtech_loramac_pid) <= 0) {
msg.type = LORARIOT_TYPE_TX_TIMEOUT;
if (msg_send(&msg, lorariot_pid) <= 0)
DEBUG("[lorariot] TX timeout, possibly lost interrupt.\n");
}
break;
case NETDEV_EVENT_RX_COMPLETE: {
......@@ -42,36 +49,30 @@ void lorariot_event_cb(netdev_t *dev, netdev_event_t event)
uint8_t radio_payload[SX127X_RX_BUFFER_SIZE];
len = dev->driver->recv(dev, NULL, 0, 0);
dev->driver->recv(dev, radio_payload, len, &packet_info);
semtech_loramac_radio_events.RxDone(radio_payload,
len, packet_info.rssi, packet_info.snr);