Skip to content

Commit 92bb4b6

Browse files
authored
Merge pull request #584 from adafruit/pb-error-msgs
Pb error msgs
2 parents 9a75742 + 4d1c204 commit 92bb4b6

17 files changed

+570
-167
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,8 @@ src/.vscode/settings.json
4444

4545
examples/Wippersnapper_demo/build/
4646

47-
#Platformio artifacts
47+
# Platformio artifacts
4848
.pio/
49+
50+
# Secrets
51+
data/

platformio.ini

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,22 @@ lib_deps =
8282
; Common build environment for ESP32 platform
8383
[common:esp32]
8484
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
85-
lib_ignore = WiFiNINA
85+
lib_ignore = WiFiNINA, WiFi101
8686
monitor_filters = esp32_exception_decoder, time
8787

8888
; Common build environment for ESP8266 platform
8989
[common:esp8266]
9090
platform = espressif8266
91-
lib_ignore = WiFiNINA, Adafruit TinyUSB Library
91+
lib_ignore = WiFiNINA, WiFi101, Adafruit TinyUSB Library
9292

9393
; Common build environment for Atmel/Microchip SAMDx platform
9494
[common:atsamd]
9595
platform = atmelsam
96+
platform_packages =
97+
platformio/framework-arduino-samd-adafruit@^1.7.13
98+
platformio/tool-jlink@^1.78811.0
9699
lib_ldf_mode = deep
97-
100+
lib_archive = no ; debug timer issues see https://community.platformio.org/t/choose-usb-stack-as-tiny-usb/22451/5
98101

99102
[common:rp2040]
100103
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
@@ -110,6 +113,9 @@ build_flags = -DUSE_TINYUSB
110113
lib_ignore = WiFiNINA, WiFi101, Adafruit Zero DMA Library
111114
lib_compat_mode = soft ; can be strict once pio detects SleepyDog on RP2040
112115

116+
117+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Individual Board Definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
118+
113119
; ESP32-x Boards ;
114120

115121
; Adafruit ESP32 Feather
@@ -292,14 +298,39 @@ build_flags = -DUSE_TINYUSB=1
292298
[env:adafruit_pyportal_m4_titano]
293299
extends = common:atsamd
294300
board = adafruit_pyportal_m4_titano
295-
; build_type = debug
301+
build_type = debug
302+
upload_protocol = sam-ba
296303
; upload_protocol = jlink
297-
; debug_tool = jlink
304+
debug_tool = jlink
305+
monitor_port = auto
298306
; monitor_port = jlink
299-
; debug_init_break =
307+
; monitor_port = socket://localhost:19021
308+
; debug_init_break = tbreak clearConfiguration
300309
lib_ignore = USBHost
301-
build_flags = -DUSE_TINYUSB=1
302-
-DADAFRUIT_PYPORTAL_M4_TITANO
310+
build_flags = -DUSE_TINYUSB
311+
-D__SAMD51J20A__
312+
-DCRYSTALLESS
313+
-DADAFRUIT_PYPORTAL_M4_TITANO
314+
-D__SAMD51__
315+
-D__FPU_PRESENT
316+
-DARM_MATH_CM4
317+
-mfloat-abi=hard
318+
-mfpu=fpv4-sp-d16
319+
-DCORE_DEBUG_LEVEL=5
320+
-DARDUINO_USB_CDC_ON_BOOT=1
321+
-DCFG_TUSB_DEBUG=1
322+
-DDEBUG=1
323+
-DNDEBUG=1
324+
-DUSE_AIRLIFT=1
325+
-g
326+
; -DUSBCON
327+
; -UCDC_DISABLED
328+
; -UPLUGGABLE_USB_DISABLED
329+
; -DCDC_ENABLED
330+
; -DPLUGGABLE_USB_ENABLED
331+
; -DSERIAL_DEBUG=1
332+
; -DSERIAL_PORT=Serial1
333+
; -DSERCOM_INSTANCE_SERIAL=1
303334

304335
; Adafruit Metro M4 Airlift Lite
305336
[env:adafruit_metro_m4_airliftlite]

src/Wippersnapper.cpp

Lines changed: 127 additions & 85 deletions
Large diffs are not rendered by default.

src/Wippersnapper.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,57 @@
5959
{} ///< Prints line from debug output.
6060
#endif
6161

62+
#define WS_DELAY_WITH_WDT(timeout) \
63+
{ \
64+
unsigned long start = millis(); \
65+
while (millis() - start < timeout) { \
66+
delay(10); \
67+
yield(); \
68+
feedWDT(); \
69+
if (millis() < start) { \
70+
start = millis(); /* if rollover */ \
71+
} \
72+
} \
73+
} ///< Delay function
74+
75+
/**************************************************************************/
76+
/*!
77+
@brief Retry a function until a condition is met or a timeout is reached.
78+
@param func
79+
The function to retry.
80+
@param result_type
81+
The type of the result of the function.
82+
@param result_var
83+
The variable to store the last result of the function.
84+
@param condition
85+
The condition to check the result against.
86+
@param timeout
87+
The maximum time to retry the function.
88+
@param interval
89+
The time to wait between retries.
90+
@param ...
91+
The arguments to pass to the function.
92+
*/
93+
/**************************************************************************/
94+
#define RETRY_FUNCTION_UNTIL_TIMEOUT(func, result_type, result_var, condition, \
95+
timeout, interval, ...) \
96+
{ \
97+
unsigned long startTime = millis(); \
98+
while (millis() - startTime < timeout) { \
99+
result_type result_var = func(__VA_ARGS__); \
100+
if (condition(result_var)) { \
101+
break; \
102+
} \
103+
if (startTime > millis()) { \
104+
startTime = millis(); /* if rollover */ \
105+
} \
106+
WS_DELAY_WITH_WDT(interval); \
107+
} \
108+
} ///< Retry a function until a condition is met or a timeout is reached.
109+
110+
// Wippersnapper pb helpers
111+
#include <nanopb/ws_pb_helpers.h>
112+
62113
// Wippersnapper components
63114
#include "components/analogIO/Wippersnapper_AnalogIO.h"
64115
#include "components/digitalIO/Wippersnapper_DigitalGPIO.h"
@@ -220,6 +271,7 @@ class Wippersnapper {
220271
void disconnect();
221272

222273
virtual void getMacAddr();
274+
virtual int32_t getRSSI();
223275
virtual void setupMQTTClient(const char *clientID);
224276

225277
virtual ws_status_t networkStatus();

src/components/analogIO/Wippersnapper_AnalogIO.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ bool Wippersnapper_AnalogIO::encodePinEvent(
280280
// Encode signal message
281281
pb_ostream_t stream =
282282
pb_ostream_from_buffer(WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
283-
if (!pb_encode(&stream, wippersnapper_signal_v1_CreateSignalRequest_fields,
284-
&outgoingSignalMsg)) {
283+
if (!ws_pb_encode(&stream, wippersnapper_signal_v1_CreateSignalRequest_fields,
284+
&outgoingSignalMsg)) {
285285
WS_DEBUG_PRINTLN("ERROR: Unable to encode signal message");
286286
return false;
287287
}

src/components/ds18x20/ws_ds18x20.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ bool ws_ds18x20::addDS18x20(
108108
memset(WS._buffer_outgoing, 0, sizeof(WS._buffer_outgoing));
109109
pb_ostream_t ostream =
110110
pb_ostream_from_buffer(WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
111-
if (!pb_encode(&ostream, wippersnapper_signal_v1_Ds18x20Response_fields,
112-
&msgInitResp)) {
111+
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_Ds18x20Response_fields,
112+
&msgInitResp)) {
113113
WS_DEBUG_PRINTLN("ERROR: Unable to encode msg_init response message!");
114114
return false;
115115
}
@@ -257,9 +257,9 @@ void ws_ds18x20::update() {
257257
memset(WS._buffer_outgoing, 0, sizeof(WS._buffer_outgoing));
258258
pb_ostream_t ostream = pb_ostream_from_buffer(
259259
WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
260-
if (!pb_encode(&ostream,
261-
wippersnapper_signal_v1_Ds18x20Response_fields,
262-
&msgDS18x20Response)) {
260+
if (!ws_pb_encode(&ostream,
261+
wippersnapper_signal_v1_Ds18x20Response_fields,
262+
&msgDS18x20Response)) {
263263
WS_DEBUG_PRINTLN(
264264
"ERROR: Unable to encode DS18x20 event responsemessage!");
265265
snprintf(buffer, 100,
@@ -296,6 +296,8 @@ void ws_ds18x20::update() {
296296
WS_DEBUG_PRINT("PUBLISHING -> msgDS18x20Response Event Message...");
297297
if (!WS._mqtt->publish(WS._topic_signal_ds18_device,
298298
WS._buffer_outgoing, msgSz, 1)) {
299+
WS_DEBUG_PRINTLN("ERROR: Unable to publish DS18x20 event message - "
300+
"MQTT Publish failed!");
299301
return;
300302
};
301303
WS_DEBUG_PRINTLN("PUBLISHED!");

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,8 @@ bool WipperSnapper_Component_I2C::encodePublishI2CDeviceEventMsg(
859859
memset(WS._buffer_outgoing, 0, sizeof(WS._buffer_outgoing));
860860
pb_ostream_t ostream =
861861
pb_ostream_from_buffer(WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
862-
if (!pb_encode(&ostream, wippersnapper_signal_v1_I2CResponse_fields,
863-
msgi2cResponse)) {
862+
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_I2CResponse_fields,
863+
msgi2cResponse)) {
864864
WS_DEBUG_PRINTLN(
865865
"ERROR: Unable to encode I2C device event response message!");
866866
return false;
@@ -873,6 +873,7 @@ bool WipperSnapper_Component_I2C::encodePublishI2CDeviceEventMsg(
873873
WS_DEBUG_PRINT("PUBLISHING -> I2C Device Sensor Event Message...");
874874
if (!WS._mqtt->publish(WS._topic_signal_i2c_device, WS._buffer_outgoing,
875875
msgSz, 1)) {
876+
WS_DEBUG_PRINTLN("ERROR: MQTT Publish failed!");
876877
return false;
877878
};
878879
WS_DEBUG_PRINTLN("PUBLISHED!");

src/components/pixels/ws_pixels.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ void ws_pixels::publishAddStrandResponse(bool is_success,
170170
memset(WS._buffer_outgoing, 0, sizeof(WS._buffer_outgoing));
171171
pb_ostream_t ostream =
172172
pb_ostream_from_buffer(WS._buffer_outgoing, sizeof(WS._buffer_outgoing));
173-
if (!pb_encode(&ostream, wippersnapper_signal_v1_PixelsResponse_fields,
174-
&msgInitResp)) {
173+
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_PixelsResponse_fields,
174+
&msgInitResp)) {
175175
WS_DEBUG_PRINTLN("ERROR: Unable to encode "
176176
"wippersnapper_signal_v1_PixelsResponse message!");
177177
return;

src/components/register/Wippersnapper_Register.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool Wippersnapper::encodePubRegistrationReq() {
4646
pb_ostream_t _msg_stream =
4747
pb_ostream_from_buffer(_message_buffer, sizeof(_message_buffer));
4848

49-
_status = pb_encode(
49+
_status = ws_pb_encode(
5050
&_msg_stream,
5151
wippersnapper_description_v1_CreateDescriptionRequest_fields, &_message);
5252
size_t _message_len = _msg_stream.bytes_written;
@@ -107,9 +107,10 @@ void Wippersnapper::decodeRegistrationResp(char *data, uint16_t len) {
107107
// create input stream for buffer
108108
pb_istream_t stream = pb_istream_from_buffer(buffer, len);
109109
// decode the stream
110-
if (!pb_decode(&stream,
111-
wippersnapper_description_v1_CreateDescriptionResponse_fields,
112-
&message)) {
110+
if (!ws_pb_decode(
111+
&stream,
112+
wippersnapper_description_v1_CreateDescriptionResponse_fields,
113+
&message)) {
113114
WS.haltError("Could not decode registration response");
114115
}
115116
// Decode registration response message
@@ -140,7 +141,7 @@ void Wippersnapper::decodeRegistrationResp(char *data, uint16_t len) {
140141
pb_ostream_t _msg_stream =
141142
pb_ostream_from_buffer(_message_buffer, sizeof(_message_buffer));
142143

143-
bool _status = pb_encode(
144+
bool _status = ws_pb_encode(
144145
&_msg_stream, wippersnapper_description_v1_RegistrationComplete_fields,
145146
&msg);
146147
size_t _message_len = _msg_stream.bytes_written;

src/components/uart/drivers/ws_uart_drv_pm25aqi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ class ws_uart_drv_pm25aqi : public ws_uart_drv {
185185
uint8_t mqttBuffer[512] = {0};
186186
pb_ostream_t ostream =
187187
pb_ostream_from_buffer(mqttBuffer, sizeof(mqttBuffer));
188-
if (!pb_encode(&ostream, wippersnapper_signal_v1_UARTResponse_fields,
189-
&msgUARTResponse)) {
188+
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_UARTResponse_fields,
189+
&msgUARTResponse)) {
190190
Serial.println("[ERROR, UART]: Unable to encode device response!");
191191
return;
192192
}

0 commit comments

Comments
 (0)