-
Notifications
You must be signed in to change notification settings - Fork 105
/
gnss_atcmd_main.c
751 lines (612 loc) · 18.6 KB
/
gnss_atcmd_main.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
/****************************************************************************
* gnss_atcmd/gnss_atcmd_main.c
*
* Copyright 2018,2019 Sony Semiconductor Solutions Corporation
*
* 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 Sony Semiconductor Solutions Corporation 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 OWNER 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <poll.h>
#include <debug.h>
#include <errno.h>
#include <sched.h>
#include <semaphore.h>
#include <signal.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <termios.h>
#include <arch/chip/gnss.h>
#include "gpsutils/cxd56_gnss_nmea.h"
#if defined(CONFIG_EXAMPLES_GNSS_ATCMD_USB)
#include "gnss_usbserial.h"
#endif /* if defined(CONFIG_EXAMPLES_GNSS_ATCMD_USB) */
#include "gnss_atcmd.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define GNSS_POLL_FD_NUM 2
#define GNSS_POLL_TIMEOUT_FOREVER -1
#define GNSS_SIG_TERM 18
#define GNSS_SIG_SPECTRUM 19
#define GNSS_SIG_DCREPORT 20
#define GNSS_SIG_SARRLM 21
#define CMD_RBUF_SIZE 128
#define READ_FD cmdfds[GNSS_ATCMD_READ_FD]
#define WRITE_FD cmdfds[GNSS_ATCMD_WRITE_FD]
#define _USE_STATIC_NMEA_BUF
#ifdef _DEBUG
#define dbg_printf printf
#else
#define dbg_printf(FMT, ...)
#endif
#if defined(CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM) || \
defined(CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT) || \
defined(CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM)
#define USE_ATCMD_SUB_THREAD
#endif
#ifdef USE_ATCMD_SUB_THREAD
#ifndef CONFIG_EXAMPLES_GNSS_ATCMD_SUB_STACKSIZE
#define CONFIG_EXAMPLES_GNSS_ATCMD_SUB_STACKSIZE 1024
#endif
#ifndef CONFIG_EXAMPLES_GNSS_ATCMD_SUB_PRIORITY
#define CONFIG_EXAMPLES_GNSS_ATCMD_SUB_PRIORITY CONFIG_EXAMPLES_GNSS_ATCMD_PRIORITY
#endif
#endif /* ifdef USE_ATCMD_SUB_THREAD */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_STDINOUT
#define TTYS_NAME "stdin/stdout"
#endif
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_TTYS0
#define TTYS_NAME "/dev/ttyS0"
#endif
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_TTYS1
#define TTYS_NAME "/dev/ttyS1"
#endif
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_TTYS2
#define TTYS_NAME "/dev/ttyS2"
#endif
#ifndef CONFIG_EXAMPLES_GNSS_ATCMD_STDINOUT
#define CONFIG_EXAMPLES_GNSS_ATCMD_CREATE_EMULATOR_PTHREAD
#endif /* ifndef CONFIG_EXAMPLES_GNSS_ATCMD_TTYS */
/****************************************************************************
* Private Types
****************************************************************************/
typedef struct
{
int8_t sing;
uint8_t degree;
uint8_t minute;
uint32_t frac;
} ST_DMS;
/****************************************************************************
* Private Data
****************************************************************************/
static struct gnss_atcmd_info atcmd_info;
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_CREATE_EMULATOR_PTHREAD
static pthread_t atcmd_tid;
#endif /* ifndef CONFIG_EXAMPLES_GNSS_ATCMD_CREATE_EMULATOR_PTHREAD */
static struct cxd56_gnss_positiondata_s posdat;
static int cmdfds[2];
static char cmd_rbuf[CMD_RBUF_SIZE];
#ifdef _USE_STATIC_NMEA_BUF
static char nmea_buf[NMEA_SENTENCE_MAX_LEN];
#endif
#ifdef USE_ATCMD_SUB_THREAD
static sem_t syncsem;
static pthread_t atcmd_sub_tid;
#endif /* ifdef USE_ATCMD_SUB_THREAD */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM
static NMEA_SPECTRUM_DATA spectrumdat;
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT
static struct cxd56_gnss_dcreport_data_s dcreport;
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM
static struct cxd56_gnss_gal_sarrlm_s sarrlm;
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM */
/****************************************************************************
* Private Functions
****************************************************************************/
static int print_nmea(int fd)
{
int ret;
ret = lseek(fd, CXD56_GNSS_READ_OFFSET_LAST_GNSS, SEEK_SET);
if (ret < 0)
{
ret = errno;
printf("lseek error %d\n", ret);
goto _err1;
}
ret = read(fd, &posdat, sizeof(posdat));
if (ret < 0)
{
ret = errno;
printf("read error %d\n", ret);
goto _err1;
}
NMEA_Output(&posdat);
_err1:
return ret;
}
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM
static int print_spectrum(int fd)
{
int ret;
do
{
ret = lseek(fd, CXD56_GNSS_READ_OFFSET_SPECTRUM, SEEK_SET);
if (ret < 0)
{
ret = errno;
printf("lseek error %d\n", ret);
goto _err1;
}
ret = read(fd, &spectrumdat, sizeof(spectrumdat));
if (ret < 0)
{
ret = errno;
printf("read error %d\n", ret);
goto _err1;
}
else if (ret == 0)
{
goto _err1;
}
NMEA_OutputSpectrum(&spectrumdat);
}
while (1);
_err1:
return ret;
}
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT
static int print_dcreport(int fd)
{
int ret;
ret = lseek(fd, CXD56_GNSS_READ_OFFSET_DCREPORT, SEEK_SET);
if (ret < 0)
{
ret = errno;
printf("lseek error %d\n", ret);
goto _err1;
}
ret = read(fd, &dcreport, sizeof(dcreport));
if (ret < 0)
{
ret = errno;
printf("read error %d\n", ret);
goto _err1;
}
NMEA_DcReport_Output(&dcreport);
_err1:
return ret;
}
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM
static int print_sarrlm(int fd)
{
int ret;
ret = lseek(fd, CXD56_GNSS_READ_OFFSET_SARRLM, SEEK_SET);
if (ret < 0)
{
ret = errno;
printf("lseek error %d\n", ret);
goto _err1;
}
ret = read(fd, &sarrlm, sizeof(sarrlm));
if (ret < 0)
{
ret = errno;
printf("read error %d\n", ret);
goto _err1;
}
NMEA_GalSarRlm_Output(&sarrlm);
_err1:
return ret;
}
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM */
/* output NMEA */
FAR static char *reqbuf(uint16_t size)
{
#ifdef _USE_STATIC_NMEA_BUF
if (size > sizeof(nmea_buf))
{
printf("reqbuf error: oversize %d\n", size);
return NULL;
}
return nmea_buf;
#else
return malloc(size);
#endif
}
static void freebuf(FAR char *buf)
{
#ifdef _USE_STATIC_NMEA_BUF
#else
free(buf);
#endif
}
static int outnmea(FAR char *buf)
{
return gnss_atcmd_printf(WRITE_FD, "%s", buf);
}
static int outbin(FAR char *buf, uint32_t len)
{
return write(WRITE_FD, buf, (size_t)len);
}
#ifdef USE_ATCMD_SUB_THREAD
static int set_signal(int fd, int signo, uint8_t gnsssig, bool enable)
{
struct cxd56_gnss_signal_setting_s setting;
setting.fd = fd;
setting.enable = enable;
setting.gnsssig = gnsssig;
setting.signo = signo;
setting.data = NULL;
return ioctl(fd, CXD56_GNSS_IOCTL_SIGNAL_SET, (unsigned long)&setting);
}
static int signal2own(int signo, void *data)
{
int ret;
union sigval value;
value.sival_ptr = data;
ret = sigqueue(getpid(), signo, value);
return ret;
}
#endif /* ifdef USE_ATCMD_SUB_THREAD */
static FAR void atcmd_emulator(FAR void *arg)
{
int fd = -1;
int ret;
int remain;
struct pollfd fds[GNSS_POLL_FD_NUM];
char * bufhead;
NMEA_OUTPUT_CB funcs;
#if !defined(CONFIG_EXAMPLES_GNSS_ATCMD_USB)
struct termios tio;
const speed_t baudRate = B115200;
#endif /* if !defined(CONFIG_EXAMPLES_GNSS_ATCMD_USB) */
/* program start */
printf("Start GNSS_ATCMD!!\n");
fd = open("/dev/gps", O_RDONLY);
if (fd < 0)
{
printf("open error:%d,%d\n", fd, errno);
ret = -ENODEV;
goto _err;
}
/* Init NMEA library */
NMEA_InitMask();
funcs.bufReq = reqbuf;
funcs.out = outnmea;
funcs.outBin = outbin;
funcs.bufFree = freebuf;
NMEA_RegistOutputFunc(&funcs);
#if defined(CONFIG_EXAMPLES_GNSS_ATCMD_USB)
/* Open ttyUSB-CDC */
ret = gnss_usbserial_open(cmdfds);
if (ret < 0)
{
printf("usb open error. %d\n", ret);
goto _err;
}
#else
# if defined(CONFIG_EXAMPLES_GNSS_ATCMD_STDINOUT)
/* Open tty0 using nsh */
cmdfds[GNSS_ATCMD_WRITE_FD] = fileno(stdout);
cmdfds[GNSS_ATCMD_READ_FD] = fileno(stdin);
# else
/* Open tty1/tty2 */
cmdfds[GNSS_ATCMD_WRITE_FD] = cmdfds[GNSS_ATCMD_READ_FD] =
open(TTYS_NAME, O_RDWR);
# endif
ret = errno;
if (cmdfds[GNSS_ATCMD_WRITE_FD] < 0 || cmdfds[GNSS_ATCMD_READ_FD] < 0)
{
printf("%s open error. %d\n", TTYS_NAME, ret);
goto _err;
}
/* Fill the termios struct with the current values. */
tcgetattr(cmdfds[GNSS_ATCMD_READ_FD], &tio);
/* tty: setup parameters */
tio.c_cflag |= CREAD; /* Enable receive */
tio.c_cflag |= CLOCAL; /* Local line, no modem control */
tio.c_cflag &= ~CSIZE; /* Clean the bits */
tio.c_cflag |= CS8; /* Data bit 8bit */
tio.c_cflag &= ~CSTOPB; /* Stop bit 1bit */
tio.c_cflag &= ~PARENB; /* Paritiy none */
cfsetspeed(&tio, baudRate);
/* tty: set to tty device */
tcsetattr(cmdfds[GNSS_ATCMD_READ_FD], TCSANOW, &tio);
#endif
atcmd_info.gnssfd = fd;
atcmd_info.wfd = WRITE_FD;
atcmd_info.rfd = READ_FD;
bufhead = cmd_rbuf;
remain = sizeof(cmd_rbuf);
do
{
int sz;
int n;
#ifdef USE_ATCMD_SUB_THREAD
sem_post(&syncsem);
#endif /* ifdef USE_ATCMD_SUB_THREAD */
memset(fds, 0, sizeof(fds));
fds[0].fd = READ_FD;
fds[0].events = POLLIN;
fds[1].fd = fd;
fds[1].events = POLLIN;
ret = poll(fds, GNSS_POLL_FD_NUM, GNSS_POLL_TIMEOUT_FOREVER);
if (ret <= 0 && errno != EINTR)
{
printf("poll error %d,%d,%lx,%lx\n", ret, errno, fds[0].events,
fds[0].revents);
break;
}
if (fds[1].revents & POLLIN)
{
print_nmea(fd);
}
#ifdef USE_ATCMD_SUB_THREAD
ret = sem_wait(&syncsem);
if (ret < 0)
{
printf("unexpected wait syncsem error%d\n", ret);
goto _err;
}
#endif /* ifdef USE_ATCMD_SUB_THREAD */
if (fds[0].revents & POLLIN)
{
sz = read(READ_FD, bufhead, remain);
if (sz < 0)
{
continue;
}
remain -= sz;
if (remain > 0)
{
for (n = 0; n < sz; n++, bufhead++)
{
if (*bufhead == '\r' || *bufhead == '\n' || *bufhead == '\0')
{
break;
}
}
if (n == sz)
{
continue;
}
sz = bufhead - cmd_rbuf + 1;
}
else
{
sz = sizeof(cmd_rbuf);
bufhead = &cmd_rbuf[sz - 1];
}
*bufhead = '\0';
dbg_printf("# %*s\n", sz, cmd_rbuf);
#ifdef _DEBUG
write(WRITE_FD, cmd_rbuf, sz);
#endif
ret = gnss_atcmd_exec(&atcmd_info, cmd_rbuf, sz);
remain = sizeof(cmd_rbuf);
bufhead = cmd_rbuf;
}
}
while (ret != -ESHUTDOWN);
#ifdef USE_ATCMD_SUB_THREAD
sem_post(&syncsem);
#endif /* ifdef USE_ATCMD_SUB_THREAD */
/* close tty */
#if defined(CONFIG_EXAMPLES_GNSS_ATCMD_USB)
gnss_usbserial_close(cmdfds);
#elif defined(CONFIG_EXAMPLES_GNSS_ATCMD_TTY1) || \
defined(CONFIG_EXAMPLES_GNSS_ATCMD_TTY2)
close(cmdfds[GNSS_ATCMD_READ_FD]);
close(cmdfds[GNSS_ATCMD_WRITE_FD]);
#endif
_err:
#ifdef USE_ATCMD_SUB_THREAD
/* Send signal to sub pthread and force exit it */
signal2own(GNSS_SIG_TERM, NULL);
pthread_join(atcmd_sub_tid, NULL);
sem_destroy(&syncsem);
#endif /* ifdef USE_ATCMD_SUB_THREAD */
/* close GPS device */
if (fd >= 0)
{
ret = close(fd);
if (ret < 0)
{
printf("device close error\n");
}
}
printf("Stop GNSS_ATCMD!!\n");
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_CREATE_EMULATOR_PTHREAD
pthread_detach(pthread_self());
/* This pthread has returned, and exit */
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_CREATE_EMULATOR_PTHREAD */
}
#ifdef USE_ATCMD_SUB_THREAD
static FAR void subthread_handler(FAR void *arg)
{
int ret;
int signo;
sigset_t mask;
ret = sem_wait(&syncsem);
if (ret < 0)
{
printf("unexpected wait syncsem error%d\n", ret);
goto _err;
}
/* Init signal */
sigemptyset(&mask);
sigaddset(&mask, GNSS_SIG_TERM);
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM
ret =
set_signal(atcmd_info.gnssfd, GNSS_SIG_SPECTRUM, CXD56_GNSS_SIG_SPECTRUM, 1);
if (ret < 0)
{
printf("GNSS spectrum signal set error\n");
goto _err;
}
sigaddset(&mask, GNSS_SIG_SPECTRUM);
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT
ret =
set_signal(atcmd_info.gnssfd, GNSS_SIG_DCREPORT, CXD56_GNSS_SIG_DCREPORT, 1);
if (ret < 0)
{
printf("GNSS DC report signal set error\n");
goto _err;
}
sigaddset(&mask, GNSS_SIG_DCREPORT);
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM
ret =
set_signal(atcmd_info.gnssfd, GNSS_SIG_SARRLM, CXD56_GNSS_SIG_SARRLM, 1);
if (ret < 0)
{
printf("GNSS SAR/RLM signal set error\n");
goto _err;
}
sigaddset(&mask, GNSS_SIG_SARRLM);
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM */
sem_post(&syncsem);
do
{
signo = sigwaitinfo(&mask, NULL);
if (signo < 0)
{
continue;
}
else if (signo == GNSS_SIG_TERM)
{
goto _exit;
}
ret = sem_wait(&syncsem);
if (ret < 0)
{
printf("unexpected wait syncsem error%d\n", ret);
goto _exit;
}
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM
if (signo == GNSS_SIG_SPECTRUM)
{
print_spectrum(atcmd_info.gnssfd);
}
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT
if (signo == GNSS_SIG_DCREPORT)
{
print_dcreport(atcmd_info.gnssfd);
}
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM
if (signo == GNSS_SIG_SARRLM)
{
print_sarrlm(atcmd_info.gnssfd);
}
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM */
sem_post(&syncsem);
}
while (1);
_exit:
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SPECRUM
set_signal(atcmd_info.gnssfd, GNSS_SIG_SPECTRUM, CXD56_GNSS_SIG_SPECTRUM, 0);
#endif
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_DCREPORT
set_signal(atcmd_info.gnssfd, GNSS_SIG_DCREPORT, CXD56_GNSS_SIG_DCREPORT, 0);
#endif
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_SUPPORT_SARRLM
set_signal(atcmd_info.gnssfd, GNSS_SIG_SARRLM, CXD56_GNSS_SIG_SARRLM, 0);
#endif
_err:
printf("GNSS exit subthread handler\n");
}
#endif /* ifdef USE_ATCMD_SUB_THREAD */
/****************************************************************************
* gnss_atcmd_main
****************************************************************************/
int main(int argc, FAR char *argv[])
{
pthread_attr_t tattr;
struct sched_param param;
int ret = 0;
#ifdef USE_ATCMD_SUB_THREAD
ret = sem_init(&syncsem, 0, 0);
if (ret < 0)
{
_err("Failed to initialize syncsem!\n");
goto _err;
}
#endif /* ifdef USE_ATCMD_SUB_THREAD */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_CREATE_EMULATOR_PTHREAD
pthread_attr_init(&tattr);
tattr.stacksize = CONFIG_EXAMPLES_GNSS_ATCMD_STACKSIZE;
param.sched_priority = CONFIG_EXAMPLES_GNSS_ATCMD_PRIORITY;
pthread_attr_setschedparam(&tattr, ¶m);
ret = pthread_create(&atcmd_tid, &tattr, (pthread_startroutine_t)atcmd_emulator,
(pthread_addr_t)NULL);
if (ret != 0)
{
ret = -ret; /* pthread_create does not modify errno. */
goto _err;
}
#endif /* ifdef CONFIG_EXAMPLES_GNSS_ATCMD_CREATE_EMULATOR_PTHREAD */
#ifdef USE_ATCMD_SUB_THREAD
pthread_attr_init(&tattr);
tattr.stacksize = CONFIG_EXAMPLES_GNSS_ATCMD_SUB_STACKSIZE;
param.sched_priority = CONFIG_EXAMPLES_GNSS_ATCMD_SUB_PRIORITY;
pthread_attr_setschedparam(&tattr, ¶m);
ret = pthread_create(&atcmd_sub_tid, &tattr, (pthread_startroutine_t)subthread_handler,
(pthread_addr_t)NULL);
if (ret != 0)
{
ret = -ret; /* pthread_create does not modify errno. */
}
#endif /* ifdef USE_ATCMD_SUB_THREAD */
#ifdef CONFIG_EXAMPLES_GNSS_ATCMD_CREATE_EMULATOR_PTHREAD
/* Wait for finishing atcmd thread */
pthread_join(atcmd_tid, NULL);
#else
atcmd_emulator(NULL);
#endif /* ifndef CONFIG_EXAMPLES_GNSS_ATCMD_CREATE_EMULATOR_PTHREAD */
_err:
return ret;
}