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

Fix some bugs and add more logs.

parent 63b3e0b4
......@@ -28,7 +28,7 @@ RESET_ON_START ?= 1
CFLAGS += -DRESET_ON_START=$(RESET_ON_START)
# We use "IMAG" region in LoRaMAC-node.
REGION ?= EU868
REGION ?= IMAG
CFLAGS += -DREGION_$(REGION)
......
......@@ -24,7 +24,7 @@ v1.0.
// Debug an I2C result.
#define DS75_DEBUG(text, res) \
if ((res) != 0) DEBUG("[ds75]" text ": %i\n", (res));
if ((res) != 0) DEBUG("[ds75] " text ": %i\n", (res));
// Initialize DS75LX module.
......
......@@ -21,7 +21,7 @@ This project is under the MIT license
#define DS75_I2C_DEV (I2C_DEV(0))
// Default I2C address to use.
#define DS75_I2C_ADDRESS (0x68)
#define DS75_I2C_ADDRESS (0x48)
// DS75LX resolution.
......
......@@ -12,20 +12,45 @@ This project is under the MIT license
#include "providers/providers.h"
#include "commands/commands.h"
#include <xtimer.h>
#include <stdio.h>
// TMP: send a ping message.
static void send_message(void)
{
lorariot_mcps_t mcps = LORARIOT_UNCONFIRMED(DR_0);
mcps.buffer = (uint8_t *)"Ballon!";
mcps.len = 7;
puts("Sending message ...");
pvd_send(&pvd_orange_bm, &mcps);
puts("Message sent!");
}
// Entry point of the whole application.
int main(void)
{
puts("=============================");
puts("LoRaWAN Benchmark application");
puts("=============================");
lorariot_init();
ds75_init();
cmds_init();
// cmds_init();
#if RESET_ON_START
// If enable, reset all providers when the application starts.
pvd_reset_all();
#endif
puts("Hello !\n");
xtimer_sleep(10);
while (true) {
send_message();
xtimer_sleep(30);
}
}
......@@ -10,9 +10,11 @@ This project is under the MIT license
#include "providers.h"
#include "app.h"
#include <debug.h>
#include <periph/eeprom.h>
#define ENABLE_DEBUG (1)
#include <debug.h>
// Configure LoRaMAC driver with provider information.
void pvd_otaa_enable(provider_t *pvd)
......@@ -48,7 +50,7 @@ void pvd_otaa_reset(provider_t *pvd)
// If join failed, we can't continue running the application because all
// messages will be lost.
if (loraraiot_otaa(&otaa_req) != LORARIOT_SUCCESS) {
DEBUG("[otaa] join error for devui [%2x ..]", *otaa->deveui);
DEBUG("[otaa] join error for devui [%02X..]\n", *otaa->deveui);
PANIC("Can't join network using OTAA");
}
......
......@@ -9,13 +9,17 @@ This project is under the MIT license
#include "providers.h"
#include "lorakeys.h"
#include "appmem.h"
#include <stddef.h>
#define ENABLE_DEBUG (1)
#include <debug.h>
// Orange provider for benchmark.
static pvd_otta_t orange_bm_otta = {
0 /* EEPROM_ORANGE_BM */,
EEPROM_ORANGE_BM,
ORANGE_BM_DEVEUI,
ORANGE_BM_APPEUI,
ORANGE_BM_APPKEY
......@@ -26,10 +30,10 @@ provider_t pvd_orange_bm = PVD_IMPLEM_OTAA(orange_bm_otta);
// Orange provider for commands.
static pvd_otta_t orange_cmd_otta = {
0 /* EEPROM_ORANGE_BM */,
ORANGE_BM_DEVEUI,
ORANGE_BM_APPEUI,
ORANGE_BM_APPKEY
EEPROM_ORANGE_CMD,
ORANGE_CMD_DEVEUI,
ORANGE_CMD_APPEUI,
ORANGE_CMD_APPKEY
};
provider_t pvd_orange_cmd = PVD_IMPLEM_OTAA(orange_cmd_otta);
......@@ -39,7 +43,7 @@ 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
// &pvd_orange_cmd
};
// Number of defined providers.
......@@ -51,6 +55,7 @@ static provider_t *pvd_all[] = {
*/
void pvd_reset_all(void)
{
DEBUG("[providers] reseting all providers\n");
for (size_t i = 0; i < PVD_COUNT; i++)
pvd_reset(pvd_all[i]);
}
/*
Non-voltaile memory distribution.
Copyright (C) 2019, ENSIMAG students
This project is under the MIT license
*/
/*
iM880A-L board has a 128 KB flash memory and 4 KB EEPROM.
OTAA join cache takes 32 bytes + 4 bytes for the frame counter.
*/
// EEPROM space for join cache (36 bytes).
#define EEPROM_ORANGE_BM 0
#define EEPROM_ORANGE_CMD 36
......@@ -9,6 +9,11 @@ This project is under the MIT license
// Orange provider for benchmark.
#define ORANGE_BM_DEVEUI { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
#define ORANGE_BM_APPEUI { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
#define ORANGE_BM_APPKEY { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
#define ORANGE_BM_DEVEUI { 0x0A, 0x5A, 0xCB, 0x4B, 0x41, 0xB9, 0x5E, 0x50 }
#define ORANGE_BM_APPEUI { 0xB9, 0x9B, 0xBD, 0xF2, 0x3D, 0xD9, 0xBE, 0xC4 }
#define ORANGE_BM_APPKEY { 0x4B, 0x20, 0xEF, 0x23, 0xB1, 0xC3, 0xA9, 0x39, 0x3F, 0x03, 0x4F, 0x65, 0x27, 0xCA, 0x71, 0xF2 }
// Orange provider for command.
#define ORANGE_CMD_DEVEUI { 0x18, 0xC0, 0x81, 0xB5, 0x70, 0x9C, 0x54, 0x55 }
#define ORANGE_CMD_APPEUI { 0x90, 0x5C, 0x55, 0x55, 0xC7, 0xCD, 0x88, 0xBE }
#define ORANGE_CMD_APPKEY { 0x30, 0xB8, 0xDC, 0x3A, 0xDF, 0x36, 0x30, 0x38, 0x07, 0xD0, 0x3F, 0x02, 0x23, 0x03, 0xB0, 0x3A }
......@@ -15,6 +15,9 @@ LGPLv2.1 license.
// Make OTAA join request in LoRaRIOT thread.
static void _otaa(lorariot_otaa_t *otaa)
{
DEBUG("[lorariot] making OTAA activation\n");
LoRaMacTestRxWindowsOn(true);
MibRequestConfirm_t mibReq;
mibReq.Type = MIB_NETWORK_JOINED;
mibReq.Param.IsNetworkJoined = false;
......@@ -28,11 +31,7 @@ static void _otaa(lorariot_otaa_t *otaa)
mlmeReq.Req.Join.Datarate = otaa->dr;
uint8_t status = LoRaMacMlmeRequest(&mlmeReq);
msg_t msg;
msg.type = LORARIOT_TYPE_LORAMAC_JOIN;
msg.content.value = status;
msg_send(&msg, lorariot.caller_pid);
lorariot_debug_status("MLME join", status);
}
......
......@@ -10,8 +10,6 @@ LGPLv2.1 license.
#include "controller.h"
#include <debug.h>
#include <net/netdev/lora.h>
#include <net/loramac.h>
......@@ -67,14 +65,17 @@ void *lorariot_event_loop(void *arg)
} break;
case LORARIOT_TYPE_RX_TIMEOUT: {
DEBUG("[lorariot] RX timer timeout\n");
lorariot_radio_ev.RxTimeout();
} break;
case LORARIOT_TYPE_TX_TIMEOUT: {
DEBUG("[lorariot] TX timer timeout\n");
lorariot_radio_ev.TxTimeout();
} break;
case LORARIOT_TYPE_MAC_TIMEOUT: {
DEBUG("[lorariot] MAC timer timeout\n");
void (*callback)(void) = msg.content.ptr;
callback();
} break;
......@@ -94,7 +95,7 @@ void *lorariot_event_loop(void *arg)
} break;
default:
DEBUG("[semtech-loramac] Unexpected msg type '%04x'\n", msg.type);
DEBUG("[lorariot] Unexpected msg type '%04x'\n", msg.type);
}
}
}
......@@ -139,8 +140,9 @@ int lorariot_init(void)
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);
LoRaMacStatus_t status = LoRaMacInitialization(&lorariot_radio_ev,
&lorariot_primitives, &lorariot_callbacks, LORAMAC_REGION_IMAG);
lorariot_debug_status("init", status);
return 0;
}
......@@ -33,9 +33,10 @@ void lorariot_mcps_confirm(McpsConfirm_t *confirm)
void lorariot_mlme_confirm(MlmeConfirm_t *confirm)
{
DEBUG("[lorariot] MLME confirm event: %d\n", confirm->MlmeRequest);
lorariot_debug_status_ev("MLME confirm", confirm->Status);
switch (confirm->MlmeRequest) {
case MLME_JOIN: {
DEBUG("[lorariot] join response: %d\n", confirm->Status);
msg_t msg;
msg.type = LORARIOT_TYPE_LORAMAC_JOIN;
msg.content.value = confirm->Status;
......
......@@ -93,7 +93,7 @@ static bool VerifyTxFreq(uint32_t freq, uint8_t *band)
* \brief Count and get enabled channels (for TX).
*
* \param [IN] joined Have we joined with the backend server?
* \param [IN] datarate Datarate to use on the channel (DR_0 to DR_5).
* \param [IN] datarate Datarate to use on the channel (DR_CUSTOM to DR_6).
* \param [IN] channelsMask ???
* \param [IN] channels ???
* \param [IN] bands ???
......@@ -119,7 +119,8 @@ static uint8_t CountNbOfEnabledChannels(bool joined, int8_t datarate, uint16_t *
continue; // Channel can't be used for join requests.
}
if (RegionCommonValueInRange(datarate, channels[i + j].DrRange.Fields.Min,
if (datarate != DR_CUSTOM &&
RegionCommonValueInRange(datarate, channels[i + j].DrRange.Fields.Min,
channels[i + j].DrRange.Fields.Max) == false)
{ // Check if the current channel selection supports the given datarate.
continue;
......@@ -645,9 +646,9 @@ LoRaMacStatus_t RegionIMAGChannelAdd(ChannelAddParams_t* channelAdd)
return LORAMAC_STATUS_PARAMETER_INVALID;
// Validate the datarate range.
if (RegionCommonValueInRange(channelAdd->NewChannel->DrRange.Fields.Min, DR_CUSTOM, DR_5) == false)
if (RegionCommonValueInRange(channelAdd->NewChannel->DrRange.Fields.Min, DR_0, DR_5) == false)
drInvalid = true;
if (RegionCommonValueInRange(channelAdd->NewChannel->DrRange.Fields.Max, DR_CUSTOM, DR_5) == false)
if (RegionCommonValueInRange(channelAdd->NewChannel->DrRange.Fields.Max, DR_0, DR_5) == false)
drInvalid = true;
if (channelAdd->NewChannel->DrRange.Fields.Min > channelAdd->NewChannel->DrRange.Fields.Max)
drInvalid = true;
......
......@@ -173,19 +173,19 @@ This project is under the MIT license
* LoRaMac default channel 1
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
#define IMAG_LC1 { 868100000, 0, { ( ( DR_5 << 4 ) | -1 ) }, 1 }
#define IMAG_LC1 { 868100000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
/*!
* LoRaMac default channel 2
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
#define IMAG_LC2 { 868300000, 0, { ( ( DR_5 << 4 ) | -1 ) }, 1 }
#define IMAG_LC2 { 868300000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
/*!
* LoRaMac default channel 3
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
#define IMAG_LC3 { 868500000, 0, { ( ( DR_5 << 4 ) | -1 ) }, 1 }
#define IMAG_LC3 { 868500000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
/*!
* LoRaMac channels which are allowed for the join procedure
......
......@@ -66,7 +66,7 @@ bool RegionIMAGTxConfig(TxConfigParams_t *txConfig, int8_t *txPower, TimerTime_t
// parameters (CRC, fixLen) are fixed.
// Calculate physical TX power.
int8_t phyTxPower = (txConfig->Datarate == DR_CUSTOM) ?
int8_t phyTxPower = (CustomParams.Power != 0) ?
CustomParams.Power : LimitAndComputeTxPowerIMAG(txConfig);
// Get the datarate to use (custom or default one).
......@@ -75,10 +75,10 @@ bool RegionIMAGTxConfig(TxConfigParams_t *txConfig, int8_t *txPower, TimerTime_t
// Get bandwidth to use.
uint32_t bandwidth = (txConfig->Datarate == DR_CUSTOM) ?
CustomParams.Bandwidth : 0 /* BW125 */ ;
CustomParams.Bandwidth : 0 /* BW125 */ ; // TODO: fix value for DR_6.
// Get coderate to use.
uint8_t coderate = (txConfig->Datarate == DR_CUSTOM) ?
uint8_t coderate = (CustomParams.Coderate != 0) ?
CustomParams.Coderate : 1 /* 4/5 */ ;
// Now transmit these parameters to radio module.
......@@ -111,7 +111,7 @@ void RegionIMAGComputeRxWindowParameters(int8_t datarate, uint8_t minRxSymbols,
rxConfigParams->Datarate = MIN(datarate, DR_5);
// TODO: is the server always using a BW of 125 kHz?
rxConfigParams->Bandwidth = 0 /* BW125 */ ;
rxConfigParams->Bandwidth = 0 /* BW125 */ ; // TODO: fix value for DR_6.
uint8_t phyDr = (datarate == DR_CUSTOM) ?
CustomParams.Datarate : DataratesIMAG[rxConfigParams->Datarate];
......
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