Commit 7d067d80 authored by Guillaume Gonnet's avatar Guillaume Gonnet
Browse files

Add benchmark module.

parent c0e772b5
......@@ -34,7 +34,7 @@ CFLAGS += -DREGION_$(REGION)
# All modules defined in this application.
USEMODULE += cubsat-app
# USEMODULE += cubsat-app-benchmark
USEMODULE += cubsat-app-benchmark
USEMODULE += cubsat-app-cmds
USEMODULE += cubsat-app-providers
USEMODULE += cubsat-app-drivers
......
......@@ -6,6 +6,7 @@
MODULE := cubsat-app
DIRS += benchmark
DIRS += commands
DIRS += providers
DIRS += drivers
......
#
# Cubsat benchmark module.
#
# Copyright (C) 2019, ENSIMAG students
# This project is under the MIT license
MODULE := cubsat-app-benchmark
include $(RIOTBASE)/Makefile.base
/*
Run the LoRaWAN benchmark.
Copyright (C) 2019, ENSIMAG students
This project is under the MIT license
*/
#include "benchmark.h"
// Transmission powers to test.
uint8_t bm_power[] = { 2, 5, 8, 11, 14, 15, 16, 17, 18, 19 };
// Datarates to test.
uint8_t bm_dr[] = { DR_0, DR_1, DR_2, DR_3, DR_4, DR_5 };
// Coding rates to test.
uint8_t bm_cr[] = { CR_4_5, CR_4_8 };
// Providers to test.
provider_t *bm_pvd[] = { &pvd_orange_bm, &pvd_ttn_bm };
// Count the number of elements in an array.
#define CNT(array) (uint8_t)(sizeof(array) / sizeof(*array))
// Iterate on the given parameter.
#define foreach_param(name) \
for (uint8_t name ## _i = 0; name ## _i < CNT(bm_ ## name); name ## _i++)
// Run the benchmark.
void bm_run(void)
{
bm_payload.port = 50; // TODO: change port.
foreach_param(power) // Power: 10 values
foreach_param(cr) // Coding rate: 2 values
foreach_param(dr) // Datarate: 6 values
foreach_param(pvd) { // Providers: 2 values
bm_encode_payload(power_i, dr_i, cr_i);
pvd_send(bm_pvd[pvd_i], &bm_payload);
}
}
/*
Run the LoRaWAN benchmark.
Copyright (C) 2019, ENSIMAG students
This project is under the MIT license
*/
#pragma once
#include "providers/providers.h"
#include "lorariot.h"
// Static payload for benchmark.
extern lorariot_mcps_t bm_payload;
// Transmission powers to test.
extern uint8_t bm_powers[];
// Datarates to test.
extern uint8_t bm_dr[];
// Coding rates to test.
extern uint8_t bm_cr[];
// Providers to test.
extern provider_t *bm_pvd[];
/**
* @brief Encode message data to the payload.
* @param power_i Transmission power (index in `bm_powers`).
* @param dr_i Datarate (index in `bm_dr`).
* @param cr_i Coding rate (index in `bm_cr`).
*/
void bm_encode_payload(uint8_t power_i, uint8_t dr_i, uint8_t cr_i);
/**
* @brief Run the benchmark.
*/
void bm_run(void);
/*
Encode message data to the payload.
Copyright (C) 2019, ENSIMAG students
This project is under the MIT license
*/
#include "benchmark.h"
// Buffer that contains encoded data.
uint8_t bm_buffer[10];
// Static payload for benchmark.
lorariot_mcps_t bm_payload = LORARIOT_UNCONFIRMED_EX(DR_0, 50, 10, bm_buffer);
// Encode message data to the payload.
void bm_encode_payload(uint8_t power_i, uint8_t dr_i, uint8_t cr_i)
{
// Encode LoRa settings (on 8 bits).
bm_buffer[0] =
((dr_i & 0b111) << 5) |
((cr_i & 0b1) << 4) |
((power_i & 0b1111) << 0);
// Encode temperature (on 9 bits).
// TODO.
// Encode latitude (on 23 bits, we assume it's > 0).
// TODO.
// Encode longitude (on 24 bits).
// TODO.
// Encode altitude (on 16 bits);
// TODO.
// Change MCPS parameters for the next frame.
bm_payload.code_rate = bm_cr[cr_i];
bm_payload.power = bm_powers[power_i];
bm_payload.dr = bm_dr[dr_i];
}
/*
Standard benchmark.
Copyright (C) 2019, ENSIMAG students
This project is under the MIT license
*/
......@@ -66,7 +66,7 @@ extern lorariot_ctrl_t lorariot;
// MCPS data frame.
typedef struct {
uint8_t code_rate; // [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
uint8_t code_rate; // from CR_4_5 to CR_4_8
uint8_t bandwidth; // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz]
uint8_t power; // from 2 to 20 [dBm]
uint8_t sf; // from 6 to 12
......@@ -91,14 +91,31 @@ enum {
DR_6 = 6, // SF7, BW250
};
// Coding rates for `code_rate` parameter in `lorariot_mcps_t`.
enum {
CR_4_5 = 1, // 4/5
CR_4_6 = 2, // 4/6
CR_4_7 = 3, // 4/7
CR_4_8 = 4, // 4/8
};
// Initialize `lorariot_mcps_t` for a confirmed frame.
#define LORARIOT_CONFIRMED(DR) \
(lorariot_mcps_t) { 1, 0, 14, 12, (DR), 1, 0, 3, NULL }
(lorariot_mcps_t) { CR_4_5, 0, 14, 12, (DR), 1, 0, 3, NULL }
// Initialize `lorariot_mcps_t` for a confirmed frame.
#define LORARIOT_CONFIRMED_EX(DR, port, len, buffer) \
(lorariot_mcps_t) { CR_4_5, 0, 14, 12, (DR), (port), (len), 3, (buffer) }
// Initialize `lorariot_mcps_t` for an unconfirmed frame.
#define LORARIOT_UNCONFIRMED(DR) \
(lorariot_mcps_t) { 1, 0, 14, 12, (DR), 1, 0, 0, NULL }
(lorariot_mcps_t) { CR_4_5, 0, 14, 12, (DR), 1, 0, 0, NULL }
// Initialize `lorariot_mcps_t` for an unconfirmed frame.
#define LORARIOT_UNCONFIRMED_EX(DR, port, len, buffer) \
(lorariot_mcps_t) { CR_4_5, 0, 14, 12, (DR), (port), (len), 0, (buffer) }
......@@ -120,6 +137,7 @@ typedef struct {
/**
* @brief Initialize LoRaRIOT and LoRaMAC-node.
* @return `LORARIOT_SUCCESS` on success.
*/
int lorariot_init(void);
......
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