From ac38f7b003aae1cdee7a0e5921f9b1ac98e9dde6 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Sun, 5 Aug 2018 21:31:47 +1200 Subject: [PATCH 01/11] Reduced conditions for allerts triggering and clearing (-46 bytes) --- GpsTracker/Alerts.cpp | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/GpsTracker/Alerts.cpp b/GpsTracker/Alerts.cpp index 9a39699..33bab8c 100644 --- a/GpsTracker/Alerts.cpp +++ b/GpsTracker/Alerts.cpp @@ -11,25 +11,14 @@ namespace alerts { uint8_t getTriggered(PositionEntryMetadata &metadata) { config_t* config = &config::main::value; - uint8_t result = 0; + uint8_t active = 0; - if (metadata.batteryLevel <= config->alertBatteryLevel1 && !bitRead(config->activeAlerts, ALERT_BATTERY_LEVEL_1)) { - bitSet(result, ALERT_BATTERY_LEVEL_1); - } + if (metadata.batteryLevel <= config->alertBatteryLevel1) bitSet(active, ALERT_BATTERY_LEVEL_1); + if (metadata.batteryLevel <= config->alertBatteryLevel2) bitSet(active, ALERT_BATTERY_LEVEL_2); + if (metadata.temperature == ALERT_SUSPICIOUS_RTC_TEMPERATURE) bitSet(active, ALERT_RTC_TEMPERATURE_FAILURE); + if (!rtc::isAccurate()) bitSet(active, ALERT_RTC_CLOCK_FAILURE); - if (metadata.batteryLevel <= config->alertBatteryLevel2 && !bitRead(config->activeAlerts, ALERT_BATTERY_LEVEL_2)) { - bitSet(result, ALERT_BATTERY_LEVEL_2); - } - - if (metadata.temperature == ALERT_SUSPICIOUS_RTC_TEMPERATURE && !bitRead(config->activeAlerts, ALERT_RTC_TEMPERATURE_FAILURE)) { - bitSet(result, ALERT_RTC_TEMPERATURE_FAILURE); - } - - if (!rtc::isAccurate() && !bitRead(config->activeAlerts, ALERT_RTC_CLOCK_FAILURE)) { - bitSet(result, ALERT_RTC_CLOCK_FAILURE); - } - - return result; + return config->activeAlerts ^ active; } void add(uint8_t mask) { @@ -44,19 +33,11 @@ namespace alerts { config_t* config = &config::main::value; uint8_t clearMask = 0; - if ((config->activeAlerts & (_BV(ALERT_BATTERY_LEVEL_1) | _BV(ALERT_BATTERY_LEVEL_2))) && metadata.batteryLevel >= config->alertBatteryLevelClear) { - clearMask |= _BV(ALERT_BATTERY_LEVEL_1) | _BV(ALERT_BATTERY_LEVEL_2); - } - - if (bitRead(config->activeAlerts, ALERT_RTC_TEMPERATURE_FAILURE) && metadata.temperature != ALERT_SUSPICIOUS_RTC_TEMPERATURE) { - bitSet(clearMask, ALERT_RTC_TEMPERATURE_FAILURE); - } - - if (bitRead(config->activeAlerts, ALERT_RTC_CLOCK_FAILURE) && rtc::isAccurate()) { - bitSet(clearMask, ALERT_RTC_CLOCK_FAILURE); - } + if (metadata.batteryLevel >= config->alertBatteryLevelClear) clearMask |= _BV(ALERT_BATTERY_LEVEL_1) | _BV(ALERT_BATTERY_LEVEL_2); + if (metadata.temperature != ALERT_SUSPICIOUS_RTC_TEMPERATURE) bitSet(clearMask, ALERT_RTC_TEMPERATURE_FAILURE); + if (rtc::isAccurate()) bitSet(clearMask, ALERT_RTC_CLOCK_FAILURE); - if (!clearMask) return; //save a write to eeprom if there is no change + if (!config->activeAlerts || !clearMask) return; //save a write to eeprom if there is no change config->activeAlerts &= ~clearMask; config::main::save(); } From cb6bacfde57986c9a1c8d535b69c6e429b0ff505 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Sun, 5 Aug 2018 22:56:14 +1200 Subject: [PATCH 02/11] Moved files around for vscode --- .gitignore | 266 +----------------- GpsTracker/Alerts.cpp => Alerts.cpp | 0 GpsTracker/Alerts.h => Alerts.h | 0 GpsTracker/Config.cpp => Config.cpp | 0 GpsTracker/Config.h => Config.h | 0 GpsTracker/Core.cpp => Core.cpp | 0 GpsTracker/Core.h => Core.h | 0 GpsTracker/Debug.cpp => Debug.cpp | 0 GpsTracker/Debug.h => Debug.h | 0 GpsTracker/Flash.cpp => Flash.cpp | 0 GpsTracker/Flash.h => Flash.h | 0 GpsTracker/Gps.cpp => Gps.cpp | 0 GpsTracker/Gps.h => Gps.h | 0 GpsTracker/GpsTracker.h => GpsTracker.h | 0 GpsTracker/GpsTracker.ino => GpsTracker.ino | 0 GpsTracker/~AutoRecover.GpsTracker.vcxproj0 | 143 ---------- GpsTracker/Hardware.cpp => Hardware.cpp | 0 GpsTracker/Hardware.h => Hardware.h | 0 GpsTracker/Logging.cpp => Logging.cpp | 0 GpsTracker/Logging.h => Logging.h | 0 GpsTracker/MainUnit.cpp => MainUnit.cpp | 0 GpsTracker/MainUnit.h => MainUnit.h | 0 GpsTracker/Network.cpp => Network.cpp | 0 GpsTracker/Network.h => Network.h | 0 ...nsBackup.cpp => NetworkPositionsBackup.cpp | 0 ...itionsBackup.h => NetworkPositionsBackup.h | 0 ...itionsConfig.h => NetworkPositionsConfig.h | 0 GpsTracker/Pins.h => Pins.h | 0 GpsTracker/Positions.cpp => Positions.cpp | 0 GpsTracker/Positions.h => Positions.h | 0 ...PositionsBackup.cpp => PositionsBackup.cpp | 0 .../PositionsBackup.h => PositionsBackup.h | 0 GpsTracker/Rtc.cpp => Rtc.cpp | 4 +- GpsTracker/Rtc.h => Rtc.h | 0 GpsTracker/SdCard.cpp => SdCard.cpp | 0 GpsTracker/SdCard.h => SdCard.h | 0 ...sitionsBackup.cpp => SdPositionsBackup.cpp | 0 ...SdPositionsBackup.h => SdPositionsBackup.h | 0 ...sitionsConfig.cpp => SdPositionsConfig.cpp | 0 ...SdPositionsConfig.h => SdPositionsConfig.h | 0 GpsTracker/Time2.cpp => Time2.cpp | 0 GpsTracker/Time2.h => Time2.h | 0 42 files changed, 3 insertions(+), 410 deletions(-) rename GpsTracker/Alerts.cpp => Alerts.cpp (100%) rename GpsTracker/Alerts.h => Alerts.h (100%) rename GpsTracker/Config.cpp => Config.cpp (100%) rename GpsTracker/Config.h => Config.h (100%) rename GpsTracker/Core.cpp => Core.cpp (100%) rename GpsTracker/Core.h => Core.h (100%) rename GpsTracker/Debug.cpp => Debug.cpp (100%) rename GpsTracker/Debug.h => Debug.h (100%) rename GpsTracker/Flash.cpp => Flash.cpp (100%) rename GpsTracker/Flash.h => Flash.h (100%) rename GpsTracker/Gps.cpp => Gps.cpp (100%) rename GpsTracker/Gps.h => Gps.h (100%) rename GpsTracker/GpsTracker.h => GpsTracker.h (100%) rename GpsTracker/GpsTracker.ino => GpsTracker.ino (100%) delete mode 100644 GpsTracker/~AutoRecover.GpsTracker.vcxproj0 rename GpsTracker/Hardware.cpp => Hardware.cpp (100%) rename GpsTracker/Hardware.h => Hardware.h (100%) rename GpsTracker/Logging.cpp => Logging.cpp (100%) rename GpsTracker/Logging.h => Logging.h (100%) rename GpsTracker/MainUnit.cpp => MainUnit.cpp (100%) rename GpsTracker/MainUnit.h => MainUnit.h (100%) rename GpsTracker/Network.cpp => Network.cpp (100%) rename GpsTracker/Network.h => Network.h (100%) rename GpsTracker/NetworkPositionsBackup.cpp => NetworkPositionsBackup.cpp (100%) rename GpsTracker/NetworkPositionsBackup.h => NetworkPositionsBackup.h (100%) rename GpsTracker/NetworkPositionsConfig.h => NetworkPositionsConfig.h (100%) rename GpsTracker/Pins.h => Pins.h (100%) rename GpsTracker/Positions.cpp => Positions.cpp (100%) rename GpsTracker/Positions.h => Positions.h (100%) rename GpsTracker/PositionsBackup.cpp => PositionsBackup.cpp (100%) rename GpsTracker/PositionsBackup.h => PositionsBackup.h (100%) rename GpsTracker/Rtc.cpp => Rtc.cpp (95%) rename GpsTracker/Rtc.h => Rtc.h (100%) rename GpsTracker/SdCard.cpp => SdCard.cpp (100%) rename GpsTracker/SdCard.h => SdCard.h (100%) rename GpsTracker/SdPositionsBackup.cpp => SdPositionsBackup.cpp (100%) rename GpsTracker/SdPositionsBackup.h => SdPositionsBackup.h (100%) rename GpsTracker/SdPositionsConfig.cpp => SdPositionsConfig.cpp (100%) rename GpsTracker/SdPositionsConfig.h => SdPositionsConfig.h (100%) rename GpsTracker/Time2.cpp => Time2.cpp (100%) rename GpsTracker/Time2.h => Time2.h (100%) diff --git a/.gitignore b/.gitignore index 85b7e92..371c8d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,267 +1,5 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - # Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ [Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -project.fragment.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -#*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -#VisualMicro -__vm/ -#Line endings unifier -.leu \ No newline at end of file +#Visual Studio code +.vscode/ \ No newline at end of file diff --git a/GpsTracker/Alerts.cpp b/Alerts.cpp similarity index 100% rename from GpsTracker/Alerts.cpp rename to Alerts.cpp diff --git a/GpsTracker/Alerts.h b/Alerts.h similarity index 100% rename from GpsTracker/Alerts.h rename to Alerts.h diff --git a/GpsTracker/Config.cpp b/Config.cpp similarity index 100% rename from GpsTracker/Config.cpp rename to Config.cpp diff --git a/GpsTracker/Config.h b/Config.h similarity index 100% rename from GpsTracker/Config.h rename to Config.h diff --git a/GpsTracker/Core.cpp b/Core.cpp similarity index 100% rename from GpsTracker/Core.cpp rename to Core.cpp diff --git a/GpsTracker/Core.h b/Core.h similarity index 100% rename from GpsTracker/Core.h rename to Core.h diff --git a/GpsTracker/Debug.cpp b/Debug.cpp similarity index 100% rename from GpsTracker/Debug.cpp rename to Debug.cpp diff --git a/GpsTracker/Debug.h b/Debug.h similarity index 100% rename from GpsTracker/Debug.h rename to Debug.h diff --git a/GpsTracker/Flash.cpp b/Flash.cpp similarity index 100% rename from GpsTracker/Flash.cpp rename to Flash.cpp diff --git a/GpsTracker/Flash.h b/Flash.h similarity index 100% rename from GpsTracker/Flash.h rename to Flash.h diff --git a/GpsTracker/Gps.cpp b/Gps.cpp similarity index 100% rename from GpsTracker/Gps.cpp rename to Gps.cpp diff --git a/GpsTracker/Gps.h b/Gps.h similarity index 100% rename from GpsTracker/Gps.h rename to Gps.h diff --git a/GpsTracker/GpsTracker.h b/GpsTracker.h similarity index 100% rename from GpsTracker/GpsTracker.h rename to GpsTracker.h diff --git a/GpsTracker/GpsTracker.ino b/GpsTracker.ino similarity index 100% rename from GpsTracker/GpsTracker.ino rename to GpsTracker.ino diff --git a/GpsTracker/~AutoRecover.GpsTracker.vcxproj0 b/GpsTracker/~AutoRecover.GpsTracker.vcxproj0 deleted file mode 100644 index 1555d93..0000000 --- a/GpsTracker/~AutoRecover.GpsTracker.vcxproj0 +++ /dev/null @@ -1,143 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {C5F80730-F44F-4478-BDAE-6634EFC2CA88} - GpsTracker - GpsTracker - - - - Application - true - - - MultiByte - - - Application - false - - - true - MultiByte - - - - - - - - - - - - - - - - - - - - Level3 - Disabled - true - $(ProjectDir)..\GpsTracker;$(ProjectDir)..\..\libraries\E24;$(ProjectDir)..\..\libraries\SIM808;$(ProjectDir)..\..\libraries\uDS3231;$(ProjectDir)..\..\libraries\ArduinoLog;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src;$(ProjectDir)..\..\libraries\Low-Power;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial\src;$(ProjectDir)..\..\libraries\SdFat\src;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\libraries;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries;$(ProjectDir)..\..\libraries;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr\;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.8.1\include;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.2\include;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.3\include;%(AdditionalIncludeDirectories) - $(ProjectDir)__vm\.GpsTracker.vsarduino.h;%(ForcedIncludeFiles) - false - __AVR_ATmega328p__;__AVR_ATmega328P__;_DEBUG=1;_VMDEBUG=1;F_CPU=8000000L;ARDUINO=10805;ARDUINO_AVR_PRO;ARDUINO_ARCH_AVR;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions) - - - true - - - - - Level3 - Disabled - true - true - true - $(ProjectDir)..\GpsTracker;$(ProjectDir)..\..\libraries\E24;$(ProjectDir)..\..\libraries\SIM808;$(ProjectDir)..\..\libraries\uDS3231;$(ProjectDir)..\..\libraries\ArduinoLog;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial\src;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src;$(ProjectDir)..\..\libraries\Low-Power;$(ProjectDir)..\..\libraries\SdFat\src;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\libraries;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries;$(ProjectDir)..\..\libraries;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr\;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.8.1\include;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.2\include;$(ProjectDir)..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.3\include;%(AdditionalIncludeDirectories) - $(ProjectDir)__vm\.GpsTracker.vsarduino.h;%(ForcedIncludeFiles) - false - __AVR_ATmega328p__;__AVR_ATmega328P__;F_CPU=8000000L;ARDUINO=10805;ARDUINO_AVR_PRO;ARDUINO_ARCH_AVR;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions) - - - true - true - true - - - - - - - VisualMicroDebugger - - - - CppCode - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/GpsTracker/Hardware.cpp b/Hardware.cpp similarity index 100% rename from GpsTracker/Hardware.cpp rename to Hardware.cpp diff --git a/GpsTracker/Hardware.h b/Hardware.h similarity index 100% rename from GpsTracker/Hardware.h rename to Hardware.h diff --git a/GpsTracker/Logging.cpp b/Logging.cpp similarity index 100% rename from GpsTracker/Logging.cpp rename to Logging.cpp diff --git a/GpsTracker/Logging.h b/Logging.h similarity index 100% rename from GpsTracker/Logging.h rename to Logging.h diff --git a/GpsTracker/MainUnit.cpp b/MainUnit.cpp similarity index 100% rename from GpsTracker/MainUnit.cpp rename to MainUnit.cpp diff --git a/GpsTracker/MainUnit.h b/MainUnit.h similarity index 100% rename from GpsTracker/MainUnit.h rename to MainUnit.h diff --git a/GpsTracker/Network.cpp b/Network.cpp similarity index 100% rename from GpsTracker/Network.cpp rename to Network.cpp diff --git a/GpsTracker/Network.h b/Network.h similarity index 100% rename from GpsTracker/Network.h rename to Network.h diff --git a/GpsTracker/NetworkPositionsBackup.cpp b/NetworkPositionsBackup.cpp similarity index 100% rename from GpsTracker/NetworkPositionsBackup.cpp rename to NetworkPositionsBackup.cpp diff --git a/GpsTracker/NetworkPositionsBackup.h b/NetworkPositionsBackup.h similarity index 100% rename from GpsTracker/NetworkPositionsBackup.h rename to NetworkPositionsBackup.h diff --git a/GpsTracker/NetworkPositionsConfig.h b/NetworkPositionsConfig.h similarity index 100% rename from GpsTracker/NetworkPositionsConfig.h rename to NetworkPositionsConfig.h diff --git a/GpsTracker/Pins.h b/Pins.h similarity index 100% rename from GpsTracker/Pins.h rename to Pins.h diff --git a/GpsTracker/Positions.cpp b/Positions.cpp similarity index 100% rename from GpsTracker/Positions.cpp rename to Positions.cpp diff --git a/GpsTracker/Positions.h b/Positions.h similarity index 100% rename from GpsTracker/Positions.h rename to Positions.h diff --git a/GpsTracker/PositionsBackup.cpp b/PositionsBackup.cpp similarity index 100% rename from GpsTracker/PositionsBackup.cpp rename to PositionsBackup.cpp diff --git a/GpsTracker/PositionsBackup.h b/PositionsBackup.h similarity index 100% rename from GpsTracker/PositionsBackup.h rename to PositionsBackup.h diff --git a/GpsTracker/Rtc.cpp b/Rtc.cpp similarity index 95% rename from GpsTracker/Rtc.cpp rename to Rtc.cpp index 26d8b45..861e3a2 100644 --- a/GpsTracker/Rtc.cpp +++ b/Rtc.cpp @@ -11,7 +11,7 @@ using namespace utils; namespace rtc { - + void setup() { VERBOSE("setup"); hardware::i2c::powerOn(); @@ -19,8 +19,6 @@ namespace rtc { RTC.control(DS3231_A1_INT_ENABLE, DS3231_OFF); //Alarm 1 OFF RTC.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN ON hardware::i2c::powerOff(); - - //TODO : check wether the osc has been halted (meaning the battery could be dead) } float getTemperature() { diff --git a/GpsTracker/Rtc.h b/Rtc.h similarity index 100% rename from GpsTracker/Rtc.h rename to Rtc.h diff --git a/GpsTracker/SdCard.cpp b/SdCard.cpp similarity index 100% rename from GpsTracker/SdCard.cpp rename to SdCard.cpp diff --git a/GpsTracker/SdCard.h b/SdCard.h similarity index 100% rename from GpsTracker/SdCard.h rename to SdCard.h diff --git a/GpsTracker/SdPositionsBackup.cpp b/SdPositionsBackup.cpp similarity index 100% rename from GpsTracker/SdPositionsBackup.cpp rename to SdPositionsBackup.cpp diff --git a/GpsTracker/SdPositionsBackup.h b/SdPositionsBackup.h similarity index 100% rename from GpsTracker/SdPositionsBackup.h rename to SdPositionsBackup.h diff --git a/GpsTracker/SdPositionsConfig.cpp b/SdPositionsConfig.cpp similarity index 100% rename from GpsTracker/SdPositionsConfig.cpp rename to SdPositionsConfig.cpp diff --git a/GpsTracker/SdPositionsConfig.h b/SdPositionsConfig.h similarity index 100% rename from GpsTracker/SdPositionsConfig.h rename to SdPositionsConfig.h diff --git a/GpsTracker/Time2.cpp b/Time2.cpp similarity index 100% rename from GpsTracker/Time2.cpp rename to Time2.cpp diff --git a/GpsTracker/Time2.h b/Time2.h similarity index 100% rename from GpsTracker/Time2.h rename to Time2.h From a371b8556d916cd3a1d30933e855922f5d5d1a03 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Sun, 5 Aug 2018 23:03:23 +1200 Subject: [PATCH 03/11] Added workspace to scm --- gpstracker.code-workspace | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 gpstracker.code-workspace diff --git a/gpstracker.code-workspace b/gpstracker.code-workspace new file mode 100644 index 0000000..1f9a02e --- /dev/null +++ b/gpstracker.code-workspace @@ -0,0 +1,26 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "../libraries/SIM808" + }, + { + "path": "../libraries/uDS3231" + }, + { + "path": "../libraries/E24" + }, + { + "path": "../libraries/Low-Power" + }, + { + "path": "../libraries/ArduinoLog" + } + ], + "settings": { + "C_Cpp.intelliSenseEngineFallback": "Disabled", + "C_Cpp.intelliSenseEngine": "Tag Parser" + } +} \ No newline at end of file From 4e7fa881186621b457a9584ab0fe473e8851abe4 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Sun, 5 Aug 2018 23:18:50 +1200 Subject: [PATCH 04/11] Added intellisense configuration file --- .vscode/c_cpp_properties.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..62faa60 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,22 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/../libraries/SIM808", + "${workspaceFolder}/../libraries/uDS3231", + "${workspaceFolder}/../libraries/E24", + "${workspaceFolder}/../libraries/Low-Power", + "${workspaceFolder}/../libraries/ArduinoLog", + "${config:arduino.path}/tools/**", + "${config:arduino.path}/hardware/arduino/avr/**", + "${config:arduino.path}/hardware/tools/avr/avr/include/**" + ], + "intelliSenseMode": "clang-x64", + "cStandard": "c11", + "cppStandard": "c++11" + } + ], + "version": 4 +} \ No newline at end of file From 809531acce24a12ed3b8463a0dd6e976c9c50b9f Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 6 Aug 2018 12:23:47 +1200 Subject: [PATCH 05/11] Fix network not being powered off if not available --- Core.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Core.cpp b/Core.cpp index 5c72ba7..c53faf3 100644 --- a/Core.cpp +++ b/Core.cpp @@ -65,7 +65,10 @@ namespace core { network::powerOn(); networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS); - if (!network::isAvailable(networkStatus.stat)) return NO_ALERTS_NOTIFIED; + if (!network::isAvailable(networkStatus.stat)) { + network::powerOff(); + return NO_ALERTS_NOTIFIED; + } strncpy_P(buffer, PSTR("Alerts !"), SMS_BUFFER_SIZE); if (bitRead(triggered, ALERT_BATTERY_LEVEL_1) || bitRead(triggered, ALERT_BATTERY_LEVEL_2)) { @@ -102,7 +105,7 @@ namespace core { float distance = gps::getDistanceFromPrevious(); //did we missed positions because we were sleeping ? if (distance > GPS_DEFAULT_MISSED_POSITION_GAP_KM) stoppedInARow = 0; else stoppedInARow = min(stoppedInARow + 1, SLEEP_DEFAULT_STOPPED_THRESHOLD + 1); //avoid overflow on REALLY long stops - + if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) { result = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; } @@ -119,14 +122,14 @@ namespace core { uint16_t mapSleepTime(uint8_t velocity) { uint16_t result; uint16_t currentTime = 0xFFFF; - + if (rtc::isAccurate()) { tmElements_t time; rtc::getTime(time); currentTime = SLEEP_TIMING_TIME(time.Hour, time.Minute); } - + for (uint8_t i = flash::getArraySize(config::defaultSleepTimings); i--;) { sleepTimings_t timing; flash::read(&config::defaultSleepTimings[i], timing); From 2af81daeaa4dde8585fcf1cbfe62f037a8455878 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 6 Aug 2018 12:26:39 +1200 Subject: [PATCH 06/11] Reduced hex size by reversing if condition (-33bytes) --- Core.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/Core.cpp b/Core.cpp index c53faf3..09a8ba7 100644 --- a/Core.cpp +++ b/Core.cpp @@ -56,6 +56,7 @@ namespace core { SIM808RegistrationStatus networkStatus; char buffer[SMS_BUFFER_SIZE]; const __FlashStringHelper * backupFailureString = F(" Backup battery failure ?"); + bool notified = false; uint8_t triggered = alerts::getTriggered(metadata); if (!triggered) return NO_ALERTS_NOTIFIED; @@ -65,27 +66,24 @@ namespace core { network::powerOn(); networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS); - if (!network::isAvailable(networkStatus.stat)) { - network::powerOff(); - return NO_ALERTS_NOTIFIED; - } + if (network::isAvailable(networkStatus.stat)) { + strncpy_P(buffer, PSTR("Alerts !"), SMS_BUFFER_SIZE); + if (bitRead(triggered, ALERT_BATTERY_LEVEL_1) || bitRead(triggered, ALERT_BATTERY_LEVEL_2)) { + details::appendToSmsBuffer(buffer, PSTR("\n- Battery at %d%%."), metadata.batteryLevel); + } - strncpy_P(buffer, PSTR("Alerts !"), SMS_BUFFER_SIZE); - if (bitRead(triggered, ALERT_BATTERY_LEVEL_1) || bitRead(triggered, ALERT_BATTERY_LEVEL_2)) { - details::appendToSmsBuffer(buffer, PSTR("\n- Battery at %d%%."), metadata.batteryLevel); - } + if (bitRead(triggered, ALERT_RTC_TEMPERATURE_FAILURE)) { + details::appendToSmsBuffer(buffer, PSTR("\n- Temperature is %dC.%S"), static_cast(metadata.temperature * 100), backupFailureString); + } - if (bitRead(triggered, ALERT_RTC_TEMPERATURE_FAILURE)) { - details::appendToSmsBuffer(buffer, PSTR("\n- Temperature is %dC.%S"), static_cast(metadata.temperature * 100), backupFailureString); - } + if (bitRead(triggered, ALERT_RTC_CLOCK_FAILURE)) { + details::appendToSmsBuffer(buffer, PSTR("\n- RTC was stopped.%S"), backupFailureString); + } - if (bitRead(triggered, ALERT_RTC_CLOCK_FAILURE)) { - details::appendToSmsBuffer(buffer, PSTR("\n- RTC was stopped.%S"), backupFailureString); + notified = network::sendSms(buffer); + if (!notified) NOTICE_MSG("notifyFailure", "SMS not sent !"); } - bool notified = network::sendSms(buffer); - if (!notified) NOTICE_MSG("notifyFailure", "SMS not sent !"); - network::powerOff(); return notified ? triggered : NO_ALERTS_NOTIFIED; //If not notified, the alerts state should not be persisted (so we can retry to notify them) } From 818faef87b39d983133a82a87e47f271dbe04a00 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 6 Aug 2018 13:48:24 +1200 Subject: [PATCH 07/11] Reduced code size when only one backup method is enabled (22 bytes) --- Core.cpp | 2 +- Positions.cpp | 54 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/Core.cpp b/Core.cpp index 09a8ba7..faf9115 100644 --- a/Core.cpp +++ b/Core.cpp @@ -140,7 +140,7 @@ namespace core { } - VERBOSE_FORMAT("computeSleepTime", "%d,%d", velocity, result); + VERBOSE_FORMAT("mapSleepTime", "%d,%d", velocity, result); return result; } } \ No newline at end of file diff --git a/Positions.cpp b/Positions.cpp index f4ab051..5feea1e 100644 --- a/Positions.cpp +++ b/Positions.cpp @@ -4,7 +4,7 @@ #include "Gps.h" #if BACKUP_ENABLE_SDCARD || BACKUP_ENABLE_NETWORK -#define BACKUPS_ENABLED BACKUP_ENABLE_SDCARD + BACKUP_ENABLE_NETWORK +#define BACKUPS_ENABLED (BACKUP_ENABLE_SDCARD + BACKUP_ENABLE_NETWORK) #endif #if BACKUP_ENABLE_SDCARD @@ -21,8 +21,10 @@ #define ENTRIES_ADDR CONFIG_RESERVED_SIZE namespace positions { -#ifdef BACKUPS_ENABLED +#if BACKUPS_ENABLED > 1 backup::PositionsBackup **_backups; +#elif BACKUPS_ENABLED == 1 + backup::PositionsBackup * _backup; #endif namespace details { @@ -36,28 +38,44 @@ namespace positions { void setup() { details::maxEntryIndex = (E24_MAX_ADDRESS(hardware::i2c::eeprom.getSize()) - ENTRIES_ADDR) / ENTRY_RESERVED_SIZE; -#ifdef BACKUPS_ENABLED + +#if BACKUPS_ENABLED > 0 + backup::PositionsBackup * backup = NULL; +#if BACKUPS_ENABLED > 1 uint8_t backupIdx = 0; _backups = new backup::PositionsBackup*[BACKUPS_ENABLED]; +#endif //BACKUPS_ENABLED > 1 #if BACKUP_ENABLE_SDCARD - _backups[backupIdx] = new backup::sd::SdPositionsBackup(); - _backups[backupIdx]->setup(); + backup = new backup::sd::SdPositionsBackup(); + backup->setup(); +#if BACKUPS_ENABLED > 1 + _backups[backupIdx] = backup; backupIdx++; -#endif +#endif //BACKUPS_ENABLED > 1 +#endif //BACKUP_ENABLE_SDCARD + #if BACKUP_ENABLE_NETWORK - _backups[backupIdx] = new backup::net::NetworkPositionsBackup(); - _backups[backupIdx]->setup(); + backup = new backup::net::NetworkPositionsBackup(); + backup->setup(); +#if BACKUPS_ENABLED > 1 + _backups[backupIdx] = backup; backupIdx++; -#endif -#endif +#endif //BACKUPS_ENABLED > 1 +#endif //BACKUP_ENABLE_NETWORK + +#if BACKUPS_ENABLED == 1 + _backup = backup; +#endif //BACKUPS_ENABLED == 1 +#endif //BACKUPS_ENABLED > 0 + } bool acquire(PositionEntryMetadata &metadata) { NOTICE("acquire"); timestamp_t before; - + gps::powerOn(); before = rtc::getTime(); SIM808_GPS_STATUS gpsStatus = gps::acquireCurrentPosition(GPS_DEFAULT_TOTAL_TIMEOUT_MS); @@ -95,7 +113,7 @@ namespace positions { hardware::i2c::powerOn(); hardware::i2c::eeprom.writeBlock(entryAddress, entry); - NOTICE_FORMAT("appendLast", "Saved @ %X : [%d%% @ %dmV] [%f°C] [TTF : %d, Status : %d, Position : %s]", entryAddress, entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); + NOTICE_FORMAT("appendLast", "Saved @ %X : [%d%% @ %dmV] [%f�C] [TTF : %d, Status : %d, Position : %s]", entryAddress, entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); config->lastEntry++; if (config->lastEntry > details::maxEntryIndex) config->lastEntry = 0; @@ -112,13 +130,13 @@ namespace positions { uint16_t entryAddress = details::getEntryAddress(index); if (entryAddress == -1) return false; - VERBOSE_FORMAT("get", "Reading entry n°%d @ %X", index, entryAddress); + VERBOSE_FORMAT("get", "Reading entry n�%d @ %X", index, entryAddress); hardware::i2c::powerOn(); hardware::i2c::eeprom.readBlock(entryAddress, entry); hardware::i2c::powerOff(); - NOTICE_FORMAT("get", "Read from EEPROM @ %X : [%d%% @ %dmV] [%f°C] [TTF : %d, Status : %d, Position : %s]", entryAddress, entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); + NOTICE_FORMAT("get", "Read from EEPROM @ %X : [%d%% @ %dmV] [%f�C] [TTF : %d, Status : %d, Position : %s]", entryAddress, entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); return true; } @@ -141,18 +159,22 @@ namespace positions { } void prepareBackup() { -#ifdef BACKUPS_ENABLED +#if BACKUPS_ENABLED > 1 for (int i = 0; i < BACKUPS_ENABLED; i++) { _backups[i]->prepare(); } +#elif BACKUPS_ENABLED == 1 + _backup->prepare(); #endif } void doBackup(bool force) { -#ifdef BACKUPS_ENABLED +#if BACKUPS_ENABLED > 1 for (int i = 0; i < BACKUPS_ENABLED; i++) { _backups[i]->backup(force); } +#elif BACKUPS_ENABLED == 1 + _backup->backup(force); #endif } } \ No newline at end of file From 5498b9ae675e8fa651407979bd29ef2780a3bbf7 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 6 Aug 2018 14:04:02 +1200 Subject: [PATCH 08/11] Remove intermediate variable (-48 bytes) --- Core.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Core.cpp b/Core.cpp index faf9115..591c175 100644 --- a/Core.cpp +++ b/Core.cpp @@ -95,9 +95,10 @@ namespace core { } bool updateSleepTime() { - uint8_t velocity = gps::getVelocity(); - uint16_t result = mapSleepTime(velocity); bool goingLongSleep = false; + uint8_t velocity = gps::getVelocity(); + + sleepTime = mapSleepTime(velocity); if (velocity < SLEEP_TIMING_MIN_MOVING_VELOCITY) { float distance = gps::getDistanceFromPrevious(); //did we missed positions because we were sleeping ? @@ -105,15 +106,13 @@ namespace core { else stoppedInARow = min(stoppedInARow + 1, SLEEP_DEFAULT_STOPPED_THRESHOLD + 1); //avoid overflow on REALLY long stops if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) { - result = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; + sleepTime = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; } else if (stoppedInARow == SLEEP_DEFAULT_STOPPED_THRESHOLD) goingLongSleep = true; } else stoppedInARow = 0; - sleepTime = result; NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime); - return goingLongSleep; } From b943cc347874bbbed509b095473a4815b81c2f0a Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 6 Aug 2018 16:14:12 +1200 Subject: [PATCH 09/11] Reworked network isAvailable condition to gain 26 bytes on hex size --- Network.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Network.cpp b/Network.cpp index 5ec6ff6..c812668 100644 --- a/Network.cpp +++ b/Network.cpp @@ -37,7 +37,7 @@ namespace network { report = hardware::sim808::device.getSignalQuality(); NOTICE_FORMAT("waitForRegistered", "%d, [%d %ddBm]", currentStatus.stat, report.ssri, report.attenuation); - + if (report.ssri < NETWORK_DEFAULT_NO_NETWORK_QUALITY_THRESHOLD) noReliableNetwork++; else noReliableNetwork = 0; if (noReliableNetwork > NETWORK_DEFAULT_NO_NETWORK_TRIES) { @@ -50,14 +50,15 @@ namespace network { } while (timeout > 1); - report = hardware::sim808::device.getSignalQuality(); + report = hardware::sim808::device.getSignalQuality(); //FIXME : report does not match currentStatus NOTICE_FORMAT("waitForRegistered", "%d, [%d %ddBm]", currentStatus.stat, report.ssri, report.attenuation); - return currentStatus; + return currentStatus; //FIXME : on last loop waited for nothing } bool isAvailable(SIM808_NETWORK_REGISTRATION_STATE state) { - return state == SIM808_NETWORK_REGISTRATION_STATE::REGISTERED || - state == SIM808_NETWORK_REGISTRATION_STATE::ROAMING; + return static_cast(state) & + (static_cast(SIM808_NETWORK_REGISTRATION_STATE::REGISTERED) | static_cast(SIM808_NETWORK_REGISTRATION_STATE::ROAMING)) + != 0; } bool enableGprs() { From 71c8cf6f4fc1f2562bb1340efb284dfe3f1f3006 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 6 Aug 2018 16:31:29 +1200 Subject: [PATCH 10/11] Removed mainunit:sleep (-130 bytes) --- Debug.cpp | 15 ++++++--------- Debug.h | 1 - GpsTracker.ino | 3 --- MainUnit.cpp | 8 -------- MainUnit.h | 1 - 5 files changed, 6 insertions(+), 22 deletions(-) diff --git a/Debug.cpp b/Debug.cpp index 078585a..b899171 100644 --- a/Debug.cpp +++ b/Debug.cpp @@ -32,7 +32,6 @@ MENU_ENTRY(EEPROM_ADD_ENTRY, "[a] Add last entry to EEPROM"); MENU_ENTRY(EEPROM_BACKUP_ENTRIES, "[B] Backup EEPROM entries"); MENU_ENTRY(NOTIFY_FAILURES, "[F] Notify failures"); MENU_ENTRY(CLEAR_ALERTS, "[A] Clear alerts"); -MENU_ENTRY(SLEEP, "[S] Sleep for 8s"); MENU_ENTRY(SLEEP_DEEP, "[s] Deep sleep for 10s"); MENU_ENTRY(QUESTION, "?"); @@ -56,7 +55,6 @@ const PROGMEM uint8_t commandIdMapping[] = { 'B', static_cast(debug::GPSTRACKER_DEBUG_COMMAND::EEPROM_BACKUP_ENTRIES), 'F', static_cast(debug::GPSTRACKER_DEBUG_COMMAND::NOTIFY_FAILURES), 'A', static_cast(debug::GPSTRACKER_DEBUG_COMMAND::CLEAR_ALERTS), - 'S', static_cast(debug::GPSTRACKER_DEBUG_COMMAND::SLEEP), 's', static_cast(debug::GPSTRACKER_DEBUG_COMMAND::SLEEP_DEEP), }; @@ -97,7 +95,6 @@ const char * const MENU_ENTRIES[] PROGMEM = { MENU_CLEAR_ALERTS, MENU_SEPARATOR, - MENU_SLEEP, MENU_SLEEP_DEEP, MENU_QUESTION @@ -115,7 +112,7 @@ namespace debug { namespace details { inline void displayPosition(PositionEntry entry) { - Log.notice(F("%d%%, %dmV, %f°C, %ds, %d, %s\n"), entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); + Log.notice(F("%d%%, %dmV, %f�C, %ds, %d, %s\n"), entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); } } @@ -131,7 +128,7 @@ namespace debug { size_t mappingArraySize = flash::getArraySize(commandIdMapping); char commandId; - for (uint8_t i = 0; i < mappingArraySize; i += 2) { + for (uint8_t i = 0; i < mappingArraySize; i += 2) { commandId = pgm_read_byte_near(commandIdMapping + i); if (commandId == id) return static_cast(pgm_read_byte_near(commandIdMapping + i + 1)); } @@ -144,7 +141,7 @@ namespace debug { size_t menuSize = flash::getArraySize(MENU_ENTRIES); uint8_t intermediate_timeout = 50; - do { + do { for (uint8_t i = 0; i < menuSize; i++) { Serial.println(reinterpret_cast(pgm_read_word_near(&MENU_ENTRIES[i]))); } @@ -162,7 +159,7 @@ namespace debug { command = parseCommand(Serial.read()); while (Serial.available()) Serial.read(); //flushing input } while (command == GPSTRACKER_DEBUG_COMMAND::NONE); - + return command; } @@ -272,7 +269,7 @@ namespace debug { void notifyFailures() { PositionEntryMetadata metadata = { 1, //all battery alerts should goes on with this - 3800, //doesn't matter + 3800, //doesn't matter ALERT_SUSPICIOUS_RTC_TEMPERATURE, 0, SIM808_GPS_STATUS::OFF @@ -286,7 +283,7 @@ namespace debug { void clearAlerts() { PositionEntryMetadata metadata = { 100, //all battery alerts should goes off with this - 3800, //doesn't matter + 3800, //doesn't matter 10, 0, SIM808_GPS_STATUS::OFF diff --git a/Debug.h b/Debug.h index d9a1cd0..b02fea7 100644 --- a/Debug.h +++ b/Debug.h @@ -33,7 +33,6 @@ namespace debug { EEPROM_BACKUP_ENTRIES, NOTIFY_FAILURES, CLEAR_ALERTS, - SLEEP, SLEEP_DEEP }; diff --git a/GpsTracker.ino b/GpsTracker.ino index 6e382a1..984c9bb 100644 --- a/GpsTracker.ino +++ b/GpsTracker.ino @@ -86,9 +86,6 @@ void loop() { case debug::GPSTRACKER_DEBUG_COMMAND::CLEAR_ALERTS: debug::clearAlerts(); break; - case debug::GPSTRACKER_DEBUG_COMMAND::SLEEP: - mainunit::sleep(period_t::SLEEP_8S); - break; case debug::GPSTRACKER_DEBUG_COMMAND::SLEEP_DEEP: mainunit::deepSleep(10); break; diff --git a/MainUnit.cpp b/MainUnit.cpp index e72e2aa..1fdb6bc 100644 --- a/MainUnit.cpp +++ b/MainUnit.cpp @@ -35,14 +35,6 @@ namespace mainunit { attachInterrupt(digitalPinToInterrupt(RTC_WAKE), interrupt, FALLING); } - void sleep(period_t period) { - NOTICE_FORMAT("sleep", "Period : %d", period); - details::prepareSleep(); - LowPower.powerDown(period, ADC_OFF, BOD_OFF); - details::wokeUp(); - - } - void deepSleep(uint16_t seconds) { NOTICE_FORMAT("deepSleep", "%d seconds", seconds); interruptIn(seconds); diff --git a/MainUnit.h b/MainUnit.h index 8a7b633..791894a 100644 --- a/MainUnit.h +++ b/MainUnit.h @@ -4,6 +4,5 @@ #include namespace mainunit { - void sleep(period_t period); void deepSleep(uint16_t seconds); } \ No newline at end of file From f96b40c6c496ef4895bbfd4dde4676ffa02ed6df Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 6 Aug 2018 16:50:47 +1200 Subject: [PATCH 11/11] Made sure devices are powered off on sleep and obtained 112 bytes(???) --- MainUnit.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MainUnit.cpp b/MainUnit.cpp index 1fdb6bc..ff385c7 100644 --- a/MainUnit.cpp +++ b/MainUnit.cpp @@ -10,8 +10,12 @@ namespace mainunit { namespace details { void prepareSleep() { + //forcing the power off of ALL devices for safety + hardware::sim808::powerOff(); + hardware::i2c::powerOff(true); + hardware::sim808::simSerial.end(); //avoid woke up by SoftwareSerial interrupt - delay(5); //ensure message have been printed out + delay(5); //ensure log messages have been printed out } void wokeUp() {