@@ -49,7 +49,7 @@ ws_sdcard::ws_sdcard()
4949/* *************************************************************************/
5050ws_sdcard::~ws_sdcard () {
5151 if (is_mode_offline) {
52- _sd.end (); // Close the SD card
52+ _sd.end (); // Close the SD card interface
5353 }
5454 is_mode_offline = false ;
5555}
@@ -181,6 +181,7 @@ bool ws_sdcard::InitPCF8523() {
181181*/
182182/* *************************************************************************/
183183bool ws_sdcard::InitSoftRTC () {
184+ // NOTE: RTC_Soft always returns void
184185 _rtc_soft->begin (DateTime (F (__DATE__), F (__TIME__)));
185186 return true ;
186187}
@@ -360,7 +361,7 @@ bool ws_sdcard::ParseDigitalIOAdd(
360361 strcpy (msg_DigitalIOAdd.pin_name , pin);
361362
362363 if (period == 0.0 ) {
363- WS_DEBUG_PRINTLN (" [SD] Parsing Error: Digital pin period not found !" );
364+ WS_DEBUG_PRINTLN (" [SD] Parsing Error: Invalid pin period!" );
364365 return false ;
365366 }
366367 msg_DigitalIOAdd.period = period;
@@ -662,24 +663,17 @@ bool ws_sdcard::ValidateChecksum(JsonDocument &doc) {
662663bool ws_sdcard::parseConfigFile () {
663664 DeserializationError error;
664665 JsonDocument doc;
665-
666666 delay (5000 );
667- // TODO: THIS IS JUST FOR DEBUG Testing, remove for PR review
668- WS_DEBUG_PRINT (" SD card capacity: " );
669- WS_DEBUG_PRINTLN (_sd_capacity);
670- WS_DEBUG_PRINT (" Maximum number of log files: " );
671- WS_DEBUG_PRINTLN (_sd_max_num_log_files);
672- WS_DEBUG_PRINT (" Maximum size of log file: " );
673- WS_DEBUG_PRINTLN (_max_sz_log_file);
674667
668+ // Parse configuration data
675669#ifndef OFFLINE_MODE_DEBUG
676670 WS_DEBUG_PRINTLN (" [SD] Parsing config.json..." );
677- doc = WsV2._config_doc ; // Use the config document from the filesystem
671+ doc = WsV2._config_doc ;
678672#else
679673 // Use test data rather than data from the filesystem
680674 if (!_use_test_data) {
681675 WS_DEBUG_PRINTLN (" [SD] Parsing Serial Input..." );
682- WS_DEBUG_PRINT (_serialInput);
676+ WS_DEBUG_PRINTLN (_serialInput);
683677 error = deserializeJson (doc, _serialInput.c_str (), MAX_LEN_CFG_JSON);
684678 } else {
685679 WS_DEBUG_PRINTLN (" [SD] Parsing Test Data..." );
@@ -700,7 +694,7 @@ bool ws_sdcard::parseConfigFile() {
700694 WS_DEBUG_PRINTLN (" [SD] Checksum mismatch, file has been modified from its "
701695 " original state!" );
702696 }
703- WS_DEBUG_PRINTLN (" [SD] JSON checksum OK!" );
697+ WS_DEBUG_PRINTLN (" [SD] Checksum OK!" );
704698
705699 // Begin parsing the JSON document
706700 JsonObject exportedFromDevice = doc[" exportedFromDevice" ];
@@ -722,7 +716,7 @@ bool ws_sdcard::parseConfigFile() {
722716
723717 WS_DEBUG_PRINTLN (" Parsing exportedFromDevice object..." );
724718
725- // We don't talk to IO here, perform an "offline" device check-in
719+ // We don't talk to IO here, mock an "offline" device check-in
726720 CheckIn (exportedFromDevice[" totalGPIOPins" ] | 0 ,
727721 exportedFromDevice[" totalAnalogPins" ] | 0 ,
728722 exportedFromDevice[" referenceVoltage" ] | 0.0 );
@@ -733,7 +727,6 @@ bool ws_sdcard::parseConfigFile() {
733727 setStatusLEDBrightness (exportedFromDevice[" statusLEDBrightness" ] | 0.3 );
734728
735729 WS_DEBUG_PRINTLN (" Configuring RTC..." );
736-
737730#ifndef OFFLINE_MODE_WOKWI
738731 const char *json_rtc = exportedFromDevice[" rtc" ] | " SOFT_RTC" ;
739732 WS_DEBUG_PRINT (" RTC Type: " );
@@ -742,8 +735,6 @@ bool ws_sdcard::parseConfigFile() {
742735 WS_DEBUG_PRINTLN (" [SD] Runtime Error: Failed to to configure RTC!" );
743736 return false ;
744737 }
745- #else
746- WS_DEBUG_PRINTLN (" [SD] Did not configure RTC for Wokwi..." );
747738#endif
748739
749740 WS_DEBUG_PRINTLN (" Parsing components array..." );
@@ -873,7 +864,7 @@ uint32_t ws_sdcard::GetTimestamp() {
873864 @returns A string representation of the SensorType enum.
874865*/
875866/* *************************************************************************/
876- const char *SensorTypeToString (wippersnapper_sensor_SensorType sensorType) {
867+ const char *SensorTypeToSIUnit (wippersnapper_sensor_SensorType sensorType) {
877868 switch (sensorType) {
878869 case wippersnapper_sensor_SensorType_SENSOR_TYPE_UNSPECIFIED:
879870 return " UNSPECIFIED" ;
@@ -969,12 +960,10 @@ const char *SensorTypeToString(wippersnapper_sensor_SensorType sensorType) {
969960/* *************************************************************************/
970961void ws_sdcard::BuildJSONDoc (JsonDocument &doc, uint8_t pin, float value,
971962 wippersnapper_sensor_SensorType read_type) {
972- char pin_name[12 ];
973- sprintf (pin_name, " A%d" , pin);
974963 doc[" timestamp" ] = GetTimestamp ();
975- doc[" pin" ] = pin_name ;
964+ doc[" pin" ] = " A " + String (pin) ;
976965 doc[" value" ] = value;
977- doc[" si_unit" ] = SensorTypeToString (read_type);
966+ doc[" si_unit" ] = SensorTypeToSIUnit (read_type);
978967}
979968
980969/* *************************************************************************/
@@ -992,12 +981,10 @@ void ws_sdcard::BuildJSONDoc(JsonDocument &doc, uint8_t pin, float value,
992981/* *************************************************************************/
993982void ws_sdcard::BuildJSONDoc (JsonDocument &doc, uint8_t pin, uint16_t value,
994983 wippersnapper_sensor_SensorType read_type) {
995- char pin_name[12 ];
996- sprintf (pin_name, " A%d" , pin);
997984 doc[" timestamp" ] = GetTimestamp ();
998- doc[" pin" ] = pin_name ;
985+ doc[" pin" ] = " A " + String (pin) ;
999986 doc[" value" ] = value;
1000- doc[" si_unit" ] = SensorTypeToString (read_type);
987+ doc[" si_unit" ] = SensorTypeToSIUnit (read_type);
1001988}
1002989
1003990/* *************************************************************************/
@@ -1015,12 +1002,10 @@ void ws_sdcard::BuildJSONDoc(JsonDocument &doc, uint8_t pin, uint16_t value,
10151002/* *************************************************************************/
10161003void ws_sdcard::BuildJSONDoc (JsonDocument &doc, uint8_t pin, bool value,
10171004 wippersnapper_sensor_SensorType read_type) {
1018- char pin_name[12 ];
1019- sprintf (pin_name, " D%d" , pin);
10201005 doc[" timestamp" ] = GetTimestamp ();
1021- doc[" pin" ] = pin_name ;
1006+ doc[" pin" ] = " D " + String (pin) ;
10221007 doc[" value" ] = value;
1023- doc[" si_unit" ] = SensorTypeToString (read_type);
1008+ doc[" si_unit" ] = SensorTypeToSIUnit (read_type);
10241009}
10251010
10261011/* *************************************************************************/
@@ -1154,7 +1139,7 @@ bool ws_sdcard::LogDS18xSensorEventToSD(
11541139 doc[" timestamp" ] = timestamp;
11551140 doc[" pin" ] = event_msg->onewire_pin ;
11561141 doc[" value" ] = event_msg->sensor_events [i].value .float_value ;
1157- doc[" si_unit" ] = SensorTypeToString (event_msg->sensor_events [i].type );
1142+ doc[" si_unit" ] = SensorTypeToSIUnit (event_msg->sensor_events [i].type );
11581143 LogJSONDoc (doc);
11591144 }
11601145 return true ;
@@ -1190,7 +1175,7 @@ bool ws_sdcard::LogI2cDeviceEvent(
11901175 doc[" timestamp" ] = GetTimestamp ();
11911176 doc[" value" ] = msg_device_event->i2c_device_events [i].value .float_value ;
11921177 doc[" si_unit" ] =
1193- SensorTypeToString (msg_device_event->i2c_device_events [i].type );
1178+ SensorTypeToSIUnit (msg_device_event->i2c_device_events [i].type );
11941179 if (!LogJSONDoc (doc))
11951180 return false ;
11961181 }
@@ -1286,25 +1271,13 @@ void ws_sdcard::waitForSerialConfig() {
12861271 char c = Serial.read ();
12871272 _serialInput += c;
12881273 if (_serialInput.endsWith (" \\ n" )) {
1289- WS_DEBUG_PRINTLN (" [SD] End of JSON string detected!" );
12901274 break ;
12911275 }
12921276 }
12931277 }
12941278 }
1295- // Trim the newline
1279+ // Remove the newline
12961280 _serialInput.trim ();
1297-
1298- // Print out the received JSON string
1299- // TODO: REMOVE this for the PR
1300- WS_DEBUG_PRINT (" [SD][Debug] JSON string received!" );
1301- if (_use_test_data) {
1302- WS_DEBUG_PRINTLN (" [from json test data]" );
1303- WS_DEBUG_PRINTLN (json_test_data);
1304- } else {
1305- WS_DEBUG_PRINTLN (_serialInput);
1306- }
1307-
13081281 WS_DEBUG_PRINTLN (" [SD] JSON string received!" );
13091282}
13101283#endif
0 commit comments