Skip to content

Commit 5b5463c

Browse files
committed
[SD] Refactor diagram, doxygen sd class
1 parent 27aa7d4 commit 5b5463c

File tree

4 files changed

+144
-54
lines changed

4 files changed

+144
-54
lines changed

src/Wippersnapper_V2.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,8 @@ class Wippersnapper_V2 {
254254
#endif
255255
bool got_checkin_response; ///< True if a checkin response was received, False
256256
///< otherwise.
257-
258-
wippersnapper_signal_BrokerToDevice _signalB2dV2;
259-
pb_ostream_t _signalStream;
260-
size_t _szMessageBuf; // TODO: Delete
261-
uint8_t _msgBuf[512]; // TODO: Delete
262-
std::vector<std::vector<uint8_t>> _sharedConfigBuffers;
263-
257+
std::vector<std::vector<uint8_t>>
258+
_sharedConfigBuffers; ///< Shared JSON config buffers for offline mode
264259
private:
265260
void _initV2();
266261

src/components/ds18x20/model.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ wippersnapper_ds18x20_Ds18x20Event *DS18X20Model::GetDS18x20EventMsg() {
135135
/*************************************************************************/
136136
/*!
137137
@brief Encodes a Ds18x20Event message.
138-
@param onewire_pin
139-
The OneWire bus' pin where the sensor is located.
140-
@param sensor_events_count
141-
The number of sensorevent messages to encode.
142-
@param sensor_events
143-
The sensorevent messages to encode.
144138
@return True if the message was successfully encoded, False otherwise.
145139
*/
146140
/*************************************************************************/

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,18 @@ ws_sdcard::ws_sdcard() {
3939
ws_sdcard::~ws_sdcard() {
4040
// TODO: Close any open files
4141
// Then, end the SD card (ends SPI transaction)
42-
_sd.end();
42+
if (mode_offline) {
43+
_sd.end();
44+
mode_offline = false;
45+
}
4346
}
4447

48+
/**************************************************************************/
49+
/*!
50+
@brief Enables logging via a physical RTC to a SD-card, if available.
51+
Otherwise, enables logging using millis() timestamps.
52+
*/
53+
/**************************************************************************/
4554
void ws_sdcard::EnableLogging() {
4655
// Attempt to search for a DS3231 RTC
4756
WS_DEBUG_PRINTLN("Searching for DS1307 RTC...");
@@ -99,6 +108,14 @@ void ws_sdcard::EnableLogging() {
99108
}
100109
}
101110

111+
/**************************************************************************/
112+
/*!
113+
@brief Searches for and parses the JSON configuration file and sets up
114+
the hardware accordingly.
115+
@returns True if the JSON file was successfully parsed and the hardware
116+
was successfully configured. False otherwise.
117+
*/
118+
/**************************************************************************/
102119
bool ws_sdcard::parseConfigFile() {
103120
File32 file_config; // TODO: MAke this global?
104121
#ifndef OFFLINE_MODE_DEBUG
@@ -385,7 +402,14 @@ bool ws_sdcard::parseConfigFile() {
385402
return true;
386403
}
387404

388-
// Returns true if input points to a valid JSON string
405+
/**************************************************************************/
406+
/*!
407+
@brief Validates a JSON string.
408+
@param input
409+
A JSON string to validate.
410+
@returns True if the provided JSON string is valid, False otherwise.
411+
*/
412+
/**************************************************************************/
389413
bool ws_sdcard::validateJson(const char *input) {
390414
JsonDocument doc, filter;
391415

@@ -394,8 +418,13 @@ bool ws_sdcard::validateJson(const char *input) {
394418
return error == DeserializationError::Ok;
395419
}
396420

397-
// Waits for incoming config file and parses it
398-
// TODO: Split out parsing into parseConfigFile() and just read here
421+
/**************************************************************************/
422+
/*!
423+
@brief Waits for a valid JSON string to be received via the hardware's
424+
serial input or from a hardcoded test JSON string.
425+
@returns True if a valid JSON string was received, False otherwise.
426+
*/
427+
/**************************************************************************/
399428
bool ws_sdcard::waitForSerialConfig() {
400429

401430
// We provide three ways to use this function:
@@ -525,6 +554,12 @@ bool ws_sdcard::waitForSerialConfig() {
525554
return true;
526555
}
527556

557+
/**************************************************************************/
558+
/*!
559+
@brief Obtains a timestamp from the hardware (or software) RTC.
560+
@returns The current timestamp, in unixtime format.
561+
*/
562+
/**************************************************************************/
528563
uint32_t ws_sdcard::GetTimestamp() {
529564
// Obtain RTC timestamp (TODO - refactor this out)
530565
DateTime now;
@@ -540,6 +575,14 @@ uint32_t ws_sdcard::GetTimestamp() {
540575
return now.unixtime();
541576
}
542577

578+
/**************************************************************************/
579+
/*!
580+
@brief Converts a SensorType enum to a string.
581+
@param sensorType
582+
The SensorType enum to convert.
583+
@returns A string representation of the SensorType enum.
584+
*/
585+
/**************************************************************************/
543586
const char *SensorTypeToString(wippersnapper_sensor_SensorType sensorType) {
544587
switch (sensorType) {
545588
case wippersnapper_sensor_SensorType_SENSOR_TYPE_UNSPECIFIED:
@@ -621,6 +664,18 @@ const char *SensorTypeToString(wippersnapper_sensor_SensorType sensorType) {
621664
}
622665
}
623666

667+
/**************************************************************************/
668+
/*!
669+
@brief Logs a GPIO sensor event to the SD card.
670+
@param pin
671+
The GPIO pin number.
672+
@param value
673+
The sensor value.
674+
@param read_type
675+
The sensor type.
676+
@returns True if the event was successfully logged, False otherwise.
677+
*/
678+
/**************************************************************************/
624679
bool ws_sdcard::LogGPIOSensorEventToSD(
625680
uint8_t pin, float value, wippersnapper_sensor_SensorType read_type) {
626681
// Get the pin name in the correct format ("A0", "A1", etc.)
@@ -641,6 +696,18 @@ bool ws_sdcard::LogGPIOSensorEventToSD(
641696
return true;
642697
}
643698

699+
/**************************************************************************/
700+
/*!
701+
@brief Logs a GPIO sensor event to the SD card.
702+
@param pin
703+
The GPIO pin number.
704+
@param value
705+
The sensor value.
706+
@param read_type
707+
The sensor type.
708+
@returns True if the event was successfully logged, False otherwise.
709+
*/
710+
/**************************************************************************/
644711
bool ws_sdcard::LogGPIOSensorEventToSD(
645712
uint8_t pin, uint16_t value, wippersnapper_sensor_SensorType read_type) {
646713
// Get the pin name in the correct format ("A0", "A1", etc.)
@@ -661,6 +728,18 @@ bool ws_sdcard::LogGPIOSensorEventToSD(
661728
return true;
662729
}
663730

731+
/**************************************************************************/
732+
/*!
733+
@brief Logs a GPIO sensor event to the SD card.
734+
@param pin
735+
The GPIO pin number.
736+
@param value
737+
The sensor value.
738+
@param read_type
739+
The sensor type.
740+
@returns True if the event was successfully logged, False otherwise.
741+
*/
742+
/**************************************************************************/
664743
bool ws_sdcard::LogGPIOSensorEventToSD(
665744
uint8_t pin, bool value, wippersnapper_sensor_SensorType read_type) {
666745
// Get the pin name in the correct format ("A0", "A1", etc.)
@@ -681,6 +760,18 @@ bool ws_sdcard::LogGPIOSensorEventToSD(
681760
return true;
682761
}
683762

763+
/**************************************************************************/
764+
/*!
765+
@brief Logs a GPIO sensor event to the SD card.
766+
@param pin
767+
The GPIO pin number.
768+
@param value
769+
The sensor value.
770+
@param read_type
771+
The sensor type.
772+
@returns True if the event was successfully logged, False otherwise.
773+
*/
774+
/**************************************************************************/
684775
bool ws_sdcard::LogDS18xSensorEventToSD(
685776
wippersnapper_ds18x20_Ds18x20Event *event_msg) {
686777
// Get the RTC's timestamp

tests/diagram.json

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,31 @@
2828
"rotate": 270,
2929
"attrs": {}
3030
},
31-
{ "type": "wokwi-potentiometer", "id": "pot1", "top": -1.3, "left": 182.2, "attrs": {} },
32-
{ "type": "wokwi-potentiometer", "id": "pot2", "top": -1.3, "left": 95.8, "attrs": {} },
31+
{ "type": "wokwi-potentiometer", "id": "pot1", "top": -87.7, "left": 143.8, "attrs": {} },
32+
{ "type": "wokwi-potentiometer", "id": "pot2", "top": -1.3, "left": 143.8, "attrs": {} },
3333
{
3434
"type": "wokwi-pushbutton",
3535
"id": "btn1",
36-
"top": -0.4,
37-
"left": 256.4,
36+
"top": 9.2,
37+
"left": 74,
3838
"rotate": 270,
3939
"attrs": { "color": "green" }
4040
},
41-
{ "type": "board-ds18b20", "id": "temp1", "top": -145.13, "left": 311.28, "attrs": {} },
41+
{ "type": "board-ds18b20", "id": "temp1", "top": -87.53, "left": 272.88, "attrs": {} },
4242
{
4343
"type": "wokwi-resistor",
4444
"id": "r1",
45-
"top": -52.8,
46-
"left": 345.05,
45+
"top": 4.8,
46+
"left": 277.85,
4747
"rotate": 90,
4848
"attrs": { "value": "7400" }
4949
},
50-
{ "type": "board-ds18b20", "id": "temp2", "top": -145.13, "left": 167.28, "attrs": {} },
50+
{ "type": "board-ds18b20", "id": "temp2", "top": -87.53, "left": 234.48, "attrs": {} },
5151
{
5252
"type": "wokwi-resistor",
5353
"id": "r2",
54-
"top": -63.8,
55-
"left": 191.15,
54+
"top": -6.2,
55+
"left": 239.15,
5656
"rotate": 270,
5757
"attrs": { "value": "7400" }
5858
}
@@ -66,26 +66,31 @@
6666
[ "sd1:DO", "esp:D19", "orange", [ "v124.8", "h-125.01" ] ],
6767
[ "rtc1:SDA", "esp:D21", "blue", [ "v115.2", "h-183.1" ] ],
6868
[ "rtc1:SCL", "esp:D22", "green", [ "v105.6", "h-163.7" ] ],
69-
[ "pot2:SIG", "esp:D27", "green", [ "v19.2", "h143.6" ] ],
69+
[ "pot2:SIG", "esp:D27", "green", [ "h-0.4", "v76.8", "h-345.9" ] ],
7070
[ "esp:3V3", "bb1:bp.1", "red", [ "h-9.6", "v39" ] ],
7171
[ "sd1:VCC", "bb1:bp.18", "red", [ "v0" ] ],
7272
[ "rtc1:GND", "bb1:bn.25", "black", [ "v0" ] ],
73-
[ "sd1:GND", "bb1:bn.20", "black", [ "v0" ] ],
7473
[ "esp:GND.1", "bb1:bn.3", "black", [ "v0" ] ],
7574
[ "bb1:33b.h", "bb1:33b.g", "green", [ "v0" ] ],
7675
[ "rtc1:5V", "esp:VIN", "red", [ "v-19.2", "h-269.2" ] ],
77-
[ "pot1:SIG", "esp:D14", "blue", [ "v67.2", "h-365.2", "v-163.2" ] ],
78-
[ "pot2:GND", "bb1:bn.31", "black", [ "v0" ] ],
79-
[ "pot2:VCC", "bb1:bn.33", "red", [ "v0" ] ],
80-
[ "pot1:GND", "bb1:bn.39", "black", [ "v0" ] ],
81-
[ "pot1:VCC", "bb1:bp.41", "red", [ "v0" ] ],
82-
[ "btn1:1.l", "esp:D4", "violet", [ "v67.2", "h-451.1" ] ],
83-
[ "btn1:2.r", "bb1:bn.46", "black", [ "v-9.8", "h-38.2", "v126.1" ] ],
76+
[ "pot1:SIG", "esp:D14", "blue", [ "v9.6", "h-48.4", "v144", "h-316.8", "v-172.8" ] ],
77+
[ "btn1:1.l", "esp:D4", "orange", [ "v57.6", "h-268.7" ] ],
8478
[ "temp1:GND", "bb1:bn.48", "black", [ "v0" ] ],
8579
[ "temp1:DQ", "r1:1", "green", [ "v0" ] ],
8680
[ "temp1:VCC", "r1:2", "red", [ "v0" ] ],
87-
[ "r1:2", "bb1:bp.50", "red", [ "v56.4", "h-37.6" ] ],
88-
[ "r1:1", "esp:D12", "green", [ "v-76.8", "h-557.5" ] ],
81+
[ "r1:1", "esp:D12", "green", [ "v-124.8", "h-490.3" ] ],
82+
[ "temp2:GND", "bb1:bn.36", "black", [ "v0" ] ],
83+
[ "temp2:DQ", "r2:2", "violet", [ "v0" ] ],
84+
[ "temp2:VCC", "r2:1", "red", [ "v0" ] ],
85+
[ "esp:D25", "r2:2", "violet", [ "v-96", "h412.8" ] ],
86+
[ "sd1:GND", "bb1:bn.21", "black", [ "v0" ] ],
87+
[ "btn1:2.r", "bb1:tn.31", "black", [ "h9.8", "v-67.3" ] ],
88+
[ "pot1:GND", "bb1:tn.32", "black", [ "h-38.4", "v-47.9" ] ],
89+
[ "pot1:VCC", "bb1:bp.39", "red", [ "h18.4", "v116.1" ] ],
90+
[ "pot2:GND", "bb1:bn.35", "black", [ "v0" ] ],
91+
[ "pot2:VCC", "bb1:bp.37", "red", [ "v0" ] ],
92+
[ "r2:1", "bb1:bp.44", "red", [ "h0" ] ],
93+
[ "r1:2", "bb1:bp.47", "red", [ "h0" ] ],
8994
[ "esp:VIN", "bb1:4t.a", "", [ "$bb" ] ],
9095
[ "esp:GND.2", "bb1:5t.a", "", [ "$bb" ] ],
9196
[ "esp:D13", "bb1:6t.a", "", [ "$bb" ] ],
@@ -128,22 +133,27 @@
128133
[ "rtc1:SDA", "bb1:33t.a", "", [ "$bb" ] ],
129134
[ "rtc1:SCL", "bb1:34t.a", "", [ "$bb" ] ],
130135
[ "rtc1:SQW", "bb1:35t.a", "", [ "$bb" ] ],
131-
[ "pot1:GND", "bb1:48b.j", "", [ "$bb" ] ],
132-
[ "pot1:SIG", "bb1:49b.j", "", [ "$bb" ] ],
133-
[ "pot1:VCC", "bb1:50b.j", "", [ "$bb" ] ],
134-
[ "pot2:GND", "bb1:39b.j", "", [ "$bb" ] ],
135-
[ "pot2:SIG", "bb1:40b.j", "", [ "$bb" ] ],
136-
[ "pot2:VCC", "bb1:41b.j", "", [ "$bb" ] ],
137-
[ "btn1:1.l", "bb1:55b.i", "", [ "$bb" ] ],
138-
[ "btn1:2.l", "bb1:57b.i", "", [ "$bb" ] ],
139-
[ "btn1:1.r", "bb1:55t.d", "", [ "$bb" ] ],
140-
[ "btn1:2.r", "bb1:57t.d", "", [ "$bb" ] ],
141-
[ "temp2:GND", "bb1:bn.36", "black", [ "v0" ] ],
142-
[ "temp2:DQ", "r2:2", "violet", [ "v0" ] ],
143-
[ "r2:1", "bb1:49t.b", "", [ "$bb" ] ],
144-
[ "temp2:VCC", "r2:1", "red", [ "v0" ] ],
145-
[ "r2:1", "bb1:bp.36", "red", [ "v19.2", "h-38.4", "v106.5" ] ],
146-
[ "esp:D25", "r2:2", "violet", [ "v-124.8", "h364.8" ] ]
136+
[ "pot1:GND", "bb1:44t.c", "", [ "$bb" ] ],
137+
[ "pot1:SIG", "bb1:45t.c", "", [ "$bb" ] ],
138+
[ "pot1:VCC", "bb1:46t.c", "", [ "$bb" ] ],
139+
[ "pot2:GND", "bb1:44b.j", "", [ "$bb" ] ],
140+
[ "pot2:SIG", "bb1:45b.j", "", [ "$bb" ] ],
141+
[ "pot2:VCC", "bb1:46b.j", "", [ "$bb" ] ],
142+
[ "btn1:1.l", "bb1:36b.j", "", [ "$bb" ] ],
143+
[ "btn1:2.l", "bb1:38b.j", "", [ "$bb" ] ],
144+
[ "btn1:1.r", "bb1:36t.e", "", [ "$bb" ] ],
145+
[ "btn1:2.r", "bb1:38t.e", "", [ "$bb" ] ],
146+
[ "r1:1", "bb1:58t.c", "", [ "$bb" ] ],
147+
[ "r1:2", "bb1:58b.g", "", [ "$bb" ] ],
148+
[ "r2:1", "bb1:54b.f", "", [ "$bb" ] ],
149+
[ "r2:2", "bb1:54t.b", "", [ "$bb" ] ],
150+
[ "temp1:GND", "bb1:55t.a", "", [ "$bb" ] ],
151+
[ "temp1:DQ", "bb1:56t.a", "", [ "$bb" ] ],
152+
[ "temp1:VCC", "bb1:57t.a", "", [ "$bb" ] ],
153+
[ "temp2:GND", "bb1:51t.a", "", [ "$bb" ] ],
154+
[ "temp2:DQ", "bb1:52t.a", "", [ "$bb" ] ],
155+
[ "temp2:VCC", "bb1:53t.a", "", [ "$bb" ] ],
156+
[ "esp:GND.2", "bb1:tn.3", "black", [ "v0" ] ]
147157
],
148158
"serialMonitor": { "display": "terminal", "newline": "lf" },
149159
"dependencies": {}

0 commit comments

Comments
 (0)