Browse Source

test workflow in debug console

Thomas Buck 1 year ago
parent
commit
03daa0ec1e
6 changed files with 135 additions and 20 deletions
  1. 2
    0
      include/config.h
  2. 24
    0
      include/main.h
  3. 5
    5
      src/ble.c
  4. 94
    4
      src/console.c
  5. 2
    4
      src/log.c
  6. 8
    7
      src/main.c

+ 2
- 0
include/config.h View File

@@ -39,4 +39,6 @@
39 39
 #define DISK_BLOCK_COUNT 256
40 40
 #endif // DEBUG_DISK_WRITE_SOURCES
41 41
 
42
+//#define TEST_VOLCANO_AUTO_CONNECT "xx:xx:xx:xx:xx:xx 1"
43
+
42 44
 #endif // __CONFIG_H__

+ 24
- 0
include/main.h View File

@@ -0,0 +1,24 @@
1
+/*
2
+ * main.h
3
+ *
4
+ * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * See <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef __MAIN_H__
20
+#define __MAIN_H__
21
+
22
+void main_loop_hw(void);
23
+
24
+#endif // __MAIN_H__

+ 5
- 5
src/ble.c View File

@@ -243,7 +243,7 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
243 243
             return;
244 244
         }
245 245
         gatt_event_service_query_result_get_service(packet, &services[service_idx].service);
246
-        debug("got service %s result", uuid128_to_str(services[service_idx].service.uuid128));
246
+        //debug("got service %s result", uuid128_to_str(services[service_idx].service.uuid128));
247 247
         break;
248 248
 
249 249
     case GATT_EVENT_CHARACTERISTIC_QUERY_RESULT:
@@ -252,7 +252,7 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
252 252
             return;
253 253
         }
254 254
         gatt_event_characteristic_query_result_get_characteristic(packet, &services[service_idx].chars[characteristic_idx].c);
255
-        debug("got characteristic %s result", uuid128_to_str(services[service_idx].chars[characteristic_idx].c.uuid128));
255
+        //debug("got characteristic %s result", uuid128_to_str(services[service_idx].chars[characteristic_idx].c.uuid128));
256 256
         break;
257 257
 
258 258
     case GATT_EVENT_QUERY_COMPLETE: {
@@ -269,17 +269,17 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
269 269
             break;
270 270
 
271 271
         case TC_W4_SERVICE:
272
-            debug("service %s complete", uuid128_to_str(services[service_idx].service.uuid128));
272
+            //debug("service %s complete", uuid128_to_str(services[service_idx].service.uuid128));
273 273
             state = TC_READY;
274 274
             break;
275 275
 
276 276
         case TC_W4_CHARACTERISTIC:
277
-            debug("characteristic %s complete", uuid128_to_str(services[service_idx].chars[characteristic_idx].c.uuid128));
277
+            //debug("characteristic %s complete", uuid128_to_str(services[service_idx].chars[characteristic_idx].c.uuid128));
278 278
             state = TC_READY;
279 279
             break;
280 280
 
281 281
         case TC_W4_WRITE:
282
-            debug("write complete");
282
+            //debug("write complete");
283 283
             state = TC_WRITE_COMPLETE;
284 284
             break;
285 285
 

+ 94
- 4
src/console.c View File

@@ -18,10 +18,12 @@
18 18
 
19 19
 #include <inttypes.h>
20 20
 #include <string.h>
21
-#include "pico/stdlib.h"
22 21
 #include <unistd.h>
23 22
 #include <stdio.h>
24 23
 
24
+#include "pico/stdlib.h"
25
+#include "hardware/watchdog.h"
26
+
25 27
 #include "config.h"
26 28
 #include "log.h"
27 29
 #include "util.h"
@@ -36,12 +38,11 @@
36 38
 #include "image.h"
37 39
 #include "volcano.h"
38 40
 #include "serial.h"
41
+#include "main.h"
39 42
 
40
-#define CNSL_BUFF_SIZE 1024
43
+#define CNSL_BUFF_SIZE 64
41 44
 #define CNSL_REPEAT_MS 500
42 45
 
43
-//#define TEST_VOLCANO_AUTO_CONNECT "xx:xx:xx:xx:xx:xx 1"
44
-
45 46
 #define VOLCANO_AUTO_CONNECT {                                    \
46 47
     ble_scan(BLE_SCAN_OFF);                                       \
47 48
     bd_addr_t addr;                                               \
@@ -112,6 +113,7 @@ static void cnsl_interpret(const char *line) {
112 113
         println(" vwtt X - Volcano write target temperature");
113 114
         println("  vwh X - Set heater to 1 or 0");
114 115
         println("  vwp X - Set heater to 1 or 0");
116
+        println("     vt - Run a hard-coded test workflow");
115 117
         println("");
116 118
         println("Press Enter with no input to repeat last command.");
117 119
         println("Use repeat to continuously execute last command.");
@@ -306,6 +308,94 @@ static void cnsl_interpret(const char *line) {
306 308
                 println("success");
307 309
             }
308 310
         }
311
+    } else if (strcmp(line, "vt") == 0) {
312
+#ifdef TEST_VOLCANO_AUTO_CONNECT
313
+        VOLCANO_AUTO_CONNECT
314
+#endif // TEST_VOLCANO_AUTO_CONNECT
315
+
316
+        println("init workflow test");
317
+        volcano_set_pump_state(false);
318
+        volcano_set_heater_state(false);
319
+        volcano_set_target_temp(1850);
320
+        volcano_set_heater_state(true);
321
+
322
+        println("wait for 185");
323
+        while (volcano_get_current_temp() < 1840) {
324
+            main_loop_hw();
325
+        }
326
+
327
+        println("wait for 10s");
328
+        uint32_t start = to_ms_since_boot(get_absolute_time());
329
+        while ((to_ms_since_boot(get_absolute_time()) - start) < (10 * 1000)) {
330
+            main_loop_hw();
331
+        }
332
+
333
+        println("pumping");
334
+        volcano_set_pump_state(true);
335
+
336
+        println("wait for 10s");
337
+        start = to_ms_since_boot(get_absolute_time());
338
+        while ((to_ms_since_boot(get_absolute_time()) - start) < (10 * 1000)) {
339
+            main_loop_hw();
340
+        }
341
+
342
+        println("step done");
343
+        volcano_set_pump_state(false);
344
+        volcano_set_target_temp(1950);
345
+
346
+        println("wait for 195");
347
+        while (volcano_get_current_temp() < 1940) {
348
+            main_loop_hw();
349
+        }
350
+
351
+        println("wait for 5s");
352
+        start = to_ms_since_boot(get_absolute_time());
353
+        while ((to_ms_since_boot(get_absolute_time()) - start) < (5 * 1000)) {
354
+            main_loop_hw();
355
+        }
356
+
357
+        println("pumping");
358
+        volcano_set_pump_state(true);
359
+
360
+        println("wait for 20s");
361
+        start = to_ms_since_boot(get_absolute_time());
362
+        while ((to_ms_since_boot(get_absolute_time()) - start) < (20 * 1000)) {
363
+            main_loop_hw();
364
+        }
365
+
366
+        println("step done");
367
+        volcano_set_pump_state(false);
368
+        volcano_set_target_temp(2050);
369
+
370
+        println("wait for 205");
371
+        while (volcano_get_current_temp() < 2040) {
372
+            main_loop_hw();
373
+        }
374
+
375
+        println("wait for 5s");
376
+        start = to_ms_since_boot(get_absolute_time());
377
+        while ((to_ms_since_boot(get_absolute_time()) - start) < (5 * 1000)) {
378
+            main_loop_hw();
379
+        }
380
+
381
+        println("pumping");
382
+        volcano_set_pump_state(true);
383
+
384
+        println("wait for 20s");
385
+        start = to_ms_since_boot(get_absolute_time());
386
+        while ((to_ms_since_boot(get_absolute_time()) - start) < (20 * 1000)) {
387
+            main_loop_hw();
388
+        }
389
+
390
+        println("turning off");
391
+        volcano_set_pump_state(false);
392
+        volcano_set_heater_state(false);
393
+
394
+        println("done");
395
+
396
+#ifdef TEST_VOLCANO_AUTO_CONNECT
397
+        ble_disconnect();
398
+#endif // TEST_VOLCANO_AUTO_CONNECT
309 399
     } else {
310 400
         println("unknown command \"%s\"", line);
311 401
     }

+ 2
- 4
src/log.c View File

@@ -22,7 +22,7 @@
22 22
 #include "ff.h"
23 23
 
24 24
 #include "config.h"
25
-#include "usb.h"
25
+#include "main.h"
26 26
 #include "usb_cdc.h"
27 27
 #include "serial.h"
28 28
 #include "ring.h"
@@ -134,9 +134,7 @@ void debug_wait_input(const char *format, ...) {
134 134
     serial_set_reroute(true);
135 135
 
136 136
     while (!got_input) {
137
-        watchdog_update();
138
-        usb_run();
139
-        serial_run();
137
+        main_loop_hw();
140 138
     }
141 139
 
142 140
     usb_cdc_set_reroute(false);

+ 8
- 7
src/main.c View File

@@ -36,6 +36,13 @@
36 36
 #include "state.h"
37 37
 #include "serial.h"
38 38
 
39
+void main_loop_hw(void) {
40
+    watchdog_update();
41
+    usb_run();
42
+    serial_run();
43
+    heartbeat_run();
44
+}
45
+
39 46
 int main(void) {
40 47
     // required for debug console
41 48
     cnsl_init();
@@ -90,15 +97,9 @@ int main(void) {
90 97
     state_switch(STATE_SCAN);
91 98
 
92 99
     while (1) {
93
-        watchdog_update();
94
-
95
-        heartbeat_run();
100
+        main_loop_hw();
96 101
         buttons_run();
97
-
98
-        usb_run();
99
-        serial_run();
100 102
         cnsl_run();
101
-
102 103
         battery_run();
103 104
         state_run();
104 105
     }

Loading…
Cancel
Save