Snorktracker
 All Data Structures Files Functions Variables Macros Pages
Data.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 SFini
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
27 class MyData
28 {
29 public:
33  class RtcData {
34  public:
36 
41 
44 
49 
52 
53  long crcValue;
54 
55  public:
56  RtcData();
57 
58  bool isValid();
59  void setCRC();
60  long getCRC();
61  } rtcData;
62 
63  String status;
64  String restartInfo;
65  bool isOtaActive;
66  bool isPowerOn;
67  bool isLowPower;
68  bool isGsmActive;
69  bool isGpsActive;
70 
73 
74  double voltage;
75  double temperature;
76  double humidity;
77  double pressure;
78 
79  String softAPIP;
81  String stationIP;
82 
83  String modemInfo;
84  String modemIP;
85  String imei;
86  String cop;
87  String signalQuality;
88  String batteryLevel;
89  String batteryVolt;
90 
93 
94  bool isMoving;
95  double movingDistance;
96 
99 
100 public:
101  MyData();
102 
103  long secondsSincePowerOn();
104  long getActiveTimeSec();
106  long getPowerOnTimeSec();
108 
109  double getPowerConsumption();
111 };
112 
113 /* ******************************************** */
114 
115 MyData::RtcData::RtcData()
116  : aktiveTimeSec(0)
117  , powerOnTimeSec(0)
118  , deepSleepTimeSec(0)
119  , deepSleepStartSec(0)
120  , lowPowerActiveTimeSec(0)
121  , lowPowerPowerOnTimeSec(0)
122  , lastBme280ReadSec(0)
123  , lastSmsCheckSec(0)
124  , lastGpsReadSec(0)
125  , lastMqttPublishSec(0)
126  , mqttSendCount(0)
127  , mqttLastSentTime(0)
128 {
129  crcValue = getCRC();
130 }
131 
134 {
135  return getCRC() == crcValue;
136 }
137 
140 {
141  crcValue = getCRC();
142 }
143 
146 {
147  long crc = 0;
148 
149  crc = crc32(crc, (unsigned char *) &lastGps, sizeof(MyGps));
150  crc = crc32(crc, (unsigned char *) &aktiveTimeSec, sizeof(long));
151  crc = crc32(crc, (unsigned char *) &powerOnTimeSec, sizeof(long));
152  crc = crc32(crc, (unsigned char *) &deepSleepTimeSec, sizeof(long));
153  crc = crc32(crc, (unsigned char *) &deepSleepStartSec, sizeof(long));
154  crc = crc32(crc, (unsigned char *) &lowPowerActiveTimeSec, sizeof(long));
155  crc = crc32(crc, (unsigned char *) &lowPowerPowerOnTimeSec, sizeof(long));
156  crc = crc32(crc, (unsigned char *) &lastBme280ReadSec, sizeof(long));
157  crc = crc32(crc, (unsigned char *) &lastSmsCheckSec, sizeof(long));
158  crc = crc32(crc, (unsigned char *) &lastGpsReadSec, sizeof(long));
159  crc = crc32(crc, (unsigned char *) &lastMqttPublishSec, sizeof(long));
160  crc = crc32(crc, (unsigned char *) &mqttSendCount, sizeof(long));
161  crc = crc32(crc, (unsigned char *) &mqttLastSentTime, sizeof(long));
162 
163  return crc;
164 }
165 
168  : isOtaActive(false)
169  , isPowerOn(false)
170  , isLowPower(false)
171  , isGsmActive(false)
172  , isGpsActive(false)
173  , secondsToDeepSleep(-1)
174  , awakeTimeOffsetSec(0)
175  , voltage(0.0)
176  , temperature(0.0)
177  , humidity(0.0)
178  , pressure(0.0)
179  , isMoving(false)
180  , movingDistance(0.0)
181  , lastGpsUpdateSec(0)
182  , waitingForGps(false)
183 {
184 }
185 
188 {
190 }
191 
194 {
195  return rtcData.aktiveTimeSec + millis() / 1000;
196 }
197 
200 {
201  if (!isLowPower) {
203  } else {
204  return rtcData.lowPowerActiveTimeSec + millis() / 1000;
205  }
206 }
207 
210 {
211  if (!isPowerOn) {
212  return rtcData.powerOnTimeSec;
213  } else {
214  return rtcData.powerOnTimeSec + millis() / 1000;
215  }
216 }
217 
220 {
221  if (!isLowPower || !isPowerOn) {
223  } else {
224  return rtcData.lowPowerPowerOnTimeSec + millis() / 1000;
225  }
226 }
227 
232 {
236 }
237 
242 {
246 }
long aktiveTimeSec
Time in active mode without current millis().
Definition: Data.h:37
void setCRC()
Definition: Data.h:139
long lowPowerPowerOnTimeSec
Timestamp of the last deep sleep start.
Definition: Data.h:43
long awakeTimeOffsetSec
Awake time offset for SaveSettings.
Definition: Data.h:72
bool isValid()
Definition: Data.h:133
long getLowPowerPowerOnTimeSec()
Definition: Data.h:219
String status
Status information.
Definition: Data.h:63
class MyData::RtcData rtcData
Data to store in the RTC memory.
StringList consoleCmds
open commands to send to the sim808 module
Definition: Data.h:97
double getLowPowerPowerConsumption()
Definition: Data.h:241
MyData()
Definition: Data.h:167
#define POWER_CONSUMPTION_ACTIVE
Power consumption if Active in mA.
Definition: Config.h:42
Definition: Data.h:27
bool waitingForGps
We are trying to get a location.
Definition: Data.h:92
long crc32(long crc, unsigned char *buf, size_t len)
Definition: Utils.h:77
StringList logInfos
received sim808 answers or other logs
Definition: Data.h:98
String softAPIP
registered ip of the access point
Definition: Data.h:79
long powerOnTimeSec
Time the sim808 is on power without current millis..
Definition: Data.h:38
#define POWER_CONSUMPTION_POWER_ON
Power consumption if SIM808 Active in mA.
Definition: Config.h:43
long crcValue
CRC of the RtcData.
Definition: Data.h:53
String imei
IMEI of the sim card.
Definition: Data.h:85
long mqttLastSentTime
Last mqtt sent timestamp.
Definition: Data.h:51
double temperature
Current BME280 temperature.
Definition: Data.h:75
MyGps lastGps
Last known gps location without timeout.
Definition: Data.h:35
double getPowerConsumption()
Definition: Data.h:231
long lowPowerActiveTimeSec
Timestamp of the last deep sleep start.
Definition: Data.h:42
bool isGpsActive
Is the gs part of the sim808 activated?
Definition: Data.h:69
double pressure
Current BME280 pressure.
Definition: Data.h:77
long getCRC()
Definition: Data.h:145
#define POWER_CONSUMPTION_DEEP_SLEEP
Power consumption if in deep sleep mode in mA.
Definition: Config.h:44
String signalQuality
Quality of the signal.
Definition: Data.h:87
bool isPowerOn
Is the power of the sim808 switched on?
Definition: Data.h:66
String batteryVolt
Battery volt of the sim808 module.
Definition: Data.h:89
long mqttSendCount
How many time the mqtt data successfully sent.
Definition: Data.h:50
String restartInfo
Information on restart.
Definition: Data.h:64
String cop
Operator selection.
Definition: Data.h:86
long getPowerOnTimeSec()
Definition: Data.h:209
String stationIP
registered station ip
Definition: Data.h:81
bool isMoving
Is moving recognized.
Definition: Data.h:94
double voltage
Current supply voltage.
Definition: Data.h:74
String batteryLevel
Battery level of the sim808 module.
Definition: Data.h:88
long lastMqttPublishSec
Timestamp from the last send.
Definition: Data.h:48
long getLowPowerActiveTimeSec()
Definition: Data.h:199
String modemInfo
Information from SIM808.
Definition: Data.h:83
String softAPmacAddress
module mac address
Definition: Data.h:80
String modemIP
registered modem ip
Definition: Data.h:84
long secondsToDeepSleep
Time until next deepsleep. -1 = disabled.
Definition: Data.h:71
bool isGsmActive
Is the sim808 modul connected to a gsm network?
Definition: Data.h:68
long deepSleepTimeSec
Time in deep sleep mode.
Definition: Data.h:39
long lastGpsUpdateSec
Elapsed Time of last read.
Definition: Data.h:91
long deepSleepStartSec
Timestamp of the last deep sleep start.
Definition: Data.h:40
long secondsSincePowerOn()
Definition: Data.h:187
double humidity
Current BME280 humidity.
Definition: Data.h:76
long lastBme280ReadSec
Timestamp of the last BME280 read.
Definition: Data.h:45
bool isOtaActive
Is OverTheAir update active?
Definition: Data.h:65
long lastSmsCheckSec
Timestamp of the last sms check.
Definition: Data.h:46
long lastGpsReadSec
Timestamp of the last gps read.
Definition: Data.h:47
Definition: Gps.h:129
long getActiveTimeSec()
Definition: Data.h:193
double movingDistance
Minimum distance for moving flag.
Definition: Data.h:95
bool isLowPower
Is the power below min voltage?
Definition: Data.h:67