-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfiguration.c
320 lines (262 loc) · 8.16 KB
/
configuration.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
#include <string.h>
/* ----- Local Includes ----------------------------------------------------- */
#include "configuration.h"
#include "electricui.h"
#include "app_task_ids.h"
#include "app_tasks.h"
#include "app_events.h"
#include "app_signals.h"
#include "app_times.h"
#include "app_version.h"
#include "event_subscribe.h"
#include "hal_uuid.h"
typedef struct
{
// Microcontroller info
uint8_t cpu_load; //percentage
uint8_t cpu_clock; //speed in Mhz
} SystemData_t;
typedef struct
{
char build_branch[12];
char build_info[12];
char build_date[12];
char build_time[12];
char build_type[12];
char build_name[12];
} BuildInfo_t;
typedef struct
{
uint8_t id; // index of the task (pseudo priority)
uint8_t ready;
uint8_t queue_used;
uint8_t queue_max;
uint32_t waiting_max;
uint32_t burst_max;
char name[12]; // human readable taskname set during app_tasks setup
} Task_Info_t;
SystemData_t sys_stats;
BuildInfo_t fw_info;
Task_Info_t task_info[TASK_MAX] = { 0 };
float cpu_temp;
char device_nickname[16] = "xsens-mti";
char reset_cause[20] = "No Reset Cause";
uint32_t sensor_status = { 0 };
// IMU data
float pry[3] = { 0 };
float quaternion[4] = { 0 };
float acceleration[3] = { 0 };
float free_acceleration[3] = { 0 };
float rate_of_turn[3] = { 0 };
float magnetics[3] = { 0 };
uint32_t imu_pressure = 0;
float imu_temperature = 0;
eui_message_t ui_variables[] = {
// Higher level system setup information
EUI_CHAR_ARRAY_RO( "name", device_nickname ),
EUI_CHAR_ARRAY_RO( "reset_type", reset_cause ),
EUI_CUSTOM( "sys", sys_stats ),
EUI_CUSTOM( "fwb", fw_info ),
EUI_CUSTOM( "tasks", task_info ),
EUI_FLOAT_ARRAY_RO( "quat", quaternion ),
EUI_FLOAT_ARRAY_RO( "pose", pry ),
EUI_FLOAT_ARRAY_RO( "acc", acceleration ),
EUI_FLOAT_ARRAY_RO( "fracc", free_acceleration ),
EUI_FLOAT_ARRAY_RO( "rot", rate_of_turn ),
EUI_FLOAT_ARRAY_RO( "mag", magnetics ),
EUI_UINT32_RO( "baro", imu_pressure ),
EUI_FLOAT_RO( "temp", imu_temperature ),
EUI_CUSTOM_RO( "ok", sensor_status),
};
/* ----- Public Functions --------------------------------------------------- */
PUBLIC void
configuration_init( void )
{
//perform any setup here if needed
configuration_set_defaults();
// Load settings from flash memory
// configuration_load();
}
/* -------------------------------------------------------------------------- */
PUBLIC void
configuration_set_defaults( void )
{
//set build info to hardcoded values
memset( &fw_info.build_branch, 0, sizeof( fw_info.build_branch ) );
memset( &fw_info.build_info, 0, sizeof( fw_info.build_info ) );
memset( &fw_info.build_date, 0, sizeof( fw_info.build_date ) );
memset( &fw_info.build_time, 0, sizeof( fw_info.build_time ) );
memset( &fw_info.build_type, 0, sizeof( fw_info.build_type ) );
memset( &fw_info.build_name, 0, sizeof( fw_info.build_name ) );
strcpy( (char *)&fw_info.build_branch, ProgramBuildBranch );
strcpy( (char *)&fw_info.build_info, ProgramBuildInfo );
strcpy( (char *)&fw_info.build_date, ProgramBuildDate );
strcpy( (char *)&fw_info.build_time, ProgramBuildTime );
strcpy( (char *)&fw_info.build_type, ProgramBuildType );
strcpy( (char *)&fw_info.build_name, ProgramName );
}
/* -------------------------------------------------------------------------- */
PUBLIC void
configuration_electric_setup( void )
{
EUI_TRACK( ui_variables );
eui_setup_identifier( (char *)HAL_UUID, 12 ); //header byte is 96-bit, therefore 12-bytes
}
PUBLIC void
configuration_eui_callback( uint8_t link, eui_interface_t *interface, uint8_t message )
{
// Provided the callbacks - use this to fire callbacks when a variable changes etc
switch( message )
{
case EUI_CB_TRACKED: {
// UI received a tracked message ID and has completed processing
eui_header_t header = interface->packet.header;
void * payload = interface->packet.data_in;
uint8_t * name_rx = interface->packet.id_in;
// See if the inbound packet name matches our intended variable
if( strcmp( (char *)name_rx, "h" ) == 0 )
{
// got a UI heartbeat
}
break;
}
case EUI_CB_UNTRACKED:
// UI passed in an untracked message ID
break;
case EUI_CB_PARSE_FAIL:
// Inbound message parsing failed, this callback help while debugging
break;
default:
break;
}
}
/* -------------------------------------------------------------------------- */
PUBLIC void
config_set_reset_cause( const char *reset_description )
{
memset( &reset_cause, 0, sizeof( reset_cause ) );
strcpy( (char *)&reset_cause, reset_description );
}
/* -------------------------------------------------------------------------- */
PUBLIC void
config_report_error( char *error_string )
{
// Send the text to the UI for display to user
eui_message_t err_message = { .id = "err",
.type = TYPE_CHAR,
.size = strlen( error_string ),
{ .data = error_string } };
eui_send_untracked( &err_message );
}
/* -------------------------------------------------------------------------- */
// System Statistics and Settings
PUBLIC void
config_set_cpu_load( uint8_t percent )
{
sys_stats.cpu_load = percent;
}
PUBLIC void
config_set_cpu_clock( uint32_t clock )
{
sys_stats.cpu_clock = clock / 1000000; //convert to Mhz
}
PUBLIC void
config_update_task_statistics( void )
{
for( uint8_t id = ( TASK_MAX - 1 ); id > 0; id-- )
{
StateTask *t = app_task_by_id( id );
if( t )
{
task_info[id].id = t->id;
task_info[id].ready = t->ready;
task_info[id].queue_used = t->eventQueue.used;
task_info[id].queue_max = t->eventQueue.max;
task_info[id].waiting_max = t->waiting_max;
task_info[id].burst_max = t->burst_max;
memset( &task_info[id].name, 0, sizeof( task_info[0].name ) );
strcpy( (char *)&task_info[id].name, t->name );
}
}
//app_task_clear_statistics();
}
/* -------------------------------------------------------------------------- */
PUBLIC void
config_set_temp_cpu( float temp )
{
cpu_temp = temp;
}
/* -------------------------------------------------------------------------- */
PUBLIC void
config_update_quaternion( float q0, float q1, float q2, float q3 )
{
quaternion[0] = q0;
quaternion[1] = q1;
quaternion[2] = q2;
quaternion[3] = q3;
eui_send_tracked( "quat" );
}
PUBLIC void
config_update_pry( float p, float r, float y )
{
pry[0] = p;
pry[1] = r;
pry[2] = y;
eui_send_tracked( "pose" );
}
PUBLIC void
config_update_acceleration( float x, float y, float z )
{
acceleration[0] = x;
acceleration[1] = y;
acceleration[2] = z;
eui_send_tracked( "acc" );
}
PUBLIC void
config_update_free_acceleration( float x, float y, float z )
{
free_acceleration[0] = x;
free_acceleration[1] = y;
free_acceleration[2] = z;
eui_send_tracked( "fracc" );
}
PUBLIC void
config_update_rate_of_turn( float x, float y, float z )
{
rate_of_turn[0] = x;
rate_of_turn[1] = y;
rate_of_turn[2] = z;
eui_send_tracked( "rot" );
}
PUBLIC void
config_update_magnetometer( float x, float y, float z )
{
magnetics[0] = x;
magnetics[1] = y;
magnetics[2] = z;
eui_send_tracked( "mag" );
}
PUBLIC void
config_update_pressure( uint32_t pressure )
{
imu_pressure = pressure;
eui_send_tracked( "baro" );
}
PUBLIC void
config_update_imu_temperature( float temp )
{
imu_temperature = temp;
eui_send_tracked( "temp" );
}
PUBLIC void
config_update_imu_status_fields( uint32_t word )
{
// Only send if the status changes
if( sensor_status != word )
{
sensor_status = word;
eui_send_tracked( "ok" );
}
}
/* ----- Private Functions -------------------------------------------------- */
/* ----- End ---------------------------------------------------------------- */