Commit 76c8eaf2 authored by Guillaume Gonnet's avatar Guillaume Gonnet
Browse files

Continue LoRaRIOT implemenation.

parent 02f67500
......@@ -22,6 +22,11 @@ DEVELHELP ?= 1
# Change this to 0 show compiler invocation lines by default.
QUIET ?= 1
# Reset EEPROM data on start?
RESET_ON_START ?= 1
CFLAGS += -DRESET_ON_START=$(RESET_ON_START)
# We use "IMAG" region in LoRaMAC-node.
REGION ?= EU868
CFLAGS += -DREGION_$(REGION)
......@@ -29,8 +34,9 @@ CFLAGS += -DREGION_$(REGION)
# All modules defined in this application.
USEMODULE += cubsat-app
USEMODULE += cubsat-app-providers
# USEMODULE += cubsat-app-benchmark
USEMODULE += cubsat-app-cmds
USEMODULE += cubsat-app-providers
USEMODULE += lorariot-ctrl
USEMODULE += lorariot-adapter
USEMODULE += lorariot-region
......
......@@ -6,6 +6,7 @@
MODULE := cubsat-app
DIRS += commands
DIRS += providers
INCLUDES += $(LORARIOT_INC) -I$(CURDIR)
......
......@@ -8,6 +8,7 @@ This project is under the MIT license
*/
#include <mutex.h>
#include <panic.h>
#include <stdint.h>
#include <stdbool.h>
......
......@@ -8,6 +8,7 @@ This project is under the MIT license
*/
#include "lorariot.h"
#include "providers/providers.h"
#include <stdio.h>
......@@ -17,5 +18,10 @@ int main(void)
{
lorariot_init();
#if RESET_ON_START
// If enable, reset all providers when the application starts.
pvd_reset_all();
#endif
puts("Hello !\n");
}
#
# Cubsat benchmark application.
# Cubsat provider module.
#
# Copyright (C) 2019, ENSIMAG students
# This project is under the MIT license
......
......@@ -12,23 +12,43 @@ This project is under the MIT license
// Configure LoRaMAC driver with provider information.
void pvd_otaa_configure(provider_t *pvd)
void pvd_otaa_enable(provider_t *pvd)
{
// TODO: read join response and frame counter from EEPROM.
(void)pvd;
// lorariot_replay_otaa();
}
// Save frame counter from last uplink message.
void pvd_otaa_update(provider_t *pvd)
{
// TODO.
(void)pvd;
}
// Force (re)joining the network.
void pvd_otaa_join(provider_t *pvd)
void pvd_otaa_reset(provider_t *pvd)
{
// TODO: set app keys.
// Set OTAA information.
pvd_otta_t *otaa = pvd->data;
lorariot_otaa_t otaa_req = { otaa->deveui, otaa->appeui, otaa->appkey, DR_0 };
// If join failed, we can't continue running the application because all
// messages will be lost.
if (loraraiot_otaa(&otaa_req) != LORARIOT_JOIN_SUCCEEDED)
PANIC("Can't join Orange network.");
// if (loramac_join_otaa() != OK)
// PANIC("Can't join Orange network.");
// TODO: save join response.
(void)pvd;
// Resend the join message to port 6.
lorariot_mcps_t mcps = LORARIOT_CONFIRMED(DR_0);
lorariot_send(&mcps);
}
......@@ -10,6 +10,8 @@ This project is under the MIT license
#include "providers.h"
#include "lorakeys.h"
#include <stddef.h>
// Orange provider for benchmark.
static pvd_otta_t orange_bm_otta = {
......@@ -31,3 +33,24 @@ static pvd_otta_t orange_cmd_otta = {
};
provider_t pvd_orange_cmd = PVD_IMPLEM_OTAA(orange_cmd_otta);
// All defined providers.
static provider_t *pvd_all[] = {
&pvd_orange_bm,
&pvd_orange_cmd
};
// Number of defined providers.
#define PVD_COUNT (sizeof(pvd_all) / sizeof(*pvd_all))
/**
* @brief Reset all providers.
*/
void pvd_reset_all(void)
{
for (size_t i = 0; i < PVD_COUNT; i++)
pvd_reset(pvd_all[i]);
}
......@@ -15,12 +15,14 @@ This project is under the MIT license
struct provider_t;
typedef void (*pvd_enable_t)(struct provider_t *);
typedef void (*pvd_join_t)(struct provider_t *);
typedef void (*pvd_update_t)(struct provider_t *);
typedef void (*pvd_reset_t)(struct provider_t *);
typedef struct provider_t {
void *data; // Provider specific data.
pvd_enable_t enable;
pvd_join_t join;
pvd_enable_t enable; // Called when the provider is selected.
pvd_update_t update; // Called after a message is sent.
pvd_reset_t reset; // Called to reset the provider.
} provider_t;
......@@ -33,12 +35,14 @@ typedef struct pvd_otta_t {
} pvd_otta_t;
// OTAA provider implementation.
void pvd_otaa_configure(provider_t *pvd);
void pvd_otaa_join(provider_t *pvd);
void pvd_otaa_enable(provider_t *pvd);
void pvd_otaa_update(provider_t *pvd);
void pvd_otaa_reset(provider_t *pvd);
// Feed a provider using default OTAA implementation.
#define PVD_IMPLEM_OTAA(otaa_info) \
{ &(otaa_info), pvd_otaa_configure, pvd_otaa_join }
{ &(otaa_info), pvd_otaa_enable, pvd_otaa_update, pvd_otaa_reset }
// Orange providers.
......@@ -55,3 +59,14 @@ extern provider_t pvd_ttn_bm;
* @param mcps MCPS information (data, DR, ...).
*/
void pvd_send(provider_t *pvd, lorariot_mcps_t *mcps);
/**
* @brief Reset a specific provider.
* @param pvd the provider to reset.
*/
void pvd_reset(provider_t *pvd);
/**
* @brief Reset all providers.
*/
void pvd_reset_all(void);
/*
Send some data using a provider.
Send and reset provider functions.
Copyright (C) 2019, ENSIMAG students
This project is under the MIT license
......@@ -19,17 +19,6 @@ static provider_t *current_pvd;
static mutex_t send_mutex = MUTEX_INIT;
// Change the current provider.
static void change_provider(provider_t *pvd)
{
// TODO.
// pvd->enable(pvd);
(void)pvd;
}
/**
* @brief Send some data using the specified provider.
* @param pvd the provider to use.
......@@ -40,10 +29,12 @@ void pvd_send(provider_t *pvd, lorariot_mcps_t *mcps)
// Wait for the current LoRaMAC-node operation to be completed.
mutex_lock(&send_mutex);
// The wanted provider is not the current provider, we must switch to this
// provider.
if (current_pvd != pvd)
change_provider(pvd);
// If the wanted provider is not the current provider, we must switch to
// this provider.
if (current_pvd != pvd) {
pvd->enable(pvd);
current_pvd = pvd;
}
// Send the MCPS message.
lorariot_send(mcps);
......@@ -55,3 +46,25 @@ void pvd_send(provider_t *pvd, lorariot_mcps_t *mcps)
// Unlock one other waiting thread.
mutex_unlock(&send_mutex);
}
/**
* @brief Reset a specific provider.
* @param pvd the provider to reset.
*/
void pvd_reset(provider_t *pvd)
{
// Wait for the current LoRaMAC-node operation to be completed.
mutex_lock(&send_mutex);
// Now reset the provider. It will surely make a join request, that's why we
// have wait for `send_mutex`.
pvd->reset(pvd);
// Reset function is does not necessarily change the current provider, we
// mark `current_pvd` as dirty.
current_pvd = NULL;
// Unlock one other waiting thread.
mutex_unlock(&send_mutex);
}
/*
Manage activation using OTAA / ABP.
This file is based on "semtech-loramac" module from RIOT OS, under the
LGPLv2.1 license.
*/
#include "controller.h"
// Make OTAA join request in LoRaRIOT thread.
static void _otaa(lorariot_otaa_t *otaa)
{
MibRequestConfirm_t mibReq;
mibReq.Type = MIB_NETWORK_JOINED;
mibReq.Param.IsNetworkJoined = false;
LoRaMacMibSetRequestConfirm(&mibReq);
MlmeReq_t mlmeReq;
mlmeReq.Type = MLME_JOIN;
mlmeReq.Req.Join.DevEui = otaa->deveui;
mlmeReq.Req.Join.AppEui = otaa->appeui;
mlmeReq.Req.Join.AppKey = otaa->appkey;
mlmeReq.Req.Join.Datarate = otaa->dr;
uint8_t ret = LoRaMacMlmeRequest(&mlmeReq);
msg_t msg;
msg.type = MSG_TYPE_LORAMAC_JOIN;
msg.content.value = SEMTECH_LORAMAC_BUSY;
msg_send(&msg, semtech_loramac_pid);
}
// Make OTAA join request.
int loraraiot_otaa(lorariot_otaa_t *otaa)
{
// Call `LoRaMacMlmeRequest` in event loop thread.
lorariot.caller_pid = thread_getpid();
lorariot_call((lorariot_func_t)_otaa, otaa);
// Wait for join status from LoRaMAC-node.
msg_t msg;
msg_receive(&msg);
return (uint8_t)msg.content.value;
}
......@@ -7,6 +7,8 @@ LGPLv2.1 license.
*/
#pragma once
#include "lorariot.h"
#include "LoRaMac.h"
......
......@@ -7,6 +7,8 @@ LGPLv2.1 license.
*/
#pragma once
#include <stdint.h>
......@@ -53,6 +55,19 @@ typedef struct {
} lorariot_mcps_t;
// Datarate for `dr` parameter in `lorariot_mcps_t`.
enum {
DR_CUSTOM = -1,
DR_0 = 0, // SF12, BW125
DR_1 = 1, // SF11, BW125
DR_2 = 2, // SF10, BW125
DR_3 = 3, // SF9, BW125
DR_4 = 4, // SF8, BW125
DR_5 = 5, // SF7, BW125
DR_6 = 6, // SF7, BW250
};
// Initialize `lorariot_mcps_t` for a confirmed frame.
#define LORARIOT_CONFIRMED(DR) \
(lorariot_mcps_t) { 1, 0, 14, 12, (DR), 1, 0, 3, NULL }
......@@ -63,11 +78,33 @@ typedef struct {
// OTAA join information.
typedef struct {
uint8_t *deveui;
uint8_t *appeui;
uint8_t *appkey;
uint8_t dr;
} lorariot_otaa_t;
// ABP join information.
typedef struct {
} lorariot_abp_t;
/**
* @brief Initialize LoRaRIOT and LoRaMAC-node.
*/
int lorariot_init(void);
/**
* @brief Make OTAA join request.
* @param otaa OTAA information.
*/
int loraraiot_otaa(lorariot_otaa_t *otaa);
/**
* @brief Call a function in LoRaRIOT event loop.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment