Skip to content

Commit 8d51126

Browse files
author
Scott Powell
committed
Merge branch 'dev' into regions-request
2 parents 3af2549 + 3eaaf96 commit 8d51126

File tree

9 files changed

+119
-13
lines changed

9 files changed

+119
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Please submit PR's using 'dev' as the base branch!
8989
For minor changes just submit your PR and I'll try to review it, but for anything more 'impactful' please open an Issue first and start a discussion. Is better to sound out what it is you want to achieve first, and try to come to a consensus on what the best approach is, especially when it impacts the structure or architecture of this codebase.
9090

9191
Here are some general principals you should try to adhere to:
92-
* Keep it simple. Please, don't think like a high-level lang programmer. Think embedded, and keep code concise, without any unecessary layers.
92+
* Keep it simple. Please, don't think like a high-level lang programmer. Think embedded, and keep code concise, without any unnecessary layers.
9393
* No dynamic memory allocation, except during setup/begin functions.
9494
* Use the same brace and indenting style that's in the core source modules. (A .clang-format is prob going to be added soon, but please do NOT retroactively re-format existing code. This just creates unnecessary diffs that make finding problems harder)
9595

@@ -106,7 +106,7 @@ There are a number of fairly major features in the pipeline, with no particular
106106
- [ ] Core + Apps: support for LZW message compression
107107
- [ ] Core: dynamic CR (Coding Rate) for weak vs strong hops
108108
- [ ] Core: new framework for hosting multiple virtual nodes on one physical device
109-
- [ ] V2 protocol spec: discussion and concensus around V2 packet protocol, including path hashes, new encryption specs, etc
109+
- [ ] V2 protocol spec: discussion and consensus around V2 packet protocol, including path hashes, new encryption specs, etc
110110

111111
## 📞 Get Support
112112

src/helpers/esp32/SerialWifiInterface.cpp

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ bool SerialWifiInterface::isWriteBusy() const {
4343
return false;
4444
}
4545

46+
bool SerialWifiInterface::hasReceivedFrameHeader() {
47+
return received_frame_header.type != 0 && received_frame_header.length != 0;
48+
}
49+
50+
void SerialWifiInterface::resetReceivedFrameHeader() {
51+
received_frame_header.type = 0;
52+
received_frame_header.length = 0;
53+
}
54+
4655
size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) {
4756
// check if new client connected
4857
auto newClient = server.available();
@@ -54,6 +63,9 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) {
5463

5564
// switch active connection to new client
5665
client = newClient;
66+
67+
// forget received frame header
68+
resetReceivedFrameHeader();
5769

5870
}
5971

@@ -86,13 +98,69 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) {
8698
send_queue[i] = send_queue[i + 1];
8799
}
88100
} else {
89-
int len = client.available();
90-
if (len > 0) {
91-
uint8_t buf[MAX_FRAME_SIZE + 4];
92-
client.readBytes(buf, len);
93-
memcpy(dest, buf+3, len-3); // remove header (don't even check ... problems are on the other dir)
94-
return len-3;
101+
102+
// check if we are waiting for a frame header
103+
if(!hasReceivedFrameHeader()){
104+
105+
// make sure we have received enough bytes for a frame header
106+
// 3 bytes frame header = (1 byte frame type) + (2 bytes frame length as unsigned 16-bit little endian)
107+
int frame_header_length = 3;
108+
if(client.available() >= frame_header_length){
109+
110+
// read frame header
111+
client.readBytes(&received_frame_header.type, 1);
112+
client.readBytes((uint8_t*)&received_frame_header.length, 2);
113+
114+
}
115+
95116
}
117+
118+
// check if we have received a frame header
119+
if(hasReceivedFrameHeader()){
120+
121+
// make sure we have received enough bytes for the required frame length
122+
int available = client.available();
123+
int frame_type = received_frame_header.type;
124+
int frame_length = received_frame_header.length;
125+
if(frame_length > available){
126+
WIFI_DEBUG_PRINTLN("Waiting for %d more bytes", frame_length - available);
127+
return 0;
128+
}
129+
130+
// skip frames that are larger than MAX_FRAME_SIZE
131+
if(frame_length > MAX_FRAME_SIZE){
132+
WIFI_DEBUG_PRINTLN("Skipping frame: length=%d is larger than MAX_FRAME_SIZE=%d", frame_length, MAX_FRAME_SIZE);
133+
while(frame_length > 0){
134+
uint8_t skip[1];
135+
int skipped = client.read(skip, 1);
136+
frame_length -= skipped;
137+
}
138+
resetReceivedFrameHeader();
139+
return 0;
140+
}
141+
142+
// skip frames that are not expected type
143+
// '<' is 0x3c which indicates a frame sent from app to radio
144+
if(frame_type != '<'){
145+
WIFI_DEBUG_PRINTLN("Skipping frame: type=0x%x is unexpected", frame_type);
146+
while(frame_length > 0){
147+
uint8_t skip[1];
148+
int skipped = client.read(skip, 1);
149+
frame_length -= skipped;
150+
}
151+
resetReceivedFrameHeader();
152+
return 0;
153+
}
154+
155+
// read frame data to provided buffer
156+
client.readBytes(dest, frame_length);
157+
158+
// ready for next frame
159+
resetReceivedFrameHeader();
160+
return frame_length;
161+
162+
}
163+
96164
}
97165
}
98166

src/helpers/esp32/SerialWifiInterface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ class SerialWifiInterface : public BaseSerialInterface {
1212
WiFiServer server;
1313
WiFiClient client;
1414

15+
struct FrameHeader {
16+
uint8_t type;
17+
uint16_t length;
18+
};
19+
1520
struct Frame {
1621
uint8_t len;
1722
uint8_t buf[MAX_FRAME_SIZE];
1823
};
1924

25+
FrameHeader received_frame_header;
26+
2027
#define FRAME_QUEUE_SIZE 4
2128
int recv_queue_len;
2229
Frame recv_queue[FRAME_QUEUE_SIZE];
@@ -33,6 +40,8 @@ class SerialWifiInterface : public BaseSerialInterface {
3340
_isEnabled = false;
3441
_last_write = 0;
3542
send_queue_len = recv_queue_len = 0;
43+
received_frame_header.type = 0;
44+
received_frame_header.length = 0;
3645
}
3746

3847
void begin(int port);
@@ -47,6 +56,9 @@ class SerialWifiInterface : public BaseSerialInterface {
4756

4857
size_t writeFrame(const uint8_t src[], size_t len) override;
4958
size_t checkRecvFrame(uint8_t dest[]) override;
59+
60+
bool hasReceivedFrameHeader();
61+
void resetReceivedFrameHeader();
5062
};
5163

5264
#if WIFI_DEBUG_LOGGING && ARDUINO

src/helpers/radiolib/CustomLR1110.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CustomLR1110 : public LR1110 {
1010
size_t getPacketLength(bool update) override {
1111
size_t len = LR1110::getPacketLength(update);
1212
if (len == 0 && getIrqStatus() & RADIOLIB_LR11X0_IRQ_HEADER_ERR) {
13-
// we've just recieved a corrupted packet
13+
// we've just received a corrupted packet
1414
// this may have triggered a bug causing subsequent packets to be shifted
1515
// call standby() to return radio to known-good state
1616
// recvRaw will call startReceive() to restart rx

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ void EnvironmentSensorManager::rakGPSInit(){
615615
MESH_DEBUG_PRINTLN("No GPS found");
616616
gps_active = false;
617617
gps_detected = false;
618+
Serial1.end();
618619
return;
619620
}
620621

@@ -653,8 +654,7 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){
653654

654655
_location = &RAK12500_provider;
655656
return true;
656-
}
657-
else if(Serial1){
657+
} else if (Serial1.available()) {
658658
MESH_DEBUG_PRINTLN("Serial GPS init correctly and is turned on");
659659
if(PIN_GPS_EN){
660660
gpsResetPin = PIN_GPS_EN;
@@ -664,6 +664,8 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){
664664
gps_detected = true;
665665
return true;
666666
}
667+
668+
pinMode(ioPin, INPUT);
667669
MESH_DEBUG_PRINTLN("GPS did not init with this IO pin... try the next");
668670
return false;
669671
}

variants/heltec_v3/platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ build_flags =
189189
-D WIFI_DEBUG_LOGGING=1
190190
-D WIFI_SSID='"myssid"'
191191
-D WIFI_PWD='"mypwd"'
192+
-D OFFLINE_QUEUE_SIZE=256
192193
; -D MESH_PACKET_LOGGING=1
193194
; -D MESH_DEBUG=1
194195
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
@@ -341,6 +342,7 @@ build_flags =
341342
-D WIFI_DEBUG_LOGGING=1
342343
-D WIFI_SSID='"myssid"'
343344
-D WIFI_PWD='"mypwd"'
345+
-D OFFLINE_QUEUE_SIZE=256
344346
; -D MESH_PACKET_LOGGING=1
345347
; -D MESH_DEBUG=1
346348
build_src_filter = ${Heltec_lora32_v3.build_src_filter}

variants/heltec_v4/platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ build_flags =
176176
-D WIFI_DEBUG_LOGGING=1
177177
-D WIFI_SSID='"myssid"'
178178
-D WIFI_PWD='"mypwd"'
179+
-D OFFLINE_QUEUE_SIZE=256
179180
; -D MESH_PACKET_LOGGING=1
180181
; -D MESH_DEBUG=1
181182
build_src_filter = ${Heltec_lora32_v4.build_src_filter}

variants/thinknode_m6/platformio.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ build_src_filter = ${ThinkNode_M6.build_src_filter}
9090
+<helpers/nrf52/SerialBLEInterface.cpp>
9191
+<helpers/ui/MomentaryButton.cpp>
9292
+<../examples/companion_radio/*.cpp>
93-
+<../examples/companion_radio/ui-new/*.cpp>
9493
lib_deps =
9594
${ThinkNode_M6.lib_deps}
9695
densaugeo/base64 @ ~1.4.0
@@ -113,7 +112,6 @@ build_src_filter = ${ThinkNode_M6.build_src_filter}
113112
+<helpers/ui/buzzer.cpp>
114113
+<helpers/ui/MomentaryButton.cpp>
115114
+<../examples/companion_radio/*.cpp>
116-
+<../examples/companion_radio/ui-new/*.cpp>
117115
lib_deps =
118116
${ThinkNode_M6.lib_deps}
119117
densaugeo/base64 @ ~1.4.0

variants/xiao_s3_wio/platformio.ini

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,29 @@ lib_deps =
195195
densaugeo/base64 @ ~1.4.0
196196
adafruit/Adafruit SSD1306 @ ^2.5.13
197197

198+
[env:Xiao_S3_WIO_companion_radio_wifi]
199+
extends = Xiao_S3_WIO
200+
build_src_filter = ${Xiao_S3_WIO.build_src_filter}
201+
+<helpers/ui/NullDisplayDriver.cpp>
202+
+<helpers/esp32/*.cpp>
203+
+<helpers/ui/MomentaryButton.cpp>
204+
+<../examples/companion_radio/*.cpp>
205+
build_flags =
206+
${Xiao_S3_WIO.build_flags}
207+
-I examples/companion_radio/ui-new
208+
-D MAX_CONTACTS=350
209+
-D MAX_GROUP_CHANNELS=40
210+
-D OFFLINE_QUEUE_SIZE=256
211+
-D WIFI_DEBUG_LOGGING=1
212+
-D WIFI_SSID='"myssid"'
213+
-D WIFI_PWD='"password"'
214+
; -D BLE_DEBUG_LOGGING=1
215+
; -D MESH_PACKET_LOGGING=1
216+
; -D MESH_DEBUG=1
217+
lib_deps =
218+
${Xiao_S3_WIO.lib_deps}
219+
densaugeo/base64 @ ~1.4.0
220+
198221
[env:Xiao_S3_WIO_sensor]
199222
extends = Xiao_S3_WIO
200223
build_src_filter = ${Xiao_S3_WIO.build_src_filter}

0 commit comments

Comments
 (0)