Skip to content

Commit ccac2a4

Browse files
author
Evgeny Kapinos
committed
bug with linker is here arduino/Arduino#1071 (comment)
1 parent 127ca1c commit ccac2a4

11 files changed

+172
-296
lines changed

Growbox/Growbox.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// Growbox
1818
#include "Global.h"
1919
#include "Controller.h"
20+
#include "StorageHelper.h"
2021
#include "Thermometer.h"
2122
#include "RAK410_XBeeWifi.h"
2223
#include "WebServer.h"

Growbox/Logger.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ int LoggerClass::getLogRecordsCount(){
5757
}
5858

5959
LogRecord LoggerClass::getLogRecordByIndex(int index){
60-
LogRecord logRecord;
61-
GB_StorageHelper.getLogRecordByIndex(index, logRecord);
62-
return logRecord;
60+
return GB_StorageHelper.getLogRecordByIndex(index);
6361
}
6462

6563
/////////////////////////////////////////////////////////////////////
@@ -105,7 +103,7 @@ const __FlashStringHelper* LoggerClass::getLogRecordDescription(LogRecord &logRe
105103
}
106104
}
107105

108-
String LoggerClass::getLogRecordSuffix(const LogRecord &logRecord){
106+
String LoggerClass::getLogRecordDescriptionSuffix(const LogRecord &logRecord){
109107
String out;
110108
if (isTemperature(logRecord)) {
111109
byte temperature = (logRecord.data & B00111111);
@@ -142,7 +140,7 @@ void LoggerClass::printLogRecordToSerialMonotior(const LogRecord &logRecord, con
142140
}
143141
Serial.print(getLogRecordPrefix(logRecord));
144142
Serial.print(description);
145-
Serial.print(getLogRecordSuffix(logRecord));
143+
Serial.print(getLogRecordDescriptionSuffix(logRecord));
146144

147145
Serial.println();
148146
}

Growbox/Logger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class LoggerClass {
3232

3333
static String getLogRecordPrefix(const LogRecord &logRecord);
3434
static const __FlashStringHelper* getLogRecordDescription(LogRecord &logRecord);
35-
static String getLogRecordSuffix(const LogRecord &logRecord);
35+
static String getLogRecordDescriptionSuffix(const LogRecord &logRecord);
3636

3737
static boolean isEvent(const LogRecord &logRecord);
3838
static boolean isError(const LogRecord &logRecord);

Growbox/RAK410_XBeeWifi.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ boolean RAK410_XBeeWifiClass::isPresent(){ // check if the device is present
2222
}
2323

2424
/////////////////////////////////////////////////////////////////////
25-
// STARTUP //
25+
// WORKFLOW //
2626
/////////////////////////////////////////////////////////////////////
2727

2828
void RAK410_XBeeWifiClass::init(){
@@ -88,28 +88,6 @@ void RAK410_XBeeWifiClass::updateWiFiStatus(){
8888

8989
}
9090

91-
boolean RAK410_XBeeWifiClass::restartWifi(){
92-
boolean isWiFiPresent = false;
93-
94-
for (byte i = 0; i < 2; i++){ // Sometimes first command returns ERROR, two attempts
95-
96-
String input = wifiExecuteRawCommand(F("at+reset=0"), 500); // spec boot time 210 // NOresponse checked wrong
97-
98-
isWiFiPresent = StringUtils::flashStringEquals(input, FS(S_WIFI_RESPONSE_WELLCOME));
99-
if (isWiFiPresent) {
100-
break;
101-
}
102-
if (g_useSerialMonitor && input.length() > 0){
103-
showWifiMessage(F("Not correct wellcome message: "), false);
104-
PrintUtils::printWithoutCRLF(input);
105-
Serial.print(FS(S_Next));
106-
PrintUtils::printHEX(input);
107-
Serial.println();
108-
}
109-
}
110-
return isWiFiPresent;
111-
}
112-
11391
/////////////////////////////////////////////////////////////////////
11492
// TCP //
11593
/////////////////////////////////////////////////////////////////////
@@ -391,6 +369,28 @@ boolean RAK410_XBeeWifiClass::sendCloseConnection(const byte wifiPortDescriptor)
391369
//private:
392370

393371

372+
boolean RAK410_XBeeWifiClass::restartWifi(){
373+
boolean isWiFiPresent = false;
374+
375+
for (byte i = 0; i < 2; i++){ // Sometimes first command returns ERROR, two attempts
376+
377+
String input = wifiExecuteRawCommand(F("at+reset=0"), 500); // spec boot time 210 // NOresponse checked wrong
378+
379+
isWiFiPresent = StringUtils::flashStringEquals(input, FS(S_WIFI_RESPONSE_WELLCOME));
380+
if (isWiFiPresent) {
381+
break;
382+
}
383+
if (g_useSerialMonitor && input.length() > 0){
384+
showWifiMessage(F("Not correct wellcome message: "), false);
385+
PrintUtils::printWithoutCRLF(input);
386+
Serial.print(FS(S_Next));
387+
PrintUtils::printHEX(input);
388+
Serial.println();
389+
}
390+
}
391+
return isWiFiPresent;
392+
}
393+
394394
boolean RAK410_XBeeWifiClass::startupWebServer(boolean forceDefaultParameters){
395395

396396
if (!wifiExecuteCommand(F("at+scan=0"), 5000)){

Growbox/RAK410_XBeeWifi.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ class RAK410_XBeeWifiClass{
3131

3232
boolean isPresent(); // check if the device is present
3333

34-
/////////////////////////////////////////////////////////////////////
35-
// STARTUP //
34+
/////////////////////////////////////////////////////////////////////
35+
// WORKFLOW //
3636
/////////////////////////////////////////////////////////////////////
3737

3838
void init();
3939
void updateWiFiStatus();
4040

41-
boolean restartWifi();
42-
4341
/////////////////////////////////////////////////////////////////////
4442
// TCP //
4543
/////////////////////////////////////////////////////////////////////
@@ -62,21 +60,17 @@ class RAK410_XBeeWifiClass{
6260

6361

6462
private:
63+
64+
/////////////////////////////////////////////////////////////////////
65+
// TCP //
66+
/////////////////////////////////////////////////////////////////////
67+
68+
boolean restartWifi();
6569
boolean startupWebServer(boolean forceDefaultParameters = false);
6670

6771
boolean wifiExecuteCommand(const __FlashStringHelper* command = 0, size_t maxResponseDeleay = WIFI_RESPONSE_DEFAULT_DELAY, boolean rebootIfNoResponse=true);
6872
String wifiExecuteRawCommand(const __FlashStringHelper* command = 0, size_t maxResponseDeleay = WIFI_RESPONSE_DEFAULT_DELAY);
6973

70-
template <class T> void showWifiMessage(T str, boolean newLine = true){
71-
if (g_useSerialMonitor){
72-
Serial.print(F("WIFI> "));
73-
Serial.print(str);
74-
if (newLine){
75-
Serial.println();
76-
}
77-
}
78-
}
79-
8074
template <class T> unsigned int wifiExecuteCommandPrint(T command){
8175
unsigned int rez = Serial1.print(command);
8276

@@ -93,6 +87,20 @@ class RAK410_XBeeWifiClass{
9387
return rez;
9488
}
9589

90+
/////////////////////////////////////////////////////////////////////
91+
// OTHER //
92+
/////////////////////////////////////////////////////////////////////
93+
94+
template <class T> void showWifiMessage(T str, boolean newLine = true){
95+
if (g_useSerialMonitor){
96+
Serial.print(F("WIFI> "));
97+
Serial.print(str);
98+
if (newLine){
99+
Serial.println();
100+
}
101+
}
102+
}
103+
96104
};
97105

98106
extern RAK410_XBeeWifiClass RAK410_XBeeWifi;
@@ -127,5 +135,6 @@ extern RAK410_XBeeWifiClass RAK410_XBeeWifi;
127135

128136

129137

138+
130139

131140

Growbox/StorageHelper.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ word StorageHelperClass::getLogRecordsCount(){
103103
}
104104
}
105105

106-
boolean StorageHelperClass::getLogRecordByIndex(word index, LogRecord &logRecord){
106+
LogRecord StorageHelperClass::getLogRecordByIndex(word index){
107107
if (index >= getLogRecordsCount()){
108108
return false;
109109
}
@@ -121,12 +121,11 @@ boolean StorageHelperClass::getLogRecordByIndex(word index, LogRecord &logRecord
121121
}
122122
//Serial.print("logRecordOffset"); Serial.println(logRecordOffset);
123123
if (planeIndex < LOG_CAPACITY_ARDUINO){
124-
logRecord = EEPROM.readBlock<LogRecord>(sizeof(BootRecord) + planeIndex*sizeof(logRecord));
124+
return EEPROM.readBlock<LogRecord>(sizeof(BootRecord) + planeIndex*sizeof(LogRecord));
125125
}
126126
else {
127-
logRecord = EEPROM_AT24C32.readBlock<LogRecord>((planeIndex-LOG_CAPACITY_ARDUINO)*sizeof(logRecord));
127+
return EEPROM_AT24C32.readBlock<LogRecord>((planeIndex-LOG_CAPACITY_ARDUINO)*sizeof(LogRecord));
128128
}
129-
return true;
130129
}
131130

132131
/////////////////////////////////////////////////////////////////////

Growbox/StorageHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class StorageHelperClass{
3333
boolean isLogOverflow();
3434

3535
word getLogRecordsCount();
36-
boolean getLogRecordByIndex(word index, LogRecord &logRecord);
36+
LogRecord getLogRecordByIndex(word index);
3737

3838
/////////////////////////////////////////////////////////////////////
3939
// GROWBOX COMMANDS //

Growbox/StringUtils.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,30 @@ String StringUtils::floatToString(float number){
144144
}
145145

146146

147-
String StringUtils::timeToString(time_t time){
147+
String StringUtils::timeToString(time_t time, boolean getDate, boolean getTime){
148148
String out;
149149

150150
tmElements_t tm;
151151
breakTime(time, tm);
152152

153153
//out += '[';
154-
out += getFixedDigitsString(tm.Hour, 2);
155-
out += ':';
156-
out += getFixedDigitsString(tm.Minute, 2);
157-
out += ':';
158-
out += getFixedDigitsString(tm.Second, 2);
159-
out += ' ';
160-
out += getFixedDigitsString(tm.Day, 2);
161-
out +='.';
162-
out += getFixedDigitsString(tm.Month, 2);
163-
out += '.';
164-
out += getFixedDigitsString(tmYearToCalendar(tm.Year), 4);
154+
if (getDate){
155+
out += getFixedDigitsString(tm.Day, 2);
156+
out +='.';
157+
out += getFixedDigitsString(tm.Month, 2);
158+
out += '.';
159+
out += getFixedDigitsString(tmYearToCalendar(tm.Year), 4);
160+
}
161+
if (getDate && getTime){
162+
out += ' ';
163+
}
164+
if (getTime){
165+
out += getFixedDigitsString(tm.Hour, 2);
166+
out += ':';
167+
out += getFixedDigitsString(tm.Minute, 2);
168+
out += ':';
169+
out += getFixedDigitsString(tm.Second, 2);
170+
}
165171
//out += ']';
166172
return out;
167173
}
@@ -174,3 +180,5 @@ String StringUtils::timeToString(time_t time){
174180

175181

176182

183+
184+

Growbox/StringUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace StringUtils {
3737
String getFixedDigitsString(const int number, const byte numberOfDigits);
3838
String byteToHexString(byte number, boolean addPrefix = false);
3939
String floatToString(float number);
40-
String timeToString(time_t time);
40+
String timeToString(time_t time, boolean getDate=true, boolean getTime=true);
4141

4242
}
4343

0 commit comments

Comments
 (0)