kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Minor improvements and debug for LoRaWAN code
rodzic
486f09396b
commit
1ca21bc39b
|
@ -1 +1 @@
|
||||||
tar cvzf esp32-ogn-tracker-bin.tgz flash_USB?.sh esptool.py build/partitions.bin build/bootloader/bootloader.bin build/app-template.bin
|
tar cvzf esp32-ogn-tracker-bin.tgz flash_USB?.sh esptool.py build/partitions.bin build/bootloader/bootloader.bin build/app-template.bin utils/read_log utils/serial_dump
|
||||||
|
|
|
@ -830,14 +830,22 @@ void OLED_DrawLoRaWAN(u8g2_t *OLED, GPS_Position *GPS) // draw LoRaWAN status pa
|
||||||
#ifdef WITH_LORAWAN
|
#ifdef WITH_LORAWAN
|
||||||
const char *StateName[4] = { "Not-Joined", "Join-Req", "+Joined+", "PktSend" } ;
|
const char *StateName[4] = { "Not-Joined", "Join-Req", "+Joined+", "PktSend" } ;
|
||||||
int Len=Format_String(Line, "LoRaWAN: ");
|
int Len=Format_String(Line, "LoRaWAN: ");
|
||||||
if(WANdev.State<=3) Len+=Format_String(Line+Len, StateName[WANdev.State]);
|
if(WANdev.State==2) Len+=Format_Hex(Line+Len, WANdev.DevAddr);
|
||||||
|
else if(WANdev.State<=3) Len+=Format_String(Line+Len, StateName[WANdev.State]);
|
||||||
else Len+=Format_Hex(Line+Len, WANdev.State);
|
else Len+=Format_Hex(Line+Len, WANdev.State);
|
||||||
Line[Len]=0;
|
Line[Len]=0; u8g2_DrawStr(OLED, 0, 24, Line);
|
||||||
u8g2_DrawStr(OLED, 0, 24, Line);
|
|
||||||
Len =Format_String(Line , "Up: "); Len+=Format_Hex(Line+Len, (uint16_t)WANdev.UpCount);
|
Len =Format_String(Line , "Up: "); Len+=Format_Hex(Line+Len, (uint16_t)WANdev.UpCount);
|
||||||
Len+=Format_String(Line+Len, " Dn: "); Len+=Format_Hex(Line+Len, (uint16_t)WANdev.DnCount);
|
Len+=Format_String(Line+Len, " Dn: "); Len+=Format_Hex(Line+Len, (uint16_t)WANdev.DnCount);
|
||||||
Line[Len]=0;
|
Line[Len]=0; u8g2_DrawStr(OLED, 0, 36, Line);
|
||||||
u8g2_DrawStr(OLED, 0, 36, Line);
|
|
||||||
|
Len =Format_String(Line , "Rx:");
|
||||||
|
Len+=Format_SignDec(Line+Len, (int16_t)WANdev.RxRSSI, 3);
|
||||||
|
Len+=Format_String(Line+Len, "dBm ");
|
||||||
|
Len+=Format_SignDec(Line+Len, ((int16_t)WANdev.RxSNR*10+2)>>2, 2, 1);
|
||||||
|
Len+=Format_String(Line+Len, "dB");
|
||||||
|
Line[Len]=0; u8g2_DrawStr(OLED, 0, 48, Line);
|
||||||
|
|
||||||
// if(WANdev.State>=2) { }
|
// if(WANdev.State>=2) { }
|
||||||
/*
|
/*
|
||||||
Len=0;
|
Len=0;
|
||||||
|
|
|
@ -33,7 +33,7 @@ class LoRaWANnode
|
||||||
uint32_t LastTx; // [sec] last transmission
|
uint32_t LastTx; // [sec] last transmission
|
||||||
uint32_t RxCount; // [packets] received from the network
|
uint32_t RxCount; // [packets] received from the network
|
||||||
uint32_t LastRx; // [sec] when last heard from the network
|
uint32_t LastRx; // [sec] when last heard from the network
|
||||||
uint8_t RxSNR; // SNR on receive
|
int8_t RxSNR; // [0.25dB] SNR on receive
|
||||||
int8_t RxRSSI; // [dBm] signal strength
|
int8_t RxRSSI; // [dBm] signal strength
|
||||||
union
|
union
|
||||||
{ uint8_t Flags;
|
{ uint8_t Flags;
|
||||||
|
|
|
@ -123,7 +123,7 @@ void app_main(void)
|
||||||
#ifdef WITH_SOUND
|
#ifdef WITH_SOUND
|
||||||
xTaskCreate(vTaskSOUND, "SOUND", 2048, 0, tskIDLE_PRIORITY+3, 0);
|
xTaskCreate(vTaskSOUND, "SOUND", 2048, 0, tskIDLE_PRIORITY+3, 0);
|
||||||
#endif
|
#endif
|
||||||
xTaskCreate(vTaskTICK , "TICK", 1024, 0, tskIDLE_PRIORITY+2, 0);
|
xTaskCreate(vTaskTICK , "TICK", 1024, 0, tskIDLE_PRIORITY+3, 0);
|
||||||
// xTaskCreate(vTaskCTRL, "CTRL", 1536, 0, tskIDLE_PRIORITY+2, 0);
|
// xTaskCreate(vTaskCTRL, "CTRL", 1536, 0, tskIDLE_PRIORITY+2, 0);
|
||||||
vTaskCTRL(0); // run directly the CTRL task, instead of creating a separate one.
|
vTaskCTRL(0); // run directly the CTRL task, instead of creating a separate one.
|
||||||
|
|
||||||
|
|
57
main/rf.cpp
57
main/rf.cpp
|
@ -204,7 +204,7 @@ static uint8_t StartRFchip(void)
|
||||||
#endif
|
#endif
|
||||||
return Version; } // read the RF chip version and return it
|
return Version; } // read the RF chip version and return it
|
||||||
|
|
||||||
static TickType_t WAN_RespTick = xTaskGetTickCount(); // when to expect the WAN response
|
static TickType_t WAN_RespTick = 0; // when to expect the WAN response
|
||||||
static RFM_LoRa_RxPacket WAN_RxPacket; // packet received from WAN
|
static RFM_LoRa_RxPacket WAN_RxPacket; // packet received from WAN
|
||||||
// static WAN_Setup()
|
// static WAN_Setup()
|
||||||
// static WAN_Back()
|
// static WAN_Back()
|
||||||
|
@ -273,16 +273,16 @@ extern "C"
|
||||||
{ if(WAN_RespLeft<=5) WANdev.State--;
|
{ if(WAN_RespLeft<=5) WANdev.State--;
|
||||||
else if(WAN_RespLeft<200) { WANrx=1; }
|
else if(WAN_RespLeft<200) { WANrx=1; }
|
||||||
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
||||||
Format_String(CONS_UART_Write, "LoRaWAN Rx: ");
|
Format_UnsDec(CONS_UART_Write, xTaskGetTickCount(), 4, 3);
|
||||||
|
Format_String(CONS_UART_Write, "s LoRaWAN Rx: ");
|
||||||
Format_SignDec(CONS_UART_Write, WAN_RespLeft);
|
Format_SignDec(CONS_UART_Write, WAN_RespLeft);
|
||||||
Format_String(CONS_UART_Write, "ms ");
|
|
||||||
Format_UnsDec(CONS_UART_Write, xTaskGetTickCount());
|
|
||||||
Format_String(CONS_UART_Write, "ms\n");
|
Format_String(CONS_UART_Write, "ms\n");
|
||||||
xSemaphoreGive(CONS_Mutex);
|
xSemaphoreGive(CONS_Mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(WANrx)
|
if(WANrx) // if reception expected from WAN
|
||||||
{ TRX.WriteMode(RF_OPMODE_STANDBY); // TRX to standby
|
{ int RxLen=0;
|
||||||
|
TRX.WriteMode(RF_OPMODE_STANDBY); // TRX to standby
|
||||||
TRX.setLoRa(); // switch to LoRa mode (through sleep)
|
TRX.setLoRa(); // switch to LoRa mode (through sleep)
|
||||||
TRX.WriteMode(RF_OPMODE_LORA_STANDBY); // TRX in standby
|
TRX.WriteMode(RF_OPMODE_LORA_STANDBY); // TRX in standby
|
||||||
SetFreqPlanWAN(); // WAN frequency plan
|
SetFreqPlanWAN(); // WAN frequency plan
|
||||||
|
@ -290,31 +290,37 @@ extern "C"
|
||||||
TRX.setChannel(WANdev.Chan); // set the channel
|
TRX.setChannel(WANdev.Chan); // set the channel
|
||||||
TRX.LoRa_InvertIQ(1); TRX.LoRa_setCRC(0); TRX.LoRa_setIRQ(0); // setup for WAN RX
|
TRX.LoRa_InvertIQ(1); TRX.LoRa_setCRC(0); TRX.LoRa_setIRQ(0); // setup for WAN RX
|
||||||
TRX.WriteMode(RF_OPMODE_LORA_RX_SINGLE); // wait for a single packet
|
TRX.WriteMode(RF_OPMODE_LORA_RX_SINGLE); // wait for a single packet
|
||||||
int Wait=WAN_RespLeft+100;
|
int Wait=WAN_RespLeft+100; // 100ms timeout after the expected reception
|
||||||
for( ; Wait>0; Wait--)
|
for( ; Wait>0; Wait--)
|
||||||
{ vTaskDelay(1);
|
{ vTaskDelay(1);
|
||||||
if(TRX.readIRQ()) break; }
|
if(TRX.readIRQ()) break; } // IRQ signals packet reception
|
||||||
if(Wait)
|
if(Wait)
|
||||||
{ TRX.LoRa_ReceivePacket(WAN_RxPacket);
|
{ TRX.LoRa_ReceivePacket(WAN_RxPacket);
|
||||||
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
||||||
Format_String(CONS_UART_Write, "LoRaWAN Rx: ");
|
Format_UnsDec(CONS_UART_Write, xTaskGetTickCount(), 4, 3);
|
||||||
|
Format_String(CONS_UART_Write, "s LoRaWAN Rx: ");
|
||||||
Format_UnsDec(CONS_UART_Write, (uint16_t)WAN_RxPacket.Len);
|
Format_UnsDec(CONS_UART_Write, (uint16_t)WAN_RxPacket.Len);
|
||||||
Format_String(CONS_UART_Write, "B/");
|
Format_String(CONS_UART_Write, "B/");
|
||||||
Format_UnsDec(CONS_UART_Write, (unsigned)Wait);
|
Format_UnsDec(CONS_UART_Write, (unsigned)Wait);
|
||||||
Format_String(CONS_UART_Write, "ms ");
|
|
||||||
Format_UnsDec(CONS_UART_Write, xTaskGetTickCount());
|
|
||||||
Format_String(CONS_UART_Write, "ms\n");
|
Format_String(CONS_UART_Write, "ms\n");
|
||||||
xSemaphoreGive(CONS_Mutex);
|
xSemaphoreGive(CONS_Mutex);
|
||||||
if(WANdev.State==1) WANdev.procJoinAccept(WAN_RxPacket);
|
if(WANdev.State==1) WANdev.procJoinAccept(WAN_RxPacket); // if join-request state then expect a join-accept packet
|
||||||
else if(WANdev.State==3) WANdev.procRxData(WAN_RxPacket);
|
else if(WANdev.State==3) RxLen=WANdev.procRxData(WAN_RxPacket); // if data send then respect ACK and/or downlink data packet
|
||||||
}
|
}
|
||||||
else WANdev.State--;
|
else WANdev.State--;
|
||||||
WANdev.WriteToNVS();
|
|
||||||
TRX.setFSK(); // back to FSK
|
TRX.setFSK(); // back to FSK
|
||||||
SetFreqPlanOGN(); // OGN frequency plan
|
SetFreqPlanOGN(); // OGN frequency plan
|
||||||
TRX.OGN_Configure(0, OGN_SYNC); // OGN config
|
TRX.OGN_Configure(0, OGN_SYNC); // OGN config
|
||||||
SetRxChannel();
|
SetRxChannel();
|
||||||
TRX.WriteMode(RF_OPMODE_RECEIVER); // switch to receive mode
|
TRX.WriteMode(RF_OPMODE_RECEIVER); // switch to receive mode
|
||||||
|
WANdev.WriteToNVS(); // store new WAN state in flash
|
||||||
|
if(RxLen>0) // if Downlink data received
|
||||||
|
{ xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
||||||
|
Format_String(CONS_UART_Write, "LoRaWAN Msg: ");
|
||||||
|
Format_UnsDec(CONS_UART_Write, (uint16_t)RxLen);
|
||||||
|
Format_String(CONS_UART_Write, "B");
|
||||||
|
Format_String(CONS_UART_Write, "\n");
|
||||||
|
xSemaphoreGive(CONS_Mutex); }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#else
|
#else
|
||||||
|
@ -412,17 +418,17 @@ extern "C"
|
||||||
const FANET_Packet *FNTpkt = FNT_TxFIFO.getRead(0); // read the packet from the FANET transmitt queue
|
const FANET_Packet *FNTpkt = FNT_TxFIFO.getRead(0); // read the packet from the FANET transmitt queue
|
||||||
if(FNTpkt) // was there any ?
|
if(FNTpkt) // was there any ?
|
||||||
{ TRX.setLoRa(); // switch TRX to LoRa
|
{ TRX.setLoRa(); // switch TRX to LoRa
|
||||||
TRX.FNT_Configure();
|
TRX.FNT_Configure(); // configure for FANET
|
||||||
// TRX.setChannel(0); // configure for FANET
|
// TRX.setChannel(0); // configure for FANET
|
||||||
TRX.WriteTxPower(Parameters.getTxPower());
|
TRX.WriteTxPower(Parameters.getTxPower()); // transmission power
|
||||||
TRX.WriteMode(RF_OPMODE_LORA_RX_CONT);
|
TRX.WriteMode(RF_OPMODE_LORA_RX_CONT); // continous receiver mode
|
||||||
vTaskDelay(2);
|
vTaskDelay(2);
|
||||||
for(uint8_t Wait=50; Wait; Wait--)
|
for(uint8_t Wait=50; Wait; Wait--) //
|
||||||
{ vTaskDelay(1);
|
{ vTaskDelay(1); // every milisecond
|
||||||
uint8_t Stat = TRX.ReadByte(REG_LORA_MODEM_STATUS);
|
uint8_t Stat = TRX.ReadByte(REG_LORA_MODEM_STATUS); // receiver status
|
||||||
if((Stat&0x0B)==0) break; }
|
if((Stat&0x0B)==0) break; } // 0:signal-det, 1:signal-sync, 3:header-valid
|
||||||
TRX.WriteMode(RF_OPMODE_LORA_STANDBY);
|
TRX.WriteMode(RF_OPMODE_LORA_STANDBY);
|
||||||
TRX.FNT_SendPacket(FNTpkt->Byte, FNTpkt->Len);
|
TRX.FNT_SendPacket(FNTpkt->Byte, FNTpkt->Len); // transmit the FANET packet
|
||||||
FNT_TxFIFO.Read(); // remove the last packet from the queue
|
FNT_TxFIFO.Read(); // remove the last packet from the queue
|
||||||
/*
|
/*
|
||||||
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
||||||
|
@ -500,11 +506,10 @@ extern "C"
|
||||||
if(Mode!=RF_OPMODE_LORA_TX) break; }
|
if(Mode!=RF_OPMODE_LORA_TX) break; }
|
||||||
WAN_RespTick=xTaskGetTickCount()+RespDelay; // when to expect the response: 5sec after the end of Join-Request packet
|
WAN_RespTick=xTaskGetTickCount()+RespDelay; // when to expect the response: 5sec after the end of Join-Request packet
|
||||||
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
||||||
Format_String(CONS_UART_Write, "LoRaWAN Tx: ");
|
Format_UnsDec(CONS_UART_Write, xTaskGetTickCount(), 4, 3);
|
||||||
|
Format_String(CONS_UART_Write, "s LoRaWAN Tx: ");
|
||||||
Format_UnsDec(CONS_UART_Write, (unsigned)TxPktLen);
|
Format_UnsDec(CONS_UART_Write, (unsigned)TxPktLen);
|
||||||
Format_String(CONS_UART_Write, "B ");
|
Format_String(CONS_UART_Write, "B\n");
|
||||||
Format_UnsDec(CONS_UART_Write, xTaskGetTickCount());
|
|
||||||
Format_String(CONS_UART_Write, "ms\n");
|
|
||||||
xSemaphoreGive(CONS_Mutex);
|
xSemaphoreGive(CONS_Mutex);
|
||||||
}
|
}
|
||||||
TRX.setFSK(); // back to FSK
|
TRX.setFSK(); // back to FSK
|
||||||
|
|
Ładowanie…
Reference in New Issue