/
bhy2cli_callbacks.c
5436 lines (4410 loc) · 173 KB
/
bhy2cli_callbacks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2cli_callbacks.c
* @brief Source file for the command line utility callbacks
*
*/
#define BHY2CLI_VER_MAJOR "0"
#define BHY2CLI_VER_MINOR "4"
#define BHY2CLI_VER_BUGFIX "9"
#ifdef __STDC_ALLOC_LIB__
#define __STDC_WANT_LIB_EXT2__ 1
#else
#define _POSIX_C_SOURCE 200809L
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <signal.h>
#include <ctype.h>
#include <sys/stat.h>
#include <math.h>
#if defined(PC)
#include <dirent.h>
#endif
#include "coines.h"
#include "bhy2cli_callbacks.h"
#include "common_callbacks.h"
#include "common.h"
#include "parse.h"
#include "verbose.h"
#include "dinject.h"
#include "post_mortem.h"
#define BHY2_ASSERT(x) assert_rslt = x; if (assert_rslt) check_bhy2_api(__LINE__, __FUNCTION__, assert_rslt)
#define BHY2CLI_MAX_STRING_LENGTH UINT16_C(32)
/* Contains all parameters of the of custom virtual sensors
* required for parsing */
typedef struct BHY2_PACKED custom_driver_information
{
char sensor_name[BHY2CLI_MAX_STRING_LENGTH];
uint16_t sensor_payload : 7;
uint16_t sensor_id : 8;
uint16_t is_registered : 1;
char output_formats[BHY2CLI_MAX_STRING_LENGTH];
} custom_driver_information_t;
/* Contains information about klio capabilities and current state, as well as runtime configuration */
static struct
{
uint8_t max_patterns;
uint8_t max_pattern_blob_size;
uint8_t auto_load_pattern_write_index;
uint8_t auto_load_pattern;
}
klio_vars;
static int8_t assert_rslt;
static uint8_t fifo_buffer[2048];
static bool sensors_active[256] = { false };
static bool first_run = true;
/* Added to report the final swim data to mobile APP when swim is disabled */
static struct bhy2_swim_algo_output swim_data;
/* Static global table that contains the payloads of present custom virtual sensors, derived by a parameter read */
static custom_driver_information_t custom_driver_information[(BHY2_SENSOR_ID_CUSTOM_END - BHY2_SENSOR_ID_CUSTOM_START) +
1];
static bool klio_enabled = false;
struct data_inject dinject;
/*!
* @brief To convert string input to int
*/
uint32_t string_to_int(const char *str)
{
char int_str[32] = { 0 };
strncpy(int_str, str, strlen(str));
int_str[strlen(str)] = '\0';
return (uint32_t)strtol(int_str, NULL, 0);
}
static cli_callback_table_t bhy2_cli_callbacks[] = {
{ 0, "", 0, NULL, NULL }, /* Empty characters creates a new line */
{ 'h', "help", 0, help_callback, help_help }, /* Print all available commands */
{ 0, "version", 0, version_callback, version_help }, /* Prints the HW, SW versions and build date*/
{ 'v', "verb", 1, verbose_callback, verb_help }, /* Change verbose of received outputs */
{ 'b', "ramb", 1, ramb_callback, ramb_help }, /* Reset, Load firmware to RAM and boot */
{ 'd', "flb", 1, flb_callback, flb_help }, /* Reset, Load firmware to Flash and boot */
{ 'n', "reset", 0, reset_callback, reset_help }, /* Trigger a soft reset to the sensor */
{ 'a', "addse", 1, addse_callback, addse_help }, /* Add a custom sensor */
{ 'g', "boot", 1, boot_callback, boot_help }, /* Boot from RAM or Flash */
{ 'c', "actse", 1, actse_callback, actse_help }, /* Activate/De-activate a sensor */
{ 0, "schema", 0, schema_callback, schema_help }, /* Get schema information of the loaded sensors */
{ 0, "hexse", 1, hexse_callback, hexse_help }, /* Stream sensor data in hex */
{ 0, "dactse", 0, dactse_callback, dactse_help }, /* Deactivate all the active sensors */
{ 0, "lsactse", 0, lsactse_callback, lsactse_help }, /* List all the active sensors */
{ 0, "dmode", 1, dmode_callback, dmode_help }, /* Switch to Data Injection mode */
{ 0, "dinject", 1, dinject_callback, dinject_help }, /* Compute virtual sensor output from raw IMU data */
{ 'e', "erase", 0, erase_callback, erase_help }, /* Erase the external Flash */
{ 0, "efd", 0, efd_callback, efd_help }, /* Erase the Flash descriptor */
{ 'r', "rd", 1, rd_callback, rd_help }, /* Read registers */
{ 'u', "ram", 1, ram_callback, ram_help }, /* Upload firmware to RAM */
{ 'f', "fl", 1, fl_callback, fl_help }, /* Upload firmware to Flash */
{ 'w', "wr", 1, wr_callback, wr_help }, /* Write registers */
{ 'i', "info", 0, info_callback, info_help }, /* Get information of the state of the device and loaded sensors */
{ 's', "rdp", 1, rdp_callback, rdp_help }, /* Read a parameter */
{ 't', "wrp", 1, wrp_callback, wrp_help }, /* Write a parameter */
{ 'p', "physeninfo", 1, physeninfo_callback, physeninfo_help }, /* Read Physical Sensor Information */
{ 'm', "postm", 1, pm_callback, pm_help }, /* Get Post Mortem Data */
{ 0, "logse", 1, logse_callback, logse_help }, /* Log sensor data in binary */
{ 0, "attlog", 1, attlog_callback, attlog_help }, /* Attach a log file for logging */
{ 0, "detlog", 1, detlog_callback, detlog_help }, /* Detach a log file for logging */
{ 0, "kstatus", 0, kstatus_callback, kstatus_help }, /* Get Klio status */
{ 0, "ksetstate", 4, ksetstate_callback, ksetstate_help }, /* Set Klio state */
{ 0, "kgetstate", 0, kgetstate_callback, kgetstate_help }, /* Get Klio state */
{ 0, "kldpatt", 2, kldpatt_callback, kldpatt_help }, /* Load Klio pattern */
{ 0, "kenpatt", 1, kenpatt_callback, kenpatt_help }, /* Enable Klio pattern */
{ 0, "kdispatt", 1, kdispatt_callback, kdispatt_help }, /* Disable Klio pattern */
{ 0, "kdisapatt", 1, kdisapatt_callback, kdisapatt_help }, /* Disable Klio adaptive pattern */
{ 0, "kswpatt", 1, kswpatt_callback, kswpatt_help }, /* Switch Klio pattern between left/right hand */
{ 0, "kautldpatt", 2, kautldpatt_callback, kautldpatt_help }, /* Auto-load Klio patterns */
{ 0, "kgetparam", 1, kgetparam_callback, kgetparam_help }, /* Get Klio parameters */
{ 0, "ksetparam", 2, ksetparam_callback, ksetparam_help }, /* Set Klio parameters */
{ 0, "ksimscore", 2, ksimscore_callback, ksimscore_help }, /* Get Klio Similarity score */
{ 0, "kmsimscore", 2, kmsimscore_callback, kmsimscore_help }, /* Get Multiple Klio Similarity score */
{ 0, "swim", 3, swim_callback, swim_help }, /* Configure the Swim recognition */
{ 0, "swimver", 0, swimver_callback, swimver_help }, /* Get the Swim Version */
{ 0, "swimgetfreq", 0, swimgetfreq_callback, swimgetfreq_help }, /* Get the Swim frequency */
{ 0, "swimsetfreq", 2, swimsetfreq_callback, swimsetfreq_help }, /* Set the Swim frequency */
{ 0, "swimgetaxes", 0, swimgetaxes_callback, swimgetaxes_help }, /* Get the Swim orientation sensor */
{ 0, "swimsetaxes", 1, swimsetaxes_callback, swimsetaxes_help }, /* Set the Swim orientation sensor */
{ 0, "mtapen", 1, mtapen_callback, mtapen_help }, /* Enable/Disable Multi Tap Sensor */
{ 0, "mtapinfo", 0, mtapinfo_callback, mtapinfo_help }, /* Get Multi Tap Sensor Info */
{ 0, "mtapsetcnfg", 3, mtapsetcnfg_callback, mtapsetcnfg_help }, /* Set the Multi Tap Configuration */
{ 0, "mtapgetcnfg", 0, mtapgetcnfg_callback, mtapgetcnfg_help }, /* Get the Multi Tap Configuration */
{ 0, "accsetfoc", 3, accsetfoc_callback, accsetfoc_help }, /* Set the Accelerometer Fast Offset Calibration */
{ 0, "accgetfoc", 0, accgetfoc_callback, accgetfoc_help }, /* Get the Accelerometer Fast Offset Calibration */
{ 0, "accsetpwm", 1, accsetpwm_callback, accsetpwm_help }, /* Set the Accelerometer Power Mode */
{ 0, "accgetpwm", 0, accgetpwm_callback, accgetpwm_help }, /* Get the Accelerometer Power Mode */
{ 0, "gyrosetfoc", 3, gyrosetfoc_callback, gyrosetfoc_help }, /* Set the Gyroscope Fast Offset Calibration */
{ 0, "gyrogetfoc", 0, gyrogetfoc_callback, gyrogetfoc_help }, /* Get the Gyroscope Fast Offset Calibration */
{ 0, "gyrosetois", 1, gyrosetois_callback, gyrosetois_help }, /* Set the Gyroscope OIS Mode*/
{ 0, "gyrogetois", 0, gyrogetois_callback, gyrogetois_help }, /* Get the Gyroscope OIS Mode*/
{ 0, "gyrosetfs", 1, gyrosetfs_callback, gyrosetfs_help }, /* Set the Gyroscope Fast Startup Mode */
{ 0, "gyrogetfs", 0, gyrogetfs_callback, gyrogetfs_help }, /* Get the Gyroscope Fast Startup Mode*/
{ 0, "gyrosetcrt", 0, gyrosetcrt_callback, gyrosetcrt_help }, /* Set the Gyroscope CRT state*/
{ 0, "gyrogetcrt", 0, gyrogetcrt_callback, gyrogetcrt_help }, /* Get the Gyroscope CRT status*/
{ 0, "gyrosetpwm", 1, gyrosetpwm_callback, gyrosetpwm_help }, /* Set the Gyroscope Power Mode */
{ 0, "gyrogetpwm", 0, gyrogetpwm_callback, gyrogetpwm_help }, /* Get the Gyroscope Power Mode */
{ 0, "gyrosettat", 1, gyrosettat_callback, gyrosettat_help }, /* Set the Gyroscope Timer Auto Trim state*/
{ 0, "gyrogettat", 0, gyrogettat_callback, gyrogettat_help }, /* Get the Gyroscope Timer Auto Trim status*/
{ 0, "wwwsetcnfg", 8, wwwsetcnfg_callback, wwwsetcnfg_help }, /* Set the Wrist Wear Wakeup Configuration */
{ 0, "wwwgetcnfg", 0, wwwgetcnfg_callback, wwwgetcnfg_help }, /* Get the Wrist Wear Wakeup Configuration */
{ 0, "amsetcnfg", 1, amsetcnfg_callback, amsetcnfg_help }, /* Set the Any Motion Configuration */
{ 0, "amgetcnfg", 0, amgetcnfg_callback, amgetcnfg_help }, /* Get the Any Motion Configuration */
{ 0, "nmsetcnfg", 1, nmsetcnfg_callback, nmsetcnfg_help }, /* Set the No Motion Configuration */
{ 0, "nmgetcnfg", 0, nmgetcnfg_callback, nmgetcnfg_help }, /* Get the No Motion Configuration */
{ 0, "wgdsetcnfg", 10, wgdsetcnfg_callback, wgdsetcnfg_help }, /* Set the Wrist Gesture Detection Configuration */
{ 0, "wgdgetcnfg", 0, wgdgetcnfg_callback, wgdgetcnfg_help }, /* Get the Wrist Gesture Detection Configuration */
{ 0, "hmctrig", 0, hmctrig_callback, hmctrig_help }, /* Trigger Head Misalignment Calibration */
{ 0, "hmcsetcnfg", 4, hmcsetcnfg_callback, hmcsetcnfg_help }, /* Set Head Misalignment Configuration */
{ 0, "hmcgetcnfg", 0, hmcgetcnfg_callback, hmcgetcnfg_help }, /* Get Head Misalignment Configuration */
{ 0, "hmcsetdefcnfg", 0, hmcsetdefcnfg_callback, hmcsetdefcnfg_help }, /* Set Default Head Misalignment
* Configuration */
{ 0, "hmcver", 0, hmcver_callback, hmcver_help }, /* Get Head Misalignment Calibrator Version */
{ 0, "hmcsetcalcorrq", 4, hmcsetcalcorrq_callback, hmcsetcalcorrq_help }, /* Set Head Misalignment Quaternion
* Calibration Correction */
{ 0, "hmcgetcalcorrq", 0, hmcgetcalcorrq_callback, hmcgetcalcorrq_help }, /* Get Head Misalignment Quaternion
* Calibration Correction */
{ 0, "hosetheadcorrq", 1, hosetheadcorrq_callback, hosetheadcorrq_help }, /* Get Head Orientation
* Quaternion Initial Head
* Correction */
{ 0, "hogetheadcorrq", 0, hogetheadcorrq_callback, hogetheadcorrq_help }, /* Get Head Orientation
* Quaternion Initial Head
* Correction */
{ 0, "hover", 0, hover_callback, hover_help }, /* Get Head Orientation Version */
{ 0, "hosetheadcorre", 1, hosetheadcorre_callback, hosetheadcorre_help }, /* Get Head Orientation Euler
* Initial Head Correction */
{ 0, "hogetheadcorre", 0, hogetheadcorre_callback, hogetheadcorre_help }, /* Get Head Orientation Euler Initial Head
* Correction */
#ifndef PC
{ 0, "echo", 1, echo_callback, echo_help }, /* Toggle the echo setting */
{ 0, "heart", 1, heartbeat_callback, heartbeat_help }, /* Toggle the heartbeat message setting */
{ 0, "mklog", 1, mklog_callback, mklog_help }, /* Make a log file */
{ 0, "rm", 1, rm_callback, rm_help }, /* Remove a file */
{ 0, "ls", 0, ls_callback, ls_help }, /* List files */
{ 0, "wrfile", 2, wrfile_callback, wrfile_help }, /* Write content to a file */
{ 0, "rdfile", 1, rdfile_callback, rdfile_help }, /* Read content from a file */
{ 0, "slabel", 1, slabel_callback, slabel_help }, /* Write a binary label into the log file */
{ 0, "cls", 0, cls_callback, cls_help }, /* Clear screen */
{ 0, "strbuf", 1, streambuff_callback, streambuff_help }, /* Enable streaming buffer */
#endif
};
static void check_bhy2_api(unsigned int line, const char *func, int8_t val);
static void reset_hub(struct bhy2_dev *bhy2);
static bool upload_to_ram(const char *filepath, struct bhy2_dev *bhy2);
static void print_boot_status(uint8_t boot_status);
static void boot_ram(struct bhy2_dev *bhy2);
static void show_info(struct bhy2_dev *bhy2);
static void boot_flash(struct bhy2_dev *bhy2);
static bool upload_to_flash(const char *filepath, struct bhy2_dev *bhy2);
static void wr_regs(const char *payload, struct bhy2_dev *bhy2);
static void rd_regs(const char *payload, struct bhy2_dev *bhy2);
static void rd_param(const char *payload, struct bhy2_dev *bhy2);
static void wr_param(const char *payload, struct bhy2_dev *bhy2);
static void rd_phy_sensor_info(const char *payload, struct bhy2_dev *bhy2);
static void erase_flash(uint32_t end_addr, struct bhy2_dev *bhy2);
static void activate_sensor(const char *sensor_parameters, uint8_t parse_flag, struct bhy2_cli_ref *ref);
static void parse_custom_sensor_default(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
static void parse_custom_sensor(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
static void add_sensor(const char *payload, struct bhy2_cli_ref *cli_ref);
static void klio_enable(struct bhy2_dev *bhy2);
static void klio_status(struct bhy2_dev *bhy2);
static void klio_set_state(const char *arg1, const char *arg2, const char *arg3, const char *arg4,
struct bhy2_dev *bhy2);
static void klio_get_state(struct bhy2_dev *bhy2);
static void klio_load_pattern(const char *arg1, const char *arg2, struct bhy2_dev *bhy2);
static void klio_get_parameter(const uint8_t *arg, struct bhy2_dev *bhy2);
static void klio_set_parameter(const char *arg1, char *arg2, struct bhy2_dev *bhy2);
static void klio_similarity_score(const uint8_t *arg1, const uint8_t *arg2, struct bhy2_dev *bhy2);
static void klio_similarity_score_multiple(const char *arg1, const char *arg2, struct bhy2_dev *bhy2);
static void klio_pattern_state_operation(const uint8_t enable, const char *arg1, struct bhy2_dev *bhy2);
void parse_klio(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
void parse_klio_log(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
void parse_swim(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
void parse_acc_gyro(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
void parse_multitap(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
void parse_wrist_gesture_detect(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
void parse_air_quality(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
void parse_hmc(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
void parse_oc(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
void parse_ec(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
static void log_data(uint8_t sid, uint64_t tns, uint8_t event_size, uint8_t *event_payload, struct logbin_dev *logdev);
static void write_meta_info(struct logbin_dev *log, struct bhy2_dev *bhy2);
static void stream_hex_data(uint8_t sid, uint32_t ts, uint32_t tns, uint8_t event_size, uint8_t *event_payload);
static void schema_info(struct bhy2_dev *bhy2);
cli_callback_table_t *bhy2_get_cli_callbacks(void)
{
return bhy2_cli_callbacks;
}
uint8_t bhy2_get_n_cli_callbacks(void)
{
return sizeof(bhy2_cli_callbacks) / sizeof(cli_callback_table_t);
}
void bhy2_callbacks_init(struct bhy2_cli_ref *cli_ref)
{
struct bhy2_dev *bhy2 = &cli_ref->bhy2;
uint8_t expected_data;
for (uint8_t i = BHY2_SENSOR_ID_CUSTOM_START;
i <= BHY2_SENSOR_ID_CUSTOM_END; i++)
{
custom_driver_information[i - BHY2_SENSOR_ID_CUSTOM_START].is_registered = 0;
strcpy(custom_driver_information[i - BHY2_SENSOR_ID_CUSTOM_START].sensor_name, "Undefined custom sensor");
}
/* Print Copyright build date */
PRINT("Copyright (c) 2023 Bosch Sensortec GmbH\r\n");
PRINT("Version %s.%s.%s Build date: " __DATE__ "\r\n", BHY2CLI_VER_MAJOR, BHY2CLI_VER_MINOR, BHY2CLI_VER_BUGFIX);
#ifdef BHY2_USE_I2C
BHY2_ASSERT(bhy2_init(BHY2_I2C_INTERFACE, bhy2_i2c_read, bhy2_i2c_write, bhy2_delay_us, BHY2_RD_WR_LEN, NULL,
bhy2));
#else
BHY2_ASSERT(bhy2_init(BHY2_SPI_INTERFACE, bhy2_spi_read, bhy2_spi_write, bhy2_delay_us, BHY2_RD_WR_LEN, NULL,
bhy2));
#endif
/* Install virtual sensor callbacks */
bhy2_install_callbacks(&cli_ref->bhy2, &cli_ref->parse_table);
coines_delay_msec(100); /* Wait for flash firmware to load if applicable */
uint8_t product_id;
BHY2_ASSERT(bhy2_get_product_id(&product_id, bhy2));
if (product_id == BHY2_PRODUCT_ID)
{
uint8_t feat_status;
BHY2_ASSERT(bhy2_get_feature_status(&feat_status, bhy2));
INFO("Device found\r\n");
if (feat_status & BHY2_FEAT_STATUS_OPEN_RTOS_MSK)
{
INFO("RTOS based firmware running\r\n");
BHY2_ASSERT(bhy2_update_virtual_sensor_list(bhy2));
}
}
else
{
ERROR("Device not found, Check connections and power. Product ID read 0x%x\r\n", product_id);
#ifdef PC
exit(1);
#endif
}
/* Config status channel */
BHY2_ASSERT(bhy2_set_host_intf_ctrl(BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL, bhy2));
BHY2_ASSERT(bhy2_get_host_intf_ctrl(&expected_data, bhy2));
if (!(expected_data & BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL))
{
WARNING("Expected Host Interface Control (0x06) to have bit 0x%x to be set\r\n",
BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL);
}
}
bool bhy2_are_sensors_active(void)
{
for (uint16_t i = 0; i < 256; i++)
{
if (sensors_active[i])
{
return true;
}
}
return false;
}
void bhy2_exit(struct bhy2_cli_ref *cli_ref)
{
for (uint16_t i = 0; i < 256; i++)
{
if (sensors_active[i])
{
bhy2_set_virt_sensor_cfg(i, 0.0f, 0, &cli_ref->bhy2);
sensors_active[i] = false;
}
}
if (cli_ref->parse_table.logdev.logfile)
{
fclose(cli_ref->parse_table.logdev.logfile);
cli_ref->parse_table.logdev.logfile = NULL;
memset(cli_ref->parse_table.logdev.logfilename, 0, sizeof(cli_ref->parse_table.logdev.logfilename));
}
}
void bhy2_data_parse_callback(struct bhy2_cli_ref *cli_ref)
{
if (get_interrupt_status())
{
BHY2_ASSERT(bhy2_get_and_process_fifo(fifo_buffer, sizeof(fifo_buffer), &cli_ref->bhy2));
}
}
bhy2_fifo_parse_callback_t bhy2_get_callback(uint8_t sensor_id)
{
bhy2_fifo_parse_callback_t callback = NULL;
switch (sensor_id)
{
case BHY2_SENSOR_ID_ACC:
case BHY2_SENSOR_ID_ACC_WU:
case BHY2_SENSOR_ID_ACC_PASS:
case BHY2_SENSOR_ID_ACC_RAW:
case BHY2_SENSOR_ID_ACC_RAW_WU:
case BHY2_SENSOR_ID_ACC_BIAS:
case BHY2_SENSOR_ID_ACC_BIAS_WU:
case BHY2_SENSOR_ID_GRA:
case BHY2_SENSOR_ID_GRA_WU:
case BHY2_SENSOR_ID_LACC:
case BHY2_SENSOR_ID_LACC_WU:
case BHY2_SENSOR_ID_MAG:
case BHY2_SENSOR_ID_MAG_WU:
case BHY2_SENSOR_ID_MAG_PASS:
case BHY2_SENSOR_ID_MAG_RAW:
case BHY2_SENSOR_ID_MAG_RAW_WU:
case BHY2_SENSOR_ID_MAG_BIAS:
case BHY2_SENSOR_ID_MAG_BIAS_WU:
case BHY2_SENSOR_ID_GYRO:
case BHY2_SENSOR_ID_GYRO_WU:
case BHY2_SENSOR_ID_GYRO_PASS:
case BHY2_SENSOR_ID_GYRO_RAW:
case BHY2_SENSOR_ID_GYRO_RAW_WU:
case BHY2_SENSOR_ID_GYRO_BIAS:
case BHY2_SENSOR_ID_GYRO_BIAS_WU:
callback = parse_3axis_s16;
break;
case BHY2_SENSOR_ID_ORI:
case BHY2_SENSOR_ID_ORI_WU:
callback = parse_euler;
break;
case BHY2_SENSOR_ID_RV:
case BHY2_SENSOR_ID_RV_WU:
case BHY2_SENSOR_ID_GAMERV:
case BHY2_SENSOR_ID_GAMERV_WU:
case BHY2_SENSOR_ID_GEORV:
case BHY2_SENSOR_ID_GEORV_WU:
callback = parse_quaternion;
break;
case BHY2_SENSOR_ID_HUM:
case BHY2_SENSOR_ID_HUM_WU:
callback = parse_scalar_u8;
break;
case BHY2_SENSOR_ID_GAS:
case BHY2_SENSOR_ID_GAS_WU:
callback = parse_scalar_u32;
break;
case BHY2_SENSOR_ID_DEVICE_ORI:
case BHY2_SENSOR_ID_DEVICE_ORI_WU:
callback = parse_device_ori;
break;
case BHY2_SENSOR_ID_TEMP:
case BHY2_SENSOR_ID_TEMP_WU:
callback = parse_s16_as_float;
break;
case BHY2_SENSOR_ID_BARO:
case BHY2_SENSOR_ID_BARO_WU:
callback = parse_u24_as_float;
break;
case BHY2_SENSOR_ID_KLIO:
callback = parse_klio;
break;
case BHY2_SENSOR_ID_KLIO_LOG:
callback = parse_klio_log;
break;
case BHY2_SENSOR_ID_SWIM:
callback = parse_swim;
break;
case BHY2_SENSOR_ID_SI_ACCEL:
case BHY2_SENSOR_ID_SI_GYROS:
callback = parse_acc_gyro;
break;
case BHY2_SENSOR_ID_LIGHT:
case BHY2_SENSOR_ID_LIGHT_WU:
callback = parse_s16_as_float;
break;
case BHY2_SENSOR_ID_PROX:
case BHY2_SENSOR_ID_PROX_WU:
case BHY2_SENSOR_ID_EXCAMERA:
callback = parse_scalar_u8;
break;
case BHY2_SENSOR_ID_STC:
case BHY2_SENSOR_ID_STC_WU:
case BHY2_SENSOR_ID_STC_LP:
case BHY2_SENSOR_ID_STC_LP_WU:
callback = parse_scalar_u32;
break;
case BHY2_SENSOR_ID_SIG:
case BHY2_SENSOR_ID_STD:
case BHY2_SENSOR_ID_STD_WU:
case BHY2_SENSOR_ID_TILT_DETECTOR:
case BHY2_SENSOR_ID_WAKE_GESTURE:
case BHY2_SENSOR_ID_GLANCE_GESTURE:
case BHY2_SENSOR_ID_PICKUP_GESTURE:
case BHY2_SENSOR_ID_SIG_LP:
case BHY2_SENSOR_ID_SIG_LP_WU:
case BHY2_SENSOR_ID_STD_LP:
case BHY2_SENSOR_ID_STD_LP_WU:
case BHY2_SENSOR_ID_WRIST_TILT_GESTURE:
case BHY2_SENSOR_ID_STATIONARY_DET:
case BHY2_SENSOR_ID_ANY_MOTION_LP:
case BHY2_SENSOR_ID_ANY_MOTION_LP_WU:
case BHI3_SENSOR_ID_NO_MOTION_LP_WU:
case BHY2_SENSOR_ID_MOTION_DET:
case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU:
callback = parse_scalar_event;
break;
case BHY2_SENSOR_ID_AR:
case BHI3_SENSOR_ID_AR_WEAR_WU:
callback = parse_activity;
break;
case BHY2_SENSOR_ID_GPS:
callback = parse_gps;
break;
case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU:
callback = parse_wrist_gesture_detect;
break;
case BHI3_SENSOR_ID_MULTI_TAP:
callback = parse_multitap;
break;
case BHY2_SENSOR_ID_AIR_QUALITY:
callback = parse_air_quality;
break;
case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG:
callback = parse_hmc;
break;
case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q:
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q:
callback = parse_oc;
break;
case BHY2_SENSOR_ID_IMU_HEAD_ORI_E:
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E:
callback = parse_ec;
break;
default:
callback = parse_generic;
break;
}
return callback;
}
int8_t kstatus_help(void *ref)
{
PRINT(" kstatus\r\n");
PRINT(" = Get and reset current klio driver status\r\n");
return CLI_OK;
}
int8_t kstatus_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s\r\n", argv[0]);
klio_enable(&cli_ref->bhy2);
klio_status(&cli_ref->bhy2);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t ksetstate_help(void *ref)
{
PRINT(" ksetstate <le> <lr> <re> <rr>\r\n");
PRINT(" = Set klio state\r\n");
PRINT(" <le> learning enable (0/1)\r\n");
PRINT(" <lr> learning reset (0/1)\r\n");
PRINT(" <re> recognition enable (0/1)\r\n");
PRINT(" <rr> recognition reset (0/1)\r\n");
return CLI_OK;
}
int8_t ksetstate_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s %s %s %s\r\n",
(char *)argv[0],
(char *)argv[1],
(char *)argv[2],
(char *)argv[3],
(char *)argv[4]);
klio_enable(&cli_ref->bhy2);
klio_set_state((char *)argv[1], (char *)argv[2], (char *)argv[3], (char *)argv[4], &cli_ref->bhy2);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t kgetstate_help(void *ref)
{
PRINT(" kgetstate\r\n");
PRINT(" = Get current Klio state\r\n");
return CLI_OK;
}
int8_t kldpatt_help(void *ref)
{
PRINT(" kldpatt <index> <pattern>\r\n");
PRINT(" = Load a pattern/adaptive pattern for recognition. If loading an\r\n");
PRINT(" adaptive pattern, a regular pattern must have been previously\r\n");
PRINT(" loaded on the given index\r\n");
PRINT(" <index> pattern index to write to\r\n");
PRINT(" <pattern> pattern/adaptive pattern as bare hex bytestring\r\n");
return CLI_OK;
}
int8_t kenpatt_help(void *ref)
{
PRINT(" kenpatt <patterns>\r\n");
PRINT(" = Enable pattern ids for recognition\r\n");
PRINT(" <patterns> pattern indices to enable, specified as 0,1,4 etc\r\n");
return CLI_OK;
}
int8_t kdispatt_help(void *ref)
{
PRINT(" kdispatt <patterns>\r\n");
PRINT(" = Disable pattern ids for recognition\r\n");
PRINT(" <patterns> pattern indices to disable, specified as 0,1,4 etc\r\n");
return CLI_OK;
}
int8_t kdisapatt_help(void *ref)
{
PRINT(" kdisapatt <patterns>\r\n");
PRINT(" = Disable pattern adaptation for given pattern ids\r\n");
PRINT(" <patterns> pattern indices to disable, specified as 0,1,4 etc\r\n");
return CLI_OK;
}
int8_t kswpatt_help(void *ref)
{
PRINT(" kswpatt <patterns>\r\n");
PRINT(" = Switch pattern between left/right hand\r\n");
PRINT(" <patterns> pattern indices to switch, specified as 0,1,4 etc\r\n");
return CLI_OK;
}
int8_t kautldpatt_help(void *ref)
{
PRINT(" kautldpatt <enable> <index>\r\n");
PRINT(" = Automatically use learnt patterns for recognition\r\n");
PRINT(" <enable> enable or disable (1/0)\r\n");
PRINT(" <index> pattern index to start loading into (normally 0)\r\n");
return CLI_OK;
}
int8_t kgetparam_help(void *ref)
{
PRINT(" kgetparam <param>\r\n");
PRINT(" = Print klio parameter\r\n");
PRINT(" <param> parameter id, see documentation\r\n");
return CLI_OK;
}
int8_t kgetstate_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s\r\n", argv[0]);
klio_enable(&cli_ref->bhy2);
klio_get_state(&cli_ref->bhy2);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t kldpatt_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s\r\n", argv[0], argv[1]);
klio_enable(&cli_ref->bhy2);
klio_load_pattern((char *)argv[1], (char *)argv[2], &cli_ref->bhy2);
PRINT("Loaded pattern %s for recognition\r\n", argv[1]);
return CLI_OK;
}
int8_t kenpatt_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s\r\n", argv[0], argv[1]);
klio_enable(&cli_ref->bhy2);
klio_pattern_state_operation(KLIO_PATTERN_STATE_ENABLE, (char *)argv[1], &cli_ref->bhy2);
PRINT("Enabled pattern %s for recognition\r\n", argv[1]);
return CLI_OK;
}
int8_t kdispatt_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s\r\n", argv[0], argv[1]);
klio_enable(&cli_ref->bhy2);
klio_pattern_state_operation(KLIO_PATTERN_STATE_DISABLE, (char *)argv[1], &cli_ref->bhy2);
PRINT("Disabled pattern %s from recognition\r\n", argv[1]);
return CLI_OK;
}
int8_t kdisapatt_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s\r\n", argv[0], argv[1]);
klio_enable(&cli_ref->bhy2);
klio_pattern_state_operation(KLIO_PATTERN_STATE_AP_DISABLE, (char *)argv[1], &cli_ref->bhy2);
PRINT("Disable adaptation for pattern %s\r\n", argv[1]);
return CLI_OK;
}
int8_t kswpatt_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s\r\n", argv[0], argv[1]);
klio_enable(&cli_ref->bhy2);
klio_pattern_state_operation(KLIO_PATTERN_STATE_SWITCH_HAND, (char *)argv[1], &cli_ref->bhy2);
PRINT("Switched pattern to opposite hand for pattern %s\r\n", argv[1]);
return CLI_OK;
}
int8_t kautldpatt_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s %s\r\n", argv[0], argv[1], argv[2]);
klio_enable(&cli_ref->bhy2);
klio_vars.auto_load_pattern = atoi((char *)argv[1]);
klio_vars.auto_load_pattern_write_index = atoi((char *)argv[2]);
PRINT("Klio auto load pattern %s, starting from index %s\r\n",
(klio_vars.auto_load_pattern == 0) ? "Disabled" : "Enabled",
argv[2]);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t kgetparam_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s\r\n", argv[0], argv[1]);
klio_enable(&cli_ref->bhy2);
klio_get_parameter(argv[1], &cli_ref->bhy2);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t ksetparam_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s %s\r\n", argv[0], argv[1], argv[2]);
klio_enable(&cli_ref->bhy2);
klio_set_parameter((char *)argv[1], (char *)argv[2], &cli_ref->bhy2);
PRINT("Set value %s for parameter id %s\r\n", argv[2], argv[1]);
return CLI_OK;
}
int8_t ksimscore_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s\r\n", argv[0], argv[1], argv[2]);
klio_enable(&cli_ref->bhy2);
klio_similarity_score(argv[1], argv[2], &cli_ref->bhy2);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t kmsimscore_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s\r\n", argv[0], argv[1], argv[2]);
klio_enable(&cli_ref->bhy2);
klio_similarity_score_multiple((const char *)argv[1], (const char *)argv[2], &cli_ref->bhy2);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t ksetparam_help(void *ref)
{
PRINT(" ksetparam <param> <value>\r\n");
PRINT(" = Set klio parameter\r\n");
PRINT(" <param> parameter id, see documentation\r\n");
PRINT(" <value> depends on parameter id, see documentation\r\n");
return CLI_OK;
}
int8_t ksimscore_help(void *ref)
{
PRINT(" ksimscore <pattern1> <pattern2>\r\n");
PRINT(" = Print similarity score for two patterns\r\n");
PRINT(" <pattern1> first pattern as bare hex bytestring\r\n");
PRINT(" <pattern2> second pattern as bare hex bytestring\r\n");
return CLI_OK;
}
int8_t kmsimscore_help(void *ref)
{
PRINT(" kmsimscore <base index> <comparison indices>\r\n");
PRINT(" = Print similarity score for one or more stored patterns\r\n");
PRINT(" <base index> compare the patterns in <comparison indices> with this pattern index\r\n");
PRINT(
" <comparison indices> pattern indices to compare with pattern in base index, specified as 0,1,4 etc\r\n");
return CLI_OK;
}
int8_t version_help(void *ref)
{
PRINT(" version\r\n");
PRINT(" = Prints the version\r\n");
return CLI_OK;
}
int8_t version_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct coines_board_info board_info;
INFO("Executing %s\r\n", argv[0]);
coines_get_board_info(&board_info);
PRINT("HW info:: Board: %u, HW ID: %X, Shuttle ID: %X, SW ID: %X\r\n",
board_info.board,
board_info.hardware_id,
board_info.shuttle_id,
board_info.software_id);
PRINT("SW Version: %s.%s.%s\r\nBuild date: " __DATE__ "\r\n\r\n\r\n",
BHY2CLI_VER_MAJOR,
BHY2CLI_VER_MINOR,
BHY2CLI_VER_BUGFIX);
return CLI_OK;
}
int8_t help_help(void *ref)
{
PRINT("Usage:\r\n");
PRINT("bhy2cli [<options>]\r\n");
PRINT("Options:\r\n");
PRINT(" -h OR help\t= Print this usage message\r\n");
return CLI_OK;
}
int8_t help_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s\r\n", argv[0]);
cli_help(ref, &(cli_ref->cli_dev));
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t info_help(void *ref)
{
PRINT(" -i OR info\t= Show device information: Device ID,\r\n");
PRINT(" \t ROM version, RAM version, Power state,\r\n");
PRINT(" \t list of available sensors,\r\n");
PRINT(" \t content of Boot Status register,\r\n");
PRINT(" \t content of Error value register\r\n");
return CLI_OK;
}
int8_t info_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s\r\n", argv[0]);
show_info(&cli_ref->bhy2);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t ramb_help(void *ref)
{
PRINT(" -b OR ramb <firmware path>\r\n");
PRINT(" \t= Reset, upload specified firmware to RAM and boot from RAM\r\n");
PRINT(" \t [equivalent to using \"reset ram <firmware> boot r\" successively]\r\n");
return CLI_OK;
}
int8_t ramb_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s\r\n", argv[0], argv[1]);
reset_hub(&cli_ref->bhy2);
if (upload_to_ram((char *)argv[1], &cli_ref->bhy2))
{
boot_ram(&cli_ref->bhy2);
bhy2_get_virt_sensor_list(&cli_ref->bhy2);
}
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t flb_help(void *ref)
{
PRINT(" -d OR flb <firmware path>\r\n");
PRINT(" \t= Reset, upload specified firmware to Flash and boot from Flash\r\n");
PRINT(" \t [equivalent to using \"reset fl <firmware path> boot f\" successively]\r\n");
return CLI_OK;
}
int8_t flb_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s %s\r\n", argv[0], argv[1]);
reset_hub(&cli_ref->bhy2);
if (upload_to_flash((char *)argv[1], &cli_ref->bhy2))
{
boot_flash(&cli_ref->bhy2);
bhy2_get_virt_sensor_list(&cli_ref->bhy2);
}
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t reset_help(void *ref)
{
PRINT(" -n OR reset\t= Reset sensor hub\r\n");
return CLI_OK;
}
int8_t reset_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref;
INFO("Executing %s\r\n", argv[0]);
reset_hub(&cli_ref->bhy2);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t addse_help(void *ref)
{
PRINT(" -a OR addse <sensor id>:<sensor name>:<total output payload in bytes>:\r\n");
PRINT(" <output_format_0>:<output_format_1>\r\n");
PRINT(" \t= Register the expected payload of a new custom virtual sensor\r\n");
PRINT(" \t -Valid output_formats: u8: Unsigned 8 Bit, u16: Unsigned 16 Bit, u32:\r\n");
PRINT(" \t Unsigned 32 Bit, s8: Signed 8 Bit, s16: Signed 16 Bit, s32: Signed 32 Bit,\r\n");
PRINT(" \t f: Float, c: Char \r\n");
PRINT(" \t -e.g.: addse 160:\"Lean Orientation\":2:c:c \r\n");
PRINT(" \t -Note that the corresponding virtual sensor has to be enabled in the same function\r\n");
PRINT(" \t call (trailing actse option), since the registration of the sensor is temporary. \r\n");
return CLI_OK;
}
int8_t addse_callback(uint8_t argc, uint8_t *argv[], void *ref)
{
INFO("Executing %s %s\r\n", argv[0], argv[1]);
add_sensor((char *)argv[1], ref);
PRINT("\r\n\r\n");
return CLI_OK;
}
int8_t rd_help(void *ref)
{
PRINT(" -r OR rd <adr>[:<len>]\r\n");
PRINT(" \t= Read from register address <adr> for length <len> bytes\r\n");
PRINT(" \t -If input <len> is not provided, the default read length is 1 byte\r\n");