203 Commits

Author SHA1 Message Date
6a9d09ddf3 updated .gitignore to exclude vscode-stuff 2024-01-11 12:43:49 +01:00
ef8f27e495 updated also the remaining libs 2024-01-11 12:42:24 +01:00
eee7baaece Updated some Libraries (Json and Webserver) 2024-01-11 10:41:20 +01:00
58c6bc820a added checksum to auto-generated files 2024-01-10 19:09:18 +01:00
925167ec3c small Layout-change of OLED during OTA 2024-01-09 22:52:28 +01:00
c236322667 reworked the WebUI-Websocket-Comm 2024-01-09 22:51:45 +01:00
157d59963c updated CodeGeneration 2024-01-09 20:47:28 +01:00
ac28ab21d4 missed to add comments for webui.cpp 2024-01-09 13:12:20 +01:00
a7ea17ef05 changed Config-Default-code 2024-01-09 13:12:09 +01:00
f52f4103f6 used ChatGPT to add comments and proper Headers to all SourceFiles 2024-01-09 12:54:05 +01:00
62cc2bf982 made index.html static - websocket everywhere 2024-01-09 12:17:13 +01:00
e375fab048 make restart chooseable in SystemShutdown 2024-01-09 12:15:39 +01:00
16d6aee420 fixed Bug in EEPROM-Page Handling 2024-01-09 10:46:36 +01:00
eaf2ad4933 first Values updated by websockets! 2023-12-25 02:05:22 +01:00
9c2e039bf8 fixed css minifying 2023-12-25 02:04:31 +01:00
3d7e798310 removed feature-defines for CAN and Websockets 2023-12-25 00:44:24 +01:00
e8a93a600e CAN-Debug now with timeout after failed send 2023-12-11 21:34:40 +01:00
be53089726 webfiles now get packed and comments removed 2023-12-11 19:09:51 +01:00
e85eef271b improved sanity-check of config-values 2023-12-11 19:09:29 +01:00
cc93236b8e moved javascript from html file to external script 2023-12-11 19:07:38 +01:00
51b80f08a5 added Notification to WebUI 2023-12-04 22:05:39 +01:00
a576c7b70c DTC in WebUI now handled via Websocket 2023-12-04 02:18:16 +01:00
aa3a2106aa added KTM 1290 Superduke (2023) to CAN-Sources 2023-12-03 23:49:41 +01:00
f8a195bd4b changed order of I2C-Init to fix EE-Issues 2023-12-03 22:53:35 +01:00
b20481140c fixed package-Issue in prebuild-Script 2023-12-03 19:49:46 +01:00
b37c0a05be dtc-buildscript now via template and utf-8 2023-10-20 12:05:27 +02:00
2138f640ee reworked DTC-Data handling 2023-09-27 19:13:54 +02:00
d593e40f38 fixed typo in define 2023-09-27 10:39:37 +02:00
3bb9bf694e fixed some warnings 2023-09-27 09:59:35 +02:00
f320fb1ca6 disable CAN when used InputTrigger - shared Pin 2023-09-25 23:01:23 +02:00
b775738e20 fixed platform.ini-File 2023-09-25 07:26:42 +02:00
c42de4b24c added CAN-Debug-Message 2023-09-25 07:21:33 +02:00
ce9f1a2306 fix of type 2023-09-25 07:19:17 +02:00
e1770527ab added some \n in Debug-Messages 2023-09-25 07:18:46 +02:00
aff1d40297 some Code-simplification 2023-09-25 07:17:38 +02:00
caff1c185f restructured Project Build Configuration 2023-05-01 11:59:19 +02:00
bea78c0020 some refactoring 2023-05-01 11:29:22 +02:00
744f8c431c added Hostname to WebUI-Info 2023-03-20 23:38:13 +01:00
e9567602d3 Date updated on Webfiles 2023-03-19 18:03:52 +01:00
0469b183f2 restructured Folder-Structure 2023-03-19 18:03:28 +01:00
e3392d92c4 Changed DTC for CAN-Signal timeout (Startup-delay) 2023-03-18 15:21:18 +01:00
6a6227ed85 DTC-Debug Formatting 2023-03-18 15:20:16 +01:00
c8f5cda4ba more work done on the Debugger 2023-03-14 23:30:26 +01:00
0bc7d0862b prevent Crash if pulsePerRev is set to 0 2023-03-10 10:25:01 +01:00
c593b8a546 added Connection-Schemata of PCB Rev 1.2 2023-03-03 22:41:02 +01:00
6221262dbf EEPROM Backup and Restore works 2023-03-03 22:01:32 +01:00
83e288fdcf added Shutdown-Anim for LED 2023-03-03 11:39:43 +01:00
9c4c4a14b4 show measurement only when Source is Pulse 2023-03-03 10:52:52 +01:00
49b3598275 added Function to WebUI to measure Pulses 2023-03-03 10:51:16 +01:00
8fdd09f32f Version-String Format change 2023-03-03 10:48:19 +01:00
f87d2aaeca more Versioninfo for easier identification 2023-03-02 23:35:41 +01:00
34c50df2e9 Replaced FastLED by Adafruit Neopixel 2023-03-02 22:30:42 +01:00
cb3d49ad13 made "Timer"-Feature disabled by define 2023-03-02 17:40:25 +01:00
f02a53e161 fixed FlashVersion File 2023-03-02 17:39:30 +01:00
50208e4a1a fixed some PCB_rev-define-Stuff 2023-03-02 17:38:57 +01:00
a563182f3e reload EEPROM after format to maintain DTCs 2023-03-02 17:38:13 +01:00
335b883043 fixed cannot shutdown when in ErrorState 2023-03-02 17:37:43 +01:00
fb366b4976 added Documentation 2023-02-28 22:16:19 +01:00
367a41527d Updated FW-Version 2023-02-28 10:12:18 +01:00
5460a70f6d Added STL_Files for Case 2023-02-28 10:11:33 +01:00
3b4a22bff7 corrected some DTC-Stuff 2023-02-24 19:28:06 +01:00
df209a788b fixed Debug-Output in WebserverCallback (this time for real) 2023-02-24 19:25:59 +01:00
a6031798da moved DTC Processing to own File 2023-02-24 19:24:26 +01:00
00cba7b5ac DTC-Severity was not correctly set on new DTCs 2023-02-24 19:23:31 +01:00
034b6c918b fixed sysStat-Behaviour 2023-02-24 19:22:51 +01:00
3af678f3f8 fixed DebugOutput in WebserverCallback 2023-02-24 19:22:33 +01:00
32107a45db removed RemoteDebug-Library Stuff 2023-02-24 00:52:51 +01:00
a446a51c07 updated FastLED-Lib 2023-02-24 00:06:31 +01:00
5b41090add reworked debugger enabling 2023-02-24 00:05:51 +01:00
2376d14b5d fixed warning 2023-02-24 00:05:21 +01:00
77a94de2eb new debugger and websockets 2023-02-23 23:14:58 +01:00
c9a6e4c870 fixed warning 2023-02-23 17:46:36 +01:00
9ac161ee4c fixed Display-Bug with Remain Distance 2023-02-23 17:46:28 +01:00
1f8b085598 small improvement of DTC-Handling for CAN 2023-02-20 09:18:14 +01:00
46f98b1244 fixes... 2023-02-19 14:42:40 +01:00
9e87a05418 replaced var-name bc. encoding Issues with special char 2023-02-19 14:29:38 +01:00
140414ee8b minor FormatTweaks for DTC-DebugVal in WebUI 2022-09-02 00:10:21 +02:00
371e21429d WebUI adjusted and prepared EE-Backup-Stuff 2022-09-01 23:46:20 +02:00
64f9e102a5 Disabled autocorrect of Config after SanityCheck 2022-09-01 23:00:19 +02:00
dc4dbb05ca Format-Fixes and DTC-Debgval in WebUI visible 2022-09-01 22:47:25 +02:00
8c0db2ffd9 Implemented DebugVal for DTCs and SanityCheck 2022-09-01 22:46:00 +02:00
c6b47fffaf changed color of Bargraph-Text on WebUI 2022-09-01 21:31:27 +02:00
1b49ed4a2e Sanity-Check for ConfigValues 2022-09-01 21:29:07 +02:00
4167a222d7 ATOMIC_FS_UPDATE now Projecte-Define 2022-08-28 23:27:28 +02:00
f9498dac7d made FW-Version same Format as FS.Version 2022-08-28 23:27:01 +02:00
b9f658b111 FlashFS now gzip-Updatefiles & FS-Versioning imp. 2022-08-28 23:26:09 +02:00
4e34aaa24a Added Documentation 2022-08-24 23:13:27 +02:00
084925b844 missed include 2022-08-24 23:10:11 +02:00
e6a861185c Purging now also possible from WebUI 2022-08-24 23:09:26 +02:00
e12971b971 some debugging 2022-08-24 23:08:57 +02:00
4f5fdb7af4 corrected Tank-Lvel-Calculation 2022-08-24 23:08:29 +02:00
730f020f41 Updated DTC-Descriptions 2022-08-24 22:13:30 +02:00
3af1cfcb1b unimportant Serial Format Fix 2022-08-24 21:00:17 +02:00
685832cff8 Improved EEPROM-Formatting 2022-08-24 20:59:00 +02:00
3811834927 json now gets also gzipped 2022-08-24 20:58:12 +02:00
0025f8b0be DTC-Description now via Modal-Dialog 2022-08-24 16:49:40 +02:00
a30f56ff58 small fix 2022-08-24 07:30:51 +02:00
26942dd946 fixed missing name-tag in index.html 2022-08-24 07:27:53 +02:00
c997949c5b disabled Serial-debugging 2022-08-23 21:43:04 +02:00
1b0498ee5a fixed icons in manifest-File 2022-08-23 21:42:45 +02:00
82043ed9be re-added Firmware-Upload-Button after BS4-Update 2022-08-23 01:11:53 +02:00
f67817adb5 Format-Tweaks on WebUI 2022-08-23 00:50:52 +02:00
da19ebcc09 changed FlashVersion and incereased Buffer-Size 2022-08-23 00:48:00 +02:00
eaf2c9d8a8 DTC-Icon-fix 2022-08-23 00:12:03 +02:00
9072f2b3e2 added Google-Based Font locally 2022-08-23 00:11:44 +02:00
7d669dc04f updated .gitignore 2022-08-22 23:39:57 +02:00
79a7ca6fc1 renamed data-folder to data_src 2022-08-22 23:39:33 +02:00
821e94eec8 Updated WebUI to Bootstrap 4 2022-08-22 23:36:27 +02:00
0d9acaf43e preparing utility-script for gzip-littlefs 2022-08-22 23:32:51 +02:00
35361449eb some Fixes on Webui 2022-08-22 21:25:14 +02:00
45363b10fe missed ) on if-statement 2022-08-22 14:53:56 +02:00
c7f26bee32 made EEPROM-Format on WebUI more "secure" 2022-08-22 14:49:14 +02:00
984affb5a7 missed adjust of declaration for GetFlashVersion 2022-08-22 14:45:44 +02:00
d78c73d61f fixed missed define-change for WiFi-Clientmode 2022-08-22 14:29:40 +02:00
812a094e50 prevent Lube if Tank is empty (DryRun-Protection) 2022-08-22 14:29:01 +02:00
2ada3d9a61 EEPROM reset-Function added to WebUI 2022-08-22 14:28:32 +02:00
6ffe239cae Added DTC for LittleFS-Image Version mismatch 2022-08-22 14:26:37 +02:00
bd4c1d9d53 DTCs now hav severity and improved DTCMaintenance 2022-08-22 14:13:55 +02:00
808709f5c2 sanity-check now functional 2022-08-22 09:23:01 +02:00
080742c88c Math error ! -.- 2022-08-21 20:31:48 +02:00
38185e9056 improved DTC-Handling for EEPROM 2022-08-21 19:57:20 +02:00
17ed1ff7fa Added define to disable flashing of LED 2022-08-21 15:47:58 +02:00
0e34e7121f changed PurgePulse Vars to uint16_t 2022-08-21 15:47:22 +02:00
4ce550c668 start of sanitycheck-header 2022-08-21 11:28:58 +02:00
a6f5b4ef65 HTML5-compliance fix 2022-08-19 12:30:21 +02:00
7c38d02bf8 Fixed crash bc Stackoverflow from within Webserver 2022-08-19 11:25:26 +02:00
01ba4b7333 WebUI improvement to prevent empty fields 2022-08-19 08:34:37 +02:00
3048c6c2a1 changed restart behaviour after Firmware-Update 2022-08-19 08:16:33 +02:00
a6ae30d655 WebUI-improvements 2022-08-19 00:15:40 +02:00
01af8cba3c Improved Feature Control 2022-08-19 00:10:42 +02:00
4843cc15c9 Merge branches 'master' and 'master' of ssh://git.hiabuto.net:2222/souko/Kettenoeler 2022-08-14 17:38:49 +02:00
0b9ef67c39 multiple changes 2022-08-14 17:38:45 +02:00
94e34fb593 Bugfix in DTC and SystemStatus Handling 2022-05-27 13:33:44 +02:00
ad6332acd4 Restructured Folders 2022-05-07 23:24:42 +02:00
f514ee62fc Updated BOM-Excel for PCB Rev 1.4 2022-05-07 23:23:11 +02:00
b0ddece378 some Improvements with DTC and Init at Startup 2022-05-06 22:38:24 +02:00
d5508137d3 some Info avout FW-Version added to WebUI 2022-05-06 22:35:44 +02:00
27437555f8 Added Odometer and added EEPROM-End Detection 2022-05-05 21:07:24 +02:00
1c0ab060ff changed PreProcessor-Stuff for Feature-Handling 2022-05-04 23:06:15 +02:00
2b5039b8ab changed EEPROM-Stuff and added DTC if EE-Ver changed 2022-05-02 20:29:17 +02:00
c3e71d4759 Disabled WiFi-Client-Mode 2022-05-01 20:41:36 +02:00
3c0a7c3c59 Added BOM for PCB V 1.3 2022-05-01 20:41:16 +02:00
818d5843b3 Fixed Bug in DTC-Handling 2022-05-01 15:15:32 +02:00
872f577d35 more DTCs 2022-03-10 19:44:43 +01:00
cda2bb7afc removed some Serial.print 2022-03-09 23:05:17 +01:00
dab826b862 Added DTC-Table in WebUI and improved DTC-System 2022-03-09 20:25:02 +01:00
6e0b7581eb removed unnececary stuff 2022-03-08 23:03:10 +01:00
3fffc1f0b1 added Form for Lubrication-Setting on WebUI 2022-03-08 22:32:16 +01:00
c0a6069006 EEPROM-request now reset after Execution 2022-03-08 22:32:01 +01:00
a74f02fc61 huge improvement on WebUI with caching 2022-03-08 22:31:37 +01:00
606bf4e3ee env-update 2022-03-08 21:25:37 +01:00
e68a0b4d3e more progress on webUI 2022-03-08 21:23:52 +01:00
86e289f56f improved crc 2022-03-08 21:23:27 +01:00
7a84b80126 added dtcs for Signal-Timeout and empty tank 2022-03-08 21:23:06 +01:00
0bc6d01a5f more webui 2022-02-27 22:23:58 +01:00
6ba4c40166 more WebUI-Progress 2022-02-17 09:17:16 +01:00
fa23e72fbc Added HW-Serialport to Pinheader 2022-02-15 23:28:10 +01:00
7bd01a108a more Progress on WebUI 2022-02-15 23:27:53 +01:00
355b00a6cc fixed depencies 2022-02-15 23:27:39 +01:00
b361db164d type correction 2022-02-15 23:27:25 +01:00
16ec5d6e6d removed SoftwareSerial 2022-02-15 23:27:14 +01:00
d940d7aa78 More WebUI-Stuff 2022-02-15 22:37:58 +01:00
7167efd1b1 more Progress on WebUI 2022-02-15 20:58:32 +01:00
cc4a23f6df Starting to replace ESPUI-Lib due to OOM-Issues 2022-02-10 22:33:52 +01:00
00b28e5d5e Added first Code for GPS-Module Support 2022-02-10 22:32:40 +01:00
8b4e55d2dd moved some Strings to Flash 2022-02-10 22:31:11 +01:00
e6fa1e1ccd made RemoteDebug optional per define 2022-02-10 09:54:24 +01:00
efae15867a moved Tank-stuff to correct Tab in WebUI 2022-02-05 01:29:27 +01:00
7187d512e5 changed WebUI-Title 2022-02-05 00:31:16 +01:00
5824a32ad2 Code Formatting (Prettier) 2022-02-04 23:34:51 +01:00
055183ce90 PersistenceData gets stored cyclic now. 2022-02-04 22:26:26 +01:00
6ae9c273cb fixed warnings 2022-02-04 21:33:27 +01:00
d92818d4e5 CAN ist working 2022-02-04 21:28:49 +01:00
1ace7a8d6a Reworked method to calc traveled distance 2022-02-04 21:28:18 +01:00
39fc8af955 Reworked EEPROM-Handling by Flag 2022-02-04 21:24:15 +01:00
9571f5bbcc Titleblock in Schematic 2022-01-31 09:26:29 +01:00
b029243760 Added defines for PCB_revisions 2022-01-31 09:26:10 +01:00
152a324c9d Added Config-options fpr Different SpeedSources 2022-01-19 22:23:36 +01:00
f2e0e70647 fixed missing cases in systemStatus Text 2022-01-19 22:21:54 +01:00
8e6941b5bc fixed overflow of remaining tank 2022-01-19 22:21:12 +01:00
f3ce691b7d Added CAN-Bus Interface to PCB 2022-01-15 19:35:20 +01:00
aefbdc43bc Added Build-Define for WiFi-Client 2022-01-14 21:28:50 +01:00
08c00efbdf Added BOM Excel 2022-01-14 21:28:01 +01:00
cdbeb2b8c3 converted Schematic to KiCad V6.0 2022-01-14 15:39:59 +01:00
cfc6b144f3 Reworked Button-Stuff 2022-01-14 15:36:17 +01:00
e1ca503bd2 Adjusted Pulse/Pause to match Requirements of Pump 2022-01-13 22:00:31 +01:00
d68b562126 Some Debugs and Corrections for LED-Status 2022-01-13 21:59:53 +01:00
2217d68026 Added Button-Function Rain/Normal Switch 2022-01-13 21:59:32 +01:00
acb3c97c02 periodic Update of WebUI 2022-01-12 01:10:21 +01:00
70ea944dc3 made Bleeding/Purging stored to EEPROM 2022-01-12 00:53:22 +01:00
cff7c7b29c shorter Pulses for Pump 2022-01-12 00:52:59 +01:00
ea4895c262 fixed Warnings 2022-01-12 00:52:27 +01:00
87e3d2e739 Updated PCB 2022-01-12 00:51:36 +01:00
a3d5c4ef6f fixed correct Calculation of Lube-Distance 2022-01-10 23:17:07 +01:00
febb658bf8 changed pinning and added EEPROM 2022-01-10 23:16:37 +01:00
bfa4272334 Basic Function works 2022-01-10 00:55:04 +01:00
402535051a need to reset TravelDistance after LubePulse 2022-01-10 00:03:11 +01:00
829e70d11a LED-Tweak and some first Functions für LubeApp 2022-01-10 00:02:21 +01:00
ffe943f187 WebUI config stuff 2022-01-09 20:51:16 +01:00
2e3a9f6e3f Work on EEPROM-Stuff 2022-01-08 03:14:26 +01:00
435a0e1f5a Build-Defines and stuff updated 2022-01-07 23:36:02 +01:00
01ecf5a4a4 changes in ceredentials-handling of sourcefiles 2022-01-07 21:35:06 +01:00
4bffdf932e Base Software System 2022-01-07 21:02:27 +01:00
83 changed files with 116861 additions and 1808 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
Bestellung.xlsx

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

3
Hardware/.gitignore vendored
View File

@@ -27,4 +27,5 @@ fp-info-cache
*.xml
*.csv
gerber/
gerber/
*-backups/

BIN
Hardware/BOM_Reichelt.xlsx Normal file

Binary file not shown.

74603
Hardware/Device.kicad_sym Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -169,6 +169,33 @@ X 5V 9 -100 800 100 D 50 50 1 1 W
ENDDRAW
ENDDEF
#
# Memory_EEPROM_24LC64
#
DEF Memory_EEPROM_24LC64 U 0 20 Y Y 1 F N
F0 "U" -250 250 50 H V C CNN
F1 "Memory_EEPROM_24LC64" 50 250 50 H V L CNN
F2 "" 0 0 50 H I C CNN
F3 "" 0 0 50 H I C CNN
ALIAS 24LC02 24LC00 24LC04 24LC08 24LC01 24LC512 24LC64 24LC1025 24LC32 24LC256 24LC128 CAT24C256 CAT24C128
$FPLIST
DIP*W7.62mm*
SOIC*3.9x4.9mm*
TSSOP*4.4x3mm*P0.65mm*
DFN*3x2mm*P0.5mm*
$ENDFPLIST
DRAW
S -300 200 300 -200 1 1 10 f
X A0 1 -400 100 100 R 50 50 1 1 I
X A1 2 -400 0 100 R 50 50 1 1 I
X A2 3 -400 -100 100 R 50 50 1 1 I
X GND 4 0 -300 100 U 50 50 1 1 W
X SDA 5 400 100 100 L 50 50 1 1 B
X SCL 6 400 0 100 L 50 50 1 1 I
X WP 7 400 -100 100 L 50 50 1 1 I
X VCC 8 0 300 100 D 50 50 1 1 W
ENDDRAW
ENDDEF
#
# Regulator_Switching_R-78C5.0-1.0
#
DEF Regulator_Switching_R-78C5.0-1.0 U 0 10 Y Y 1 F N

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,443 @@
{
"board": {
"design_settings": {
"defaults": {
"board_outline_line_width": 0.049999999999999996,
"copper_line_width": 0.19999999999999998,
"copper_text_italic": false,
"copper_text_size_h": 1.5,
"copper_text_size_v": 1.5,
"copper_text_thickness": 0.3,
"copper_text_upright": false,
"courtyard_line_width": 0.049999999999999996,
"dimension_precision": 4,
"dimension_units": 3,
"dimensions": {
"arrow_length": 1270000,
"extension_offset": 500000,
"keep_text_aligned": true,
"suppress_zeroes": false,
"text_position": 0,
"units_format": 1
},
"fab_line_width": 0.09999999999999999,
"fab_text_italic": false,
"fab_text_size_h": 1.0,
"fab_text_size_v": 1.0,
"fab_text_thickness": 0.15,
"fab_text_upright": false,
"other_line_width": 0.09999999999999999,
"other_text_italic": false,
"other_text_size_h": 1.0,
"other_text_size_v": 1.0,
"other_text_thickness": 0.15,
"other_text_upright": false,
"pads": {
"drill": 0.762,
"height": 1.524,
"width": 1.524
},
"silk_line_width": 0.12,
"silk_text_italic": false,
"silk_text_size_h": 1.0,
"silk_text_size_v": 1.0,
"silk_text_thickness": 0.15,
"silk_text_upright": false,
"zones": {
"45_degree_only": false,
"min_clearance": 0.19999999999999998
}
},
"diff_pair_dimensions": [],
"drc_exclusions": [],
"meta": {
"filename": "board_design_settings.json",
"version": 2
},
"rule_severities": {
"annular_width": "error",
"clearance": "error",
"copper_edge_clearance": "error",
"courtyards_overlap": "error",
"diff_pair_gap_out_of_range": "error",
"diff_pair_uncoupled_length_too_long": "error",
"drill_out_of_range": "error",
"duplicate_footprints": "warning",
"extra_footprint": "warning",
"footprint_type_mismatch": "error",
"hole_clearance": "error",
"hole_near_hole": "error",
"invalid_outline": "error",
"item_on_disabled_layer": "error",
"items_not_allowed": "error",
"length_out_of_range": "error",
"malformed_courtyard": "error",
"microvia_drill_out_of_range": "error",
"missing_courtyard": "ignore",
"missing_footprint": "warning",
"net_conflict": "warning",
"npth_inside_courtyard": "ignore",
"padstack": "error",
"pth_inside_courtyard": "ignore",
"shorting_items": "error",
"silk_over_copper": "warning",
"silk_overlap": "warning",
"skew_out_of_range": "error",
"through_hole_pad_without_hole": "error",
"too_many_vias": "error",
"track_dangling": "warning",
"track_width": "error",
"tracks_crossing": "error",
"unconnected_items": "error",
"unresolved_variable": "error",
"via_dangling": "warning",
"zone_has_empty_net": "error",
"zones_intersect": "error"
},
"rule_severitieslegacy_courtyards_overlap": true,
"rule_severitieslegacy_no_courtyard_defined": false,
"rules": {
"allow_blind_buried_vias": false,
"allow_microvias": false,
"max_error": 0.005,
"min_clearance": 0.0,
"min_copper_edge_clearance": 0.049999999999999996,
"min_hole_clearance": 0.25,
"min_hole_to_hole": 0.25,
"min_microvia_diameter": 0.19999999999999998,
"min_microvia_drill": 0.09999999999999999,
"min_silk_clearance": 0.0,
"min_through_hole_diameter": 0.3,
"min_track_width": 0.19999999999999998,
"min_via_annular_width": 0.049999999999999996,
"min_via_diameter": 0.39999999999999997,
"use_height_for_length_calcs": true
},
"track_widths": [
0.0,
0.5,
1.0,
2.0
],
"via_dimensions": [
{
"diameter": 0.0,
"drill": 0.0
},
{
"diameter": 0.7,
"drill": 0.35
},
{
"diameter": 1.0,
"drill": 0.6
},
{
"diameter": 2.0,
"drill": 1.0
}
],
"zones_allow_external_fillets": false,
"zones_use_no_outline": true
},
"layer_presets": []
},
"boards": [],
"cvpcb": {
"equivalence_files": []
},
"erc": {
"erc_exclusions": [],
"meta": {
"version": 0
},
"pin_map": [
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
1,
0,
1,
2
],
[
0,
1,
0,
0,
0,
0,
1,
1,
2,
1,
1,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
2
],
[
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
1,
2
],
[
0,
0,
0,
1,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
1,
2,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
0,
2,
1,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2
]
],
"rule_severities": {
"bus_definition_conflict": "error",
"bus_entry_needed": "error",
"bus_label_syntax": "error",
"bus_to_bus_conflict": "error",
"bus_to_net_conflict": "error",
"different_unit_footprint": "error",
"different_unit_net": "error",
"duplicate_reference": "error",
"duplicate_sheet_names": "error",
"extra_units": "error",
"global_label_dangling": "warning",
"hier_label_mismatch": "error",
"label_dangling": "error",
"lib_symbol_issues": "warning",
"multiple_net_names": "warning",
"net_not_bus_member": "warning",
"no_connect_connected": "warning",
"no_connect_dangling": "warning",
"pin_not_connected": "error",
"pin_not_driven": "error",
"pin_to_pin": "warning",
"power_pin_not_driven": "error",
"similar_labels": "warning",
"unannotated": "error",
"unit_value_mismatch": "error",
"unresolved_variable": "error",
"wire_dangling": "error"
}
},
"libraries": {
"pinned_footprint_libs": [],
"pinned_symbol_libs": []
},
"meta": {
"filename": "oiler SMD.kicad_pro",
"version": 1
},
"net_settings": {
"classes": [
{
"bus_width": 12.0,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Default",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.25,
"via_diameter": 0.8,
"via_drill": 0.4,
"wire_width": 6.0
}
],
"meta": {
"version": 2
},
"net_colors": null
},
"pcbnew": {
"last_paths": {
"gencad": "",
"idf": "",
"netlist": "Rehoiler SMD.net",
"specctra_dsn": "",
"step": "",
"vrml": ""
},
"page_layout_descr_file": ""
},
"schematic": {
"annotate_start_num": 0,
"drawing": {
"default_line_thickness": 6.0,
"default_text_size": 50.0,
"field_names": [],
"intersheets_ref_own_page": false,
"intersheets_ref_prefix": "",
"intersheets_ref_short": false,
"intersheets_ref_show": false,
"intersheets_ref_suffix": "",
"junction_size_choice": 3,
"label_size_ratio": 0.25,
"pin_symbol_size": 25.0,
"text_offset_ratio": 0.08
},
"legacy_lib_dir": "",
"legacy_lib_list": [],
"meta": {
"version": 1
},
"net_format_name": "Pcbnew",
"ngspice": {
"fix_include_paths": true,
"fix_passive_vals": false,
"meta": {
"version": 0
},
"model_mode": 0,
"workbook_filename": ""
},
"page_layout_descr_file": "",
"plot_directory": "",
"spice_adjust_passive_values": false,
"spice_external_command": "spice \"%I\"",
"subpart_first_id": 65,
"subpart_id_separator": 0
},
"sheets": [
[
"b1ddb058-f7b2-429c-9489-f4e2242ad7e5",
""
]
],
"text_variables": {}
}

3585
Hardware/oiler SMD.kicad_sch Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -92,8 +92,6 @@ F 3 "" H 6500 4200 50 0001 C CNN
$EndComp
Wire Wire Line
6500 4200 6500 3950
Wire Wire Line
8450 3050 8450 3750
Wire Wire Line
8450 3750 8600 3750
Wire Wire Line
@@ -218,8 +216,9 @@ U 1 1 61D2CD57
P 8250 4400
F 0 "D2" V 8296 4320 50 0000 R CNN
F 1 "BAT42" V 8205 4320 50 0000 R CNN
F 2 "Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal" H 8250 4225 50 0001 C CNN
F 2 "Diode_SMD:D_SOD-123" H 8250 4225 50 0001 C CNN
F 3 "http://www.vishay.com/docs/85660/bat42.pdf" H 8250 4400 50 0001 C CNN
F 4 "BAT 42" H 8250 4400 50 0001 C CNN "Reichelt Order No."
1 8250 4400
0 -1 -1 0
$EndComp
@@ -239,7 +238,7 @@ Wire Wire Line
Wire Wire Line
8250 4700 8250 4550
Wire Wire Line
8250 4250 8250 3150
8250 4250 8250 3350
$Comp
L Device:C C1
U 1 1 61D2F740
@@ -254,23 +253,23 @@ $EndComp
$Comp
L Device:C C2
U 1 1 61D32638
P 8000 3400
F 0 "C2" H 8115 3446 50 0000 L CNN
F 1 "10n" H 8115 3355 50 0000 L CNN
F 2 "Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder" H 8038 3250 50 0001 C CNN
F 3 "~" H 8000 3400 50 0001 C CNN
1 8000 3400
P 8000 3700
F 0 "C2" H 8115 3746 50 0000 L CNN
F 1 "10n" H 8115 3655 50 0000 L CNN
F 2 "Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder" H 8038 3550 50 0001 C CNN
F 3 "~" H 8000 3700 50 0001 C CNN
1 8000 3700
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR0109
U 1 1 61D32EB9
P 8000 3550
F 0 "#PWR0109" H 8000 3300 50 0001 C CNN
F 1 "GND" H 8005 3377 50 0000 C CNN
F 2 "" H 8000 3550 50 0001 C CNN
F 3 "" H 8000 3550 50 0001 C CNN
1 8000 3550
P 8000 3850
F 0 "#PWR0109" H 8000 3600 50 0001 C CNN
F 1 "GND" H 8005 3677 50 0000 C CNN
F 2 "" H 8000 3850 50 0001 C CNN
F 3 "" H 8000 3850 50 0001 C CNN
1 8000 3850
1 0 0 -1
$EndComp
$Comp
@@ -284,32 +283,15 @@ F 3 "" H 7400 3850 50 0001 C CNN
1 7400 3850
1 0 0 -1
$EndComp
Wire Wire Line
6900 3150 8000 3150
Wire Wire Line
6900 3050 8450 3050
Wire Wire Line
7400 3250 7400 3550
Wire Wire Line
8000 3250 8000 3150
Connection ~ 8000 3150
Wire Wire Line
8000 3150 8250 3150
Wire Wire Line
6900 3250 7400 3250
Wire Wire Line
7400 3250 7750 3250
Wire Wire Line
7750 3250 7750 4250
Connection ~ 7400 3250
$Comp
L Diode:BAT42 D1
U 1 1 61D35ED1
P 7750 4400
F 0 "D1" V 7796 4320 50 0000 R CNN
F 1 "BAT42" V 7705 4320 50 0000 R CNN
F 2 "Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal" H 7750 4225 50 0001 C CNN
F 2 "Diode_SMD:D_SOD-123" H 7750 4225 50 0001 C CNN
F 3 "http://www.vishay.com/docs/85660/bat42.pdf" H 7750 4400 50 0001 C CNN
F 4 "BAT 42" H 7750 4400 50 0001 C CNN "Reichelt Order No."
1 7750 4400
0 -1 -1 0
$EndComp
@@ -319,7 +301,7 @@ U 1 1 61D36E68
P 9100 2750
F 0 "D3" H 9100 2967 50 0000 C CNN
F 1 "1N4001" H 9100 2876 50 0000 C CNN
F 2 "Diode_THT:D_DO-41_SOD81_P10.16mm_Horizontal" H 9100 2575 50 0001 C CNN
F 2 "Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal" H 9100 2575 50 0001 C CNN
F 3 "http://www.vishay.com/docs/88503/1n4001.pdf" H 9100 2750 50 0001 C CNN
1 9100 2750
1 0 0 -1
@@ -338,6 +320,7 @@ F 0 "C3" H 9568 2246 50 0000 L CNN
F 1 "470µF" H 9568 2155 50 0000 L CNN
F 2 "Capacitor_SMD:CP_Elec_8x10" H 9488 2050 50 0001 C CNN
F 3 "~" H 9450 2200 50 0001 C CNN
F 4 "ECC MZS350ARA471" H 9450 2200 50 0001 C CNN "Reichelt Order No."
1 9450 2200
1 0 0 -1
$EndComp
@@ -363,6 +346,7 @@ F 0 "C4" H 10668 2246 50 0000 L CNN
F 1 "100µ" H 10668 2155 50 0000 L CNN
F 2 "Capacitor_SMD:CP_Elec_6.3x7.7" H 10588 2050 50 0001 C CNN
F 3 "~" H 10550 2200 50 0001 C CNN
F 4 "ECC HXE250ARA101" H 10550 2200 50 0001 C CNN "Reichelt Order No."
1 10550 2200
1 0 0 -1
$EndComp
@@ -378,8 +362,6 @@ F 3 "" H 10550 2350 50 0001 C CNN
1 10550 2350
1 0 0 -1
$EndComp
Wire Wire Line
7150 3350 6900 3350
$Comp
L power:GND #PWR0113
U 1 1 61D3BF4D
@@ -423,7 +405,7 @@ U 1 1 61D3DFDC
P 9300 3350
F 0 "D4" V 9254 3430 50 0000 L CNN
F 1 "1N4001" V 9345 3430 50 0000 L CNN
F 2 "Diode_THT:D_DO-41_SOD81_P10.16mm_Horizontal" H 9300 3175 50 0001 C CNN
F 2 "Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal" H 9300 3175 50 0001 C CNN
F 3 "http://www.vishay.com/docs/88503/1n4001.pdf" H 9300 3350 50 0001 C CNN
1 9300 3350
0 1 1 0
@@ -455,8 +437,6 @@ Wire Wire Line
7850 5400 7850 5450
Wire Wire Line
7150 5300 7300 5300
Wire Wire Line
7150 3350 7150 5300
Wire Wire Line
7750 4550 7750 5200
Wire Wire Line
@@ -481,94 +461,238 @@ Wire Wire Line
$Comp
L Connector_Generic:Conn_01x04 J5
U 1 1 61E12B85
P 7650 2500
F 0 "J5" H 7730 2492 50 0000 L CNN
F 1 "I2C" H 7730 2401 50 0000 L CNN
F 2 "Connector_PinHeader_2.54mm:PinHeader_1x04_P2.54mm_Vertical" H 7650 2500 50 0001 C CNN
F 3 "~" H 7650 2500 50 0001 C CNN
1 7650 2500
P 8450 2500
F 0 "J5" H 8530 2492 50 0000 L CNN
F 1 "I2C" H 8530 2401 50 0000 L CNN
F 2 "Connector_PinHeader_2.54mm:PinHeader_1x04_P2.54mm_Horizontal" H 8450 2500 50 0001 C CNN
F 3 "~" H 8450 2500 50 0001 C CNN
1 8450 2500
1 0 0 -1
$EndComp
$Comp
L power:+3.3V #PWR0116
U 1 1 61E137AF
P 7250 1550
F 0 "#PWR0116" H 7250 1400 50 0001 C CNN
F 1 "+3.3V" H 7265 1723 50 0000 C CNN
F 2 "" H 7250 1550 50 0001 C CNN
F 3 "" H 7250 1550 50 0001 C CNN
1 7250 1550
P 8050 1550
F 0 "#PWR0116" H 8050 1400 50 0001 C CNN
F 1 "+3.3V" H 8065 1723 50 0000 C CNN
F 2 "" H 8050 1550 50 0001 C CNN
F 3 "" H 8050 1550 50 0001 C CNN
1 8050 1550
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR0117
U 1 1 61E147DB
P 7400 2750
F 0 "#PWR0117" H 7400 2500 50 0001 C CNN
F 1 "GND" H 7405 2577 50 0000 C CNN
F 2 "" H 7400 2750 50 0001 C CNN
F 3 "" H 7400 2750 50 0001 C CNN
1 7400 2750
P 8200 2750
F 0 "#PWR0117" H 8200 2500 50 0001 C CNN
F 1 "GND" H 8205 2577 50 0000 C CNN
F 2 "" H 8200 2750 50 0001 C CNN
F 3 "" H 8200 2750 50 0001 C CNN
1 8200 2750
1 0 0 -1
$EndComp
Wire Wire Line
7450 2700 7400 2700
8250 2700 8200 2700
Wire Wire Line
7400 2700 7400 2750
8200 2700 8200 2750
Wire Wire Line
6900 2950 7250 2950
8050 2950 8050 2400
Wire Wire Line
7250 2950 7250 2400
8050 2400 8250 2400
Wire Wire Line
7250 2400 7450 2400
7950 2850 7950 2500
Wire Wire Line
6900 2850 7150 2850
Wire Wire Line
7150 2850 7150 2500
Wire Wire Line
7150 2500 7450 2500
7950 2500 8250 2500
$Comp
L Device:R R4
U 1 1 61E189A2
P 7150 1850
F 0 "R4" H 7080 1804 50 0000 R CNN
F 1 "4k7" H 7080 1895 50 0000 R CNN
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder" V 7080 1850 50 0001 C CNN
F 3 "~" H 7150 1850 50 0001 C CNN
1 7150 1850
P 7950 1850
F 0 "R4" H 7880 1804 50 0000 R CNN
F 1 "4k7" H 7880 1895 50 0000 R CNN
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder" V 7880 1850 50 0001 C CNN
F 3 "~" H 7950 1850 50 0001 C CNN
1 7950 1850
-1 0 0 1
$EndComp
$Comp
L Device:R R5
U 1 1 61E1955B
P 7250 2150
F 0 "R5" H 7180 2104 50 0000 R CNN
F 1 "4k7" H 7180 2195 50 0000 R CNN
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder" V 7180 2150 50 0001 C CNN
F 3 "~" H 7250 2150 50 0001 C CNN
1 7250 2150
P 8050 2150
F 0 "R5" H 7980 2104 50 0000 R CNN
F 1 "4k7" H 7980 2195 50 0000 R CNN
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder" V 7980 2150 50 0001 C CNN
F 3 "~" H 8050 2150 50 0001 C CNN
1 8050 2150
-1 0 0 1
$EndComp
Wire Wire Line
7450 2600 7050 2600
8250 2600 7850 2600
Wire Wire Line
7050 2600 7050 1600
7850 2600 7850 1600
Wire Wire Line
7050 1600 7150 1600
7850 1600 7950 1600
Wire Wire Line
7250 1600 7250 1550
Connection ~ 7150 1600
8050 1600 8050 1550
Connection ~ 7950 1600
Wire Wire Line
7150 1600 7250 1600
7950 1600 8050 1600
Wire Wire Line
7250 2000 7250 1600
Connection ~ 7250 1600
8050 2000 8050 1600
Connection ~ 8050 1600
Wire Wire Line
7150 1600 7150 1700
7950 1600 7950 1700
Wire Wire Line
7250 2300 7250 2400
Connection ~ 7250 2400
8050 2300 8050 2400
Connection ~ 8050 2400
Wire Wire Line
7150 2000 7150 2500
Connection ~ 7150 2500
7950 2000 7950 2500
Connection ~ 7950 2500
Wire Wire Line
6900 3550 7150 3550
Wire Wire Line
7150 3550 7150 5300
Wire Wire Line
6900 3450 7400 3450
Connection ~ 7400 3450
Wire Wire Line
7400 3450 7400 3550
Wire Wire Line
7400 3450 7750 3450
Wire Wire Line
7750 3450 7750 4250
Wire Wire Line
6900 3350 8000 3350
Wire Wire Line
8000 3350 8000 3550
Wire Wire Line
8000 3350 8250 3350
Connection ~ 8000 3350
Wire Wire Line
8450 3250 8450 3750
Wire Wire Line
6900 3250 8450 3250
$Comp
L Memory_EEPROM:24LC64 U3
U 1 1 61DDD4E7
P 6750 1550
F 0 "U3" H 6750 2031 50 0000 C CNN
F 1 "24LC64" H 6750 1940 50 0000 C CNN
F 2 "Package_SO:SOIC-8_3.9x4.9mm_P1.27mm" H 6750 1550 50 0001 C CNN
F 3 "http://ww1.microchip.com/downloads/en/DeviceDoc/21189f.pdf" H 6750 1550 50 0001 C CNN
1 6750 1550
1 0 0 -1
$EndComp
$Comp
L power:+3.3V #PWR0118
U 1 1 61DDE198
P 6750 1250
F 0 "#PWR0118" H 6750 1100 50 0001 C CNN
F 1 "+3.3V" H 6765 1423 50 0000 C CNN
F 2 "" H 6750 1250 50 0001 C CNN
F 3 "" H 6750 1250 50 0001 C CNN
1 6750 1250
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR0119
U 1 1 61DDE4C0
P 6750 1850
F 0 "#PWR0119" H 6750 1600 50 0001 C CNN
F 1 "GND" H 6755 1677 50 0000 C CNN
F 2 "" H 6750 1850 50 0001 C CNN
F 3 "" H 6750 1850 50 0001 C CNN
1 6750 1850
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR0120
U 1 1 61DDE71F
P 6300 1850
F 0 "#PWR0120" H 6300 1600 50 0001 C CNN
F 1 "GND" H 6305 1677 50 0000 C CNN
F 2 "" H 6300 1850 50 0001 C CNN
F 3 "" H 6300 1850 50 0001 C CNN
1 6300 1850
1 0 0 -1
$EndComp
Wire Wire Line
6350 1650 6300 1650
Wire Wire Line
6300 1650 6300 1850
Wire Wire Line
6350 1450 6300 1450
Wire Wire Line
6300 1450 6300 1550
Connection ~ 6300 1650
Wire Wire Line
6350 1550 6300 1550
Connection ~ 6300 1550
Wire Wire Line
6300 1550 6300 1650
Wire Wire Line
6900 2850 7400 2850
Wire Wire Line
6900 2950 7500 2950
Wire Wire Line
7150 1550 7400 1550
Wire Wire Line
7400 1550 7400 2850
Connection ~ 7400 2850
Wire Wire Line
7400 2850 7950 2850
Wire Wire Line
7500 1450 7500 2950
Wire Wire Line
7150 1450 7500 1450
Connection ~ 7500 2950
Wire Wire Line
7500 2950 8050 2950
$Comp
L power:GND #PWR0121
U 1 1 61DFBD18
P 7250 1850
F 0 "#PWR0121" H 7250 1600 50 0001 C CNN
F 1 "GND" H 7255 1677 50 0000 C CNN
F 2 "" H 7250 1850 50 0001 C CNN
F 3 "" H 7250 1850 50 0001 C CNN
1 7250 1850
1 0 0 -1
$EndComp
Wire Wire Line
7150 1650 7250 1650
Wire Wire Line
7250 1650 7250 1850
$Comp
L power:GND #PWR0122
U 1 1 61DEAC05
P 6000 1700
F 0 "#PWR0122" H 6000 1450 50 0001 C CNN
F 1 "GND" H 6005 1527 50 0000 C CNN
F 2 "" H 6000 1700 50 0001 C CNN
F 3 "" H 6000 1700 50 0001 C CNN
1 6000 1700
1 0 0 -1
$EndComp
$Comp
L Device:C C5
U 1 1 61DEA081
P 6000 1550
F 0 "C5" H 6115 1596 50 0000 L CNN
F 1 "10n" H 6115 1505 50 0000 L CNN
F 2 "Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder" H 6038 1400 50 0001 C CNN
F 3 "~" H 6000 1550 50 0001 C CNN
1 6000 1550
1 0 0 -1
$EndComp
$Comp
L power:+3.3V #PWR0123
U 1 1 61DEAFE2
P 6000 1400
F 0 "#PWR0123" H 6000 1250 50 0001 C CNN
F 1 "+3.3V" H 6015 1573 50 0000 C CNN
F 2 "" H 6000 1400 50 0001 C CNN
F 3 "" H 6000 1400 50 0001 C CNN
1 6000 1400
1 0 0 -1
$EndComp
$EndSCHEMATC

5
Software/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
data/
.pio
.vscode
wifi_credentials.ini
__pycache__

77
Software/assets/Logo.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 10 KiB

145
Software/codegen/dtcs.py Normal file
View File

@@ -0,0 +1,145 @@
import os
import time
from jinja2 import Environment, FileSystemLoader
import json
import sys
import filechecksum as fcs
def build_dtcs():
# Pfad zur Eingabedatei und Ausgabedatei
input_file = "src/dtc_defs.txt"
output_file = "include/dtc_defs.h"
json_output_file = "data_src/static/dtc_table.json"
# Überprüfen, ob das Verzeichnis existiert, andernfalls erstellen
json_output_dir = os.path.dirname(json_output_file)
if not os.path.exists(json_output_dir):
os.makedirs(json_output_dir)
# Mehrdimensionales Array zum Speichern der Zeilen aus der Eingabedatei
dtc_lines = []
# Lesen und analysieren der Eingabedatei
with open(input_file, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line or line.startswith("#"):
continue
parts = line.split(";")
if len(parts) == 5:
num, dtc_name, dtc_severity, title, description = [part.strip() for part in parts]
dtc_lines.append([int(num), dtc_name, dtc_severity, title, description])
# Überprüfen auf Duplikate in den DTC-Nummern und DTC-Namen
num_set = set()
dtc_name_set = set()
duplicates = []
for line in dtc_lines:
num, dtc_name, _, _, _ = line
if num in num_set:
duplicates.append(f"DTC-Nummer {num} ist ein Duplikat.")
else:
num_set.add(num)
if dtc_name in dtc_name_set:
duplicates.append(f"DTC-Name '{dtc_name}' ist ein Duplikat.")
else:
dtc_name_set.add(dtc_name)
if duplicates:
for duplicate in duplicates:
print(f"Fehler: {duplicate}")
raise ValueError("Duplicate DTC Data detected")
# Suchen nach DTC_NO_DTC und DTC_LAST_DTC
dtc_no_dtc_added = False
dtc_last_dtc_line = None
for line in dtc_lines:
_, dtc_name, _, _, _ = line
if dtc_name == "DTC_NO_DTC":
dtc_no_dtc_added = True
elif dtc_name == "DTC_LAST_DTC":
dtc_last_dtc_line = line
# Einen DTC für DTC_NO_DTC hinzufügen (wenn nicht vorhanden)
if not dtc_no_dtc_added:
dtc_lines.insert(0, [0, "DTC_NO_DTC", "DTC_NONE", "No Error", "No Error"])
# Falls DTC_LAST_DTC existiert, lösche es
if dtc_last_dtc_line:
dtc_lines.remove(dtc_last_dtc_line)
# Einen DTC für DTC_LAST_DTC hinzufügen (mit der höchsten Nummer)
if dtc_lines:
highest_num = max([line[0] for line in dtc_lines])
else:
highest_num = 0
dtc_lines.append([highest_num + 1, "DTC_LAST_DTC", "DTC_NONE", "Last Error", "Last Error"])
# Sortieren der Zeilen nach der Nummer aufsteigend
dtc_lines.sort(key=lambda x: x[0])
checksum = fcs.calculate_checksum(dtc_lines)
timestamp = int(time.time())
if fcs.read_and_compare_checksum(output_file, checksum):
print("Keine Änderungen im DTC-Headerfile erforderlich.")
else:
# DTC_NAME_CONSTANT-Makros initialisieren
dtc_macros = []
dtc_structs = []
# Verarbeiten der sortierten Zeilen
for i, line in enumerate(dtc_lines):
num, dtc_name, dtc_severity, title, description = line
dtc_macros.append(f"#define {dtc_name:<30} {num}")
comma = "," if i < len(dtc_lines) - 1 else " "
dtc_structs.append(f" {{ {dtc_name:<30}, {dtc_severity:<12} }}{comma} // {description}")
env = Environment(loader=FileSystemLoader('codegen/templates', encoding='utf-8'))
# Lade das Jinja2-Template aus der Datei
template = env.get_template('dtc_defs.h.j2')
# Erstelle ein Context-Dictionary mit den erforderlichen Daten
context = {
'timestamp_unix': timestamp,
'timestamp' : time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)),
'date' : time.strftime('%d.%m.%Y', time.localtime(timestamp)),
'dtc_macros': dtc_macros, # Übergebe die dtc_macros-Liste direkt
'dtc_structs': dtc_structs, # Übergebe die dtc_structs-Liste direkt
'checksum' : checksum
}
# Rendere das Template mit den Werten und erhalte den Header-Text
header_text = template.render(context)
# Schreibe den generierten Header-Text in die Header-Datei
with open(output_file, "w", encoding='utf-8') as f:
f.write(header_text)
print(f"Header-Datei wurde erstellt: {output_file}")
if fcs.read_and_compare_json_checksum(json_output_file, checksum):
print("Keine Änderungen im DTC-JSON-file erforderlich.")
else:
dtc_info = {
"codegenerator_checksum": checksum,
'timestamp' : time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)),
"dtc_table_data": []
}
# Verarbeiten der sortierten Zeilen
for i, line in enumerate(dtc_lines):
num, dtc_name, dtc_severity, title, description = line
dtc_info["dtc_table_data"].append({"num": num, "title": title, "description": description})
# JSON-Datei mit UTF-8-Zeichencodierung erstellen
with open(json_output_file, 'w', encoding='utf-8') as json_f:
json.dump(dtc_info, json_f, ensure_ascii=False, indent=4, separators=(',', ': '))
print(f"JSON-Datei wurde erstellt: {json_output_file}")

View File

@@ -0,0 +1,45 @@
import hashlib
import json
# Funktion zum Berechnen der SHA-256-Checksumme
def calculate_checksum(data):
sha256 = hashlib.sha256()
sha256.update(str(data).encode('utf-8'))
return sha256.hexdigest()
# Funktion zum Lesen und Vergleichen der Checksumme in einer Datei
def read_and_compare_checksum(file_path, expected_checksum):
try:
with open(file_path, 'r') as file:
content = file.read()
# Suche nach der Zeile mit der Checksumme
checksum_line_start = content.find("// CODEGENERATOR_CHECKSUM:")
if checksum_line_start != -1:
# Extrahiere die Checksumme aus der Zeile
existing_checksum = content[checksum_line_start + len("// CODEGENERATOR_CHECKSUM:"):].strip()
# Vergleiche die Checksummen
if existing_checksum == expected_checksum:
return True
except FileNotFoundError:
pass # Datei existiert nicht, was nicht schlimm ist
return False
def read_and_compare_json_checksum(json_file_path, expected_checksum):
try:
with open(json_file_path, 'r') as json_file:
# Lade das JSON aus der Datei
data = json.load(json_file)
# Überprüfe, ob "codegenerator_checksum" im JSON vorhanden ist
if "codegenerator_checksum" in data:
existing_checksum = data["codegenerator_checksum"]
# Vergleiche die Checksummen
if existing_checksum == expected_checksum:
return True
except FileNotFoundError:
pass # Datei existiert nicht, was nicht schlimm ist
return False

View File

@@ -0,0 +1,8 @@
import subprocess
revision = (
subprocess.check_output(["git", "rev-parse", "--short=10", "HEAD"])
.strip()
.decode("utf-8")
)
print("-DGIT_REV='\"%s\"'" % revision)

View File

@@ -0,0 +1,169 @@
# SCRIPT TO GZIP CRITICAL FILES FOR ACCELERATED WEBSERVING
# see also https://community.platformio.org/t/question-esp32-compress-files-in-data-to-gzip-before-upload-possible-to-spiffs/6274/10
import glob
import shutil
import gzip
import os
import subprocess
Import("env")
Import("projenv")
# Setze die Pfade zu den Tools als Variablen
html_minifier_path = os.path.join(os.getenv("APPDATA"), "npm", "html-minifier.cmd")
uglifyjs_path = os.path.join(os.getenv("APPDATA"), "npm", "uglifyjs.cmd")
terser_path = os.path.join(os.getenv("APPDATA"), "npm", "terser.cmd")
cssnano_path = os.path.join(os.getenv("APPDATA"), "npm", "cssnano.cmd")
def minify_html(input_path, output_path):
subprocess.run([html_minifier_path, '--collapse-whitespace', '--remove-comments', input_path, '-o', output_path])
def minify_js(input_path, output_path):
subprocess.run([terser_path, input_path, '-o', output_path, '-c', '-m'])
def minify_css(input_path, output_path):
subprocess.run([cssnano_path, '--no-discardUnused', input_path, output_path])
def process_file(src_path, dest_path):
_, file_extension = os.path.splitext(src_path)
# Extrahiere den Ordnerpfad im Zielverzeichnis
dest_dir = os.path.dirname(dest_path)
# Erstelle den Ordner und alle dazugehörigen Unterordner, falls sie nicht existieren
os.makedirs(dest_dir, exist_ok=True)
if file_extension.lower() == '.js':
minify_js(src_path, dest_path)
elif file_extension.lower() == '.css':
minify_css(src_path, dest_path)
elif file_extension.lower() in ['.html', '.htm']:
minify_html(src_path, dest_path)
else:
# Kopiere nicht bearbeitbare Dateien direkt in den Zielordner
shutil.copy2(src_path, dest_path)
def strip_files(src_dir, dest_dir):
# Erstelle den Zielordner und alle dazugehörigen Unterordner, falls sie nicht existieren
os.makedirs(dest_dir, exist_ok=True)
# Durchlaufe alle Dateien und Unterverzeichnisse im Quellordner
for root, _, files in os.walk(src_dir):
for filename in files:
src_path = os.path.join(root, filename)
dest_path = os.path.relpath(src_path, src_dir)
dest_path = os.path.join(dest_dir, dest_path)
# Verarbeite nur Dateien (keine Unterverzeichnisse)
process_file(src_path, dest_path)
def gzip_file(src_path, dst_path):
with open(src_path, 'rb') as src, gzip.open(dst_path, 'wb') as dst:
for chunk in iter(lambda: src.read(4096), b""):
dst.write(chunk)
def getListOfFiles(dirName):
# create a list of file and sub directories
# names in the given directory
listOfFile = os.listdir(dirName)
allFiles = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFiles = allFiles + getListOfFiles(fullPath)
else:
allFiles.append(fullPath)
return allFiles
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text # or whatever
# Compress files from 'data_src/' to 'data/'
def gzip_webfiles(source, target, env):
# Filetypes to compress
filetypes_to_gzip = ['.css', '.png', '.js', '.ico', '.woff2', '.json']
print('\nGZIP: Starting gzip-Process for LittleFS-Image...\n')
data_src_dir_path = os.path.join(env.get('PROJECT_DIR'), 'data_src')
data_temp_dir_path = os.path.join(env.get('PROJECT_DIR'), 'data_stripped')
strip_files(data_src_dir_path, data_temp_dir_path)
data_dir_path = env.get('PROJECT_DATA_DIR')
# check if data and datasrc exist. If the first exists and not the second, it renames it
if(os.path.exists(data_dir_path) and not os.path.exists(data_temp_dir_path)):
print('GZIP: Directory "'+data_dir_path +
'" exists, "'+data_temp_dir_path+'" is not found.')
print('GZIP: Renaming "' + data_dir_path +
'" to "' + data_temp_dir_path + '"')
os.rename(data_dir_path, data_temp_dir_path)
# Delete the 'data' directory
if(os.path.exists(data_dir_path)):
print('GZIP: Deleting the "data" directory ' + data_dir_path)
shutil.rmtree(data_dir_path)
# Recreate empty 'data' directory
print('GZIP: Re-creating an empty data directory ' + data_dir_path)
os.mkdir(data_dir_path)
# Determine the files to compress
files_to_copy = []
files_to_gzip = []
all_data_src = getListOfFiles(data_temp_dir_path)
for file in all_data_src:
file_name, file_extension = os.path.splitext(file)
print(file_name + " has filetype " + file_extension)
if file_extension in filetypes_to_gzip:
files_to_gzip.append(file)
else:
filename_subdir = remove_prefix(file, data_temp_dir_path)
files_to_copy.append(filename_subdir)
for file in files_to_copy:
print('GZIP: Copying file from: ' + data_temp_dir_path + file + ' to: ' + data_dir_path + file)
os.makedirs(os.path.dirname(data_dir_path + file), exist_ok=True)
shutil.copy(data_temp_dir_path + file, data_dir_path + file)
# Compress and move files
was_error = False
try:
for source_file_path in files_to_gzip:
print('GZIP: compressing... ' + source_file_path)
filename_subdir = remove_prefix(source_file_path, data_temp_dir_path)
target_file_path = data_dir_path + filename_subdir
os.makedirs(os.path.dirname(target_file_path), exist_ok=True)
print('GZIP: Compressed... ' + target_file_path)
gzip_file(source_file_path, target_file_path + ".gz")
except IOError as e:
was_error = True
print('GZIP: Failed to compress file: ' + source_file_path)
# print( 'GZIP: EXCEPTION... {}'.format( e ) )
if was_error:
print('GZIP: Failure/Incomplete.\n')
else:
print('GZIP: Compressed correctly.\n')
shutil.rmtree(data_temp_dir_path)
return
def gzip_binffiles(source, target, env):
littlefsbin = target[0].get_abspath()
targetbin = os.path.join(os.path.dirname(littlefsbin), 'filesystem.fs')
shutil.copyfile(littlefsbin, targetbin)
gzip_file(targetbin, os.path.join(str(targetbin) + '.gz'))
os.remove(targetbin)
return
# IMPORTANT, this needs to be added to call the routine
env.AddPreAction('$BUILD_DIR/littlefs.bin', gzip_webfiles)
env.AddPostAction('$BUILD_DIR/littlefs.bin', gzip_binffiles)

View File

@@ -0,0 +1,9 @@
Import("env") # pylint: disable=undefined-variable
env.Execute("\"$PYTHONEXE\" -m pip install jinja2")
env.Replace(PROGNAME="firmware_pcb_1.%s.fw" % env.GetProjectOption("custom_pcb_revision"))
import struct2json
import dtcs
struct2json.struct2json()
dtcs.build_dtcs()

View File

@@ -0,0 +1,108 @@
import os
import time
from jinja2 import Environment, FileSystemLoader
import re
import filechecksum as fcs
# Pfad zur Eingabedatei und Ausgabedatei
input_file = "include/config.h"
output_sourcefile = "src/struct2json.cpp"
output_headerfile = "include/struct2json.h"
# Liste der zu suchenden Variablen/Structs
variable_names = ['LubeConfig', 'PersistenceData']
def get_types(file_content, variable_names):
result = {}
# Entferne Kommentare, um unerwünschte Störungen zu vermeiden
file_content = re.sub(r'\/\*.*?\*\/', '', file_content, flags=re.DOTALL)
file_content = re.sub(r'\/\/.*', '', file_content)
for var_name in variable_names:
# Erstelle ein reguläres Ausdrucksmuster, um den Typ der Variable zu extrahieren
pattern = re.compile(r'\b(?:extern\s+)?(\w+)\s+' + re.escape(var_name) + r'\s*;')
match = pattern.search(file_content)
if match:
# Extrahiere den Typ aus dem Treffer
type_match = match.group(1)
result[var_name] = type_match
return result
def extract_struct_fields(file_content, variable_types):
result = {}
# Entferne Kommentare, um unerwünschte Störungen zu vermeiden
file_content = re.sub(r'\/\*.*?\*\/', '', file_content, flags=re.DOTALL)
file_content = re.sub(r'\/\/.*', '', file_content)
for var_name, var_type in variable_types.items():
# Erstelle ein reguläres Ausdrucksmuster, um das Strukturfeld zu extrahieren
pattern = re.compile(r'typedef\s+struct\s*{([^}]*)}\s*' + re.escape(var_type) + r'\s*;')
match = pattern.search(file_content)
if match:
# Extrahiere die Felder aus dem Treffer
fields_match = re.findall(r'\b(\w+)\s+(\w+)\s*;', match.group(1))
if fields_match:
result[var_name] = {'type': var_type, 'fields': {field_name: field_type for field_type, field_name in fields_match}}
return result
def struct2json():
# Überprüfen, ob die Verzeichnisse existieren, andernfalls erstellen
output_dir_source = os.path.dirname(output_sourcefile)
if not os.path.exists(output_dir_source):
os.makedirs(output_dir_source)
output_dir_header = os.path.dirname(output_headerfile)
if not os.path.exists(output_dir_header):
os.makedirs(output_dir_header)
# Unix-Zeitstempel hinzufügen
timestamp = int(time.time())
# Parse structs
with open(input_file, 'r') as file:
content = file.read()
variable_types = get_types(content, variable_names)
structs = extract_struct_fields(content, variable_types)
checksum = fcs.calculate_checksum(structs)
env = Environment(loader=FileSystemLoader('codegen/templates', encoding='utf-8'))
# Lade das Jinja2-Template aus der Datei
template_c = env.get_template('struct2json.cpp.j2')
template_h = env.get_template('struct2json.h.j2')
# Erstelle ein Context-Dictionary mit den erforderlichen Daten
context = {
'timestamp_unix': timestamp,
'timestamp' : time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)),
'date' : time.strftime('%d.%m.%Y', time.localtime(timestamp)),
'structs': structs,
'checksum': checksum
}
# Überprüfe, ob die Checksummen übereinstimmen
if fcs.read_and_compare_checksum(output_sourcefile, checksum):
print("Keine Änderungen in der Source-Datei erforderlich.")
else:
# Rendere das Template mit den Werten und erhalte den Source-Text
source_text = template_c.render(context)
# Schreibe den generierten Source-Text in die Source-Datei
with open(output_sourcefile, "w", encoding='utf-8') as f:
f.write(source_text)
print(f"Source-Datei wurde erstellt: {output_sourcefile}")
# Überprüfe, ob die Checksummen übereinstimmen
if fcs.read_and_compare_checksum(output_headerfile, checksum):
print("Keine Änderungen in der Header-Datei erforderlich.")
else:
# Rendere das Template mit den Werten und erhalte den Header-Text
header_text = template_h.render(context)
# Schreibe den generierten Header-Text in die Header-Datei
with open(output_headerfile, "w", encoding='utf-8') as f:
f.write(header_text)
print(f"Header-Datei wurde erstellt: {output_headerfile}")

View File

@@ -0,0 +1,54 @@
/**
* @file dtc_defs.h
*
* @brief Header file for Diagnostic Trouble Code (DTC) definitions in the ChainLube application.
*
* This file contains definitions for Diagnostic Trouble Codes (DTC) in the ChainLube project.
* It includes enums for DTC active status, severity levels, and specific DTC codes.
* The file also defines an array of DTC definitions and a timestamp indicating the generation time.
*
* @note This file is auto-generated by a script on {{ timestamp }}.
*
* @author Marcel Peterkau
* @date {{ date }}
*/
#ifndef DTC_DEFS_H
#define DTC_DEFS_H
#include <stdint.h>
typedef uint32_t DTCNum_t;
typedef enum
{
DTC_INACTIVE,
DTC_ACTIVE,
DTC_PREVIOUS
} DTCActive_t;
typedef enum
{
DTC_NONE,
DTC_INFO,
DTC_WARN,
DTC_CRITICAL
} DTCSeverity_t;
typedef struct {
DTCNum_t code;
DTCSeverity_t severity;
} DTC_t;
{% for dtc in dtc_macros -%}
{{ dtc }}
{% endfor %}
const DTC_t dtc_definitions[] = {
{% for struct in dtc_structs -%}
{{ struct }}
{% endfor -%}
};
#endif // DTC_DEFS_H
// CODEGENERATOR_CHECKSUM: {{ checksum }}

View File

@@ -0,0 +1,25 @@
/**
* @file struct2json.cpp
*
* @brief Implementation file for converting structs to JSON objects.
*
* @note This file is auto-generated by a script on {{ timestamp }}.
*
* @author Marcel Peterkau
* @date {{ date }}
*/
#include "struct2json.h"
{% for var_name, var_info in structs.items() -%}
void generateJsonObject_{{ var_name }}(JsonObject& data)
{
{% for field_name, field_type in var_info['fields'].items() -%}
data["{{ field_name }}"] = {{ var_name }}.{{ field_name }};
{% endfor -%}
}
{% endfor %}
// CODEGENERATOR_CHECKSUM: {{ checksum }}

View File

@@ -0,0 +1,26 @@
/**
* @file struct2json.h
*
* @brief Header file for converting structs to JSON objects.
*
* @note This file is auto-generated by a script on {{ timestamp }}.
*
* @author Marcel Peterkau
* @date {{ date }}
*/
#ifndef _STRUCT2JSON_H_
#define _STRUCT2JSON_H_
#include <Arduino.h>
#include <ArduinoJson.h>
#include "config.h"
{% for var_name, var_info in structs.items() -%}
void generateJsonObject_{{ var_name }}(JsonObject& data);
{% endfor %}
#endif /* _STRUCT2JSON_H_ */
// CODEGENERATOR_CHECKSUM: {{ checksum }}

646
Software/data_src/index.htm Normal file
View File

@@ -0,0 +1,646 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>KTM CAN Chain Oiler</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/custom.css">
<link rel="stylesheet" href="static/css/tweaks.css">
<script src="static/js/jquery.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/websocket.js"></script>
<script src="static/js/dtc_table.js"></script>
<script src="static/js/script.js"></script>
<link rel="apple-touch-icon" sizes="180x180" href="static/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="static/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="static/img/favicon-16x16.png">
<link rel="manifest" href="static/img/site.webmanifest">
</head>
<body>
<nav class="navbar fixed-top navbar-dark bg-primary" id="navbar1">
<a class="navbar-brand" href="#">
<img src="static/img/logo.png" width="30" height="30" class="d-inline-block align-top mr-1" alt="">
KTM CAN ChainLube
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar"
aria-controls="collapsingNavbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsingNavbar">
<ul class="navbar-nav nav mr-auto mt-2 mt-lg-0">
<li class="nav-item"><a class="nav-link active" role="tab" data-toggle="tab" href="#tab_home">Home</a></li>
<li class="nav-item"><a class="nav-link" role="tab" data-toggle="tab" href="#tab_maintenance">Wartung</a></li>
<li class="nav-item"><a class="nav-link" role="tab" data-toggle="tab" href="#tab_source">Einstellungen</a></li>
<li class="nav-item"><a class="nav-link" role="tab" data-toggle="tab" href="#tab_fwupdate">Update</a></li>
</ul>
</div>
</nav>
<main class="container">
<!-- Tabs Content -->
<div class="tab-content">
<!-- Div Tab Home-->
<div id="tab_home" class="tab-pane fade show active" role="tabpanel">
<div class="col text-center">
<div class="jumbotron">
<img src="static/img/logo.png" width="120" height="120" class="img-fluid" alt="">
<h3 class="pt-3">KTM CAN Chain Lube</h3>
</div>
</div>
<!-- Div Group Tank remain -->
<hr />
<p>
<h4>Tankinhalt verbleibend</h4>
<div class="progress">
<div id="tankremain" class="data-tankremain progress-bar text-light" role="progressbar" aria-valuenow="0"
aria-valuemin="0" aria-valuemax="100" style="width: 0%">
0
</div>
</div>
</p>
<!-- Div Group Tank remain -->
<!-- Div Group current Mode -->
<hr />
<p>
<h4>aktueller Modus</h4>
<input class="data-systemstatus form-control" type="text" id="sysstatus" readonly>
</p>
<!-- Div Group current Mode -->
<!-- Div Group DTC Table -->
<div id="dtc_container" hidden>
<hr />
<p>
<h4>Fehlercodes</h4>
<table class="table" id="dtc_table">
<tbody>
<tr>
<th class="col-6" scope="col">Zeitstempel</th>
<th class="col-2" scope="col">Fehlercode</th>
<th class="col-2" scope="col">Schwere</th>
<th class="col-2" scope="col">Aktiv</th>
</tr>
</tbody>
</table>
</p>
</div>
<!-- Div Group DTC Table -->
</div>
<!-- Div Tab Home-->
<!-- Div Tab Maintenance -->
<div id="tab_maintenance" class="tab-pane fade" role="tabpanel">
<h3>Wartung</h3>
<!-- Div Group Tank remain -->
<hr />
<p>
<h4>&Ouml;lvorrat</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="tankremain_maint" class="control-label col-4">Tankinhalt verbleibend</label>
<div class="col-8">
<div class="progress">
<div id="tankremain_maint" class="data-tankremain progress-bar text-light" role="progressbar"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"
style="width: 0%">
%TANK_REMAIN_CAPACITY%&#37;
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="resettank" type="submit" class="btn btn-outline-primary ml-2">Tank zurücksetzen</button>
</div>
</div>
</form>
</p>
<!-- Div Group Tank remain -->
<!-- Div Group Purging -->
<hr />
<p>
<h4>Entl&uuml;ftung</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="bleedingpulses" class="control-label col-4">Entl&uuml;ftung Dosierung</label>
<div class="col-8">
<div class="input-group">
<input id="bleedingpulses" name="bleedingpulses" value="0" type="text" class="data-bleedingpulses form-control">
<div class="input-group-append">
<span class="input-group-text">Pulse</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="maintsave" type="submit" class="btn btn-outline-primary">Speichern</button>
<button name="purgenow" type="submit" class="btn btn-outline-primary ml-2">Entlüftung starten</button>
</div>
</div>
</form>
</p>
<!-- Div Group Purging -->
<!-- Div Group Measure -->
<div %SHOW_IMPULSE_SETTINGS%>
<hr />
<p>
<h4>Einmessen</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="measuredpulses" class="control-label col-4">erfasste Pulse</label>
<div class="col-8">
<div class="input-group">
<input id="measuredpulses" name="measuredpulses" value="0" type="text" readonly
class="form-control">
<div class="input-group-append">
<span class="input-group-text">Pulse</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="measurestartstop" type="submit" class="btn btn-outline-primary">Start</button>
<button name="measurereset" type="submit" class="btn btn-outline-primary ml-2">Reset</button>
</div>
</div>
</form>
</p>
</div>
<!-- Div Group Purging -->
<!-- Div Group EEPROM formatting -->
<hr />
<p>
<h4>EEPROM formatieren</h4>
<div class="alert alert-primary alert-dismissable show fade" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>Achtung!</strong><br>
Das Formatieren der EEPROM-Bereiche sollte nur ausgeführt werden wenn es unbedingt erforderlich ist!
Hierdurch werden alle Einstellungen zurück gesetzt bzw. alle Betriebsdaten gehen verloren.
Folgende Situationen erfordern unter anderem eine Formatierung:
- Erstinitialisierung (bei neu aufgebautem Gerät)
- Firmware-Update (nur wenn es die Release-Notes fordern)
</div>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<div class="offset-4 col-8">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="reset_ee_cfg" id="reset_ee_cfg">
<label class="form-check-label" for="reset_ee_cfg">
Bereich "CFG"
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="reset_ee_pds" id="reset_ee_pds">
<label class="form-check-label" for="reset_ee_pds">
Bereich "PDS"
</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="reset_ee_btn" type="submit" class="btn btn-outline-primary">EEPROM formatieren</button>
</div>
</div>
</form>
</p>
<!-- Div Group EEPROM formatting -->
<!-- Div Group LiveDebug -->
<hr />
<p>
<h4>Live Debug</h4>
<div class="form-group row">
<textarea class="form-control" spellcheck="false" id="livedebug-out" rows="3" readonly></textarea>
</div>
<div class="form-group row">
<div class="col text-center">
<button id="btn-ws-start" class="btn btn-outline-primary">Start</button>
<button id="btn-ws-stop" class="btn btn-outline-primary ml-2">Stop</button>
</div>
</div>
</p>
<!-- Div Group LiveDebug -->
<!-- Div Group Device Reboot -->
<hr />
<p>
<h4>Ger&auml;t neustarten</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<div class="col text-center">
<button name="reboot" type="submit" class="btn btn-outline-primary">Reboot</button>
</div>
</div>
</form>
</p>
<!-- Div Group Device Reboot -->
</div>
<!-- Div Tab Maintenance -->
<!-- Div Tab Settings-->
<div id="tab_source" class="tab-pane fade" role="tabpanel">
<h3>Einstellungen</h3>
<!-- Div Group Signal Source -->
<hr />
<p>
<h4>Signalquelle</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="sourceselect" class="control-label col-4">Schnittstelle</label>
<div class="col-8">
<select id="sourceselect" name="sourceselect" class="data-sourceselect select form-control">
<option value="Impuls">Impuls</option>
<option value="GPS">GPS</option>
<option value="CAN-Bus">CAN-Bus</option>
</select>
</div>
</div>
<div class="alert alert-primary alert-dismissable show fade" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>Achtung!</strong><br>
Bei Änderung der Signalquelle wird der CAN-Oiler neu gestartet.
Dadurch wird die WiFi-Verbindung getrennt und muss neu aufgebaut werden.
</div>
<div class="form-group row">
<div class="col text-center">
<button name="sourcesave" type="submit" class="btn btn-outline-primary">&Uuml;bernehmen</button>
</div>
</div>
</form>
</p>
<!-- Div Group Signal Source -->
<!-- Div Group Source:Impulse Settings-->
<div id="showimpulse" class="data-showimpulse removeable">
<hr />
<p>
<h4>Einstellungen Impulseingang</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="tirewidth" class="control-label col-4">Reifenbreite</label>
<div class="col-8">
<div class="input-group">
<input id="tirewidth" name="tirewidth" type="text" required="required" class="data-tirewidth form-control">
<div class="input-group-append">
<span class="input-group-text">mm</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label for="tireratio" class="control-label col-4">Höhe/Breite-Verhältniss</label>
<div class="col-8">
<div class="input-group">
<input id="tireratio" name="tireratio" type="text" required="required" class="data-tireratio form-control">
<div class="input-group-append">
<span class="input-group-text">mm</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label for="tiredia" class="control-label col-4">Felgendurchmesser</label>
<div class="col-8">
<div class="input-group">
<input id="tiredia" name="tiredia" type="text" required="required" class="data-tiredia form-control">
<div class="input-group-append">
<span class="input-group-text">"</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label for="pulserev" class="control-label col-4">Pulse pro Umdrehung</label>
<div class="col-8">
<div class="input-group">
<input id="pulserev" name="pulserev" type="text" required="required" class="data-pulserev form-control">
<div class="input-group-addon"></div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="pulsesave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
</div>
<!-- Div Group Source:Impulse Settings-->
<!-- Div Group Source:CAN Settings-->
<div id="showcan" class="data-showcan removeable">
<hr />
<p>
<h4>Einstellungen CAN-Bus</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="cansource" class="control-label col-4">Model</label>
<div class="col-8">
<select id="cansource" name="cansource" class="data-cansource select form-control">
<option value="KTM 890 Adventure R (2021)">KTM 890 Adventure R (2021)</option>
<option value="KTM 1290 Superduke R (2023)">KTM 1290 Superduke R (2023)</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="cansave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
</div>
<!-- Div Group Source:CAN Settings-->
<!-- Div Group Source:GPS Settings-->
<div id="showgps" class="data-showgps removeable">
<hr />
<p>
<h4>Einstellungen GPS</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="gpsbaud" class="control-label col-4">Baudrate</label>
<div class="col-8">
<select id="gpsbaud" name="gpsbaud" class="data-gpsbaud select form-control">
</select>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="gpssave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
</div>
<!-- Div Group Source:GPS Settings-->
<!-- Div Group Lube Settings-->
<hr />
<p>
<h4>Dosierung</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="lubedistancenormal" class="control-label col-4">Normal (gr&uuml;n)</label>
<div class="col-8">
<div class="input-group">
<input id="lubedistancenormal" name="lubedistancenormal" type="text"
class="data-lubedistancenormal form-control" required="required">
<div class="input-group-append">
<span class="input-group-text">m</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label for="lubedistancerain" class="control-label col-4">Regen (blau)</label>
<div class="col-8">
<div class="input-group">
<input id="lubedistancerain" name="lubedistancerain" type="text"
class="data-lubedistancerain form-control" required="required">
<div class="input-group-append">
<span class="input-group-text">m</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="oilsave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
<!-- Div Group Lube Settings-->
<!-- Div Group Oiltank Settings -->
<hr />
<p>
<h4>&Ouml;ltank</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="tankcap" class="control-label col-4">Tankkapazität</label>
<div class="col-8">
<div class="input-group">
<input id="tankcap" name="tankcap" type="text" class="data-tankcap form-control"
required="required">
<div class="input-group-append">
<span class="input-group-text">ml</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label for="tankwarn" class="control-label col-4">Leer-Warnung</label>
<div class="col-8">
<div class="input-group">
<input id="tankwarn" name="tankwarn" type="text" class="data-tankwarn form-control"
required="required">
<div class="input-group-append">
<span class="input-group-text">&#37;</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label for="pumppulse" class="control-label col-4">Menge pro Puls</label>
<div class="col-8">
<div class="input-group">
<input id="pumppulse" name="pumppulse" type="text" class="data-pumppulse form-control"
required="required">
<div class="input-group-append">
<span class="input-group-text">µl</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="oilsave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
<!-- Div Group Oiltank Settings -->
<!-- Div Group LED Settings-->
<hr />
<p>
<h4>LED Einstellungen</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="ledmodeflash" class="control-label col-4">LED Modus blinken</label>
<div class="col-8">
<div class="form-check">
<input class="data-ledmodeflash form-check-input" type="checkbox" name="ledmodeflash" id="ledmodeflash">
<label class="form-check-label" for="ledmodeflash">
LED blinken
</label>
</div>
</div>
</div>
<div class="form-group row">
<label for="ledmaxbrightness" class="control-label col-4">Max Helligkeit</label>
<div class="col-8">
<div class="input-group">
<input id="ledmaxbrightness" name="ledmaxbrightness" type="text"
class="data-ledmaxbrightness form-control" required="required">
</div>
</div>
</div>
<div class="form-group row">
<label for="ledminbrightness" class="control-label col-4">Min Helligkeit</label>
<div class="col-8">
<div class="input-group">
<input id="ledminbrightness" name="ledminbrightness" type="text"
class="data-ledminbrightness form-control" required="required">
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="ledsave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
<!-- Div Group Lube Settings-->
</div>
<!-- Div Tab Settings -->
<!-- Div Tab Firmware Update-->
<div id="tab_fwupdate" class="tab-pane fade" role="tabpanel">
<h3>Firmware</h3>
<!-- Div Group VersionInfo -->
<hr />
<p>
<h4>Version-Info</h4>
<table class="table">
<tbody>
<tr>
<th class="col-7" scope="col">Parameter</td>
<th class="col-5" scope="col">Value</td>
</tr>
<tr>
<td>Firmware Version</td>
<td>%SW_VERSION%</td>
</tr>
<tr>
<td>Flash Version</td>
<td>%FS_VERSION%</td>
</tr>
<tr>
<td>Git Revision</td>
<td>%GIT_REV%</td>
</tr>
</table>
</p>
<!-- Div Group VersionInfo -->
<!-- Div Group EEPROM Backup -->
<hr />
<p>
<h4>EEPROM-Backup</h4>
<div class="form-group row">
<div class="col text-center">
<a class="btn btn-outline-primary" href="eejson" role="button" id="ee-backup-download">Download</a>
</div>
</div>
</p>
<!-- Div Group EEPROM Backup -->
<!-- Div Group EEPROM Restore -->
<hr />
<p>
<h4>EEPROM-Restore</h4>
<form method='POST' action='eeRestore' enctype='multipart/form-data'>
<div class="form-group row">
<div class="custom-file">
<input type="file" name="ee-restore-file" class="custom-file-input" id="ee-restore-file" accept=".ee.json"
required />
<label class="custom-file-label" for="ee-restore-file">EEPROM-Backup ausw&auml;hlen</label>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="submit" type="submit" class="btn btn-outline-primary">Restore starten</button>
</div>
</div>
</form>
</p>
<!-- Div Group EEPROM Restore -->
<!-- Div Group Firmware Update -->
<hr />
<p>
<h4>Firmware-Update</h4>
<form method='POST' action='doUpdate' enctype='multipart/form-data'>
<div class="form-group row">
<div class="custom-file">
<input type="file" name="fw-update-file" class="custom-file-input" id="fw-update-file"
accept=".fw.bin,.fs.gz" required />
<label class="custom-file-label" for="fw-update-file">Firmware-Update ausw&auml;hlen</label>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="submit" type="submit" class="btn btn-outline-primary">Update starten</button>
</div>
</div>
</form>
</p>
<!-- Div Group Firmware Update -->
</div>
<!-- Div Tab Firmware Update-->
</div>
<!-- Tabs Content -->
</main>
<!-- Footer -->
<footer class="page-footer navbar-dark bg-primary font-small fixed-bottom">
<div class="container-fluid text-center">
<div class="footer-copyright text-center py-3">
<span class="text-muted">© 2023 -
<a class="text-reset fw-bold" href="https://eventronics.de/">Marcel Peterkau</a></span>
</div>
</div>
</footer>
<!-- Footer -->
<!-- Modal Dialog -->
<div class="modal fade" id="dtcModal" tabindex="-1" role="dialog" aria-labelledby="dtcModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="dtcModalLabel">DTC-Description</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p class="dtc-desc">DTC Description</p>
<p class="dtc-debugval">DTC DebugVal</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Modal Dialog -->
</body>
</html>

View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>KTM CAN Chain Oiler</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/custom.css">
<script src="static/js/jquery.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<link rel="apple-touch-icon" sizes="180x180" href="static/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="static/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="static/img/favicon-16x16.png">
<link rel="manifest" href="static/img/site.webmanifest">
<meta http-equiv="refresh" content="3; url='index.htm'" />
</head>
<body>
<div class="container" style="display: flex; justify-content: center; align-items: center; height: 100vh">
<div class="alert alert-success">
<strong>Bitte warten!</strong> Änderungen werden übernommen.
</div>
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,27 @@
@font-face {
font-family: 'Comfortaa';
font-style: normal;
font-weight: 300;
src: url(../fonts/comfortaa.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
body {
padding-top: 70px;
margin-bottom: 70px;
}
hr {
height: 2px;
border-width: 0;
color: gray;
background-color: gray
}
.dtc-debugval {
color: #F2771A;
font: 0.8rem Inconsolata, monospace;
background-color: black;
padding: 10px;
}

View File

@@ -0,0 +1,96 @@
{
"codegenerator_checksum": "23dff82a4745f67041012080b05ec367c2dd44c6bb02974143b227ba49682b6f",
"timestamp": "2024-01-10 19:06:30",
"dtc_table_data": [
{
"num": 0,
"title": "No Error",
"description": "No Error"
},
{
"num": 1,
"title": "Ölvorrat leer",
"description": "Ölvorrat ist komplett leer. Den Ölvorrat auffüllen und im Menu 'Wartung' zurück setzen"
},
{
"num": 2,
"title": "Ölvorrat niedrig",
"description": "Ölvorrat ist unter der Warnschwelle. Den Ölvorrat demnächst auffüllen und im Menu 'Wartung' zurück setzen"
},
{
"num": 3,
"title": "kein EEPROM erkannt",
"description": "Es wurde kein EEPROM gefunden. Dies lässt einen Hardware-Defekt vermuten."
},
{
"num": 4,
"title": "EEPROM CFG Checksumme",
"description": "Die Checksumme der Config-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück"
},
{
"num": 5,
"title": "EEPROM PDS Checksumme",
"description": "Die Checksumme der Betriebsdaten-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück"
},
{
"num": 6,
"title": "EEPROM PDS Adresse",
"description": "Die Adresse der Betriebsdaten-Partition im EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück"
},
{
"num": 7,
"title": "EEPROM Version falsch",
"description": "Die Layout-Version des EEPROM stimmt nicht mit der Firmware-Version überein. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück"
},
{
"num": 8,
"title": "Flashspeicher Fehler",
"description": "Der Flashspeicher konnte nicht initialisiert werden. Aktualisieren sie Flash & Firmware"
},
{
"num": 9,
"title": "Flashversion falsch",
"description": "Die Version des Flashspeicher stimmt nicht mit der Firmware-Version überein. Aktualisieren sie den Flash mit der passenden Update-Datei"
},
{
"num": 10,
"title": "Keine GPS-Verbindung",
"description": "Es wurde kein GPS-Signal über die serielle Schnittstelle empfangen, Prüfen sie die Verbindung und das GPS-Modul"
},
{
"num": 11,
"title": "CAN-Transceiver Error",
"description": "Es konnte keine Verbindung zum CAN-Transceiver hergestellt werden. Prüfen Sie die Hardware auf Defekte"
},
{
"num": 12,
"title": "Keine CAN-Verbindung",
"description": "Es konnte kein CAN-Signal empfangen werden. Prüfen sie die Verbindung und die Einstellungen"
},
{
"num": 13,
"title": "Config-Validierung",
"description": "Ein oder mehrer Einstellungswerte sind ausserhalb plausibler Werte. Prüfen Sie Ihre Einstellungen"
},
{
"num": 14,
"title": "Dummy-DTC Info",
"description": "Ein Dummy-DTC der Schwere \"Info\" für Debugging-Zwecke"
},
{
"num": 15,
"title": "Dummy-DTC Warnung",
"description": "Ein Dummy-DTC der Schwere \"Warnung\" für Debugging-Zwecke"
},
{
"num": 16,
"title": "Dummy-DTC Kritisch",
"description": "Ein Dummy-DTC der Schwere \"Kritisch\" für Debugging-Zwecke"
},
{
"num": 17,
"title": "Last Error",
"description": "Last Error"
}
]
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@@ -0,0 +1 @@
{"name":"","short_name":"","icons":[{"src":"/static/img/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/static/img/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,199 @@
const jsonFilePath = "static/dtc_table.json";
var dtcState = {};
function processDTCNotifications(dtcArray) {
for (var i = 0; i < dtcArray.length; i++) {
var dtcInfo = dtcArray[i].split(",");
var errorCode = dtcInfo[1];
var activity = parseInt(dtcInfo[3]);
if (dtcState[errorCode]) {
// Überprüfen, ob sich der Zustand von "previous" auf "active" geändert hat
if (activity !== dtcState[errorCode]) {
dtcState[errorCode] = activity;
if (activity === 1) showDTCNotification(errorCode);
}
} else {
// DTC ist neu, Zustand speichern und Benachrichtigung anzeigen
dtcState[errorCode] = activity;
showDTCNotification(errorCode);
}
}
}
function showDTCNotification(dtctext, severity) {
// Überprüfen, ob der Browser die Notification API unterstützt
if ("Notification" in window) {
// Überprüfen, ob der Benutzer bereits Berechtigungen erteilt hat
if (Notification.permission === "granted") {
// Benachrichtigung anzeigen
showNotification(dtctext, severity);
} else if (Notification.permission !== "denied") {
// Aufforderung zur Erlaubnis einholen
Notification.requestPermission().then(function (permission) {
if (permission === "granted") {
// Benachrichtigung anzeigen
showNotification(dtctext, severity);
} else {
// Der Benutzer hat die Berechtigung abgelehnt oder das Dialogfeld geschlossen
console.log("Benachrichtigungsberechtigung wurde verweigert.");
}
});
} else {
// Der Benutzer hat die Berechtigung bereits verweigert
console.log("Benachrichtigungsberechtigung wurde bereits verweigert.");
}
}
}
// Funktion zum Anzeigen der Benachrichtigung
function showNotification(dtctext, severity) {
var severityIcon;
switch (severity) {
case 1:
severityIcon = "static/img/info.png";
break;
case 2:
severityIcon = "static/img/warn.png";
break;
case 3:
severityIcon = "static/img/critical.png";
break;
default:
severityIcon = "static/img/none.png";
}
var options = {
body: dtctext,
icon: severityIcon,
};
var notification = new Notification("KTM Chain Oiler DTC", options);
// Optional: Handle Click-Event
notification.onclick = function () {
console.log("Benachrichtigung wurde angeklickt.");
};
}
function getDescriptionForDTCNumber(number, callback) {
fetch(jsonFilePath)
.then((response) => response.json())
.then((data) => {
const foundEntry = data.find((entry) => entry.num === number);
if (foundEntry) {
const description = foundEntry.description;
const title = foundEntry.title;
callback(null, title, description);
} else {
// Wenn die Nummer nicht gefunden wurde, geben Sie einen Fehler zurück
callback(
`Beschreibung für Nummer ${number} nicht gefunden.`,
null,
null
);
}
})
.catch((error) => {
// Im Fehlerfall geben Sie den Fehler zurück
callback(error, null, null);
});
}
function fillDTCTable(dtcArray) {
// Referenz auf das Tabellen-Element
var table = document.getElementById("dtc_table");
var tablediv = document.getElementById("dtc_container");
// Prüfen, ob DTC vorhanden sind
if (dtcArray.length === 0) {
// Verstecke das Tabellen-Div, wenn keine DTC vorhanden sind
tablediv.hidden = true;
return;
} else {
// Zeige das Tabellen-Div, wenn DTC vorhanden sind
tablediv.hidden = false;
}
// Tabelle leeren, bevor sie neu gefüllt wird
table.innerHTML = "";
// Überschriften für die Tabelle erstellen
var headerRow = table.insertRow(0);
// Definition der Klassen und Scopes für die Spalten
var columnDefinitions = [
{ class: "col-6", scope: "Zeitstempel" },
{ class: "col-2", scope: "Fehlercode" },
{ class: "col-2", scope: "Schwere" },
{ class: "col-2", scope: "Aktiv" },
];
for (var i = 0; i < columnDefinitions.length; i++) {
var headerCell = headerRow.insertCell(i);
headerCell.className = `th ${columnDefinitions[i].class}`;
headerCell.scope = columnDefinitions[i].scope;
headerCell.innerHTML = columnDefinitions[i].scope;
}
// DTC-Daten in die Tabelle einfügen
for (var i = 0; i < dtcArray.length; i++) {
var dtcInfo = dtcArray[i].split(",");
var row = table.insertRow(i + 1); // +1 wegen der Überschriftenzeile
// Zeitstempel
var timestampCell = row.insertCell(0);
timestampCell.innerHTML = formatTimestamp(parseInt(dtcInfo[0]));
// Fehlercode
var errorCodeCell = row.insertCell(1);
errorCodeCell.innerHTML = dtcInfo[1];
// Schwere
var severityCell = row.insertCell(2);
var severity = parseInt(dtcInfo[2]);
// Schwere
switch (severity) {
case 1:
severityCell.innerHTML = '<img src="static/img/info.png" alt="Info" />';
break;
case 2:
severityCell.innerHTML =
'<img src="static/img/warn.png" alt="Warnung" />';
break;
case 3:
severityCell.innerHTML =
'<img src="static/img/critical.png" alt="Kritisch" />';
break;
default:
severityCell.innerHTML =
'<img src="static/img/none.png" alt="Unbekannt" />';
}
row.setAttribute("data-dtc", dtcInfo[1]);
row.setAttribute("data-debugval", dtcInfo[4]);
// Aktivität
var activityCell = row.insertCell(3);
activityCell.innerHTML = parseInt(dtcInfo[3]) === 1 ? "active" : "previous";
}
}
function formatTimestamp(milliseconds) {
const date = new Date(milliseconds);
const days = String(date.getUTCDate() - 1).padStart(2, "0");
const hours = String(date.getUTCHours()).padStart(2, "0");
const minutes = String(date.getUTCMinutes()).padStart(2, "0");
const seconds = String(date.getUTCSeconds()).padStart(2, "0");
const millisecondsFormatted = String(date.getUTCMilliseconds()).padStart(
3,
"0"
);
return `${days}-${hours}:${minutes}:${seconds}:${millisecondsFormatted}`;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,37 @@
$(".navbar-nav>li>a").on("click", function () {
$(".navbar-collapse").collapse("hide");
});
document
.querySelector(".custom-file-input")
.addEventListener("change", function (e) {
var fileName = document.getElementById("fw-update-file").files[0].name;
var nextSibling = e.target.nextElementSibling;
nextSibling.innerText = fileName;
});
$("table").on("click", "tr[data-dtc]", function () {
var dtc = $(this).data("dtc");
var debugval = $(this).data("debugval");
var modal = $("#dtcModal");
getDescriptionForDTCNumber(dtc, function (error, title, description) {
if (error) {
console.error("Fehler beim Abrufen der Beschreibung:", error);
modal.find(".modal-title").text("Fehler");
modal
.find(".dtc-desc")
.text("DTC-Beschreibung konnte nicht geladen werden");
} else {
modal.find(".modal-title").text(title);
modal.find(".dtc-desc").text(description);
if (debugval > 0) {
modal.find(".dtc-debugval").text("Debugvalue: " + debugval);
} else {
modal.find(".dtc-debugval").remove();
}
}
});
// Modal anzeigen
modal.modal("show");
});

View File

@@ -0,0 +1,190 @@
var gateway = `ws://${window.location.hostname}/ws`;
var websocket;
var statusMapping;
var staticMapping;
window.addEventListener("load", onLoad);
function initWebSocket() {
console.log("Trying to open a WebSocket connection...");
websocket = new WebSocket(gateway);
websocket.onopen = onOpen;
websocket.onclose = onClose;
websocket.onmessage = onMessage; // <-- add this line
}
function initButtons() {
document
.getElementById("btn-ws-stop")
.addEventListener("click", livedebug_stop);
document
.getElementById("btn-ws-start")
.addEventListener("click", livedebug_start);
}
function onOpen(event) {
console.log("Connection opened");
}
function onClose(event) {
console.log("Connection closed");
setTimeout(initWebSocket, 2000);
}
function onMessage(event) {
var data = event.data;
console.log("ws_msg:" + event.data + "\n");
if (data.startsWith("DEBUG:")) {
var addtext = data.slice(6);
var livedebug_out = document.getElementById("livedebug-out");
livedebug_out.value += addtext;
livedebug_out.scrollTop = livedebug_out.scrollHeight;
do_resize(livedebug_out);
return;
}
if (data.startsWith("DTC:")) {
const dtcs = data.slice(4);
const dtcArray = dtcs.trim() !== "" ? dtcs.split(";").filter(Boolean) : [];
if (dtcArray[0] != "0") {
processDTCNotifications(dtcArray);
fillDTCTable(dtcArray);
}
return;
}
if (data.startsWith("MAPPING_STATUS:")) {
const data_sliced = data.slice(15);
statusMapping = createMapping(data_sliced);
}
if (data.startsWith("MAPPING_STATIC:")) {
const data_sliced = data.slice(15);
staticMapping = createMapping(data_sliced);
}
if (data.startsWith("STATUS:")) {
const data_sliced = data.slice(7);
const result = processDataString(data_sliced, statusMapping);
console.log("STATUS:");
console.log(JSON.stringify(result, null, 2));
fillValuesToHTML(result);
return;
}
if (data.startsWith("STATIC:")) {
const data_sliced = data.slice(7);
const result = processDataString(data_sliced, staticMapping);
console.log("STATIC:");
console.log(JSON.stringify(result, null, 2));
fillValuesToHTML(result);
return;
}
}
function createMapping(mappingString) {
const mappingArray = mappingString.split(";");
const mapping = [];
mappingArray.forEach((variable) => {
if (variable !== null) mapping.push(variable.trim());
});
return mapping;
}
function processDataString(dataString, mapping) {
const valuesArray = dataString.split(";");
const dataObject = {};
valuesArray.forEach((value, index) => {
const variable = mapping[index];
if (variable) {
dataObject[variable] = value.trim();
}
});
return dataObject;
}
function onLoad(event) {
initWebSocket();
initButtons();
}
function livedebug_start() {
websocket.send("start");
}
function livedebug_stop() {
websocket.send("stop");
}
function do_resize(textbox) {
var maxrows = 15;
var minrows = 3;
var txt = textbox.value;
var cols = textbox.cols;
var arraytxt = txt.split("\n");
var rows = arraytxt.length;
for (i = 0; i < arraytxt.length; i++)
rows += parseInt(arraytxt[i].length / cols);
if (rows > maxrows) textbox.rows = maxrows;
else if (rows < minrows) textbox.rows = minrows;
else textbox.rows = rows;
}
function fillValuesToHTML(dataset) {
for (var key in dataset) {
var key_prefixed = "data-" + key;
var elements = document.getElementsByClassName(key_prefixed);
if (elements.length > 0) {
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.type === "checkbox") {
// Wenn das Element ein Kontrollkästchen ist
element.checked = dataset[key] == 1 ? true : false;
} else if (element.tagName === "SELECT") {
// Wenn das Element ein Dropdown ist
setDropdownValue(element, dataset[key]);
} else if (element.classList.contains("progress-bar")) {
// Wenn das Element eine Fortschrittsleiste ist
updateProgressBar(element, dataset[key]);
} else if (element.classList.contains("removeable")) {
// Wenn das Element ein Settingsabschnitt-div ist
if (dataset[key] == 0) element.remove();
} else {
// Standardmäßig für Textfelder und andere Elemente
element.value = dataset[key];
}
}
}
}
}
// Funktion zum Setzen des ausgewählten Werts für Dropdowns
function setDropdownValue(selectElement, value) {
for (var i = 0; i < selectElement.options.length; i++) {
if (selectElement.options[i].value === value) {
selectElement.selectedIndex = i;
break;
}
}
}
// Funktion zum Aktualisieren der Fortschrittsleiste
function updateProgressBar(progressBar, value) {
// Wert in das aria-valuenow-Attribut einfügen
progressBar.setAttribute("aria-valuenow", value);
// Breite des Fortschrittsbalkens und inneren Text aktualisieren
progressBar.style.width = value + "%";
progressBar.textContent = value + "%";
}

View File

@@ -0,0 +1 @@
1.04

39
Software/include/README Normal file
View File

@@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

38
Software/include/can.h Normal file
View File

@@ -0,0 +1,38 @@
/**
* @file can.h
*
* @brief Header file for Controller Area Network (CAN) functionality in the ChainLube application.
*
* This file provides functions and structures related to Controller Area Network (CAN)
* communication for the ChainLube project. It includes functions for initializing CAN,
* processing CAN messages, and retrieving wheel speed from CAN data.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _CAN_H_
#define _CAN_H_
#include <Arduino.h>
#include <mcp_can.h>
#include <SPI.h>
#include "common.h"
#include "globals.h"
#include "dtc.h"
#include "debugger.h"
// CAN frame structure definition
struct can_frame
{
unsigned long can_id;
uint8_t can_dlc;
uint8_t data[8] __attribute__((aligned(8)));
};
// Function prototypes
void Init_CAN();
void CAN_Process();
uint32_t Process_CAN_WheelSpeed();
#endif

70
Software/include/common.h Normal file
View File

@@ -0,0 +1,70 @@
/**
* @file common.h
*
* @brief Header file for common definitions and macros in the ChainLube application.
*
* This file defines common macros, GPIO configurations, and other shared constants
* for the ChainLube project. It includes definitions for GPIO pins, OTA delays, pulse lengths,
* and other common settings used across the project.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#define Q(x) #x
#define QUOTE(x) Q(x)
#define SET_BIT(value, bitPosition) ((value) |= (1U << (bitPosition)))
// Conditional compilation based on PCB revision
#if PCB_REV == 1
#define GPIO_BUTTON D7
#define GPIO_LED D8
#define GPIO_TRIGGER D6
#define GPIO_PUMP D5
#elif PCB_REV == 2
#define GPIO_BUTTON D7
#define GPIO_LED D8
#define GPIO_TRIGGER D6
#define GPIO_PUMP D5
#elif PCB_REV == 3
#define GPIO_BUTTON D4
#define GPIO_LED D3
#define GPIO_TRIGGER D6
#define GPIO_PUMP D0
#define GPIO_CS_CAN D8
#elif PCB_REV == 4
#define GPIO_BUTTON D4
#define GPIO_LED D3
#define GPIO_TRIGGER D6
#define GPIO_PUMP D0
#define GPIO_CS_CAN D8
#endif
#ifndef HOST_NAME
#define HOST_NAME "ChainLube_%06X" // Use printf-Formatting - Chip-ID (uin32_t) will be added
#endif
#ifndef OTA_DELAY
#define OTA_DELAY 50 // ticks -> 10ms / tick
#endif
#define LUBE_PULSE_LENGHT_MS 160
#define LUBE_PULSE_PAUSE_MS 340
// Pump pulse parameters
// -> 2Hz PumpPulse
// -> 49.7cc / h @ 2Hz
// -> 49.7 ml / h @ 2Hz
// -> 828.4µl / min @ 2Hz
// -> 828.3µl / 60s
// -> 13.81µl / 1s
// -> 6.90µl / Pulse
#define DEFAULT_PUMP_DOSE 7
#define STARTUP_DELAY 5000
#define SHUTDOWN_DELAY_MS 5000
#endif

143
Software/include/config.h Normal file
View File

@@ -0,0 +1,143 @@
/**
* @file config.h
*
* @brief Header file for configuration settings and EEPROM operations in the ChainLube application.
*
* This file defines configuration settings for the ChainLube project, including default values,
* EEPROM structures, and functions for EEPROM operations. It also defines enums for different sources
* of speed input, GPS baud rates, and CAN bus sources. Additionally, it includes functions for EEPROM handling
* such as storing, retrieving, and formatting configuration data.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _CONFIG_H_
#define _CONFIG_H_
#include <Arduino.h>
#include <Wire.h>
#include <I2C_eeprom.h>
#include "globals.h"
#include "dtc.h"
#include "common.h"
#if PCB_REV == 1 || PCB_REV == 2 || PCB_REV == 3
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC64
#elif PCB_REV == 4
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC256
#endif
// Enum for different sources of speed input
typedef enum SpeedSource_e
{
#ifdef FEATURE_ENABLE_TIMER
SOURCE_TIME,
#endif
SOURCE_IMPULSE,
SOURCE_GPS,
SOURCE_CAN
} SpeedSource_t;
// String representation of SpeedSource enum
const char SpeedSourceString[][8] = {
#ifdef FEATURE_ENABLE_TIMER
"Timer",
#endif
"Impuls",
"GPS",
"CAN-Bus"
};
const size_t SpeedSourceString_Elements = sizeof(SpeedSourceString) / sizeof(SpeedSourceString[0]);
// Enum for GPS baud rates
typedef enum GPSBaudRate_e
{
BAUD_9600,
BAUD_115200
} GPSBaudRate_t;
// String representation of GPSBaudRate enum
const char GPSBaudRateString[][7] = {
"9600",
"115200"};
const size_t GPSBaudRateString_Elements = sizeof(GPSBaudRateString) / sizeof(GPSBaudRateString[0]);
// Enum for CAN bus sources
typedef enum CANSource_e
{
KTM_890_ADV_R_2021,
KTM_1290_SD_R_2023
} CANSource_t;
// String representation of CANSource enum
const char CANSourceString[][30] = {
"KTM 890 Adventure R (2021)",
"KTM 1290 Superduke R (2023)"};
const size_t CANSourceString_Elements = sizeof(CANSourceString) / sizeof(CANSourceString[0]);
// Structure for persistence data stored in EEPROM
typedef struct
{
uint16_t writeCycleCounter;
uint32_t tankRemain_microL;
uint32_t TravelDistance_highRes_mm;
uint32_t odometer_mm;
uint32_t odometer;
uint32_t checksum;
} persistenceData_t;
// Structure for configuration settings stored in EEPROM
typedef struct
{
uint8_t EEPROM_Version;
uint32_t DistancePerLube_Default;
uint32_t DistancePerLube_Rain;
uint32_t tankCapacity_ml;
uint32_t amountPerDose_microL;
uint8_t TankRemindAtPercentage;
uint8_t PulsePerRevolution;
uint32_t TireWidth_mm;
uint32_t TireWidthHeight_Ratio;
uint32_t RimDiameter_Inch;
uint32_t DistancePerRevolution_mm;
uint16_t BleedingPulses;
SpeedSource_t SpeedSource;
GPSBaudRate_t GPSBaudRate;
CANSource_t CANSource;
bool LED_Mode_Flash;
uint8_t LED_Max_Brightness;
uint8_t LED_Min_Brightness;
uint32_t checksum;
} LubeConfig_t;
// Default configuration settings
const LubeConfig_t LubeConfig_defaults = {
0, 8000, 4000, 320, DEFAULT_PUMP_DOSE, 30, 1, 150, 70, 18, 2000, 25, SOURCE_IMPULSE,
BAUD_115200,
KTM_890_ADV_R_2021,
false,
255,
5,
0};
void InitEEPROM();
void EEPROM_Process();
void StoreConfig_EEPROM();
void GetConfig_EEPROM();
void StorePersistence_EEPROM();
void GetPersistence_EEPROM();
void FormatConfig_EEPROM();
void FormatPersistence_EEPROM();
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len);
void dumpEEPROM(uint16_t memoryAddress, uint16_t length);
void MovePersistencePage_EEPROM(boolean reset);
uint32_t ConfigSanityCheck(bool autocorrect = false);
extern LubeConfig_t LubeConfig;
extern persistenceData_t PersistenceData;
extern uint16_t eePersistenceMarker;
#endif // _CONFIG_H_

View File

@@ -0,0 +1,58 @@
/**
* @file debugger.h
*
* @brief Header file for debugging functions and status in the ChainLube application.
*
* This file declares functions and status definitions for debugging purposes in the ChainLube project.
* It includes functions to print system information, WiFi information, format EEPROM data,
* handle debug messages, and manage the status of different debug ports.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _DEBUGGER_H_
#define _DEBUGGER_H_
#include <Arduino.h>
#include "webui.h"
const char PROGMEM helpCmd[] = "sysinfo - System Info\n"
"netinfo - WiFi Info\n"
"formatPDS - Format Persistence EEPROM Data\n"
"formatCFG - Format Configuration EEPROM Data\n"
"checkEE - Check EEPROM with checksum\n"
"dumpEE1k - dump the first 1kb of EEPROM to Serial\n"
"dumpEE - dump the whole EPPROM to Serial\n"
"resetPageEE - Reset the PersistenceData Page\n"
"dumpCFG - print Config struct\n"
"dumpPDS - print PersistanceStruct\n"
"saveEE - save EE-Data\n"
"showdtc - Show all DTCs\n"
"dumpGlobals - print globals\n";
typedef enum DebugStatus_e
{
disabled,
enabled
} DebugStatus_t;
typedef enum DebugPorts_e
{
dbg_Serial,
dbg_Webui,
dbg_cntElements
} DebugPorts_t;
const char sDebugPorts[dbg_cntElements][7] = {
"Serial",
"WebUI"};
extern DebugStatus_t DebuggerStatus[dbg_cntElements];
void initDebugger();
void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data);
void Debug_pushMessage(const char *format, ...);
void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status);
void Debug_Process();
#endif

39
Software/include/dtc.h Normal file
View File

@@ -0,0 +1,39 @@
/**
* @file dtc.h
*
* @brief Header file for handling Diagnostic Trouble Codes (DTC) in the ChainLube application.
*
* This file provides definitions and functions for handling Diagnostic Trouble Codes (DTC)
* in the ChainLube project. It includes structures for DTC entries, severity levels,
* and functions for DTC maintenance and processing. DTCs are used to track system errors and issues.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _DTC_H_
#define _DTC_H_
#include <Arduino.h>
#include "dtc_defs.h"
#define MAX_DTC_STORAGE 6
typedef struct
{
DTCNum_t Number;
uint32_t timestamp;
DTCActive_t active;
uint32_t debugVal;
} DTCEntry_t;
void MaintainDTC(DTCNum_t DTC_no, boolean active, uint32_t DebugValue = 0);
void ClearDTC(DTCNum_t DTC_no);
void ClearAllDTC();
DTCNum_t getlastDTC(boolean only_active);
DTCNum_t ActiveDTCseverity(DTCSeverity_t severity);
DTCSeverity_t getSeverityForDTC(DTCNum_t targetCode);
void DTC_Process();
extern DTCEntry_t DTCStorage[MAX_DTC_STORAGE];
#endif

View File

@@ -0,0 +1,85 @@
/**
* @file dtc_defs.h
*
* @brief Header file for Diagnostic Trouble Code (DTC) definitions in the ChainLube application.
*
* This file contains definitions for Diagnostic Trouble Codes (DTC) in the ChainLube project.
* It includes enums for DTC active status, severity levels, and specific DTC codes.
* The file also defines an array of DTC definitions and a timestamp indicating the generation time.
*
* @note This file is auto-generated by a script on 2024-01-10 18:37:05.
*
* @author Marcel Peterkau
* @date 10.01.2024
*/
#ifndef DTC_DEFS_H
#define DTC_DEFS_H
#include <stdint.h>
typedef uint32_t DTCNum_t;
typedef enum
{
DTC_INACTIVE,
DTC_ACTIVE,
DTC_PREVIOUS
} DTCActive_t;
typedef enum
{
DTC_NONE,
DTC_INFO,
DTC_WARN,
DTC_CRITICAL
} DTCSeverity_t;
typedef struct {
DTCNum_t code;
DTCSeverity_t severity;
} DTC_t;
#define DTC_NO_DTC 0
#define DTC_TANK_EMPTY 1
#define DTC_TANK_LOW 2
#define DTC_NO_EEPROM_FOUND 3
#define DTC_EEPROM_CFG_BAD 4
#define DTC_EEPROM_PDS_BAD 5
#define DTC_EEPROM_PDSADRESS_BAD 6
#define DTC_EEPROM_VERSION_BAD 7
#define DTC_FLASHFS_ERROR 8
#define DTC_FLASHFS_VERSION_ERROR 9
#define DTC_NO_GPS_SERIAL 10
#define DTC_CAN_TRANSCEIVER_FAILED 11
#define DTC_NO_CAN_SIGNAL 12
#define DTC_EEPROM_CFG_SANITY 13
#define DTC_FAKE_DTC_INFO 14
#define DTC_FAKE_DTC_WARN 15
#define DTC_FAKE_DTC_CRIT 16
#define DTC_LAST_DTC 17
const DTC_t dtc_definitions[] = {
{ DTC_NO_DTC , DTC_NONE }, // No Error
{ DTC_TANK_EMPTY , DTC_CRITICAL }, // Ölvorrat ist komplett leer. Den Ölvorrat auffüllen und im Menu 'Wartung' zurück setzen
{ DTC_TANK_LOW , DTC_WARN }, // Ölvorrat ist unter der Warnschwelle. Den Ölvorrat demnächst auffüllen und im Menu 'Wartung' zurück setzen
{ DTC_NO_EEPROM_FOUND , DTC_CRITICAL }, // Es wurde kein EEPROM gefunden. Dies lässt einen Hardware-Defekt vermuten.
{ DTC_EEPROM_CFG_BAD , DTC_CRITICAL }, // Die Checksumme der Config-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück
{ DTC_EEPROM_PDS_BAD , DTC_CRITICAL }, // Die Checksumme der Betriebsdaten-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück
{ DTC_EEPROM_PDSADRESS_BAD , DTC_CRITICAL }, // Die Adresse der Betriebsdaten-Partition im EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück
{ DTC_EEPROM_VERSION_BAD , DTC_CRITICAL }, // Die Layout-Version des EEPROM stimmt nicht mit der Firmware-Version überein. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück
{ DTC_FLASHFS_ERROR , DTC_CRITICAL }, // Der Flashspeicher konnte nicht initialisiert werden. Aktualisieren sie Flash & Firmware
{ DTC_FLASHFS_VERSION_ERROR , DTC_CRITICAL }, // Die Version des Flashspeicher stimmt nicht mit der Firmware-Version überein. Aktualisieren sie den Flash mit der passenden Update-Datei
{ DTC_NO_GPS_SERIAL , DTC_CRITICAL }, // Es wurde kein GPS-Signal über die serielle Schnittstelle empfangen, Prüfen sie die Verbindung und das GPS-Modul
{ DTC_CAN_TRANSCEIVER_FAILED , DTC_CRITICAL }, // Es konnte keine Verbindung zum CAN-Transceiver hergestellt werden. Prüfen Sie die Hardware auf Defekte
{ DTC_NO_CAN_SIGNAL , DTC_WARN }, // Es konnte kein CAN-Signal empfangen werden. Prüfen sie die Verbindung und die Einstellungen
{ DTC_EEPROM_CFG_SANITY , DTC_WARN }, // Ein oder mehrer Einstellungswerte sind ausserhalb plausibler Werte. Prüfen Sie Ihre Einstellungen
{ DTC_FAKE_DTC_INFO , DTC_INFO }, // Ein Dummy-DTC der Schwere "Info" für Debugging-Zwecke
{ DTC_FAKE_DTC_WARN , DTC_WARN }, // Ein Dummy-DTC der Schwere "Warnung" für Debugging-Zwecke
{ DTC_FAKE_DTC_CRIT , DTC_CRITICAL }, // Ein Dummy-DTC der Schwere "Kritisch" für Debugging-Zwecke
{ DTC_LAST_DTC , DTC_NONE } // Last Error
};
#endif // DTC_DEFS_H
// CODEGENERATOR_CHECKSUM: 23dff82a4745f67041012080b05ec367c2dd44c6bb02974143b227ba49682b6f

View File

@@ -0,0 +1,81 @@
/**
* @file globals.h
*
* @brief Header file for global variables and enums in the ChainLube application.
*
* This file contains declarations for global variables and enums used in the ChainLube application.
* It includes enums for system status and EEPROM-related requests, as well as a struct for global variables.
* The file also defines a struct for constants and initializes it with firmware and required flash version information.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _GLOBALS_H_
#define _GLOBALS_H_
#include <Arduino.h>
typedef enum eSystem_Status
{
sysStat_Startup,
sysStat_Normal,
sysStat_Rain,
sysStat_Purge,
sysStat_Error,
sysStat_Shutdown
} tSystem_Status;
typedef enum eEERequest
{
EE_IDLE,
EE_CFG_SAVE,
EE_CFG_LOAD,
EE_CFG_FORMAT,
EE_PDS_SAVE,
EE_PDS_LOAD,
EE_PDS_FORMAT,
EE_FORMAT_ALL,
EE_ALL_SAVE
} tEERequest;
typedef struct Globals_s
{
tSystem_Status systemStatus = sysStat_Startup; /**< Current system status */
tSystem_Status resumeStatus = sysStat_Startup; /**< Status to resume after rain mode */
char systemStatustxt[16] = ""; /**< Text representation of system status */
uint16_t purgePulses = 0; /**< Number of purge pulses */
eEERequest requestEEAction = EE_IDLE;; /**< EEPROM-related request */
char DeviceName[33]; /**< Device name */
char FlashVersion[10]; /**< Flash version */
uint16_t eePersistanceAdress; /**< EEPROM persistence address */
uint8_t TankPercentage; /**< Tank percentage */
bool hasDTC; /**< Flag indicating the presence of Diagnostic Trouble Codes (DTC) */
bool measurementActive; /**< Flag indicating active measurement */
uint32_t measuredPulses; /**< Number of measured pulses */
} Globals_t;
extern Globals_t globals; /**< Global variable struct */
typedef struct Constants_s
{
uint8_t FW_Version_major; /**< Firmware version major number */
uint8_t FW_Version_minor; /**< Firmware version minor number */
uint8_t Required_Flash_Version_major; /**< Required flash version major number */
uint8_t Required_Flash_Version_minor; /**< Required flash version minor number */
char GitHash[11]; /**< Git hash string */
} Constants_t;
const Constants_t constants PROGMEM = {
1,4, // Firmware_Version
1,4, // Required Flash Version
GIT_REV // Git-Hash-String
};
/**
* @brief Initializes global variables.
*/
void initGlobals();
#endif // _GLOBALS_H_

36
Software/include/gps.h Normal file
View File

@@ -0,0 +1,36 @@
/**
* @file gps.h
*
* @brief Header file for GPS-related functions in the ChainLube application.
*
* This file contains declarations for functions related to GPS (Global Positioning System) functionality
* within the ChainLube application. It includes the initialization of the GPS module and processing of GPS
* data to calculate wheel speed. Additionally, it references other necessary header files for configuration,
* common definitions, diagnostics, and debugging.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _GPS_H_
#define _GPS_H_
#include <TinyGPSPlus.h>
#include "config.h"
#include "common.h"
#include "dtc.h"
#include "debugger.h"
/**
* @brief Initializes the GPS module.
*/
void Init_GPS();
/**
* @brief Processes GPS data to calculate wheel speed.
*
* @return Calculated wheel speed in millimeters per second.
*/
uint32_t Process_GPS_WheelSpeed();
#endif // _GPS_H_

View File

@@ -0,0 +1,45 @@
/**
* @file led_colors.h
*
* @brief Header file defining color values for LEDs in the ChainLube application.
*
* This file contains color definitions in hexadecimal format for various states and events of LEDs
* used in the ChainLube application. It provides a convenient way to reference specific colors for
* different visual indications in the system.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _LED_COLORS_H_
#define _LED_COLORS_H_
#define COLOR_RED 0xFF0000
#define COLOR_GREEN 0x00FF00
#define COLOR_BLUE 0x0000FF
#define COLOR_YELLOW 0xFF9600
#define COLOR_ORANGE 0xFF2800
#define COLOR_TEAL 0x00FF78
#define COLOR_CYAN 0x00FFFF
#define COLOR_PURPLE 0xB400FF
#define COLOR_MAGENTA 0xFF0014
#define COLOR_WHITE 0xFFFFFF
#define COLOR_BLACK 0x000000
#define COLOR_GOLD 0xFFDE1E
#define COLOR_PINK 0xF25AFF
#define COLOR_AQUA 0x32FFFF
#define COLOR_JADE 0x00FF28
#define COLOR_AMBER 0xFF6400
#define COLOR_WARM_WHITE 0xFDF5E6
#define LED_DEFAULT_COLOR COLOR_WARM_WHITE
#define LED_STARTUP_NORMAL COLOR_WARM_WHITE
#define LED_STARTUP_TANKWARN COLOR_AMBER
#define LED_NORMAL_COLOR COLOR_GREEN
#define LED_RAIN_COLOR COLOR_BLUE
#define LED_WIFI_BLINK COLOR_YELLOW
#define LED_PURGE_COLOR COLOR_MAGENTA
#define LED_ERROR_BLINK COLOR_RED
#define LED_SHUTDOWN_BLINK COLOR_CYAN
#endif /* _LED_COLORS_H_ */

View File

@@ -0,0 +1,27 @@
/**
* @file lubeapp.h
*
* @brief Header file for the ChainLube application functions.
*
* This file contains function declarations related to the main functionality of the ChainLube
* application. It includes functions for running the application and generating lubrication pulses.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _LUBEAPP_H_
#define _LUBEAPP_H_
#include <Arduino.h>
#include <stdlib.h>
#include "config.h"
#include "common.h"
#include "globals.h"
#include "dtc.h"
#include "debugger.h"
void RunLubeApp(uint32_t add_milimeters);
void LubePulse();
#endif /* _LUBEAPP_H_ */

View File

@@ -0,0 +1,49 @@
/**
* @file sanitycheck.h
*
* @brief Header file for sanity checks and configuration validation in the ChainLube application.
*
* This file contains checks and validations to ensure that the configuration and features of the
* ChainLube application are compatible with the selected PCB revision and defined parameters.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _SANITYCHECK_H_
#define _SANITYCHECK_H_
#ifndef PCB_REV
#error "You must define PCB_REV"
#else
#if PCB_REV < 1 || PCB_REV > 4
#error "Unsupported PCB-Revision"
#endif
#if PCB_REV < 3 && defined(FEATURE_ENABLE_CAN)
#error "CAN-Feature unsupported with this PCB-Rev"
#endif
#if PCB_REV < 4 && defined(DFEATURE_ENABLE_GPS)
#error "GPS-Feature unsupported with this PCB-Rev"
#endif
#endif
#ifndef ADMIN_PASSWORD
#error "You need to define ADMIN_PASSWORD for OTA-Update"
#endif
#ifdef FEATURE_ENABLE_WIFI_CLIENT
#ifndef WIFI_PASSWORD_CLIENT
#error "You must define an WIFI_PASSWORD for Client-Mode"
#endif
#ifndef WIFI_SSID_CLIENT
#error "You must define an WIFI_SSID for Client-Mode"
#endif
#endif
#ifndef WIFI_AP_PASSWORD
#error "You must define an WIFI_AP_PASSWORD for Standalone AP-Mode"
#endif
#endif // _SANITYCHECK_H_

View File

@@ -0,0 +1,26 @@
/**
* @file struct2json.h
*
* @brief Header file for converting structs to JSON objects.
*
* @note This file is auto-generated by a script on 2024-01-10 18:01:52.
*
* @author Marcel Peterkau
* @date 10.01.2024
*/
#ifndef _STRUCT2JSON_H_
#define _STRUCT2JSON_H_
#include <Arduino.h>
#include <ArduinoJson.h>
#include "config.h"
void generateJsonObject_LubeConfig(JsonObject& data);
void generateJsonObject_PersistenceData(JsonObject& data);
#endif /* _STRUCT2JSON_H_ */
// CODEGENERATOR_CHECKSUM: 9e8dd21170fd6ef8fbf8c4b156d9af751836a76081f811bf0e3ab2b1eb8ee48c

39
Software/include/webui.h Normal file
View File

@@ -0,0 +1,39 @@
/**
* @file webui.h
*
* @brief Header file for the web-based user interface (WebUI) in the ChainLube application.
*
* This file contains declarations for functions related to the initialization and processing of the
* web-based user interface (WebUI). It includes the necessary libraries and dependencies for handling
* web server functionality, asynchronous JSON operations, and live debugging through WebSockets.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _WEBUI_H_
#define _WEBUI_H_
#include <Arduino.h>
#include <FS.h>
#include <LittleFS.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <Updater.h>
#include <ESP8266mDNS.h>
#include <AsyncJson.h>
#include <ArduinoJson.h>
#include "config.h"
#include "globals.h"
#include "dtc.h"
#include "common.h"
#include "debugger.h"
#include "struct2json.h"
void initWebUI();
void Webserver_Process();
void Websocket_PushLiveDebug(String Message);
#endif // _WEBUI_H_

46
Software/lib/README Normal file
View File

@@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

88
Software/platformio.ini Normal file
View File

@@ -0,0 +1,88 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
extra_configs =
wifi_credentials.ini
default_envs = pcb_rev_1-3, pcb_rev_1-2
[env]
platform = espressif8266
board = d1_mini
framework = arduino
upload_speed = 921600
upload_protocol = espota
upload_port = 10.0.1.14
upload_flags =
--port=8266
--auth=${wifi_cred.admin_password}
build_flags =
!python codegen/git_rev_macro.py
-DWIFI_SSID_CLIENT=${wifi_cred.wifi_ssid_client}
-DWIFI_PASSWORD_CLIENT=${wifi_cred.wifi_password_client}
-DADMIN_PASSWORD=${wifi_cred.admin_password}
-DWIFI_AP_PASSWORD=${wifi_cred.wifi_ap_password}
-DWIFI_AP_IP_GW=10,0,0,1
-DATOMIC_FS_UPDATE
board_build.filesystem = littlefs
extra_scripts =
post:codegen/prepare_littlefs.py
pre:codegen/run_pre.py
monitor_filters = esp8266_exception_decoder
monitor_speed = 115200
lib_ldf_mode = deep
lib_deps =
olikraus/U8g2 @ ^2.35.9
adafruit/Adafruit NeoPixel @ ^1.12.0
sstaub/Ticker @ ^4.4.0
robtillaart/I2C_EEPROM @ ^1.8.2
esphome/ESPAsyncWebServer-esphome @ 3.1.0
bblanchon/ArduinoJson @ ^7.0.1
[env:pcb_rev_1-3]
;build_type = debug
custom_pcb_revision = 3
build_flags =
${env.build_flags}
;-DFEATURE_ENABLE_WIFI_CLIENT
;-DFEATURE_ENABLE_TIMER
-DFEATURE_ENABLE_OLED
-DCAN_DEBUG_MESSAGE
-DPCB_REV=${this.custom_pcb_revision}
board_build.ldscript = eagle.flash.4m1m.ld
lib_deps =
${env.lib_deps}
coryjfowler/mcp_can @ ^1.5.0
mikalhart/TinyGPSPlus @ ^1.0.3
[env:pcb_rev_1-2]
;build_type = debug
custom_pcb_revision = 2
build_flags =
${env.build_flags}
;-DFEATURE_ENABLE_WIFI_CLIENT
;-DFEATURE_ENABLE_TIMER
-DFEATURE_ENABLE_OLED
-DFEATURE_ENABLE_WEBSOCKETS
-DPCB_REV=${this.custom_pcb_revision}
board_build.ldscript = eagle.flash.4m1m.ld
lib_deps =
${env.lib_deps}

189
Software/src/can.cpp Normal file
View File

@@ -0,0 +1,189 @@
/**
* @file can.cpp
*
* @brief Implementation file for CAN-related functions in the ChainLube application.
*
* This file contains the implementation of functions related to CAN (Controller Area Network)
* communication within the ChainLube application. It includes the initialization of the CAN module,
* setup of masks and filters, and processing of CAN messages. Additionally, a debug message function
* is included if CAN debugging is enabled.
*
* @author Your Name
* @date Date
*/
#include "can.h"
MCP_CAN CAN0(GPIO_CS_CAN);
#ifdef CAN_DEBUG_MESSAGE
#define MAX_DEBUG_RETRIES 100
void sendCANDebugMessage();
#endif
/**
* @brief Initializes the CAN module, sets masks, and filters based on the configured CAN source.
*
* This function initializes the CAN module, sets masks and filters based on the configured CAN source
* in the application settings, and sets the CAN module in normal mode for communication.
*/
void Init_CAN()
{
if (CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) != CAN_OK)
MaintainDTC(DTC_CAN_TRANSCEIVER_FAILED, true);
CAN0.init_Mask(0, 0, 0x07FF0000); // Init first mask...
CAN0.init_Mask(1, 0, 0x07FF0000); // Init second mask...
switch (LubeConfig.CANSource)
{
case KTM_890_ADV_R_2021:
CAN0.init_Filt(0, 0, 0x012D0000); // Init first filter...
break;
case KTM_1290_SD_R_2023:
CAN0.init_Filt(0, 0, 0x012D0000); // Init first filter...
break;
default:
break;
}
CAN0.setMode(MCP_NORMAL);
}
/**
* @brief Processes CAN messages and sends a CAN debug message periodically.
*
* This function processes CAN messages and sends a CAN debug message periodically based on a time interval.
*/
void CAN_Process()
{
static uint32_t previousMillis = 0;
if (millis() - previousMillis >= 100)
{
sendCANDebugMessage();
previousMillis = millis();
}
}
/**
* @brief Processes CAN messages to determine the wheel speed based on the configured CAN source.
*
* This function reads incoming CAN messages and extracts the rear wheel speed information.
* The wheel speed is then converted to millimeters per second based on the configured CAN source.
* The function also monitors the CAN signal for potential issues and triggers diagnostic trouble codes (DTCs).
*
* @return The calculated distance traveled in millimeters since the last call.
*/
uint32_t Process_CAN_WheelSpeed()
{
#define FACTOR_RWP_KMH_890ADV 18 // Divider to convert Raw Data to km/h
#define FACTOR_RWP_KMH_1290SD 18 // Divider to convert Raw Data to km/h
can_frame canMsg;
static uint32_t lastRecTimestamp = 0;
uint16_t RearWheelSpeed_raw;
uint32_t milimeters_to_add = 0;
uint32_t RWP_millimeter_per_second = 0;
if (CAN0.readMsgBuf(&canMsg.can_id, &canMsg.can_dlc, canMsg.data) == CAN_OK)
{
switch (LubeConfig.CANSource)
{
case KTM_890_ADV_R_2021:
// raw / FACTOR_RWP_KMH_890ADV -> km/h * 100000 -> cm/h / 3600 -> cm/s
// raw * 500 -> cm/s
RearWheelSpeed_raw = (uint16_t)canMsg.data[5] << 8 | canMsg.data[6];
RWP_millimeter_per_second = (((uint32_t)RearWheelSpeed_raw * 1000000) / FACTOR_RWP_KMH_890ADV) / 3600;
break;
case KTM_1290_SD_R_2023:
// raw / FACTOR_RWP_KMH_1290SD -> km/h * 100000 -> cm/h / 3600 -> cm/s
// raw * 500 -> cm/s
RearWheelSpeed_raw = (uint16_t)canMsg.data[5] << 8 | canMsg.data[6];
RWP_millimeter_per_second = (((uint32_t)RearWheelSpeed_raw * 1000000) / FACTOR_RWP_KMH_1290SD) / 3600;
break;
default:
break;
}
uint32_t timesincelast = millis() - lastRecTimestamp;
lastRecTimestamp = millis();
milimeters_to_add = (RWP_millimeter_per_second * timesincelast) / 1000;
}
if (lastRecTimestamp > 1000)
{
MaintainDTC(DTC_NO_CAN_SIGNAL, (millis() > lastRecTimestamp + 10000 ? true : false));
}
return milimeters_to_add;
}
#ifdef CAN_DEBUG_MESSAGE
/**
* @brief Sends periodic CAN debug messages for monitoring and diagnostics.
*
* This function sends periodic CAN debug messages containing various system information for monitoring and diagnostics.
* The information includes system status, timestamps, tank percentage, DTC flags, and other relevant data.
* The debug messages are sent with a configurable multiplexer to broadcast different types of information in each cycle.
*/
void sendCANDebugMessage()
{
#define MAX_DEBUG_MULTIPLEXER 6
static uint16_t DebugSendFailTimeout = 0;
static uint8_t debugMultiplexer = 0;
byte data[8] = {debugMultiplexer, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint32_t millisValue = millis();
switch (debugMultiplexer)
{
case 0:
memcpy(&data[1], &millisValue, sizeof(millisValue));
memcpy(&data[5], &globals.purgePulses, sizeof(globals.purgePulses));
break;
case 1:
data[1] = (uint8_t)globals.systemStatus;
data[2] = (uint8_t)globals.resumeStatus;
data[3] = (uint8_t)globals.requestEEAction;
data[4] = globals.TankPercentage;
data[5] = (0x01 & globals.hasDTC) | ((0x01 & globals.measurementActive) << 1);
break;
case 2:
memcpy(&data[1], &globals.eePersistanceAdress, sizeof(globals.eePersistanceAdress));
memcpy(&data[3], &PersistenceData.tankRemain_microL, sizeof(PersistenceData.tankRemain_microL));
break;
case 3:
memcpy(&data[1], &PersistenceData.writeCycleCounter, sizeof(PersistenceData.writeCycleCounter));
memcpy(&data[3], &PersistenceData.TravelDistance_highRes_mm, sizeof(PersistenceData.TravelDistance_highRes_mm));
break;
case 4:
memcpy(&data[1], &PersistenceData.odometer_mm, sizeof(PersistenceData.odometer_mm));
break;
case 5:
memcpy(&data[1], &PersistenceData.odometer, sizeof(PersistenceData.odometer));
break;
case 6:
memcpy(&data[1], &PersistenceData.checksum, sizeof(PersistenceData.checksum));
break;
default:
break;
}
debugMultiplexer++;
debugMultiplexer = debugMultiplexer > MAX_DEBUG_MULTIPLEXER ? 0 : debugMultiplexer;
if (DebugSendFailTimeout < MAX_DEBUG_RETRIES)
{
byte sndStat = CAN0.sendMsgBuf(0x7FF, 0, 8, data);
if (sndStat != CAN_OK)
{
Debug_pushMessage("failed sending CAN-DbgMsg: %d, %d\n", sndStat, DebugSendFailTimeout);
DebugSendFailTimeout++;
}
}
else if (DebugSendFailTimeout == MAX_DEBUG_RETRIES)
{
Debug_pushMessage("disable CAN-DbgMsg due to timeout");
DebugSendFailTimeout++;
}
}
#endif

496
Software/src/config.cpp Normal file
View File

@@ -0,0 +1,496 @@
/**
* @file config.cpp
* @brief Implementation of EEPROM and configuration-related functions.
*
* This file contains functions for managing EEPROM storage and handling configuration data.
* It includes the definitions of configuration structures, EEPROM access, and utility functions.
*/
#include "config.h"
#include "debugger.h"
// Instance of I2C_eeprom for EEPROM access
I2C_eeprom ee(0x50, EEPROM_SIZE_BYTES);
// Configuration and persistence data structures
LubeConfig_t LubeConfig;
persistenceData_t PersistenceData;
// EEPROM version identifier
const uint16_t eeVersion = 2; // Increment this version when changing EEPROM structures
// Flag indicating whether EEPROM is available
boolean eeAvailable = false;
// Offsets within EEPROM for LubeConfig and PersistenceData
const uint16_t startofLubeConfig = 16;
const uint16_t startofPersistence = 16 + sizeof(LubeConfig) + (sizeof(LubeConfig) % 16);
// Function prototype to check EEPROM availability
boolean checkEEPROMavailable();
/**
* @brief Initializes EEPROM and checks its availability.
*
* This function initializes the EEPROM using the I2C_eeprom instance and checks if it's available.
*/
void InitEEPROM()
{
LubeConfig = LubeConfig_defaults;
PersistenceData = {0};
ee.begin();
checkEEPROMavailable();
}
/**
* @brief Processes EEPROM actions based on the request from the global state.
*
* This function processes EEPROM actions based on the request from the global state.
* It performs actions such as saving, loading, and formatting EEPROM data for both configuration and persistence.
*/
void EEPROM_Process()
{
switch (globals.requestEEAction)
{
case EE_CFG_SAVE:
StoreConfig_EEPROM();
globals.requestEEAction = EE_IDLE;
Debug_pushMessage("Stored EEPROM CFG\n");
break;
case EE_CFG_LOAD:
GetConfig_EEPROM();
globals.requestEEAction = EE_IDLE;
Debug_pushMessage("Loaded EEPROM CFG\n");
break;
case EE_CFG_FORMAT:
FormatConfig_EEPROM();
globals.requestEEAction = EE_IDLE;
GetConfig_EEPROM();
Debug_pushMessage("Formatted EEPROM CFG\n");
break;
case EE_PDS_SAVE:
StorePersistence_EEPROM();
globals.requestEEAction = EE_IDLE;
Debug_pushMessage("Stored EEPROM PDS\n");
break;
case EE_PDS_LOAD:
GetPersistence_EEPROM();
globals.requestEEAction = EE_IDLE;
Debug_pushMessage("Loaded EEPROM PDS\n");
break;
case EE_PDS_FORMAT:
FormatPersistence_EEPROM();
globals.requestEEAction = EE_IDLE;
GetPersistence_EEPROM();
Debug_pushMessage("Formatted EEPROM PDS\n");
break;
case EE_FORMAT_ALL:
FormatConfig_EEPROM();
FormatPersistence_EEPROM();
GetConfig_EEPROM();
GetPersistence_EEPROM();
globals.requestEEAction = EE_IDLE;
Debug_pushMessage("Formatted EEPROM ALL\n");
break;
case EE_ALL_SAVE:
StorePersistence_EEPROM();
StoreConfig_EEPROM();
globals.requestEEAction = EE_IDLE;
Debug_pushMessage("Stored EEPROM ALL\n");
break;
case EE_IDLE:
default:
globals.requestEEAction = EE_IDLE;
}
}
/**
* @brief Stores the configuration data in EEPROM.
*
* This function calculates the checksum for the configuration data, updates it, and stores it in EEPROM.
* It also performs a sanity check on the configuration and raises a diagnostic trouble code (DTC) if needed.
*/
void StoreConfig_EEPROM()
{
LubeConfig.checksum = 0;
LubeConfig.checksum = Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig));
if (!checkEEPROMavailable())
return;
ee.updateBlock(startofLubeConfig, (uint8_t *)&LubeConfig, sizeof(LubeConfig));
uint32_t ConfigSanityCheckResult = ConfigSanityCheck(false);
if (ConfigSanityCheckResult > 0)
{
MaintainDTC(DTC_EEPROM_CFG_SANITY, true, ConfigSanityCheckResult);
}
}
/**
* @brief Retrieves the configuration data from EEPROM.
*
* This function reads the configuration data from EEPROM, performs a checksum validation,
* and conducts a sanity check on the configuration. It raises a diagnostic trouble code (DTC) if needed.
*/
void GetConfig_EEPROM()
{
if (!checkEEPROMavailable())
return;
ee.readBlock(startofLubeConfig, (uint8_t *)&LubeConfig, sizeof(LubeConfig));
uint32_t checksum = LubeConfig.checksum;
LubeConfig.checksum = 0;
if (Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig)) != checksum)
{
MaintainDTC(DTC_EEPROM_CFG_BAD, true);
}
LubeConfig.checksum = checksum;
uint32_t ConfigSanityCheckResult = ConfigSanityCheck(false);
if (ConfigSanityCheckResult > 0)
{
MaintainDTC(DTC_EEPROM_CFG_SANITY, true, ConfigSanityCheckResult);
}
}
/**
* @brief Stores the persistence data in EEPROM.
*
* This function increments the write cycle counter, performs a checksum calculation on the persistence data,
* and stores it in EEPROM. It also handles EEPROM page movement when needed.
*/
void StorePersistence_EEPROM()
{
if (PersistenceData.writeCycleCounter >= 0xFFF0)
MovePersistencePage_EEPROM(false);
else
PersistenceData.writeCycleCounter++;
PersistenceData.checksum = 0;
PersistenceData.checksum = Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData));
if (!checkEEPROMavailable())
return;
ee.updateBlock(globals.eePersistanceAdress, (uint8_t *)&PersistenceData, sizeof(PersistenceData));
}
/**
* @brief Retrieves the persistence data from EEPROM.
*
* This function reads the EEPROM to get the start address of the persistence data.
* If the start address is out of range, it resets and stores defaults. Otherwise,
* it reads from EEPROM and checks if the data is correct.
*/
void GetPersistence_EEPROM()
{
if (!checkEEPROMavailable())
return;
ee.readBlock(0, (uint8_t *)&globals.eePersistanceAdress, sizeof(globals.eePersistanceAdress));
// if we got the StartAdress of Persistance and it's out of Range - we Reset it and store defaults
// otherwise we Read from eeprom and check if everything is correct
if (globals.eePersistanceAdress < startofPersistence || globals.eePersistanceAdress > ee.getDeviceSize())
{
MovePersistencePage_EEPROM(true);
FormatPersistence_EEPROM();
MaintainDTC(DTC_EEPROM_PDSADRESS_BAD, true);
}
else
{
ee.readBlock(globals.eePersistanceAdress, (uint8_t *)&PersistenceData, sizeof(PersistenceData));
uint32_t checksum = PersistenceData.checksum;
PersistenceData.checksum = 0;
if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) != checksum)
{
MaintainDTC(DTC_EEPROM_PDS_BAD, true);
}
PersistenceData.checksum = checksum;
}
}
/**
* @brief Formats the configuration partition in EEPROM.
*
* This function resets the configuration data to defaults and stores it in EEPROM.
*/
void FormatConfig_EEPROM()
{
Debug_pushMessage("Formatting Config-Partition\n");
LubeConfig = LubeConfig_defaults;
LubeConfig.EEPROM_Version = eeVersion;
StoreConfig_EEPROM();
}
/**
* @brief Formats the persistence partition in EEPROM.
*
* This function resets the persistence data to defaults and stores it in EEPROM.
*/
void FormatPersistence_EEPROM()
{
Debug_pushMessage("Formatting Persistance-Partition\n");
PersistenceData = {0};
// memset(&PersistenceData, 0, sizeof(PersistenceData));
StorePersistence_EEPROM();
}
/**
* @brief Moves the persistence page in EEPROM.
*
* This function adjusts the persistence page address and resets the write cycle counter.
*
* @param reset If true, the function resets the persistence page address to the start of the partition.
*/
void MovePersistencePage_EEPROM(boolean reset)
{
if (!checkEEPROMavailable())
return;
globals.eePersistanceAdress += sizeof(PersistenceData);
PersistenceData.writeCycleCounter = 0;
// Check if we reached the end of the EEPROM and start over at the beginning
if ((globals.eePersistanceAdress + sizeof(PersistenceData)) > ee.getDeviceSize() || reset)
{
globals.eePersistanceAdress = startofPersistence;
}
ee.updateBlock(0, (uint8_t *)&globals.eePersistanceAdress, sizeof(globals.eePersistanceAdress));
}
/**
* @brief Calculate CRC-32 checksum for a block of data.
*
* This function implements the CRC-32 algorithm.
*
* @param data Pointer to the data block.
* @param len Length of the data block in bytes.
* @return CRC-32 checksum.
*/
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len)
{
if (data == NULL)
return 0;
uint32_t crc = 0xFFFFFFFF;
uint32_t mask;
while (len--)
{
crc ^= *data++;
for (uint8_t k = 0; k < 8; k++)
{
mask = -(crc & 1);
crc = (crc >> 1) ^ (0xEDB88320 & mask);
}
}
return ~crc;
}
/**
* @brief Dump a portion of EEPROM contents for debugging.
*
* This function prints the contents of a specified portion of EEPROM in a formatted way.
*
* @param memoryAddress Starting address in EEPROM.
* @param length Number of bytes to dump.
*/
void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
{
#define BLOCK_TO_LENGTH 16
if (!checkEEPROMavailable())
return;
char ascii_buf[BLOCK_TO_LENGTH + 1];
sprintf(ascii_buf, "%*s", BLOCK_TO_LENGTH, "ASCII");
// Print column headers
Debug_pushMessage(PSTR("\nAddress "));
for (int x = 0; x < BLOCK_TO_LENGTH; x++)
Debug_pushMessage("%3d", x);
// Align address and length to BLOCK_TO_LENGTH boundaries
memoryAddress = memoryAddress / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
length = (length + BLOCK_TO_LENGTH - 1) / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
// Iterate through the specified portion of EEPROM
for (unsigned int i = 0; i < length; i++)
{
int blockpoint = memoryAddress % BLOCK_TO_LENGTH;
// Print ASCII representation header for each block
if (blockpoint == 0)
{
ascii_buf[BLOCK_TO_LENGTH] = 0;
Debug_pushMessage(" %s", ascii_buf);
Debug_pushMessage("\n0x%05X:", memoryAddress);
}
// Read and print each byte
ascii_buf[blockpoint] = ee.readByte(memoryAddress);
Debug_pushMessage(" %02X", ascii_buf[blockpoint]);
// Replace non-printable characters with dots in ASCII representation
if (ascii_buf[blockpoint] < 0x20 || ascii_buf[blockpoint] > 0x7E)
ascii_buf[blockpoint] = '.';
memoryAddress++;
}
// Print a new line at the end of the dump
Debug_pushMessage("\n");
}
/**
* @brief Check if EEPROM is available and connected.
*
* This function checks if the EEPROM is available and connected. If not, it triggers
* a diagnostic trouble code (DTC) indicating the absence of EEPROM.
*
* @return true if EEPROM is available, false otherwise.
*/
boolean checkEEPROMavailable()
{
// Check if EEPROM is connected
if (!ee.isConnected())
{
// Trigger DTC for no EEPROM found
MaintainDTC(DTC_NO_EEPROM_FOUND, true);
return false;
}
// Clear DTC for no EEPROM found since it's available now
MaintainDTC(DTC_NO_EEPROM_FOUND, false);
// EEPROM is available
return true;
}
/**
* @brief Perform sanity check on configuration settings.
*
* This function checks the validity of various configuration settings and returns a bitmask
* indicating which settings need to be reset. If autocorrect is enabled, it resets the settings
* to their default values.
*
* @param autocorrect If true, automatically correct invalid settings by resetting to defaults.
* @return A bitmask indicating which settings need to be reset.
*/
uint32_t ConfigSanityCheck(bool autocorrect)
{
uint32_t setting_reset_bits = 0;
if (!(LubeConfig.DistancePerLube_Default > 0) || !(LubeConfig.DistancePerLube_Default < 50000))
{
SET_BIT(setting_reset_bits, 0);
if (autocorrect)
LubeConfig.DistancePerLube_Default = LubeConfig_defaults.DistancePerLube_Default;
}
if (!(LubeConfig.DistancePerLube_Rain > 0) || !(LubeConfig.DistancePerLube_Rain < 50000))
{
SET_BIT(setting_reset_bits, 1);
if (autocorrect)
LubeConfig.DistancePerLube_Rain = LubeConfig_defaults.DistancePerLube_Rain;
}
if (!(LubeConfig.tankCapacity_ml > 0) || !(LubeConfig.tankCapacity_ml < 5000))
{
SET_BIT(setting_reset_bits, 2);
if (autocorrect)
LubeConfig.tankCapacity_ml = LubeConfig_defaults.tankCapacity_ml;
}
if (!(LubeConfig.amountPerDose_microL > 0) || !(LubeConfig.amountPerDose_microL < 100))
{
SET_BIT(setting_reset_bits, 3);
if (autocorrect)
LubeConfig.amountPerDose_microL = LubeConfig_defaults.amountPerDose_microL;
}
if (!(LubeConfig.TankRemindAtPercentage >= 0) || !(LubeConfig.TankRemindAtPercentage <= 100))
{
SET_BIT(setting_reset_bits, 4);
if (autocorrect)
LubeConfig.TankRemindAtPercentage = LubeConfig_defaults.TankRemindAtPercentage;
}
if (LubeConfig.SpeedSource == SOURCE_IMPULSE)
{
if (!(LubeConfig.PulsePerRevolution > 0) || !(LubeConfig.PulsePerRevolution < 1000))
{
SET_BIT(setting_reset_bits, 5);
if (autocorrect)
LubeConfig.PulsePerRevolution = LubeConfig_defaults.PulsePerRevolution;
}
if (!(LubeConfig.TireWidth_mm > 0) || !(LubeConfig.TireWidth_mm < 500))
{
SET_BIT(setting_reset_bits, 6);
if (autocorrect)
LubeConfig.TireWidth_mm = LubeConfig_defaults.TireWidth_mm;
}
if (!(LubeConfig.TireWidthHeight_Ratio > 0) || !(LubeConfig.TireWidthHeight_Ratio < 150))
{
SET_BIT(setting_reset_bits, 7);
if (autocorrect)
LubeConfig.TireWidthHeight_Ratio = LubeConfig_defaults.TireWidthHeight_Ratio;
}
if (!(LubeConfig.RimDiameter_Inch > 0) || !(LubeConfig.RimDiameter_Inch < 30))
{
SET_BIT(setting_reset_bits, 8);
if (autocorrect)
LubeConfig.RimDiameter_Inch = LubeConfig_defaults.RimDiameter_Inch;
}
if (!(LubeConfig.DistancePerRevolution_mm > 0) || !(LubeConfig.DistancePerRevolution_mm < 10000))
{
SET_BIT(setting_reset_bits, 9);
if (autocorrect)
LubeConfig.DistancePerRevolution_mm = LubeConfig_defaults.DistancePerRevolution_mm;
}
}
if (!(LubeConfig.BleedingPulses > 0) || !(LubeConfig.BleedingPulses < 1001))
{
SET_BIT(setting_reset_bits, 10);
if (autocorrect)
LubeConfig.BleedingPulses = LubeConfig_defaults.BleedingPulses;
}
if (!(LubeConfig.SpeedSource >= 0) || !(LubeConfig.SpeedSource < SpeedSourceString_Elements))
{
SET_BIT(setting_reset_bits, 11);
if (autocorrect)
LubeConfig.SpeedSource = LubeConfig_defaults.SpeedSource;
}
if (!(LubeConfig.GPSBaudRate >= 0) || !(LubeConfig.GPSBaudRate < GPSBaudRateString_Elements))
{
SET_BIT(setting_reset_bits, 12);
if (autocorrect)
LubeConfig.GPSBaudRate = LubeConfig_defaults.GPSBaudRate;
}
if (!(LubeConfig.CANSource >= 0) || !(LubeConfig.CANSource < CANSourceString_Elements))
{
SET_BIT(setting_reset_bits, 13);
if (autocorrect)
LubeConfig.CANSource = LubeConfig_defaults.CANSource;
}
// Return the bitmask indicating which settings need to be reset
return setting_reset_bits;
}

462
Software/src/debugger.cpp Normal file
View File

@@ -0,0 +1,462 @@
/**
* @file debugger.cpp
* @brief Implementation of debugging functions for monitoring and diagnostics.
*
* This file contains the implementation of various debugging functions to monitor
* and diagnose the system. It includes functions to print system information, WiFi
* details, EEPROM status, dump configuration settings, dump persistence data, show
* Diagnostic Trouble Codes (DTCs), and more.
*
* @author Marcel Peterkau
* @date 09.04.2024
*/
#include "debugger.h"
DebugStatus_t DebuggerStatus[dbg_cntElements];
String IpAddress2String(const IPAddress &ipAddress);
void processCmdDebug(String command);
void Debug_formatCFG();
void Debug_formatPersistence();
void Debug_printSystemInfo();
void Debug_printWifiInfo();
void Debug_CheckEEPOM();
void Debug_dumpConfig();
void Debug_dumpPersistance();
void Debug_ShowDTCs();
void Debug_dumpGlobals();
void Debug_printHelp();
/**
* @brief Initializes the debugger by setting the initial status for different debug ports.
* Serial debug output is turned off.
*/
void initDebugger()
{
// Set the initial status of debug ports
DebuggerStatus[dbg_Serial] = disabled;
DebuggerStatus[dbg_Webui] = disabled;
// Disable serial debug output
Serial.setDebugOutput(false);
}
/**
* @brief Processes incoming debug commands from the Serial interface.
* It reads characters from Serial and interprets them as commands.
* The recognized commands are processed accordingly.
*/
void Debug_Process()
{
// Enumeration for tracking the state of input processing
typedef enum InputProcessed_e
{
IDLE, ///< No command processing is in progress
CMD_COMPLETE, ///< Received a complete command
CMD_ABORT, ///< Received an abort command (Esc)
CMD_OVERFLOW ///< Input buffer overflow occurred
} InputProcessed_t;
static unsigned int inputCnt = 0; ///< Counter for characters in the input buffer
static char inputBuffer[32]; ///< Buffer to store the received characters
InputProcessed_t InputProcessed = IDLE; ///< State variable for input processing
// Check if there are characters available in the Serial input buffer
if (Serial.available())
{
char inputChar = Serial.read();
// Process the received character based on its value
switch (inputChar)
{
case '\n':
inputBuffer[inputCnt] = 0; // terminate the String
inputCnt = 0;
InputProcessed = CMD_COMPLETE;
break;
case 0x1B: // Esc
inputBuffer[0] = 0;
inputCnt = 0;
InputProcessed = CMD_ABORT;
break;
case 0x21 ... 0x7E: // it's a real letter or sign and not some control-chars
inputBuffer[inputCnt] = inputChar;
inputCnt++;
break;
default:
break;
}
// Check for input buffer overflow
if (inputCnt > sizeof(inputBuffer))
{
inputCnt = 0;
inputBuffer[sizeof(inputBuffer) - 1] = 0; // terminate the String
InputProcessed = CMD_OVERFLOW;
}
}
// Process the command based on the detected state of input processing
switch (InputProcessed)
{
case CMD_ABORT:
Debug_pushMessage("Abort\n");
break;
case CMD_COMPLETE:
processCmdDebug(String(inputBuffer));
break;
case CMD_OVERFLOW:
Debug_pushMessage("Input buffer overflow\n");
break;
default:
break;
}
InputProcessed = IDLE;
}
/**
* @brief Sets the status of a specific debug port (Serial or WebUI).
* Updates the status in the DebuggerStatus array and provides debug messages.
*
* @param port The debug port to set the status for (dbg_Serial or dbg_Webui).
* @param status The status to set (enabled or disabled).
*/
void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status)
{
// Display a debug message based on the provided status
if (status == disabled)
Debug_pushMessage("Disable DebugPort %s\n", sDebugPorts[port]);
// Update the status in the DebuggerStatus array
DebuggerStatus[port] = status;
// Display a debug message based on the updated status
if (status == enabled)
Debug_pushMessage("Enabled DebugPort %s\n", sDebugPorts[port]);
}
/**
* @brief Pushes a formatted debug message to the enabled debug ports (Serial or WebUI).
*
* @param format The format string for the debug message.
* @param ... Additional arguments for formatting the message.
*/
void Debug_pushMessage(const char *format, ...)
{
// Check if either the Serial or WebUI debug port is enabled
if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled))
{
char buff[64]; // Buffer to hold the formatted message
va_list arg; // Variable argument list for vsnprintf
va_start(arg, format);
// Format the message and store it in the buffer
vsnprintf(buff, sizeof(buff), format, arg);
va_end(arg);
// Send the message to the Serial debug port if enabled
if (DebuggerStatus[dbg_Serial] == enabled)
{
Serial.print(buff);
}
// Push the message to the WebUI debug port if enabled
if (DebuggerStatus[dbg_Webui] == enabled)
{
Websocket_PushLiveDebug(String(buff));
}
}
}
/**
* @brief Pushes a formatted CAN debug message to the enabled debug ports (Serial or WebUI).
*
* @param id CAN message ID.
* @param dlc Data Length Code of the CAN message.
* @param data Pointer to the data array of the CAN message.
*/
void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data)
{
// Check if either the Serial or WebUI debug port is enabled
if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled))
{
char buff[100]; // Buffer to hold the formatted message
char *p = buff; // Pointer to navigate the buffer
// Format the CAN message information into the buffer
p += snprintf(p, sizeof(buff), "CAN: 0x%08X | %d | ", id, dlc);
for (int i = 0; i < dlc; i++)
{
p += snprintf(p, sizeof(buff) - (p - buff), "%02X ", data[i]);
}
*(p++) = '\n';
*p = '\0';
// Send the formatted CAN message to the Serial debug port if enabled
if (DebuggerStatus[dbg_Serial] == enabled)
{
Serial.print(buff);
}
// Push the formatted CAN message to the WebUI debug port if enabled
if (DebuggerStatus[dbg_Webui] == enabled)
{
Websocket_PushLiveDebug(String(buff));
}
}
}
/**
* @brief Processes a debug command and performs corresponding actions.
*
* @param command The debug command to be processed.
*/
void processCmdDebug(String command)
{
// Check the received command and execute corresponding actions
if (command == "help")
Debug_printHelp();
else if (command == "sysinfo")
Debug_printSystemInfo();
else if (command == "netinfo")
Debug_printWifiInfo();
else if (command == "formatCFG")
Debug_formatCFG();
else if (command == "formatPDS")
Debug_formatPersistence();
else if (command == "checkEE")
Debug_CheckEEPOM();
else if (command == "dumpEE1k")
dumpEEPROM(0, 1024);
else if (command == "dumpEE")
dumpEEPROM(0, EEPROM_SIZE_BYTES);
else if (command == "resetPageEE")
MovePersistencePage_EEPROM(true);
else if (command == "dumpCFG")
Debug_dumpConfig();
else if (command == "dumpPDS")
Debug_dumpPersistance();
else if (command == "saveEE")
globals.requestEEAction = EE_ALL_SAVE;
else if (command == "dumpGlobals")
Debug_dumpGlobals();
else if (command == "sdbg")
SetDebugportStatus(dbg_Serial, enabled);
else if (command == "dtc_show")
Debug_ShowDTCs();
else if (command == "dtc_clear")
ClearAllDTC();
else if (command == "dtc_crit")
MaintainDTC(DTC_FAKE_DTC_CRIT, true, millis());
else if (command == "dtc_warn")
MaintainDTC(DTC_FAKE_DTC_WARN, true, millis());
else if (command == "dtc_info")
MaintainDTC(DTC_FAKE_DTC_INFO, true, millis());
else
Debug_pushMessage("unknown Command\n");
}
/**
* @brief Formats the Config-EEPROM and resets it to default values.
* Prints a debug message after formatting.
*/
void Debug_formatCFG()
{
Debug_pushMessage("Formatting Config-EEPROM and resetting to default\n");
FormatConfig_EEPROM();
}
/**
* @brief Formats the Persistence-EEPROM and resets it to default values.
* Prints a debug message after formatting.
*/
void Debug_formatPersistence()
{
Debug_pushMessage("Formatting Persistence-EEPROM and resetting to default\n");
FormatPersistence_EEPROM();
}
/**
* @brief Prints system information and status to the debug output.
*/
void Debug_printSystemInfo()
{
Debug_pushMessage("Souko's ChainOiler Mk1\n");
Debug_pushMessage("Hostname: %s\n", globals.DeviceName);
FlashMode_t ideMode = ESP.getFlashChipMode();
Debug_pushMessage("Sdk version: %s\n", ESP.getSdkVersion());
Debug_pushMessage("Core Version: %s\n", ESP.getCoreVersion().c_str());
Debug_pushMessage("Boot Version: %u\n", ESP.getBootVersion());
Debug_pushMessage("Boot Mode: %u\n", ESP.getBootMode());
Debug_pushMessage("CPU Frequency: %u MHz\n", ESP.getCpuFreqMHz());
Debug_pushMessage("Reset reason: %s\n", ESP.getResetReason().c_str());
Debug_pushMessage("Flash Size: %d\n", ESP.getFlashChipRealSize());
Debug_pushMessage("Flash Size IDE: %d\n", ESP.getFlashChipSize());
Debug_pushMessage("Flash ide mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT"
: ideMode == FM_DIO ? "DIO"
: ideMode == FM_DOUT ? "DOUT"
: "UNKNOWN"));
Debug_pushMessage("OTA-Pass: %s\n", QUOTE(ADMIN_PASSWORD));
Debug_pushMessage("Git-Revision: %s\n", constants.GitHash);
Debug_pushMessage("Sw-Version: %d.%02d\n", constants.FW_Version_major, constants.FW_Version_minor);
}
/**
* @brief Dumps the current configuration parameters to the debug output.
*/
void Debug_dumpConfig()
{
Debug_pushMessage("DistancePerLube_Default: %d\n", LubeConfig.DistancePerLube_Default);
Debug_pushMessage("DistancePerLube_Rain: %d\n", LubeConfig.DistancePerLube_Rain);
Debug_pushMessage("tankCapacity_ml: %d\n", LubeConfig.tankCapacity_ml);
Debug_pushMessage("amountPerDose_microL: %d\n", LubeConfig.amountPerDose_microL);
Debug_pushMessage("TankRemindAtPercentage: %d\n", LubeConfig.TankRemindAtPercentage);
Debug_pushMessage("PulsePerRevolution: %d\n", LubeConfig.PulsePerRevolution);
Debug_pushMessage("TireWidth_mm: %d\n", LubeConfig.TireWidth_mm);
Debug_pushMessage("TireWidthHeight_Ratio: %d\n", LubeConfig.TireWidthHeight_Ratio);
Debug_pushMessage("RimDiameter_Inch: %d\n", LubeConfig.RimDiameter_Inch);
Debug_pushMessage("DistancePerRevolution_mm: %d\n", LubeConfig.DistancePerRevolution_mm);
Debug_pushMessage("BleedingPulses: %d\n", LubeConfig.BleedingPulses);
Debug_pushMessage("SpeedSource: %d\n", LubeConfig.SpeedSource);
Debug_pushMessage("GPSBaudRate: %d\n", LubeConfig.GPSBaudRate);
Debug_pushMessage("CANSource: %d\n", LubeConfig.CANSource);
Debug_pushMessage("checksum: 0x%08X\n", LubeConfig.checksum);
}
/**
* @brief Dumps the global variables and their values to the debug output.
*/
void Debug_dumpGlobals()
{
Debug_pushMessage("systemStatus: %d\n", globals.systemStatus);
Debug_pushMessage("resumeStatus: %d\n", globals.resumeStatus);
Debug_pushMessage("systemStatustxt: %s\n", globals.systemStatustxt);
Debug_pushMessage("purgePulses: %d\n", globals.purgePulses);
Debug_pushMessage("requestEEAction: %d\n", globals.requestEEAction);
Debug_pushMessage("DeviceName: %s\n", globals.DeviceName);
Debug_pushMessage("FlashVersion: %s\n", globals.FlashVersion);
Debug_pushMessage("eePersistanceAdress: %d\n", globals.eePersistanceAdress);
Debug_pushMessage("TankPercentage: %d\n", globals.TankPercentage);
Debug_pushMessage("hasDTC: %d\n", globals.hasDTC);
}
/**
* @brief Dumps the persistence data variables and their values to the debug output.
*/
void Debug_dumpPersistance()
{
Debug_pushMessage("writeCycleCounter: %d\n", PersistenceData.writeCycleCounter);
Debug_pushMessage("tankRemain_microL: %d\n", PersistenceData.tankRemain_microL);
Debug_pushMessage("TravelDistance_highRes_mm: %d\n", PersistenceData.TravelDistance_highRes_mm);
Debug_pushMessage("checksum: %d\n", PersistenceData.checksum);
Debug_pushMessage("PSD Adress: 0x%04X\n", globals.eePersistanceAdress);
}
/**
* @brief Prints information related to WiFi to the debug output.
*/
void Debug_printWifiInfo()
{
// Add relevant code here if needed
}
/**
* @brief Checks the EEPROM data integrity by calculating and comparing checksums.
* Prints the result to the debug output.
*/
void Debug_CheckEEPOM()
{
// Check PersistenceData EEPROM checksum
uint32_t checksum = PersistenceData.checksum;
PersistenceData.checksum = 0;
if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) == checksum)
{
Debug_pushMessage("PersistenceData EEPROM Checksum OK\n");
}
else
{
Debug_pushMessage("PersistenceData EEPROM Checksum BAD\n");
}
PersistenceData.checksum = checksum;
// Check LubeConfig EEPROM checksum
checksum = LubeConfig.checksum;
LubeConfig.checksum = 0;
if (Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig)) == checksum)
{
Debug_pushMessage("LubeConfig EEPROM Checksum OK\n");
}
else
{
Debug_pushMessage("LubeConfig EEPROM Checksum BAD\n");
}
LubeConfig.checksum = checksum;
}
/**
* @brief Displays Diagnostic Trouble Codes (DTCs) along with their timestamps,
* status, and severity in a formatted manner.
*/
void Debug_ShowDTCs()
{
char buff_timestamp[16]; // Format: DD-hh:mm:ss:xxx
char buff_active[9];
// Header for the DTC display
Debug_pushMessage("\n timestamp | DTC-Nr. | status | severity\n");
// Iterate through DTCStorage and display each entry
for (uint32_t i = 0; i < MAX_DTC_STORAGE; i++)
{
if (DTCStorage[i].Number < DTC_LAST_DTC)
{
// Format timestamp
sprintf(buff_timestamp, "%02d-%02d:%02d:%02d:%03d",
DTCStorage[i].timestamp / 86400000, // Days
DTCStorage[i].timestamp / 360000 % 24, // Hours
DTCStorage[i].timestamp / 60000 % 60, // Minutes
DTCStorage[i].timestamp / 1000 % 60, // Seconds
DTCStorage[i].timestamp % 1000); // Milliseconds
// Determine DTC status
if (DTCStorage[i].active == DTC_ACTIVE)
strcpy(buff_active, "active");
else if (DTCStorage[i].active == DTC_PREVIOUS)
strcpy(buff_active, "previous");
else
strcpy(buff_active, "none");
// Display DTC information
Debug_pushMessage("%s %7d %8s %8d\n", buff_timestamp, DTCStorage[i].Number, buff_active);
}
}
}
/**
* @brief Displays the help commands for debugging through Serial or WebUI.
* Each command is printed individually in a formatted manner.
*/
void Debug_printHelp()
{
char buff[64];
// Iterate through helpCmd and display each command
for (unsigned int i = 0; i < sizeof(helpCmd) / 63; i++)
{
// Copy a portion of helpCmd to buff for display
memcpy_P(buff, (helpCmd + (i * 63)), 63);
buff[63] = 0;
// Display the help command
Debug_pushMessage(buff);
}
}

196
Software/src/dtc.cpp Normal file
View File

@@ -0,0 +1,196 @@
/**
* @file dtc.cpp
* @brief Implementation of functions related to Diagnostic Trouble Codes (DTCs).
*
* This file contains the implementation of functions that manage the status
* and registration of Diagnostic Trouble Codes in the system.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#include "dtc.h"
#include "debugger.h"
DTCEntry_t DTCStorage[MAX_DTC_STORAGE];
// Function implementations...
/**
* @brief Maintains the status of Diagnostic Trouble Codes (DTCs) in the DTCStorage array.
* Updates the status of existing DTCs or adds new ones based on their activity.
*
* @param DTC_no The number of the Diagnostic Trouble Code.
* @param active Indicates whether the DTC is active (true) or inactive (false).
* @param DebugValue Additional debugging information associated with the DTC.
*/
void MaintainDTC(DTCNum_t DTC_no, boolean active, uint32_t DebugValue)
{
// Iterate through the existing DTCs in the storage
for (int i = 0; i < MAX_DTC_STORAGE; i++)
{
// Check if the DTC with the specified number exists
if (DTCStorage[i].Number == DTC_no)
{
// If the DTC is active and was not active before, update its status
if (active && DTCStorage[i].active != DTC_ACTIVE)
{
Debug_pushMessage("DTC gone active: %d, DebugVal: %d\n", DTC_no, DebugValue);
DTCStorage[i].timestamp = millis();
DTCStorage[i].active = DTC_ACTIVE;
DTCStorage[i].debugVal = DebugValue;
}
// If the DTC is not active anymore, update its status to previous
if (!active && DTCStorage[i].active == DTC_ACTIVE)
{
Debug_pushMessage("DTC gone previous: %d\n", DTC_no);
DTCStorage[i].active = DTC_PREVIOUS;
}
return; // DTC found and processed, exit the function
}
}
// DTC was not found in the existing storage, but it is active,
// so look for free space to store the new DTC
if (active == true)
{
for (int i = 0; i < MAX_DTC_STORAGE; i++)
{
// Check for an empty slot in the storage
if (DTCStorage[i].Number == DTC_LAST_DTC)
{
Debug_pushMessage("new DTC registered: %d, DebugVal: %d\n", DTC_no, DebugValue);
DTCStorage[i].Number = DTC_no;
DTCStorage[i].timestamp = millis();
DTCStorage[i].active = DTC_ACTIVE;
DTCStorage[i].debugVal = DebugValue;
return; // New DTC registered, exit the function
}
}
}
}
/**
* @brief Clears a specific Diagnostic Trouble Code (DTC) entry.
*
* This function clears the information related to a specific DTC entry,
* setting its status to inactive and timestamp to zero.
*
* @param DTC_no The Diagnostic Trouble Code number to be cleared.
*/
void ClearDTC(DTCNum_t DTC_no)
{
for (int i = 0; i < MAX_DTC_STORAGE; i++)
{
if (DTCStorage[i].Number == DTC_no)
{
DTCStorage[i].Number = DTC_LAST_DTC;
DTCStorage[i].active = DTC_INACTIVE;
DTCStorage[i].timestamp = 0;
}
}
}
/**
* @brief Clears all Diagnostic Trouble Code (DTC) entries.
*
* This function clears all DTC entries, setting their status to inactive and
* timestamps to zero.
*/
void ClearAllDTC()
{
for (int i = 0; i < MAX_DTC_STORAGE; i++)
{
DTCStorage[i].Number = DTC_LAST_DTC;
DTCStorage[i].active = DTC_INACTIVE;
DTCStorage[i].timestamp = 0;
}
}
/**
* @brief Gets the last recorded Diagnostic Trouble Code (DTC) number.
*
* This function retrieves the DTC number of the last recorded DTC based on the
* timestamp. Optionally, it can filter only active DTCs.
*
* @param only_active If true, considers only active DTCs; otherwise, considers all.
* @return The DTC number of the last recorded DTC or DTC_LAST_DTC if none found.
*/
DTCNum_t getlastDTC(boolean only_active)
{
int8_t pointer = -1;
uint32_t lasttimestamp = 0;
for (int i = 0; i < MAX_DTC_STORAGE; i++)
{
if (DTCStorage[i].Number > 0 && DTCStorage[i].timestamp > lasttimestamp)
{
if (only_active == false || DTCStorage[i].active == DTC_ACTIVE)
{
pointer = i;
lasttimestamp = DTCStorage[i].timestamp;
}
}
}
return pointer >= 0 ? DTCStorage[pointer].Number : DTC_LAST_DTC;
}
/**
* @brief Gets the severity level for a specific Diagnostic Trouble Code (DTC).
*
* This function looks up the severity level associated with the provided DTC code
* from the predefined list of DTC definitions.
*
* @param targetCode The DTC code for which to retrieve the severity.
* @return The severity level of the specified DTC or DTC_NONE if not found.
*/
DTCSeverity_t getSeverityForDTC(DTCNum_t targetCode)
{
for (int i = 0; i < DTC_LAST_DTC; i++)
{
if (dtc_definitions[i].code == targetCode)
{
return dtc_definitions[i].severity;
}
}
return DTC_NONE;
}
/**
* @brief Processes Diagnostic Trouble Codes (DTCs) and updates system status accordingly.
*
* This function checks for the presence of active DTCs and adjusts the system status
* based on the severity of the most critical DTC. If a critical DTC is detected,
* the system status is set to sysStat_Error, potentially triggering a system shutdown.
*
* @note The function also preserves the original system status when transitioning to an error state
* and restores it when all DTCs are cleared.
*/
void DTC_Process()
{
static tSystem_Status preserverSysStatusError;
DTCNum_t lastDTC = getlastDTC(true);
if (lastDTC < DTC_LAST_DTC)
{
globals.hasDTC = true;
if (getSeverityForDTC(lastDTC) == DTC_CRITICAL && globals.systemStatus != sysStat_Shutdown)
{
if (globals.systemStatus != sysStat_Error)
{
preserverSysStatusError = globals.systemStatus;
}
globals.systemStatus = sysStat_Error;
}
}
else
{
globals.hasDTC = false;
if (globals.systemStatus == sysStat_Error)
{
globals.systemStatus = preserverSysStatusError;
}
}
}

18
Software/src/dtc_defs.txt Normal file
View File

@@ -0,0 +1,18 @@
# No. | DTC-Constant | Severity | Title | Description
#-----|------------------------------|---------------|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------
1; DTC_TANK_EMPTY; DTC_CRITICAL; Ölvorrat leer; Ölvorrat ist komplett leer. Den Ölvorrat auffüllen und im Menu 'Wartung' zurück setzen
2; DTC_TANK_LOW; DTC_WARN; Ölvorrat niedrig; Ölvorrat ist unter der Warnschwelle. Den Ölvorrat demnächst auffüllen und im Menu 'Wartung' zurück setzen
3; DTC_NO_EEPROM_FOUND; DTC_CRITICAL; kein EEPROM erkannt; Es wurde kein EEPROM gefunden. Dies lässt einen Hardware-Defekt vermuten.
4; DTC_EEPROM_CFG_BAD; DTC_CRITICAL; EEPROM CFG Checksumme; Die Checksumme der Config-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück
5; DTC_EEPROM_PDS_BAD; DTC_CRITICAL; EEPROM PDS Checksumme; Die Checksumme der Betriebsdaten-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück
6; DTC_EEPROM_PDSADRESS_BAD; DTC_CRITICAL; EEPROM PDS Adresse; Die Adresse der Betriebsdaten-Partition im EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück
7; DTC_EEPROM_VERSION_BAD; DTC_CRITICAL; EEPROM Version falsch; Die Layout-Version des EEPROM stimmt nicht mit der Firmware-Version überein. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück
8; DTC_FLASHFS_ERROR; DTC_CRITICAL; Flashspeicher Fehler; Der Flashspeicher konnte nicht initialisiert werden. Aktualisieren sie Flash & Firmware
9; DTC_FLASHFS_VERSION_ERROR; DTC_CRITICAL; Flashversion falsch; Die Version des Flashspeicher stimmt nicht mit der Firmware-Version überein. Aktualisieren sie den Flash mit der passenden Update-Datei
10; DTC_NO_GPS_SERIAL; DTC_CRITICAL; Keine GPS-Verbindung; Es wurde kein GPS-Signal über die serielle Schnittstelle empfangen, Prüfen sie die Verbindung und das GPS-Modul
11; DTC_CAN_TRANSCEIVER_FAILED; DTC_CRITICAL; CAN-Transceiver Error; Es konnte keine Verbindung zum CAN-Transceiver hergestellt werden. Prüfen Sie die Hardware auf Defekte
12; DTC_NO_CAN_SIGNAL; DTC_WARN; Keine CAN-Verbindung; Es konnte kein CAN-Signal empfangen werden. Prüfen sie die Verbindung und die Einstellungen
13; DTC_EEPROM_CFG_SANITY; DTC_WARN; Config-Validierung; Ein oder mehrer Einstellungswerte sind ausserhalb plausibler Werte. Prüfen Sie Ihre Einstellungen
14; DTC_FAKE_DTC_INFO; DTC_INFO; Dummy-DTC Info; Ein Dummy-DTC der Schwere "Info" für Debugging-Zwecke
15; DTC_FAKE_DTC_WARN; DTC_WARN; Dummy-DTC Warnung; Ein Dummy-DTC der Schwere "Warnung" für Debugging-Zwecke
16; DTC_FAKE_DTC_CRIT; DTC_CRITICAL; Dummy-DTC Kritisch; Ein Dummy-DTC der Schwere "Kritisch" für Debugging-Zwecke

29
Software/src/globals.cpp Normal file
View File

@@ -0,0 +1,29 @@
/**
* @file globals.cpp
* @brief Implementation of global variables and initialization functions.
*
* This file defines and initializes the global variables used throughout the project.
* The global variables are encapsulated in the Globals_t structure. The initGlobals function
* is responsible for initializing these variables to their default values during system startup.
*/
#include "globals.h"
// Global instance of the Globals_t structure
Globals_t globals;
/**
* @brief Initializes global variables to default values during system startup.
*
* This function sets the initial values for various global variables, ensuring proper
* initialization of system-wide parameters.
*/
void initGlobals()
{
globals.purgePulses = 0;
globals.requestEEAction = EE_IDLE;
globals.resumeStatus = sysStat_Normal;
globals.systemStatus = sysStat_Startup;
globals.measurementActive = false;
globals.measuredPulses = 0;
}

85
Software/src/gps.cpp Normal file
View File

@@ -0,0 +1,85 @@
/**
* @file gps.cpp
*
* @brief Implementation file for GPS-related functions in the ChainLube application.
*
* This file contains the implementation of functions related to GPS functionality within the ChainLube
* application. It includes the initialization of the GPS module, processing GPS data for wheel speed,
* and maintaining Diagnostic Trouble Codes (DTCs) based on GPS communication status.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#include "gps.h"
TinyGPSPlus gps;
/**
* @brief Initializes the GPS module with the specified baud rate.
*
* This function initializes the GPS module with the baud rate configured in the application settings.
* It also prints a debug message indicating the initialization status.
*/
void Init_GPS()
{
uint32_t baudrate;
switch (LubeConfig.GPSBaudRate)
{
case BAUD_9600:
baudrate = 9600;
break;
case BAUD_115200:
baudrate = 115200;
break;
default:
baudrate = 4800;
break;
}
Debug_pushMessage(PSTR("Init GPS with Baud %d\n"), baudrate);
Serial.begin(baudrate);
}
/**
* @brief Processes GPS data to calculate rear wheel speed and returns the distance traveled.
*
* This function processes GPS data received from the GPS module, calculates the rear wheel speed in
* kilometers per hour, and returns the distance traveled based on the speed and time elapsed since
* the last valid speed measurement.
*
* @return The distance traveled in millimeters since the last GPS speed measurement.
*/
uint32_t Process_GPS_WheelSpeed()
{
static uint32_t lastRecTimestamp;
static uint32_t lastValidSpeedTimestamp;
uint16_t RearWheelSpeed_kmh;
while (Serial.available() > 0)
{
uint8_t incoming = Serial.read();
if (gps.encode(incoming))
{
RearWheelSpeed_kmh = gps.speed.isValid() ? gps.speed.kmph() : 0;
if (RearWheelSpeed_kmh > 0)
{
uint32_t RWP_millimeter_per_second = ((uint32_t)RearWheelSpeed_kmh * 1000000) / 3600;
uint32_t timesincelast = millis() - lastValidSpeedTimestamp;
lastValidSpeedTimestamp = millis();
uint32_t milimeters_to_add = (RWP_millimeter_per_second * timesincelast) / 1000;
return milimeters_to_add;
}
lastRecTimestamp = millis();
}
}
// Maintain DTC for no GPS data received within a certain time frame
MaintainDTC(DTC_NO_GPS_SERIAL, (millis() > lastRecTimestamp + 10000));
return 0;
}

140
Software/src/lubeapp.cpp Normal file
View File

@@ -0,0 +1,140 @@
/**
* @file lubeapp.cpp
*
* @brief Implementation file for the ChainLube application logic.
*
* This file contains the implementation of the ChainLube application logic, including functions
* for running the main application, initiating lubrication pulses, and maintaining system status.
* Global variables related to lubrication pulses are also defined in this file.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#include "lubeapp.h"
uint32_t lubePulseTimestamp = 0;
/**
* @brief Runs the main logic of the ChainLube application based on the current system status.
*
* This function is responsible for executing the main logic of the ChainLube application. It calculates
* the tank percentage, maintains Diagnostic Trouble Codes (DTCs) related to the tank level, updates travel
* distances, triggers lubrication pulses, and handles the behavior based on the current system status
* (Startup, Normal, Rain, Purge, Error, Shutdown). It also manages the pin state of the lube pump.
*
* @param add_milimeters The additional distance traveled in millimeters to be processed by the application.
*/
void RunLubeApp(uint32_t add_milimeters)
{
// Calculate and update tank percentage
globals.TankPercentage = PersistenceData.tankRemain_microL / (LubeConfig.tankCapacity_ml * 10);
// Maintain DTCs related to tank level
MaintainDTC(DTC_TANK_EMPTY, (PersistenceData.tankRemain_microL < LubeConfig.amountPerDose_microL));
MaintainDTC(DTC_TANK_LOW, (globals.TankPercentage < LubeConfig.TankRemindAtPercentage));
// Add traveled distance in millimeters
PersistenceData.TravelDistance_highRes_mm += add_milimeters;
PersistenceData.odometer_mm += add_milimeters;
// Update odometer if necessary
if (PersistenceData.odometer_mm >= 1000000)
{
PersistenceData.odometer++;
PersistenceData.odometer_mm = 0;
}
// Handle different system statuses
switch (globals.systemStatus)
{
case sysStat_Startup:
strcpy_P(globals.systemStatustxt, PSTR("Startup"));
// Transition to Normal status after startup delay
if (millis() > STARTUP_DELAY)
{
globals.systemStatus = sysStat_Normal;
globals.resumeStatus = sysStat_Normal;
}
break;
case sysStat_Normal:
strcpy_P(globals.systemStatustxt, PSTR("Normal"));
// Trigger lube pulse if traveled distance exceeds the configured limit
if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Default)
{
LubePulse();
PersistenceData.TravelDistance_highRes_mm = 0;
}
break;
case sysStat_Rain:
strcpy_P(globals.systemStatustxt, PSTR("Rain"));
// Trigger lube pulse if traveled distance exceeds the configured limit in Rain mode
if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Rain)
{
LubePulse();
PersistenceData.TravelDistance_highRes_mm = 0;
}
break;
case sysStat_Purge:
strcpy_P(globals.systemStatustxt, PSTR("Purge"));
// Execute lube pulses during the Purge status
if (globals.purgePulses > 0)
{
// Check if enough time has passed since the last lube pulse
if (lubePulseTimestamp + LUBE_PULSE_PAUSE_MS < millis())
{
LubePulse();
globals.purgePulses--;
Debug_pushMessage("Purge remain: %d\n", globals.purgePulses);
}
}
else
{
// Transition back to the previous status after completing purge pulses
globals.systemStatus = globals.resumeStatus;
}
break;
case sysStat_Error:
strcpy_P(globals.systemStatustxt, PSTR("Error"));
break;
case sysStat_Shutdown:
strcpy_P(globals.systemStatustxt, PSTR("Shutdown"));
break;
default:
break;
}
// Maintain Pin-State of Lube-Pump
if (lubePulseTimestamp > millis())
digitalWrite(GPIO_PUMP, HIGH);
else
digitalWrite(GPIO_PUMP, LOW);
}
/**
* @brief Initiates a lubrication pulse if there is sufficient oil remaining in the tank.
*
* This function checks if there is enough oil remaining in the tank to perform a lubrication pulse.
* If there is sufficient oil, it updates the lubePulseTimestamp to trigger the pulse and decreases
* the tank oil level by the configured amount per dose (LubeConfig.amountPerDose_microL).
*/
void LubePulse()
{
// Only initiate a lubrication pulse if there is oil remaining in the tank
if (PersistenceData.tankRemain_microL > 0)
{
lubePulseTimestamp = millis() + LUBE_PULSE_LENGHT_MS;
// Prevent underrun and shift over by adjusting the tank oil level
if (PersistenceData.tankRemain_microL < LubeConfig.amountPerDose_microL)
PersistenceData.tankRemain_microL = 0;
else
PersistenceData.tankRemain_microL -= LubeConfig.amountPerDose_microL;
}
}

835
Software/src/main.cpp Normal file
View File

@@ -0,0 +1,835 @@
/**
* @file main.cpp
*
* @brief Main source file for the Souko's ChainLube Mk1 ESP8266 project.
*
* This file includes necessary libraries, defines configuration options, and declares global variables
* and function prototypes. It sets up essential components, initializes peripherals, and defines
* callbacks for interrupt service routines (ISRs) and timers. The main setup function configures the
* project, and the loop function handles the main execution loop, performing various tasks based on
* the configured options.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#include <Arduino.h>
#include <Wire.h>
#ifdef FEATURE_ENABLE_OLED
#include <U8g2lib.h>
#endif
#include <ESP8266WiFi.h>
#include <ArduinoOTA.h>
#include <Adafruit_NeoPixel.h>
#include <Ticker.h>
#include "common.h"
#include "sanitycheck.h"
#include "lubeapp.h"
#include "webui.h"
#include "config.h"
#include "globals.h"
#include "debugger.h"
#include "can.h"
#include "gps.h"
#include "dtc.h"
#include "led_colors.h"
#ifdef FEATURE_ENABLE_WIFI_CLIENT
#include <ESP8266WiFiMulti.h>
const char *ssid = QUOTE(WIFI_SSID_CLIENT);
const char *password = QUOTE(WIFI_PASSWORD_CLIENT);
const uint32_t connectTimeoutMs = 5000;
ESP8266WiFiMulti wifiMulti;
#endif
bool startSetupMode = false;
volatile uint32_t wheel_pulse = 0;
Adafruit_NeoPixel leds(1, GPIO_LED, NEO_RGB + NEO_KHZ800);
// Function-Prototypes
void IRAM_ATTR trigger_ISR();
void LED_Process(uint8_t override = false, uint32_t setColor = LED_DEFAULT_COLOR);
#ifdef FEATURE_ENABLE_OLED
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1);
void Display_Process();
#endif
void Button_Process();
void toggleWiFiAP(bool shutdown = false);
void SystemShutdown(bool restart = false);
uint32_t Process_Impulse_WheelSpeed();
void EEPROMCyclicPDS_callback();
#ifdef FEATURE_ENABLE_WIFI_CLIENT
void wifiMaintainConnectionTicker_callback();
Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS);
#endif
Ticker EEPROMCyclicPDSTicker(EEPROMCyclicPDS_callback, 60000, 0, MILLIS);
/**
* @brief Initializes the ESP8266 project, configuring various components and setting up required services.
*
* This setup function is responsible for initializing the ESP8266 project, including setting the CPU frequency,
* configuring WiFi settings, initializing DTC storage, handling WiFi client functionality (if enabled),
* initializing the Serial communication, setting up an OLED display (if enabled), initializing EEPROM,
* loading configuration and persistence data from EEPROM, initializing LEDs, setting up the chosen speed source
* (CAN, GPS, Impulse), configuring GPIO pins, setting up Over-The-Air (OTA) updates, initializing the web user interface,
* initializing global variables, starting cyclic EEPROM updates for Persistence Data Structure (PDS), and printing
* initialization status messages to Serial.
*/
void setup()
{
// Set CPU frequency to 80MHz
system_update_cpu_freq(SYS_CPU_80MHZ);
// Generate a unique device name based on ESP chip ID
snprintf(globals.DeviceName, 32, HOST_NAME, ESP.getChipId());
// Disable WiFi persistent storage
WiFi.persistent(false);
// Initialize and clear Diagnostic Trouble Code (DTC) storage
ClearAllDTC();
#ifdef FEATURE_ENABLE_WIFI_CLIENT
// Configure WiFi settings for client mode if enabled
WiFi.mode(WIFI_STA);
WiFi.setHostname(globals.DeviceName);
wifiMulti.addAP(QUOTE(WIFI_SSID_CLIENT), QUOTE(WIFI_PASSWORD_CLIENT));
WiFiMaintainConnectionTicker.start();
#else
// Disable WiFi if WiFi client feature is not enabled
WiFi.mode(WIFI_OFF);
#endif
// Initialize Serial communication
Serial.begin(115200);
Serial.print("\n\nSouko's ChainLube Mk1\n");
Serial.print(globals.DeviceName);
#ifdef FEATURE_ENABLE_OLED
// Initialize OLED display if enabled
u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8.clearDisplay();
u8x8.drawString(0, 0, "KTM ChainLube V1");
u8x8.refreshDisplay();
Serial.print("\nDisplay-Init done");
#endif
// Initialize EEPROM, load configuration, and persistence data from EEPROM
InitEEPROM();
GetConfig_EEPROM();
GetPersistence_EEPROM();
Serial.print("\nEE-Init done");
// Initialize LEDs
leds.begin();
Serial.print("\nLED-Init done");
// Initialize based on the chosen speed source (CAN, GPS, Impulse)
switch (LubeConfig.SpeedSource)
{
case SOURCE_CAN:
Init_CAN();
Serial.print("\nCAN-Init done");
break;
case SOURCE_GPS:
Init_GPS();
Serial.print("\nGPS-Init done");
break;
case SOURCE_IMPULSE:
pinMode(GPIO_TRIGGER, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(GPIO_TRIGGER), trigger_ISR, FALLING);
Serial.print("\nPulse-Input Init done");
break;
default:
break;
}
Serial.print("\nSource-Init done");
// Configure GPIO pins for button and pump control
pinMode(GPIO_BUTTON, INPUT_PULLUP);
pinMode(GPIO_PUMP, OUTPUT);
// Set up OTA updates
ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname(globals.DeviceName);
ArduinoOTA.setPassword(QUOTE(ADMIN_PASSWORD));
#ifdef FEATURE_ENABLE_OLED
// Set up OTA callbacks for OLED display if enabled
ArduinoOTA.onStart([]()
{
u8x8.clearDisplay();
u8x8.drawString(0, 6, "OTA-Update");
u8x8.refreshDisplay(); });
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
{
static bool refreshed = false;
if (!refreshed)
{
u8x8.clearDisplay();
refreshed = true;
u8x8.drawString(0, 6, "OTA Upload");
}
uint32_t percent = progress / (total / 100);
u8x8.setCursor(0, 7);
u8x8.printf("%d %%", percent);
u8x8.refreshDisplay(); });
ArduinoOTA.onEnd([]()
{
u8x8.clearDisplay();
u8x8.drawString(0, 6, "OTA-Restart");
u8x8.refreshDisplay(); });
#endif
// Begin OTA updates
ArduinoOTA.begin();
Serial.print("\nOTA-Init done");
// Initialize the web user interface
initWebUI();
Serial.print("\nWebUI-Init done");
// Initialize global variables
initGlobals();
Serial.print("\nglobals-Init done");
// Start cyclic EEPROM updates for Persistence Data Structure (PDS)
EEPROMCyclicPDSTicker.start();
Serial.print("\nSetup Done\n");
}
/**
* @brief Main execution loop for the ESP8266 project, performing various tasks based on configuration.
*
* This loop function handles different tasks based on the configured source of speed data (impulse, CAN, time, GPS).
* It calculates wheel distance, runs the lubrication application, updates the OLED display (if enabled),
* processes CAN messages, handles button input, manages LED behavior, performs EEPROM-related tasks, handles
* webserver operations, processes Diagnostic Trouble Codes (DTC), and manages debugging. Additionally, it
* integrates functionalities such as Over-The-Air (OTA) updates, cyclic EEPROM updates for Persistence Data
* Structure (PDS), WiFi connection maintenance, and system shutdown handling.
*/
void loop()
{
// Variable to store calculated wheel distance
uint32_t wheelDistance = 0;
// Switch based on the configured speed source
switch (LubeConfig.SpeedSource)
{
case SOURCE_IMPULSE:
wheelDistance = Process_Impulse_WheelSpeed();
break;
case SOURCE_CAN:
wheelDistance = Process_CAN_WheelSpeed();
break;
#ifdef FEATURE_ENABLE_TIMER
case SOURCE_TIME:
break;
#endif
case SOURCE_GPS:
wheelDistance = Process_GPS_WheelSpeed();
break;
}
// Run lubrication application with the calculated wheel distance
RunLubeApp(wheelDistance);
#ifdef FEATURE_ENABLE_OLED
// Update OLED display if enabled
Display_Process();
#endif
// Process CAN messages if the speed source is not impulse
if (LubeConfig.SpeedSource != SOURCE_IMPULSE)
{
CAN_Process();
}
// Process button input, manage LED behavior, perform EEPROM tasks, handle webserver operations,
// process Diagnostic Trouble Codes (DTC), and manage debugging
Button_Process();
LED_Process();
EEPROM_Process();
Webserver_Process();
DTC_Process();
Debug_Process();
// Handle OTA updates and update cyclic EEPROM tasks for Persistence Data Structure (PDS)
ArduinoOTA.handle();
EEPROMCyclicPDSTicker.update();
#ifdef FEATURE_ENABLE_WIFI_CLIENT
// Update WiFi connection maintenance ticker if WiFi client feature is enabled
WiFiMaintainConnectionTicker.update();
#endif
// Perform system shutdown if the status is set to shutdown
if (globals.systemStatus == sysStat_Shutdown)
SystemShutdown(false);
// Yield to allow other tasks to run
yield();
}
/**
* @brief Converts an IPAddress object to a String representation.
*
* This function takes an IPAddress object and converts it into a String representing
* the IPv4 address. Each octet of the address is separated by a dot.
*
* @param ipAddress The IPAddress object to be converted.
* @return A String representing the IPv4 address.
*/
String IpAddress2String(const IPAddress &ipAddress)
{
// Concatenate each octet of the IPAddress with dots in between
return String(ipAddress[0]) + String(".") +
String(ipAddress[1]) + String(".") +
String(ipAddress[2]) + String(".") +
String(ipAddress[3]);
}
#ifdef FEATURE_ENABLE_WIFI_CLIENT
/**
* @brief Callback function for maintaining WiFi connection and handling connection failures.
*
* This callback function is used by a ticker to periodically check the WiFi connection status.
* If the device is not connected to WiFi, it counts connection failures. If the number of failures
* exceeds a defined threshold, the function triggers the initiation of an Access Point (AP) mode
* using the `toggleWiFiAP` function.
*/
void wifiMaintainConnectionTicker_callback()
{
// Static variables to track WiFi connection failure count and maximum allowed failures
static uint32_t WiFiFailCount = 0;
const uint32_t WiFiFailMax = 20;
// Check if the device is connected to WiFi
if (wifiMulti.run(connectTimeoutMs) == WL_CONNECTED)
{
return; // Exit if connected
}
else
{
// Increment WiFi connection failure count
if (WiFiFailCount < WiFiFailMax)
{
WiFiFailCount++;
}
else
{
// Trigger AP mode if the maximum failures are reached
Debug_pushMessage("WiFi not connected! - Start AP");
toggleWiFiAP();
}
}
}
#endif
/**
* @brief Callback function for cyclically storing Persistence Data Structure (PDS) to EEPROM.
*
* This callback function is invoked periodically to store the Persistence Data Structure (PDS)
* to the EEPROM. It ensures that essential data is saved persistently, allowing the system to
* recover its state after power cycles or resets.
*/
void EEPROMCyclicPDS_callback()
{
StorePersistence_EEPROM();
}
/**
* @brief Interrupt Service Routine (ISR) triggered by wheel speed sensor pulses.
*
* This ISR is called whenever a pulse is detected from the wheel speed sensor. It increments
* the `wheel_pulse` variable, which is used to track the number of pulses received.
*/
void trigger_ISR()
{
wheel_pulse++;
}
/**
* @brief Manages LED behavior based on the current system status and user overrides.
*
* This function handles LED behavior, including startup animations, confirmation animations for
* normal and rain modes, indication for purge, error, shutdown, and normal operation. It supports
* user overrides to set a specific LED color. The LED status is determined by the current system
* status, and specific LED patterns are displayed accordingly.
*
* @param override Flag indicating whether to override the LED behavior (0: No override, 1: Override, 2: Resume previous state).
* @param SetColor The color to set when overriding the LED behavior.
*/
void LED_Process(uint8_t override, uint32_t SetColor)
{
// Enumeration to represent LED status
typedef enum
{
LED_Startup,
LED_Normal,
LED_Confirm_Normal,
LED_Rain,
LED_Confirm_Rain,
LED_Purge,
LED_Error,
LED_Shutdown,
LED_Override
} tLED_Status;
// Static variables to track LED status, system status, override color, and previous LED status
static tSystem_Status oldSysStatus = sysStat_Startup;
static tLED_Status LED_Status = LED_Startup;
static uint32_t LED_override_color = 0;
static tLED_Status LED_ResumeOverrideStatus = LED_Startup;
// Variables for managing LED animation timing
uint8_t color = 0;
uint32_t timer = 0;
uint32_t animtimer = 0;
static uint32_t timestamp = 0;
timer = millis();
// Handle LED overrides
if (override == 1)
{
if (LED_Status != LED_Override)
{
LED_ResumeOverrideStatus = LED_Status;
Debug_pushMessage("Override LED_Status\n");
}
LED_Status = LED_Override;
LED_override_color = SetColor;
}
if (override == 2)
{
if (LED_Status == LED_Override)
{
LED_Status = LED_ResumeOverrideStatus;
Debug_pushMessage("Resume LED_Status\n");
}
}
// Update LED status when system status changes
if (oldSysStatus != globals.systemStatus)
{
switch (globals.systemStatus)
{
case sysStat_Startup:
LED_Status = LED_Startup;
Debug_pushMessage("sysStat: Startup\n");
break;
case sysStat_Normal:
timestamp = timer + 3500;
LED_Status = LED_Confirm_Normal;
Debug_pushMessage("sysStat: Normal\n");
break;
case sysStat_Rain:
timestamp = timer + 3500;
LED_Status = LED_Confirm_Rain;
Debug_pushMessage("sysStat: Rain\n");
break;
case sysStat_Purge:
LED_Status = LED_Purge;
Debug_pushMessage("sysStat: Purge\n");
break;
case sysStat_Error:
LED_Status = LED_Error;
Debug_pushMessage("sysStat: Error\n");
break;
case sysStat_Shutdown:
LED_Status = LED_Shutdown;
Debug_pushMessage("sysStat: Shutdown\n");
break;
default:
break;
}
oldSysStatus = globals.systemStatus;
}
// Handle different LED statuses
switch (LED_Status)
{
case LED_Startup:
leds.setBrightness(LubeConfig.LED_Max_Brightness);
if (globals.TankPercentage < LubeConfig.TankRemindAtPercentage)
leds.setPixelColor(0, LED_STARTUP_TANKWARN);
else
leds.setPixelColor(0, LED_STARTUP_NORMAL);
break;
case LED_Confirm_Normal:
animtimer = timer % 500;
color = map(animtimer / 2, 0, 250, 0, LubeConfig.LED_Max_Brightness);
leds.setPixelColor(0, LED_NORMAL_COLOR);
if (animtimer < 250)
leds.setBrightness(color);
else
leds.setBrightness(LubeConfig.LED_Max_Brightness - color);
if (timestamp < timer)
{
LED_Status = LED_Normal;
Debug_pushMessage("LED_Status: Confirm -> Normal\n");
}
break;
case LED_Normal:
leds.setBrightness(LubeConfig.LED_Min_Brightness);
leds.setPixelColor(0, LED_NORMAL_COLOR);
if (timer % 2000 > 1950 && LubeConfig.LED_Mode_Flash == true)
leds.setBrightness(LubeConfig.LED_Max_Brightness);
else if (timer % 2000 > 1500 && WiFi.getMode() != WIFI_OFF)
leds.setPixelColor(0, LED_WIFI_BLINK);
break;
case LED_Confirm_Rain:
animtimer = timer % 500;
color = map(animtimer / 2, 0, 250, 0, LubeConfig.LED_Max_Brightness);
leds.setPixelColor(0, LED_RAIN_COLOR);
if (animtimer < 250)
leds.setBrightness(color);
else
leds.setBrightness(LubeConfig.LED_Max_Brightness - color);
if (timestamp < timer)
{
LED_Status = LED_Rain;
Debug_pushMessage("LED_Status: Confirm -> Rain\n");
}
break;
case LED_Rain:
leds.setBrightness(LubeConfig.LED_Min_Brightness);
leds.setPixelColor(0, LED_RAIN_COLOR);
if (timer % 2000 > 1950 && LubeConfig.LED_Mode_Flash == true)
leds.setBrightness(LubeConfig.LED_Max_Brightness);
else if (timer % 2000 > 1500 && WiFi.getMode() != WIFI_OFF)
leds.setPixelColor(0, LED_WIFI_BLINK);
break;
case LED_Purge:
timer = timer % 500;
color = map(timer / 2, 0, 250, LubeConfig.LED_Min_Brightness, LubeConfig.LED_Max_Brightness);
leds.setPixelColor(0, LED_PURGE_COLOR);
if (timer < 250)
leds.setBrightness(color);
else
leds.setBrightness(LubeConfig.LED_Max_Brightness - color);
break;
case LED_Error:
leds.setBrightness(LubeConfig.LED_Max_Brightness);
leds.setPixelColor(0, timer % 500 > 250 ? LED_ERROR_BLINK : 0);
break;
case LED_Shutdown:
timer = timer % 600;
leds.setPixelColor(0, LED_SHUTDOWN_BLINK);
if (timer < 500)
{
color = map(timer, 0, 500, LubeConfig.LED_Max_Brightness, LubeConfig.LED_Min_Brightness);
leds.setBrightness(color);
}
else
{
leds.setBrightness(LubeConfig.LED_Min_Brightness);
}
break;
case LED_Override:
leds.setBrightness(LubeConfig.LED_Max_Brightness);
leds.setPixelColor(0, LED_override_color);
break;
default:
break;
}
leds.show();
}
#ifdef FEATURE_ENABLE_OLED
/**
* @brief Manages the display content based on the current system status and updates the OLED display.
*
* This function handles the content to be displayed on the OLED screen, taking into account the
* current system status. It clears the display and prints relevant information such as system mode,
* remaining lubrication distance, tank level, WiFi status, speed source, and IP address. Additionally,
* it refreshes the OLED display with the updated content.
*/
void Display_Process()
{
// Static variable to track the previous system status
static tSystem_Status oldSysStatus = sysStat_Startup;
// Check if the system status has changed since the last update
if (oldSysStatus != globals.systemStatus)
{
// Clear the display and print the system title when the status changes
u8x8.clearDisplay();
u8x8.drawString(0, 0, "KTM ChainLube V1");
oldSysStatus = globals.systemStatus;
}
// Set the cursor position for displaying information on the OLED screen
u8x8.setCursor(0, 1);
// Calculate remaining lubrication distance based on system mode
uint32_t DistRemain = globals.systemStatus == sysStat_Normal ? LubeConfig.DistancePerLube_Default : LubeConfig.DistancePerLube_Rain;
DistRemain = DistRemain - (PersistenceData.TravelDistance_highRes_mm / 1000);
// Display relevant information on the OLED screen based on system status
u8x8.printf(PSTR("Mode: %10s\n"), globals.systemStatustxt);
if (globals.systemStatus == sysStat_Error)
{
// Display the last Diagnostic Trouble Code (DTC) in case of an error
u8x8.printf(PSTR("last DTC: %6d\n"), getlastDTC(false));
}
else
{
// Display information such as next lubrication distance, tank level, WiFi status, speed source, and IP address
u8x8.printf(PSTR("next Lube: %4dm\n"), DistRemain);
u8x8.printf(PSTR("Tank: %8dml\n"), PersistenceData.tankRemain_microL / 1000);
u8x8.printf(PSTR("WiFi: %10s\n"), (WiFi.getMode() == WIFI_AP ? "AP" : WiFi.getMode() == WIFI_OFF ? "OFF"
: WiFi.getMode() == WIFI_STA ? "CLIENT"
: "UNKNOWN"));
u8x8.printf(PSTR("Source: %8s\n"), SpeedSourceString[LubeConfig.SpeedSource]);
u8x8.printf("%s\n", WiFi.localIP().toString().c_str());
}
// Refresh the OLED display with the updated content
u8x8.refreshDisplay();
}
#endif
/**
* @brief Processes the button input and performs corresponding actions based on button state and timing.
*
* This function handles the button input, detecting button presses and executing actions based on
* predefined time delays. Actions include toggling WiFi, starting purge, toggling operating modes,
* and displaying feedback through LEDs. The function utilizes an enumeration to track button actions
* and manages the timing for different actions.
*/
void Button_Process()
{
// Time delays for different button actions
#define BUTTON_ACTION_DELAY_TOGGLEMODE 500
#define BUTTON_ACTION_DELAY_PURGE 3500
#define BUTTON_ACTION_DELAY_WIFI 6500
#define BUTTON_ACTION_DELAY_NOTHING 9500
// Enumeration to represent button actions
typedef enum buttonAction_e
{
BTN_INACTIVE,
BTN_NOTHING,
BTN_TOGGLEMODE,
BTN_TOGGLEWIFI,
BTN_STARTPURGE
} buttonAction_t;
// Static variables to track button state and timing
static uint32_t buttonTimestamp = 0;
static buttonAction_t buttonAction = BTN_INACTIVE;
// Check if button is pressed (LOW)
if (digitalRead(GPIO_BUTTON) == LOW)
{
// Update button timestamp on the first button press
if (buttonTimestamp == 0)
buttonTimestamp = millis();
// Check and execute actions based on predefined time delays
if (buttonTimestamp + BUTTON_ACTION_DELAY_NOTHING < millis())
{
LED_Process(1, COLOR_WARM_WHITE);
buttonAction = BTN_NOTHING;
}
else if (buttonTimestamp + BUTTON_ACTION_DELAY_WIFI < millis())
{
LED_Process(1, LED_WIFI_BLINK);
buttonAction = BTN_TOGGLEWIFI;
}
else if (buttonTimestamp + BUTTON_ACTION_DELAY_PURGE < millis())
{
LED_Process(1, LED_PURGE_COLOR);
buttonAction = BTN_STARTPURGE;
}
else if (buttonTimestamp + BUTTON_ACTION_DELAY_TOGGLEMODE < millis())
{
uint32_t color = globals.systemStatus == sysStat_Normal ? LED_RAIN_COLOR : LED_NORMAL_COLOR;
LED_Process(1, color);
buttonAction = BTN_TOGGLEMODE;
}
}
else // Button is released
{
// Execute corresponding actions based on the detected button action
if (buttonAction != BTN_INACTIVE)
{
switch (buttonAction)
{
case BTN_TOGGLEWIFI:
toggleWiFiAP();
Debug_pushMessage("Starting WiFi AP\n");
break;
case BTN_STARTPURGE:
globals.systemStatus = sysStat_Purge;
globals.purgePulses = LubeConfig.BleedingPulses;
Debug_pushMessage("Starting Purge\n");
break;
case BTN_TOGGLEMODE:
switch (globals.systemStatus)
{
case sysStat_Normal:
globals.systemStatus = sysStat_Rain;
globals.resumeStatus = sysStat_Rain;
break;
case sysStat_Rain:
globals.systemStatus = sysStat_Normal;
globals.resumeStatus = sysStat_Normal;
break;
default:
break;
}
Debug_pushMessage("Toggling Mode\n");
break;
case BTN_NOTHING:
default:
Debug_pushMessage("Nothing or invalid\n");
break;
}
// Display feedback through LEDs
LED_Process(2);
}
// Reset button state and timestamp
buttonAction = BTN_INACTIVE;
buttonTimestamp = 0;
}
}
/**
* @brief Toggles the WiFi functionality based on the current status.
*
* This function manages the WiFi state, either turning it off or starting it as an Access Point (AP),
* depending on the current mode. If the WiFi is turned off, it can be started in AP mode with the
* device name and password configured. Additionally, it may stop certain operations related to WiFi
* maintenance or display debug messages based on the defined features.
*
* @param shutdown Flag indicating whether the system is in a shutdown state.
*/
void toggleWiFiAP(bool shutdown)
{
// Check if WiFi is currently active
if (WiFi.getMode() != WIFI_OFF)
{
// Turn off WiFi
WiFi.mode(WIFI_OFF);
Debug_pushMessage("WiFi turned off\n");
// Stop WiFi maintenance connection ticker if enabled
#ifdef FEATURE_ENABLE_WIFI_CLIENT
WiFiMaintainConnectionTicker.stop();
#endif
}
else
{
// Start WiFi in Access Point (AP) mode
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0));
WiFi.softAP(globals.DeviceName, QUOTE(WIFI_AP_PASSWORD));
// Stop WiFi maintenance connection ticker if enabled and display debug messages
#ifdef FEATURE_ENABLE_WIFI_CLIENT
WiFiMaintainConnectionTicker.stop();
Debug_pushMessage("WiFi AP started, stopped Maintain-Timer\n");
#else
Debug_pushMessage("WiFi AP started\n");
#endif
}
}
/**
* @brief Performs necessary tasks before shutting down and optionally restarts the ESP.
*
* This function initiates a system shutdown, performing tasks such as storing configuration
* and persistence data to EEPROM before shutting down. If a restart is requested, the ESP
* will be restarted; otherwise, the system will enter an indefinite loop.
*
* @param restart Flag indicating whether to restart the ESP after shutdown (default: false).
*/
void SystemShutdown(bool restart)
{
static uint32_t shutdown_delay = 0;
// Initialize shutdown delay on the first call
if (shutdown_delay == 0)
{
shutdown_delay = millis() + SHUTDOWN_DELAY_MS;
Serial.printf("Shutdown requested - Restarting in %d seconds\n", SHUTDOWN_DELAY_MS / 1000);
}
// Check if the shutdown delay has elapsed
if (shutdown_delay < millis())
{
// Store configuration and persistence data to EEPROM
StoreConfig_EEPROM();
StorePersistence_EEPROM();
// Perform restart if requested, otherwise enter an indefinite loop
if (restart)
ESP.restart();
else
while (1)
;
}
}
/**
* @brief Processes the impulses from the wheel speed sensor and converts them into traveled distance.
*
* This function takes the pulse count from the wheel speed sensor and converts it into distance
* traveled in millimeters. The conversion is based on the configured parameters such as the number
* of pulses per revolution and the distance traveled per revolution.
*
* @return The calculated distance traveled in millimeters.
*/
uint32_t Process_Impulse_WheelSpeed()
{
uint32_t add_milimeters = 0;
// Calculate traveled Distance in mm
if (LubeConfig.PulsePerRevolution != 0)
add_milimeters = (wheel_pulse * (LubeConfig.DistancePerRevolution_mm / LubeConfig.PulsePerRevolution));
if (globals.measurementActive == true)
globals.measuredPulses = globals.measuredPulses + wheel_pulse;
wheel_pulse = 0;
return add_milimeters;
}

View File

@@ -0,0 +1,50 @@
/**
* @file struct2json.cpp
*
* @brief Implementation file for converting structs to JSON objects.
*
* @note This file is auto-generated by a script on 2024-01-10 18:01:52.
*
* @author Marcel Peterkau
* @date 10.01.2024
*/
#include "struct2json.h"
void generateJsonObject_LubeConfig(JsonObject& data)
{
data["EEPROM_Version"] = LubeConfig.EEPROM_Version;
data["DistancePerLube_Default"] = LubeConfig.DistancePerLube_Default;
data["DistancePerLube_Rain"] = LubeConfig.DistancePerLube_Rain;
data["tankCapacity_ml"] = LubeConfig.tankCapacity_ml;
data["amountPerDose_microL"] = LubeConfig.amountPerDose_microL;
data["TankRemindAtPercentage"] = LubeConfig.TankRemindAtPercentage;
data["PulsePerRevolution"] = LubeConfig.PulsePerRevolution;
data["TireWidth_mm"] = LubeConfig.TireWidth_mm;
data["TireWidthHeight_Ratio"] = LubeConfig.TireWidthHeight_Ratio;
data["RimDiameter_Inch"] = LubeConfig.RimDiameter_Inch;
data["DistancePerRevolution_mm"] = LubeConfig.DistancePerRevolution_mm;
data["BleedingPulses"] = LubeConfig.BleedingPulses;
data["SpeedSource"] = LubeConfig.SpeedSource;
data["GPSBaudRate"] = LubeConfig.GPSBaudRate;
data["CANSource"] = LubeConfig.CANSource;
data["LED_Mode_Flash"] = LubeConfig.LED_Mode_Flash;
data["LED_Max_Brightness"] = LubeConfig.LED_Max_Brightness;
data["LED_Min_Brightness"] = LubeConfig.LED_Min_Brightness;
data["checksum"] = LubeConfig.checksum;
}
void generateJsonObject_PersistenceData(JsonObject& data)
{
data["writeCycleCounter"] = PersistenceData.writeCycleCounter;
data["tankRemain_microL"] = PersistenceData.tankRemain_microL;
data["TravelDistance_highRes_mm"] = PersistenceData.TravelDistance_highRes_mm;
data["odometer_mm"] = PersistenceData.odometer_mm;
data["odometer"] = PersistenceData.odometer;
data["checksum"] = PersistenceData.checksum;
}
// CODEGENERATOR_CHECKSUM: 9e8dd21170fd6ef8fbf8c4b156d9af751836a76081f811bf0e3ab2b1eb8ee48c

724
Software/src/webui.cpp Normal file
View File

@@ -0,0 +1,724 @@
/**
* @file webui.cpp
*
* @brief Implementation file for web-based user interface (WebUI) functions in the ChainLube application.
*
* This file contains the implementation of functions related to the initialization and processing of the
* web-based user interface (WebUI). It includes the setup of LittleFS, handling of firmware version checks,
* initialization of mDNS, setup of web server routes, and handling of various HTTP events.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#include "webui.h"
AsyncWebServer webServer(80);
const char *PARAM_MESSAGE = "message";
String processor(const String &var);
void WebserverPOST_Callback(AsyncWebServerRequest *request);
void WebserverNotFound_Callback(AsyncWebServerRequest *request);
void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final);
void WebserverEERestore_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final);
void WebServerEEJSON_Callback(AsyncWebServerRequest *request);
void GetFlashVersion(char *buff, size_t buff_size);
AsyncWebSocket webSocket("/ws");
void WebsocketEvent_Callback(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len);
void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len);
void Websocket_RefreshClientData_DTCs(uint32_t client_id);
void Websocket_RefreshClientData_Status(uint32_t client_id, bool send_mapping = false);
void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping = false);
/**
* @brief Initializes the web-based user interface (WebUI) for the ChainLube application.
*
* This function sets up the necessary components for the WebUI, including mounting LittleFS,
* performing flash version checks, initializing mDNS, and configuring the web server with
* routes and event handlers. If any errors occur during setup, appropriate diagnostic messages
* are pushed to the debugging system, and potential error conditions are recorded as Diagnostic
* Trouble Codes (DTCs).
*
* @note This function should be called during the initialization phase of the application.
*/
void initWebUI()
{
// Attempt to mount LittleFS
if (!LittleFS.begin())
{
Debug_pushMessage("An Error has occurred while mounting LittleFS\n");
MaintainDTC(DTC_FLASHFS_ERROR, true);
return;
}
// Retrieve the flash version
GetFlashVersion(globals.FlashVersion, sizeof(globals.FlashVersion));
// Compare the flash version with the required version
char buffer[6];
snprintf(buffer, sizeof(buffer), "%d.%02d", constants.Required_Flash_Version_major, constants.Required_Flash_Version_minor);
if (strcmp(globals.FlashVersion, buffer))
{
MaintainDTC(DTC_FLASHFS_VERSION_ERROR, true);
}
// Initialize mDNS and add service
MDNS.begin(globals.DeviceName);
MDNS.addService("http", "tcp", 80);
// Set up WebSocket event handler and attach to web server
webSocket.onEvent(WebsocketEvent_Callback);
webServer.addHandler(&webSocket);
// Serve static files and define routes
webServer.serveStatic("/static/", LittleFS, "/static/").setCacheControl("max-age=360000");
webServer.serveStatic("/index.htm", LittleFS, "/index.htm").setCacheControl("max-age=360000");
webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->redirect("/index.htm"); });
webServer.onNotFound(WebserverNotFound_Callback);
webServer.on("/eejson", HTTP_GET, WebServerEEJSON_Callback);
webServer.on(
"/doUpdate", HTTP_POST, [](AsyncWebServerRequest *request) {}, WebserverFirmwareUpdate_Callback);
webServer.on(
"/eeRestore", HTTP_POST, [](AsyncWebServerRequest *request) {}, WebserverEERestore_Callback);
// Start the web server
webServer.begin();
}
/**
* @brief Processes the web server functionality for the ChainLube application.
*
* This function performs periodic processing tasks for the web server, including cleaning up
* WebSocket clients and refreshing client data when WebSocket connections are active. It ensures
* that WebSocket client data related to Diagnostic Trouble Codes (DTCs) and system status is
* updated at regular intervals.
*
* @note This function should be called in the main loop of the application.
*/
void Webserver_Process()
{
static uint32_t previousMillis = 0;
webSocket.cleanupClients();
if ((webSocket.count() > 0) && (millis() - previousMillis >= 10000))
{
Websocket_RefreshClientData_DTCs(0);
Websocket_RefreshClientData_Status(0);
previousMillis = millis();
}
}
void WebserverPOST_Callback(AsyncWebServerRequest *request)
{
request->send(LittleFS, "/post.htm", "text/html", false, processor);
Debug_pushMessage("POST:\n");
int paramsNr = request->params();
for (int i = 0; i < paramsNr; i++)
{
AsyncWebParameter *p = request->getParam(i);
Debug_pushMessage("%s : %s\n", p->name().c_str(), p->value().c_str());
// begin: POST Form Source Changed
if (p->name() == "sourceselect")
{
SpeedSource_t temp = (SpeedSource_t)p->value().toInt();
Debug_pushMessage("temp: %d", temp);
Debug_pushMessage("SpeedSource: %d", LubeConfig.SpeedSource);
if (LubeConfig.SpeedSource != temp)
{
LubeConfig.SpeedSource = temp;
globals.systemStatus = sysStat_Shutdown;
}
}
// end: POST Form Source Changed
// begin: POST Form Source Pulse Settings
if (p->name() == "tirewidth")
LubeConfig.TireWidth_mm = p->value().toInt();
if (p->name() == "tireratio")
LubeConfig.TireWidthHeight_Ratio = p->value().toInt();
if (p->name() == "tiredia")
LubeConfig.RimDiameter_Inch = p->value().toInt();
if (p->name() == "pulserev")
LubeConfig.PulsePerRevolution = p->value().toInt();
if (p->name() == "pulsesave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Source Pulse Settings
// begin: POST Form Source GPS Settings
if (p->name() == "gpsbaud")
LubeConfig.GPSBaudRate = (GPSBaudRate_t)p->value().toInt();
if (p->name() == "gpssave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Source GPS Settings
// begin: POST Form Source CAN Settings
if (p->name() == "cansource")
LubeConfig.CANSource = (CANSource_t)p->value().toInt();
if (p->name() == "cansave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Source CAN Settings
// begin: POST Form Lubrication
if (p->name() == "lubedistancenormal")
LubeConfig.DistancePerLube_Default = p->value().toInt();
if (p->name() == "lubedistancerain")
LubeConfig.DistancePerLube_Rain = p->value().toInt();
if (p->name() == "lubesave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Lubrication
// begin: POST Form Oiltank
if (p->name() == "tankcap")
LubeConfig.tankCapacity_ml = p->value().toInt();
if (p->name() == "tankwarn")
LubeConfig.TankRemindAtPercentage = p->value().toInt();
if (p->name() == "pumppulse")
LubeConfig.amountPerDose_microL = p->value().toInt();
if (p->name() == "oilsave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Oiltank
// begin: POST Form Maintenance
if (p->name() == "purgepulse")
LubeConfig.BleedingPulses = p->value().toInt();
if (p->name() == "maintsave")
globals.requestEEAction = EE_CFG_SAVE;
if (p->name() == "resettank")
{
PersistenceData.tankRemain_microL = LubeConfig.tankCapacity_ml * 1000;
globals.requestEEAction = EE_PDS_SAVE;
}
if (p->name() == "reset_ee_btn")
{
if (request->hasParam("reset_ee_pds", true))
{
AsyncWebParameter *param = request->getParam("reset_ee_pds", true);
if (param->value() == "on")
globals.requestEEAction = globals.requestEEAction == EE_CFG_FORMAT ? EE_FORMAT_ALL : EE_PDS_FORMAT;
}
if (request->hasParam("reset_ee_cfg", true))
{
AsyncWebParameter *param = request->getParam("reset_ee_cfg", true);
if (param->value() == "on")
globals.requestEEAction = globals.requestEEAction == EE_PDS_FORMAT ? EE_FORMAT_ALL : EE_CFG_FORMAT;
}
}
if (p->name() == "purgenow")
{
globals.systemStatus = sysStat_Purge;
globals.purgePulses = LubeConfig.BleedingPulses;
}
if (p->name() == "reboot")
{
globals.systemStatus = sysStat_Shutdown;
}
// end: POST Form Maintenance
// begin: POST Form LED Settings
if (p->name() == "ledmaxbrightness")
LubeConfig.LED_Max_Brightness = p->value().toInt();
if (p->name() == "ledminbrightness")
LubeConfig.LED_Min_Brightness = p->value().toInt();
if (p->name() == "ledsave")
{
if (request->hasParam("ledmodeflash", true))
{
AsyncWebParameter *param = request->getParam("ledmodeflash", true);
if (param->value() == "on")
LubeConfig.LED_Mode_Flash = true;
}
else
{
LubeConfig.LED_Mode_Flash = false;
}
globals.requestEEAction = EE_CFG_SAVE;
}
// end: POST Form LED SEttings
// begin: POST Form Measure Pulses
if (p->name() == "measurereset")
globals.measuredPulses = 0;
if (p->name() == "measurestartstop")
globals.measurementActive = !globals.measurementActive;
// end: POST Form Measure Pulses
}
}
/**
* @brief Callback function for handling HTTP 404 (Not Found) errors on the web server.
*
* This function is invoked when an HTTP request results in a 404 error (Not Found). It sends
* a simple "Not found" text response with an HTTP status code of 404.
*
* @param request Pointer to the AsyncWebServerRequest object representing the HTTP request.
*/
void WebserverNotFound_Callback(AsyncWebServerRequest *request)
{
request->send(404, "text/html", "Not found");
}
/**
* @brief Reads the flash version information from a file in LittleFS.
*
* This function reads the flash version information stored in a file named "version" in the
* LittleFS filesystem. It opens the file, reads the content until a carriage return ('\r') is
* encountered, and stores the result in the provided buffer. The buffer is null-terminated.
*
* @param buff Pointer to the buffer where the flash version information will be stored.
* @param buff_size Size of the buffer.
*/
void GetFlashVersion(char *buff, size_t buff_size)
{
File this_file = LittleFS.open("version", "r");
if (!this_file)
{ // failed to open the file, retrn empty result
buff[0] = '\0';
return;
}
if (this_file.available())
{
int bytes_read;
bytes_read = this_file.readBytesUntil('\r', buff, buff_size - 1);
buff[bytes_read] = '\0';
}
this_file.close();
}
/**
* @brief Callback function for handling firmware updates via the web server.
*
* This function is invoked during the firmware update process when a new firmware file
* is received. It handles the update process using the ESPAsyncHTTPUpdate library. The update
* process involves checking the firmware type, initializing the update, writing data, and finalizing
* the update. If the update is successful, it triggers a system shutdown.
*
* @param request Pointer to the AsyncWebServerRequest object.
* @param filename The name of the file being updated.
* @param index The index of the file being updated.
* @param data Pointer to the data buffer.
* @param len The length of the data buffer.
* @param final Boolean indicating if this is the final chunk of data.
*/
void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final)
{
if (!index)
{
Debug_pushMessage("Update");
size_t content_len = request->contentLength();
int cmd = (filename.indexOf(".fs") > -1) ? U_FS : U_FLASH;
Update.runAsync(true);
if (!Update.begin(content_len, cmd))
{
Update.printError(Serial);
}
}
if (Update.write(data, len) != len)
{
Update.printError(Serial);
}
else
{
Debug_pushMessage("Progress: %d%%\n", (Update.progress() * 100) / Update.size());
}
if (final)
{
AsyncWebServerResponse *response = request->beginResponse(302, "text/plain", "Please wait while the device reboots");
response->addHeader("Refresh", "20");
response->addHeader("Location", "/");
request->send(response);
if (!Update.end(true))
{
Update.printError(Serial);
}
else
{
Debug_pushMessage("Update complete\n");
globals.systemStatus = sysStat_Shutdown;
}
}
}
/**
* @brief Callback function for handling EEPROM restore via the web server.
*
* This function is invoked during the EEPROM restore process when a new EEPROM file
* is received. It handles the restore process by reading the data from the received file,
* deserializing the JSON data, and updating the configuration and persistence data accordingly.
* If the restore is successful, it triggers a system shutdown.
*
* @param request Pointer to the AsyncWebServerRequest object.
* @param filename The name of the file being restored.
* @param index The index of the file being restored.
* @param data Pointer to the data buffer.
* @param len The length of the data buffer.
* @param final Boolean indicating if this is the final chunk of data.
*/
void WebserverEERestore_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final)
{
bool ee_done = false;
static bool validext = false;
static char *buffer = NULL;
static uint32_t read_ptr = 0;
DeserializationError error;
if (!index)
{
validext = (filename.indexOf(".ee.json") > -1);
if (validext)
{
buffer = (char *)malloc(1536);
read_ptr = 0;
if (buffer == NULL)
Debug_pushMessage("malloc() failed for EEPROM-Restore");
}
}
if (buffer != NULL)
{
memcpy(buffer + read_ptr, data, len);
read_ptr = read_ptr + len;
}
if (final)
{
if (buffer != NULL)
{
Serial.print(buffer);
JsonDocument json;
error = deserializeJson(json, buffer);
if (error)
{
Debug_pushMessage("deserializeJson() failed: %s\n", error.f_str());
}
else
{
LubeConfig.DistancePerLube_Default = json["config"]["DistancePerLube_Default"].as<uint32_t>();
LubeConfig.DistancePerLube_Rain = json["config"]["DistancePerLube_Rain"].as<uint32_t>();
LubeConfig.tankCapacity_ml = json["config"]["tankCapacity_ml"].as<uint32_t>();
LubeConfig.amountPerDose_microL = json["config"]["amountPerDose_microL"].as<uint32_t>();
LubeConfig.TankRemindAtPercentage = json["config"]["TankRemindAtPercentage"].as<uint8_t>();
LubeConfig.PulsePerRevolution = json["config"]["PulsePerRevolution"].as<uint8_t>();
LubeConfig.TireWidth_mm = json["config"]["TireWidth_mm"].as<uint32_t>();
LubeConfig.TireWidthHeight_Ratio = json["config"]["TireWidthHeight_Ratio"].as<uint32_t>();
LubeConfig.RimDiameter_Inch = json["config"]["RimDiameter_Inch"].as<uint32_t>();
LubeConfig.DistancePerRevolution_mm = json["config"]["DistancePerRevolution_mm"].as<uint32_t>();
LubeConfig.BleedingPulses = json["config"]["BleedingPulses"].as<uint16_t>();
LubeConfig.SpeedSource = (SpeedSource_t)json["config"]["SpeedSource"].as<int>();
LubeConfig.GPSBaudRate = (GPSBaudRate_t)json["config"]["GPSBaudRate"].as<int>();
LubeConfig.CANSource = (CANSource_t)json["config"]["CANSource"].as<int>();
LubeConfig.LED_Mode_Flash = json["config"]["LED_Mode_Flash"].as<bool>();
LubeConfig.LED_Max_Brightness = json["config"]["LED_Max_Brightness"].as<uint8_t>();
LubeConfig.LED_Min_Brightness = json["config"]["LED_Min_Brightness"].as<uint8_t>();
PersistenceData.writeCycleCounter = json["persis"]["writeCycleCounter"].as<uint16_t>();
PersistenceData.tankRemain_microL = json["persis"]["tankRemain_microL"].as<uint32_t>();
PersistenceData.TravelDistance_highRes_mm = json["persis"]["TravelDistance_highRes_mm"].as<uint32_t>();
PersistenceData.odometer_mm = json["persis"]["odometer_mm"].as<uint32_t>();
PersistenceData.odometer = json["persis"]["odometer"].as<uint32_t>();
PersistenceData.checksum = json["persis"]["checksum"].as<uint32_t>();
ee_done = true;
}
}
free(buffer);
AsyncWebServerResponse *response = request->beginResponse(302, "text/plain", "Please wait while the device reboots");
response->addHeader("Refresh", "20");
response->addHeader("Location", "/");
request->send(response);
if (ee_done)
{
Debug_pushMessage("Update complete");
globals.systemStatus = sysStat_Shutdown;
}
}
}
/**
* @brief Callback function for handling EEPROM JSON request via the web server.
*
* This function is invoked when a request for EEPROM JSON data is received. It constructs a JSON
* response containing information about the firmware, configuration, and persistence data.
*
* @param request Pointer to the AsyncWebServerRequest object.
*/
void WebServerEEJSON_Callback(AsyncWebServerRequest *request)
{
AsyncResponseStream *response = request->beginResponseStream("application/json");
JsonDocument json;
JsonObject info = json.to<JsonObject>();
char buffer[16];
info["DeviceName"] = globals.DeviceName;
sprintf(buffer, "%d.%02d", constants.Required_Flash_Version_major, constants.Required_Flash_Version_minor);
info["FW-Version"] = buffer;
info["FS-Version"] = globals.FlashVersion;
snprintf_P(buffer, sizeof(buffer), "%s", constants.GitHash);
info["Git-Hash"] = buffer;
JsonObject config = json.to<JsonObject>();
generateJsonObject_LubeConfig(config);
JsonObject persis = json.to<JsonObject>();
generateJsonObject_PersistenceData(persis);
JsonObject eepart = json.to<JsonObject>();
sprintf(buffer, "0x%04X", globals.eePersistanceAdress);
eepart["PersistanceAddress"] = buffer;
serializeJsonPretty(json, *response);
response->addHeader("Content-disposition", "attachment; filename=backup.ee.json");
request->send(response);
}
/**
* @brief Callback function for handling WebSocket events.
*
* This function is invoked when events occur in the WebSocket communication, such as client connection,
* disconnection, reception of data, and others. It dispatches the events to the appropriate handlers.
*
* @param server Pointer to the AsyncWebSocket object.
* @param client Pointer to the AsyncWebSocketClient object representing the WebSocket client.
* @param type Type of WebSocket event.
* @param arg Event-specific argument.
* @param data Pointer to the received data (if applicable).
* @param len Length of the received data.
*/
void WebsocketEvent_Callback(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len)
{
switch (type)
{
case WS_EVT_CONNECT:
Debug_pushMessage("WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
Websocket_RefreshClientData_Status(client->id(), true);
Websocket_RefreshClientData_Static(client->id(), true);
Websocket_RefreshClientData_DTCs(client->id());
break;
case WS_EVT_DISCONNECT:
Debug_pushMessage("WebSocket client #%u disconnected\n", client->id());
break;
case WS_EVT_DATA:
Websocket_HandleMessage(arg, data, len);
break;
case WS_EVT_PONG:
case WS_EVT_ERROR:
break;
}
}
/**
* @brief Handles WebSocket messages received from clients.
*
* This function processes WebSocket messages, such as starting or stopping debugging,
* and provides appropriate responses.
*
* @param arg Pointer to the WebSocket frame information.
* @param data Pointer to the received data.
* @param len Length of the received data.
*/
void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len)
{
AwsFrameInfo *info = (AwsFrameInfo *)arg;
if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT)
{
data[len] = 0;
Debug_pushMessage("Got WebSocket Message: %s \n", (char *)data);
if (strcmp((char *)data, "start") == 0)
{
SetDebugportStatus(dbg_Webui, enabled);
}
else if (strcmp((char *)data, "stop") == 0)
{
SetDebugportStatus(dbg_Webui, disabled);
}
else if (strcmp((char *)data, "foo") == 0)
{
Debug_pushMessage("Got WebSocket Message 'foo' from client\n");
}
}
}
/**
* @brief Pushes live debug messages to all WebSocket clients.
*
* This function sends a live debug message to all connected WebSocket clients.
*
* @param Message The debug message to be sent.
*/
void Websocket_PushLiveDebug(String Message)
{
webSocket.textAll("DEBUG:" + Message);
}
/**
* @brief Refreshes client data related to Diagnostic Trouble Codes (DTCs) on WebSocket clients.
*
* This function constructs a DTC-related string and sends it to a specific WebSocket client or
* broadcasts it to all connected WebSocket clients.
*
* @param client_id The ID of the WebSocket client to which the data should be sent. If 0, the data
* will be broadcasted to all connected clients.
*/
void Websocket_RefreshClientData_DTCs(uint32_t client_id)
{
String temp = "DTC:";
// Build DTC-String
if (globals.hasDTC != true)
{
temp.concat(String(DTC_NO_DTC) + ";");
}
else
{
for (uint32_t i = 0; i < MAX_DTC_STORAGE; i++)
{
if (DTCStorage[i].Number < DTC_LAST_DTC)
{
temp.concat(String(DTCStorage[i].timestamp) + ",");
temp.concat(String(DTCStorage[i].Number) + ",");
temp.concat(String(getSeverityForDTC(DTCStorage[i].Number)) + ",");
temp.concat(String(DTCStorage[i].active) + ",");
temp.concat(String(DTCStorage[i].debugVal) + ";");
}
}
}
if (client_id > 0)
{
webSocket.text(client_id, temp);
}
else
{
webSocket.textAll(temp);
}
}
/**
* @brief Refreshes client data related to system status and relevant parameters on WebSocket clients.
*
* This function constructs a status-related string and sends it to a specific WebSocket client or
* broadcasts it to all connected WebSocket clients. It also sends a mapping of the status parameters.
*
* @param client_id The ID of the WebSocket client to which the data should be sent. If 0, the data
* will be broadcasted to all connected clients.
* @param send_mapping Flag indicating whether to send the parameter mapping to the client(s).
*/
void Websocket_RefreshClientData_Status(uint32_t client_id, bool send_mapping)
{
if (send_mapping)
{
const char mapping[] = "MAPPING_STATUS:"
"systemstatus;"
"tankremain;"
"odometer;";
if (client_id > 0)
webSocket.text(client_id, mapping);
else
webSocket.textAll(mapping);
}
String temp = "STATUS:";
temp.concat(String(globals.systemStatustxt) + ";");
temp.concat(String((PersistenceData.tankRemain_microL / 10) / LubeConfig.tankCapacity_ml) + ";");
temp.concat(String(PersistenceData.odometer + (PersistenceData.odometer_mm / 1000)) + ";");
if (client_id > 0)
{
webSocket.text(client_id, temp);
}
else
{
webSocket.textAll(temp);
}
}
/**
* @brief Refreshes client data related to static configuration parameters on WebSocket clients.
*
* This function constructs a static configuration-related string and sends it to a specific WebSocket client or
* broadcasts it to all connected WebSocket clients. It also sends a mapping of the static configuration parameters.
*
* @param client_id The ID of the WebSocket client to which the data should be sent. If 0, the data
* will be broadcasted to all connected clients.
* @param send_mapping Flag indicating whether to send the parameter mapping to the client(s).
*/
void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping)
{
if (send_mapping)
{
const char mapping[] = "MAPPING_STATIC:"
"lubedistancenormal;"
"lubedistancerain;"
"tankcap;"
"pumppulse;"
"tankwarn;"
"pulserev;"
"tirewidth;"
"tireratio;"
"tiredia;"
"sourceselect;"
"gpsbaud;"
"cansource;"
"ledmodeflash;"
"ledmaxbrightness;"
"ledminbrightness;"
"showimpulse;"
"showgps;"
"showcan;"
"bleedingpulses;";
if (client_id > 0)
webSocket.text(client_id, mapping);
else
webSocket.textAll(mapping);
}
String temp = "STATIC:";
temp.concat(String(LubeConfig.DistancePerLube_Default) + ";");
temp.concat(String(LubeConfig.DistancePerLube_Rain) + ";");
temp.concat(String(LubeConfig.tankCapacity_ml) + ";");
temp.concat(String(LubeConfig.amountPerDose_microL) + ";");
temp.concat(String(LubeConfig.TankRemindAtPercentage) + ";");
temp.concat(String(LubeConfig.PulsePerRevolution) + ";");
temp.concat(String(LubeConfig.TireWidth_mm) + ";");
temp.concat(String(LubeConfig.TireWidthHeight_Ratio) + ";");
temp.concat(String(LubeConfig.RimDiameter_Inch) + ";");
temp.concat(String(SpeedSourceString[LubeConfig.SpeedSource]) + ";");
temp.concat(String(GPSBaudRateString[LubeConfig.GPSBaudRate]) + ";");
temp.concat(String(CANSourceString[LubeConfig.CANSource]) + ";");
temp.concat(String(LubeConfig.LED_Mode_Flash == true ? "1" : "0") + ";");
temp.concat(String(LubeConfig.LED_Max_Brightness) + ";");
temp.concat(String(LubeConfig.LED_Min_Brightness) + ";");
temp.concat(String(LubeConfig.SpeedSource == SOURCE_IMPULSE ? "1" : "0") + ";");
temp.concat(String(LubeConfig.SpeedSource == SOURCE_GPS ? "1" : "0") + ";");
temp.concat(String(LubeConfig.SpeedSource == SOURCE_CAN ? "1" : "0") + ";");
temp.concat(String(LubeConfig.BleedingPulses) + ";");
for (uint32_t i = 0; i < SpeedSourceString_Elements; i++)
{
temp.concat(String(SpeedSourceString[i]) + ",");
}
temp.concat(";");
if (client_id > 0)
{
webSocket.text(client_id, temp);
}
else
{
webSocket.textAll(temp);
}
}

11
Software/test/README Normal file
View File

@@ -0,0 +1,11 @@
This directory is intended for PlatformIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html

View File

@@ -0,0 +1,5 @@
[wifi_cred]
admin_password = adminpass
wifi_ap_password = wifiappass
wifi_ssid_client = wifi-ssid
wifi_password_client = wifi-pass