Skip to content

Commit

Permalink
Resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
pjalocha committed Dec 21, 2021
2 parents 695817d + c2380d8 commit 2d8315e
Show file tree
Hide file tree
Showing 11 changed files with 584 additions and 140 deletions.
2 changes: 1 addition & 1 deletion bin-arch.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tar cvzf esp32-ogn-tracker-bin.tgz flash_USB?.sh esptool.py build/partitions.bin build/bootloader/bootloader.bin build/esp32-ogn-tracker.bin utils/read_log utils/serial_dump main/config.h
tar cvzf esp32-ogn-tracker-bin.tgz flash_USB?.sh flash_COM?.bat esptool.py build/partitions.bin build/bootloader/bootloader.bin build/esp32-ogn-tracker.bin utils/read_log utils/serial_dump main/config.h
27 changes: 20 additions & 7 deletions main/bt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,28 +427,39 @@ static void esp_ble_gatts_cb(esp_gatts_cb_event_t Event, esp_gatt_if_t gatts_if,
break;
case ESP_GATTS_START_EVT: // #12
break;
case ESP_GATTS_UNREG_EVT: // #6
case ESP_GATTS_STOP_EVT: //
break;
case ESP_GATTS_MTU_EVT: // #4
spp_mtu_size = Param->mtu.mtu;
case ESP_GATTS_UNREG_EVT: // #6
break;
case ESP_GATTS_CONNECT_EVT: // #14
case ESP_GATTS_CONNECT_EVT: // #14 = GATT client connect
spp_conn_id = Param->connect.conn_id;
spp_gatts_if = gatts_if;
is_connected = true;
memcpy(&spp_remote_bda, &Param->connect.remote_bda, sizeof(esp_bd_addr_t));
break;
case ESP_GATTS_DISCONNECT_EVT: // #15
case ESP_GATTS_DISCONNECT_EVT: // #15 = GATT client disconnect
is_connected = false;
esp_ble_gap_start_advertising(&spp_adv_params);
break;
case ESP_GATTS_MTU_EVT: // #4 = set MTU complete
spp_mtu_size = Param->mtu.mtu;
break;
case ESP_GATTS_READ_EVT: // #1 = request read operation
break;
case ESP_GATTS_WRITE_EVT: // #2 = request write operation
break;
case ESP_GATTS_EXEC_WRITE_EVT: // #3 = request execute write opearation
// if(Param->exec_write.exec_write_flag) { }
break;
default:
break;
}

xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
Format_String(CONS_UART_Write, "BLE_GATTS: Event ");
Format_UnsDec(CONS_UART_Write, (uint32_t)Event);
Format_String(CONS_UART_Write, ".");
Format_UnsDec(CONS_UART_Write, (uint32_t)gatts_if);
Format_String(CONS_UART_Write, "\n");
xSemaphoreGive(CONS_Mutex);
}
Expand All @@ -468,6 +479,8 @@ static void esp_ble_gap_cb(esp_gap_ble_cb_event_t Event, esp_ble_gap_cb_param_t
break;
case ESP_GAP_BLE_AUTH_CMPL_EVT: // #8 = AUTHentication CoMPLete
break;
case ESP_GAP_BLE_KEY_EVT: // #9 =
break;
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: // #6 = starting advertise complete
break;
default:
Expand Down Expand Up @@ -504,8 +517,8 @@ int BT_SPP_Init(void)
Err = esp_bt_controller_enable((esp_bt_mode_t)BTconf.mode); if(Err!=ESP_OK) return Err; // mode must be same as in BTconf
Err = esp_bluedroid_init(); if(Err!=ESP_OK) return Err; // init the BT stack
Err = esp_bluedroid_enable(); if(Err!=ESP_OK) return Err; // enable the BT stack
Err = esp_ble_gap_register_callback(esp_ble_gap_cb); if(Err!=ESP_OK) return Err;
Err = esp_ble_gatts_register_callback(esp_ble_gatts_cb); if(Err!=ESP_OK) return Err;
Err = esp_ble_gap_register_callback(esp_ble_gap_cb); if(Err!=ESP_OK) return Err; // GAP callback
Err = esp_ble_gatts_register_callback(esp_ble_gatts_cb); if(Err!=ESP_OK) return Err; // GATTS callback
Err = esp_ble_gatts_app_register(ESP_SPP_APP_ID); if(Err!=ESP_OK) return Err;

esp_ble_io_cap_t IOcap = ESP_IO_CAP_NONE; // no input and no output capabilities
Expand Down
10 changes: 7 additions & 3 deletions main/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "driver/adc.h"
#include "esp_adc_cal.h"

#if ESP_IDF_VERSION_MINOR>=3
#include "soc/adc_channel.h" // v4.3
#endif

#include "esp_system.h"
#include "esp_freertos_hooks.h"

Expand Down Expand Up @@ -278,7 +282,7 @@ GPIO HELTEC TTGO JACEK M5_JACEK T-Beam T-Beamv10 Foll

#ifdef WITH_TBEAM_V10
#ifdef WITH_SX1262
#define PIN_RFM_BUSY GPIO_NUM_32 // for the T-Beam with SX1262
#define PIN_RFM_BUSY GPIO_NUM_32 // for the T-Beam with SX1262 (watch for conflict with the LCD)
#endif
#endif

Expand All @@ -302,7 +306,7 @@ GPIO HELTEC TTGO JACEK M5_JACEK T-Beam T-Beamv10 Foll

#define RFM_SPI_HOST VSPI_HOST // or H or VSPI_HOST ?
#define RFM_SPI_DMA 1 // DMA channel
#define RFM_SPI_SPEED 4000000 // [Hz] 4MHz SPI clock rate for RF chip
#define RFM_SPI_SPEED 4000000 // [Hz] 2MHz SPI clock rate for RF chip

#ifdef WITH_ST7789
#ifdef WITH_TBEAM // old T-Beam
Expand Down Expand Up @@ -1726,7 +1730,7 @@ void IO_Configuration(void)
input_delay_ns : 0,
spics_io_num : PIN_RFM_SS,
flags : 0,
queue_size : 3,
queue_size : 1,
pre_cb : 0,
post_cb : 0
};
Expand Down
41 changes: 29 additions & 12 deletions main/lorawan.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class LoRaWANnode
uint32_t JoinNonce; // from Join-Accept: unique must not be reused
uint32_t HomeNetID; // from Join-Accept: Home Network ID
uint32_t DevAddr; // from Join-Accept: Device Address
uint8_t DLsetting; // from Join-Accept: DownLink configuration: OptNeg | RX1DRoffset | RX2 data rate
uint8_t RxDelay; // from Join-Accept:
uint8_t DLsetting; // from Join-Accept: DownLink configuration: OptNeg:1 | RX1 data rate offset:3 | RX2 data rate:4
uint8_t RxDelay; // from Join-Accept: RFU:4 | Del:4 Del=1..15s for the RX1, RX2 delay is Del+1
uint8_t State; // 0:disconencted, 1:join-request sent, 2:join-accept received, 3:uplink-packet sent
uint8_t Chan; // [0..7] Current channel being used
uint32_t UpCount; // [seq] Uplink frame counter: reset when joining the network
Expand Down Expand Up @@ -59,6 +59,9 @@ class LoRaWANnode
if(AppKey) memcpy(this->AppKey, AppKey, 16);
Reset(); }

void Disconnect(void)
{ State=0; }

uint8_t incrChan(uint8_t Step=1) { Chan+=Step; if(Chan>=Chans) Chan-=Chans; return Chan; }

int Save(FILE *File) { return fwrite(this, sizeof(LoRaWANnode), 1, File); }
Expand Down Expand Up @@ -172,24 +175,26 @@ class LoRaWANnode
{ int Len=getDataPacket(Packet, Data, DataLen, Port, Confirm); *Pkt = Packet; return Len; }

int procRxData(const RFM_LoRa_RxPacket &RxPacket)
{ int Ret=procRxData(RxPacket.Byte, RxPacket.Len); if(Ret<0) return Ret;
RxSNR += (RxPacket.SNR-RxSNR+1)/2;
{ int Ret = procRxData(RxPacket.Byte, RxPacket.Len); if(Ret<0) return Ret;
RxSNR += (RxPacket.SNR-RxSNR+1)/2; // if good packet then update the signal statistics
RxRSSI += (RxPacket.RSSI-RxRSSI+1)/2;
return Ret; }

int procRxData(const uint8_t *PktData, int PktLen)
{ if(PktLen<12) return -1;
uint8_t Type = PktData[0]>>5; if(Type!=3 && Type!=5) return -1;
uint32_t Addr=readInt<uint32_t>(PktData+1, 4);
if(Addr!=DevAddr) return 0;
uint8_t Ctrl = PktData[5]; // Frame control: ADR | RFU | ACK | FPending | FOptLen[4]
uint32_t Count=readInt<uint32_t>(PktData+6, 2);
int16_t CountDiff = Count-DnCount; //
if(CountDiff<=0) return -1; // attempt to reuse the counter: drop this packet
uint8_t Type = PktData[0]>>5; if(Type!=3 && Type!=5) return -1; // Frame Type: 3=unconfirmed data downlink, 5=confirmed data downlink
uint32_t Addr=readInt<uint32_t>(PktData+1, 4); // device address
if(Addr!=DevAddr) return 0; // check if packet is for us (it could be for somebody else)
uint8_t Ctrl = PktData[5]; // Frame Control: ADR | RFU | ACK | FPending | FOptLen[4]
uint32_t Count = readInt<uint32_t>(PktData+6, 2); // download counter
int16_t CountDiff = Count-DnCount; // how many we have missed ?
if(CountDiff<=0) return -1; // attempt to reuse the counter: drop this packet
uint32_t MIC=0;
LoRaMacComputeMic(PktData, PktLen-4, NetSesKey, Addr, 0x01, Count, &MIC);
if(memcmp(PktData+PktLen-4, &MIC, 4)) return -1; // give up if MIC does not match
uint8_t DataOfs = 8 + (Ctrl&0x0F); // where the port byte should be
uint8_t OptLen = Ctrl&0x0F; // Options: how many bytes
uint8_t DataOfs = 8 + OptLen; // where the port byte should be
if(OptLen) procRxOpt(PktData+8, OptLen); // process the options (these are not encrypted)
uint8_t DataLen = PktLen-DataOfs-4; // number of bytes of the user data field
if(DataLen) // if non-zero
{ Packet[0] = PktData[DataOfs]; // copy port number
Expand All @@ -205,8 +210,20 @@ class LoRaWANnode
if(Type==5) TxACK=1; // if ACK requested
RxPend = Ctrl&0x10; // is there more data pending to be received on next round ?
State=2;
// if(DataLen==0)
// { Packet[0]=0x00; DataLen++; // copy MAC commands to user buffer for debug
// for(uint8_t Idx=0; Idx<OptLen; Idx++)
// { Packet[DataLen++] = PktData[8+Idx]; }
// }
return DataLen; }

void procRxOpt(const uint8_t *Opt, uint8_t Len) // process the options
{ }
// { Format_String(CONS_UART_Write, "LoRaWAN Opt: ");
// for(uint8_t Idx=0; Idx<Len; Idx++)
// Format_Hex(CONS_UART_Write, Opt[Idx]);
// Format_String(CONS_UART_Write, "\n"); }

#ifdef WITH_ESP32
esp_err_t WriteToNVS(const char *Name="LoRaWAN", const char *NameSpace="TRACKER")
{ nvs_handle Handle;
Expand Down
1 change: 1 addition & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void app_main(void)
{ WANdev.Reset(getUniqueID(), Parameters.AppKey); // then reset LoRaWAN to this key
WANdev.WriteToNVS(); } // and save LoRaWAN config. to NVS
Parameters.clrAppKey(); }
WANdev.Disconnect(); // restart with network join-request/accept at each restart
#endif

CONS_UART_SetBaudrate(Parameters.CONbaud);
Expand Down
Loading

0 comments on commit 2d8315e

Please sign in to comment.