-
Notifications
You must be signed in to change notification settings - Fork 4
/
bio_demo.c
376 lines (286 loc) · 9.5 KB
/
bio_demo.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
/*---------------------------------------------------------------------------
BSD 3-Clause License
Copyright (c) 2018, feelkit
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* 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.
* 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.
---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Include files */
/*---------------------------------------------------------------------------*/
#include <tcpsupp.h>
#include <analysis.h>
#include <utility.h>
#include <cvirte.h>
#include <userint.h>
#include <ansi_c.h>
#include "bio_demo.h"
#include "serial.h"
#include "regmap_cb.h"
#include "fwup_cb.h"
#include "timer_cb.h"
#include "mmd_comm.h"
#include "local_analysis_cb.h"
#define QUEUE_LENGTH 5000
extern int PPG_handle,ECG_D_handle,PIEZO_handle;
extern int FWUpgrade_handle;
extern int l_analysis_handle;
int hpanel,cfg_handle;
static CmtThreadFunctionID serialThreadFunctionID;
unsigned char funSelectionValue = 0;
h_comm_handle_t h_comm_handle;
/*---------------------------------------------------------------------------*/
/* This is the application's entry-point. */
/*---------------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
h_comm_handle.com_ok =0 ;
h_comm_handle.com_port = 35;
h_comm_handle.s_receiving = 0;
h_comm_handle.tcp_port = 3338;
h_comm_handle.tcp_rdata_sig =0 ;
h_comm_handle.tcp_handle = 0;
h_comm_handle.tcp_ok = 0;
h_comm_handle.t_receiving = 0;
if (InitCVIRTE (0, argv, 0) == 0)
return -1;
if ((hpanel = LoadPanel (0, "bio_demo.uir", PANEL)) < 0)
return -1;
SetCtrlIndex (hpanel, PANEL_LISTBOX_FUNCTION, 0);
SetActiveCtrl (hpanel, PANEL_LISTBOX_FUNCTION);
/* Display the panel and run the UI */
DisplayPanel (hpanel);
/* Create Thread-safe Queue */
if(CmtNewTSQ (QUEUE_LENGTH, sizeof(new_tsq_t), OPT_TSQ_DYNAMIC_SIZE, &h_comm_handle.queueHandle) < 0)
return -1;
installDefaultTSQCb() ;
RunUserInterface ();
/* Free resources and return */
h_comm_handle.s_receiving = 0;
// h_comm_handle.receiving = 0;
if( h_comm_handle.tcp_ok )
DisconnectFromTCPServer (h_comm_handle.tcp_handle);
/* Destroy Thread-safe Queue */
CmtDiscardTSQ (h_comm_handle.queueHandle);
DiscardPanel (hpanel);
CloseCVIRTE ();
return 0;
}
int CVICALLBACK cfgQuitCb (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
{
DiscardPanel (panel);
break;
}
}
return 0;
}
int CVICALLBACK cfgOkCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int ret;
unsigned char port;
switch (event)
{
case EVENT_COMMIT:
{
GetCtrlAttribute(panel, PANEL_CFG_UART_CHKBOX,ATTR_CTRL_VAL,&ret);
if(ret == 1)
{
GetCtrlAttribute(panel, PANEL_CFG_COM,ATTR_CTRL_VAL,&port);
ret = Init_ComPort(port);
if( ret != 0)
{
char msg[120];
h_comm_handle.com_ok = 0 ;
h_comm_handle.com_port = 0;
sprintf (msg, "Config COM port error: %d, please reconfig!!!",ret);
MessagePopup ("This is a Message Popup",msg);
}
else
{
h_comm_handle.com_port = port;
h_comm_handle.com_ok = 1 ;
h_comm_handle.s_receiving = 1;
CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, serial_comm_recv_Thread,(void *)&h_comm_handle, &serialThreadFunctionID);
}
}
GetCtrlAttribute(panel, PANEL_CFG_TCP_CHKBOX,ATTR_CTRL_VAL,&ret);
if(ret == 1)
{
GetCtrlAttribute(panel, PANEL_CFG_TCP_PORT,ATTR_CTRL_VAL,&h_comm_handle.tcp_port);
GetCtrlAttribute(panel, PANEL_CFG_IP,ATTR_CTRL_VAL,h_comm_handle.serverip);
// CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, tcp_comm_recv_Thread,(void *)&h_comm_handle, &tcpThreadFunctionID);
h_comm_connectTcpServer(&h_comm_handle) ;
}
DiscardPanel (panel);
break;
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
/* This function is called whenever any item in the Configuration or Test */
/* menus is selected. Notice that we are passed the menubar handle and item */
/* ID of the selected item. */
/*---------------------------------------------------------------------------*/
void CVICALLBACK MenuConfigPortCb (int menubar, int menuItem,void *callbackData, int panel)
{
switch (menuItem)
{
case MENUBAR_MENU_COM :
cfg_handle = LoadPanel (hpanel, "bio_demo.uir", PANEL_CFG);
if(h_comm_handle.com_port > 0)
{
SetCtrlAttribute(cfg_handle,PANEL_CFG_COM,ATTR_DIMMED,0);
SetCtrlAttribute(cfg_handle,PANEL_CFG_COM,ATTR_CTRL_VAL,h_comm_handle.com_port);
// SetCtrlAttribute(cfg_handle,PANEL_CFG_UART_CHKBOX,ATTR_CTRL_VAL,1);
}
if(h_comm_handle.tcp_port > 0)
{
SetCtrlAttribute(cfg_handle,PANEL_CFG_TCP_PORT,ATTR_DIMMED,0);
SetCtrlAttribute(cfg_handle,PANEL_CFG_TCP_PORT,ATTR_CTRL_VAL,h_comm_handle.tcp_port);
SetCtrlAttribute(cfg_handle,PANEL_CFG_IP,ATTR_DIMMED,0);
// SetCtrlAttribute(cfg_handle,PANEL_CFG_IP,ATTR_CTRL_VAL,h_comm_handle.serverip);
SetCtrlAttribute(cfg_handle,PANEL_CFG_TCP_CHKBOX,ATTR_CTRL_VAL,1);
}
InstallPopup (cfg_handle);
break;
}
}
void CVICALLBACK MenuFirmUpgradeCb (int menubar, int menuItem,
void *callbackData, int panel)
{
unsigned char forSensor;
switch (menuItem)
{
case MENUBAR_MENU_FM_UPGRADE :
if(fwfile_malloc())
{
FWUpgrade_handle = LoadPanel (hpanel, "bio_demo.uir", PANEL_FWUP);
GetCtrlAttribute(FWUpgrade_handle, PANEL_FWUP_FW_SW,ATTR_CTRL_VAL,&forSensor);
uninstallDefaultTSQCb() ;
initFwupCb(forSensor);
InstallPopup (FWUpgrade_handle);
}
else
MessagePopup ("Error !!!","malloc fail!!!!");
break;
}
}
void CVICALLBACK MenuLocalAnalysisCb (int menubar, int menuItem,
void *callbackData, int panel)
{
switch (menuItem)
{
case MENUBAR_MENU_LOCAL_ANALYSIS :
l_analysis_handle = LoadPanel (hpanel, "bio_demo.uir", PANEL_LA);
uninstallDefaultTSQCb() ;
InstallPopup (l_analysis_handle);
break;
}
}
int CVICALLBACK FunctionTestBeginCb(int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
{
if(GetCtrlVal(panel, PANEL_LISTBOX_FUNCTION, &funSelectionValue) == 0)
{
switch(funSelectionValue)
{
case 0:
case 1:
case 2:
case 9:
case 5:
PPG_handle = LoadPanel (hpanel, "bio_demo.uir", PANEL_PPG);
uninstallDefaultTSQCb() ;
InstallPopup (PPG_handle);
break;
case 6:
PIEZO_handle = LoadPanel (hpanel, "bio_demo.uir", PANEL_PZ);
uninstallDefaultTSQCb() ;
InstallPopup (PIEZO_handle);
break;
case 3:
case 4:
ECG_D_handle = LoadPanel (hpanel, "bio_demo.uir", PANEL_ECGD);
uninstallDefaultTSQCb() ;
InstallPopup (ECG_D_handle);
break;
}
}
}
break;
}
return 0;
}
int CVICALLBACK BioSensorOnCb(int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
{
unsigned char val;
GetCtrlVal(panel, control, &val);
h_comm_sendCMD(&h_comm_handle,ON_HSENSOR_COMMAND,val,0,0);
}
break;
}
return 0;
}
/*---------------------------------------------------------------------------*/
/* Quit the UI loop. */
/*---------------------------------------------------------------------------*/
int CVICALLBACK Shutdown (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
if (event == EVENT_COMMIT)
{
// h_comm_handle.receiving = 0;
h_comm_handle.s_receiving = 0;
// uninstallDefaultTSQCb() ;
QuitUserInterface (0);
}
return 0;
}
int CVICALLBACK PanelCB (int panel, int event, void *callbackData,
int eventData1, int eventData2)
{
switch (event)
{
case EVENT_CLOSE:
// tcp_comm_handle.receiving = 0;
h_comm_handle.s_receiving = 0;
// uninstallDefaultTSQCb() ;
QuitUserInterface (0);
break;
}
return 0;
}