commit
2c7c2da4ad
@ -42,7 +42,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I
|
||||
|
||||
[common]
|
||||
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
|
||||
release_version = 1.7.979
|
||||
release_version = 1.8.0
|
||||
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
|
||||
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
|
||||
debug_level = 3
|
||||
|
@ -9,8 +9,8 @@ nvs_handle my_handle;
|
||||
esp_err_t err;
|
||||
|
||||
#define PAYLOADMASK \
|
||||
(GPS_DATA | ALARM_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | \
|
||||
SENSOR2_DATA | SENSOR3_DATA & ~BATT_DATA)
|
||||
((GPS_DATA | ALARM_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | \
|
||||
SENSOR2_DATA | SENSOR3_DATA) & ~BATT_DATA)
|
||||
|
||||
// populate cfg vars with factory settings
|
||||
void defaultConfig() {
|
||||
|
@ -21,10 +21,7 @@
|
||||
|
||||
// use interrupts only if LORA_IRQ and LORA_DIO are connected to interrupt
|
||||
// capable GPIO pins on your board, if not disable interrupts
|
||||
//#define LMIC_USE_INTERRUPTS 1
|
||||
|
||||
// needed for paxcounter code
|
||||
#define LMIC_ENABLE_user_events 1
|
||||
#define LMIC_USE_INTERRUPTS 1
|
||||
|
||||
// time sync via LoRaWAN network, note: not supported by TTNv2
|
||||
// #define LMIC_ENABLE_DeviceTimeReq 1
|
||||
|
@ -21,6 +21,23 @@ static const char TAG[] = "lora";
|
||||
QueueHandle_t LoraSendQueue;
|
||||
TaskHandle_t lmicTask = NULL, lorasendTask = NULL;
|
||||
|
||||
// table of LORAWAN MAC messages sent by the network to the device
|
||||
// format: opcode, cmdname (max 19 chars), #bytes params
|
||||
// source: LoRaWAN 1.1 Specification (October 11, 2017)
|
||||
|
||||
static mac_t table[] = {
|
||||
{0x01, "ResetConf", 1}, {0x02, "LinkCheckAns", 2},
|
||||
{0x03, "LinkADRReq", 4}, {0x04, "DutyCycleReq", 1},
|
||||
{0x05, "RXParamSetupReq", 4}, {0x06, "DevStatusReq", 0},
|
||||
{0x07, "NewChannelReq", 5}, {0x08, "RxTimingSetupReq", 1},
|
||||
{0x09, "TxParamSetupReq", 1}, {0x0A, "DlChannelReq", 4},
|
||||
{0x0B, "RekeyConf", 1}, {0x0C, "ADRParamSetupReq", 1},
|
||||
{0x0D, "DeviceTimeAns", 5}, {0x0E, "ForceRejoinReq", 2},
|
||||
{0x0F, "RejoinParamSetupReq", 1}};
|
||||
|
||||
static const uint8_t cmdtablesize =
|
||||
sizeof(table) / sizeof(table[0]); // number of commands in MAC table
|
||||
|
||||
class MyHalConfig_t : public Arduino_LMIC::HalConfiguration_t {
|
||||
|
||||
public:
|
||||
@ -545,10 +562,6 @@ void lmictask(void *pvParameters) {
|
||||
void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
|
||||
size_t nMsg) {
|
||||
|
||||
// tell the compiler that pUserData is required by the API, but we don't
|
||||
// happen to use it.
|
||||
LMIC_API_PARAMETER(pUserData);
|
||||
|
||||
// display type of received data
|
||||
if (nMsg)
|
||||
ESP_LOGI(TAG, "Received %u bytes of payload on port %u", nMsg, port);
|
||||
@ -560,7 +573,7 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
|
||||
if (port != MACPORT)
|
||||
--nMac;
|
||||
if (nMac) {
|
||||
ESP_LOGI(TAG, "Received %u MAC messages:", nMac);
|
||||
ESP_LOGI(TAG, "Received %u byte MAC message", nMac);
|
||||
// NOT WORKING YET
|
||||
// whe need to strip some protocol overhead from LMIC.frame to unwrap the
|
||||
// MAC command
|
||||
@ -582,9 +595,10 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
|
||||
|
||||
#if (TIME_SYNC_LORASERVER)
|
||||
// valid timesync answer -> call timesync processor
|
||||
if ((port >= TIMEANSWERPORT_MIN) && (port <= TIMEANSWERPORT_MAX))
|
||||
if ((port >= TIMEANSWERPORT_MIN) && (port <= TIMEANSWERPORT_MAX)) {
|
||||
recv_timesync_ans(port, pMsg, nMsg);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
// unknown port -> display info
|
||||
@ -595,34 +609,10 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
|
||||
|
||||
// transmit complete message handler
|
||||
void myTxCallback(void *pUserData, int fSuccess) {
|
||||
|
||||
/* currently no code here */
|
||||
|
||||
// tell the compiler that pUserData is required by the API, but we don't
|
||||
// happen to use it.
|
||||
LMIC_API_PARAMETER(pUserData);
|
||||
}
|
||||
|
||||
// LORAWAN MAC interpreter
|
||||
|
||||
// table of LORAWAN MAC messages sent by the network to the device
|
||||
// format: opcode, cmdname (max 19 chars), #bytes params
|
||||
// source: LoRaWAN 1.1 Specification (October 11, 2017)
|
||||
|
||||
static mac_t table[] = {
|
||||
{0x01, "ResetConf", 1}, {0x02, "LinkCheckAns", 2},
|
||||
{0x03, "LinkADRReq", 4}, {0x04, "DutyCycleReq", 1},
|
||||
{0x05, "RXParamSetupReq", 4}, {0x06, "DevStatusReq", 0},
|
||||
{0x07, "NewChannelReq", 5}, {0x08, "RxTimingSetupReq", 1},
|
||||
{0x09, "TxParamSetupReq", 1}, {0x0A, "DlChannelReq", 4},
|
||||
{0x0B, "RekeyConf", 1}, {0x0C, "ADRParamSetupReq", 1},
|
||||
{0x0D, "DeviceTimeAns", 5}, {0x0E, "ForceRejoinReq", 2},
|
||||
{0x0F, "RejoinParamSetupReq", 1}};
|
||||
|
||||
static const uint8_t cmdtablesize =
|
||||
sizeof(table) / sizeof(table[0]); // number of commands in command table
|
||||
|
||||
// decode mac message
|
||||
// decode LORAWAN MAC message
|
||||
void mac_decode(const uint8_t cmd[], const uint8_t cmdlength) {
|
||||
|
||||
if (!cmdlength)
|
||||
@ -640,15 +630,15 @@ void mac_decode(const uint8_t cmd[], const uint8_t cmdlength) {
|
||||
memmove(foundcmd, cmd + cursor,
|
||||
table[i].params); // strip opcode from cmd array
|
||||
cursor += table[i].params;
|
||||
ESP_LOGI(TAG, "Network command %s", table[i].cmdname);
|
||||
ESP_LOGD(TAG, "Network command %s", table[i].cmdname);
|
||||
} else
|
||||
ESP_LOGI(TAG, "MAC message 0x%02X with missing parameter(s)",
|
||||
ESP_LOGD(TAG, "MAC message 0x%02X with missing parameter(s)",
|
||||
table[i].opcode);
|
||||
break; // command found -> exit table lookup loop
|
||||
} // end of command validation
|
||||
} // end of command table lookup loop
|
||||
if (i < 0) { // command not found -> skip it
|
||||
ESP_LOGI(TAG, "Unknown MAC message 0x%02X", cmd[cursor]);
|
||||
ESP_LOGD(TAG, "Unknown MAC message 0x%02X", cmd[cursor]);
|
||||
cursor++;
|
||||
}
|
||||
} // command parsing loop
|
||||
|
Loading…
Reference in New Issue
Block a user