Browse Source

add checksum verifications

Ondřej Hruška 2 years ago
parent
commit
fcdb66d53a
Signed by: Ondřej Hruška <ondra@ondrovo.com> GPG key ID: 2C5FD5035250423D
1 changed files with 10 additions and 3 deletions
  1. 10 3
      main.c

+ 10 - 3
main.c View File

@@ -59,6 +59,16 @@ void main()
59 59
 	while (1) {
60 60
         last_signal = signal;
61 61
         signal = ow_reset(OW_PIN);
62
+
63
+        if (signal) {
64
+            ow_write(OW_PIN, 0x33);
65
+            ow_read_arr(OW_PIN, addr, 8);
66
+            // check if valid
67
+            if (addr[0] == 0x00 || (crc8(addr, 7) != addr[7])) {
68
+                signal = false;
69
+            }
70
+        }
71
+
62 72
         if (!signal) {
63 73
             if (last_signal) {
64 74
                 lcd_clear();
@@ -70,9 +80,6 @@ void main()
70 80
                 lcd_clear();
71 81
             }
72 82
 
73
-            ow_write(OW_PIN, 0x33);
74
-            ow_read_arr(OW_PIN, addr, 8);
75
-
76 83
             // Show chip type
77 84
             switch (addr[0]) {
78 85
                 case 0x10: