-
Notifications
You must be signed in to change notification settings - Fork 0
/
ei_main.cpp
122 lines (104 loc) · 4.22 KB
/
ei_main.cpp
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
/* Edge Impulse ingestion SDK
* Copyright (c) 2021 EdgeImpulse Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* Include ----------------------------------------------------------------- */
// #include "ei_run_classifier.h"
#include "ei_device_ti_launchxl.h"
#include "ei_run_impulse.h"
#include "ei_ti_launchxl_fs_commands.h"
#include "ei_classifier_porting.h"
#include "numpy.hpp"
#include "at_cmds.h"
/* POSIX Header files */
#include <pthread.h>
#include <semaphore.h>
void *ei_command_line_thread(void *arg0)
{
while (1) {
ei_command_line_handle();
}
return NULL;
}
/**
* @brief Init sensors, load config and run command handler
*
* @return int
*/
extern "C" int ei_main() {
ei_printf("Hello from Edge Impulse Device SDK.\r\n"
"Compiled on %s %s\r\n", __DATE__, __TIME__);
if(ei_ti_launchxl_fs_init()) {
ei_printf("ERR: Failed to initialize file system\r\n");
}
/* Intialize configuration */
static ei_config_ctx_t config_ctx = {0};
config_ctx.get_device_id = EiDevice.get_id_function();
config_ctx.set_device_id = EiDevice.set_id_function();
config_ctx.get_device_type = EiDevice.get_type_function();
config_ctx.wifi_connection_status = EiDevice.get_wifi_connection_status_function();
config_ctx.wifi_present = EiDevice.get_wifi_present_status_function();
config_ctx.load_config = &ei_ti_launchxl_fs_load_config;
config_ctx.save_config = &ei_ti_launchxl_fs_save_config;
config_ctx.list_files = NULL;
config_ctx.read_buffer = EiDevice.get_read_sample_buffer_function();
// config_ctx.take_snapshot = &ei_camera_take_snapshot_output_on_serial;
// config_ctx.start_snapshot_stream = &ei_camera_start_snapshot_stream;
EI_CONFIG_ERROR cr = ei_config_init(&config_ctx);
if (cr != EI_CONFIG_OK) {
ei_printf("Failed to initialize configuration (%d)\n", cr);
} else {
ei_printf("Loaded configuration\n");
}
/* Setup the command line commands */
ei_at_register_generic_cmds();
ei_at_cmd_register("RUNIMPULSE", "Run the impulse", run_nn_normal);
ei_at_cmd_register("RUNIMPULSECONT", "Run the impulse", run_nn_continuous_normal);
ei_at_cmd_register("RUNIMPULSEDEBUG", "Run the impulse with extra debug output", run_nn_debug);
ei_printf("Type AT+HELP to see a list of commands.\r\n> ");
EiDevice.set_state(eiStateFinished);
pthread_t thread0;
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
int detachState;
/* Set priority and stack size attributes */
pthread_attr_init(&attrs);
priParam.sched_priority = 1;
detachState = PTHREAD_CREATE_DETACHED;
retc = pthread_attr_setdetachstate(&attrs, detachState);
if (retc != 0) {
/* pthread_attr_setdetachstate() failed */
while (1);
}
pthread_attr_setschedparam(&attrs, &priParam);
retc |= pthread_attr_setstacksize(&attrs, 3072);
if (retc != 0) {
/* pthread_attr_setstacksize() failed */
while (1);
}
/* Create receive thread */
retc = pthread_create(&thread0, &attrs, ei_command_line_thread, NULL);
if (retc != 0) {
/* pthread_create() failed */
while (1);
}
return 0;
}