-
Notifications
You must be signed in to change notification settings - Fork 0
/
SensorTask.c
844 lines (551 loc) · 19.3 KB
/
SensorTask.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
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <string.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Clock.h>
/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/I2C.h>
#include <ti/drivers/UART.h>
#include <ti/drivers/ADC.h>
#include <ti/drivers/NVS.h>
#include <ti/drivers/Watchdog.h>
#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(driverlib/cpu.h)
#include DeviceFamily_constructPath(driverlib/sys_ctrl.h)
#include DeviceFamily_constructPath(driverlib/aon_batmon.h)
#include <ti/devices/cc13x0/driverlib/aux_adc.h>
/* Board Header files */
#include "Board.h"
/* Application Header files */
#include "SensorTask.h"
#include "Protocol.h"
#include "quectel_gps.h"
#include "ms560702ba03.h"
#define SENSOR_TASK_STACK_SIZE 1024
#define SENSOR_TASK_TASK_PRIORITY 3
#define SENSOR_EVENT_ALL 0xFFFFFFFF
#define BV(n) (1 << (n))
#define TIMER_TIMEOUT 1000
#define LSM6DSL_ADDRESS 0x6A
#define ON_OFF_WAIT_COUNT 3
#define ACCEL_SCALE_VALUE 0.06103701895f
#define GYRO_SCALE_VALUE 0.00875f
const PIN_Config sensorTaskPinTable[] = { LED_RED_GPIO | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
LED_BLUE_GPIO | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
BAT_EN_GPIO | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
GPS_POWER_EN_GPIO | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
HALL_SENSOR_GPIO | PIN_INPUT_EN | PIN_NOPULL,
PIN_TERMINATE
};
static PIN_Handle sensorTaskPinHandle;
static PIN_State sensorTaskPinState;
static ADC_Handle adc;
static ADC_Params ADCParams;
static UART_Handle uart;
static char uart_input_buf = 0x00;
static I2C_Handle i2c;
static I2C_Params i2cParams;
static Task_Params sensorTaskParams;
Task_Struct sensorTask; /* not static so you can see in ROV */
static uint8_t sensorTaskStack[SENSOR_TASK_STACK_SIZE];
Event_Struct sensorTaskEvent; /* not static so you can see in ROV */
static Event_Handle sensorTaskEventHandle;
Clock_Struct sensorTimerClock;
Watchdog_Handle watchdogHandle;
static quectel_gps_data_t quectel_gps_data;
static PacketSendRequestCallback packetSendRequestCallback;
static volatile uint8_t on_off_mode = 0x01;
static volatile uint8_t start_gps_state = 0x00;
static volatile uint8_t start_radio_tx_state = 0x00;
static uint8_t payload_buffer_size = 0;
static uint8_t payload_buffer[115] = { 0x00 };
static uint8_t battery_voltage = 0;
static int16_t max_ax = 0;
static int16_t max_ay = 0;
static int16_t max_az = 0;
static int16_t max_gx = 0;
static int16_t max_gy = 0;
static int16_t max_gz = 0;
static int16_t temperature = 0;
static int32_t air_pressure = 0;
static uint8_t HDOP = 0;
static int32_t latitude = 0;
static int32_t longitude = 0;
extern uint8_t radio_init;
extern uint8_t mac_address[8];
extern uint32_t collection_cycle_timeout_count;
extern uint32_t collection_cycle_timer_count;
static void uartReadCallback(UART_Handle handle, void *rxBuf, size_t size);
static void wait_ms(uint32_t wait)
{
Task_sleep(wait * 1000 / Clock_tickPeriod);
}
void scCtrlReadyCallback(void)
{
}
void scTaskAlertCallback(void)
{
}
void watchdogCallback(uintptr_t watchdogHandle)
{
while (1)
{
}
}
static void sensorTimerClockCallBack(UArg arg0)
{
collection_cycle_timeout_count++;
if (on_off_mode == 0x01)
{
if (collection_cycle_timer_count - GPS_COLLECTION_CYCLE_TIMEOUT
== collection_cycle_timeout_count)
{
start_gps_state = 0x01;
}
if (collection_cycle_timeout_count >= collection_cycle_timer_count)
{
start_radio_tx_state = 0x01;
collection_cycle_timeout_count = 0;
}
}
else
{
collection_cycle_timeout_count = 0;
}
}
static void initErrorUpdate(void)
{
for (uint8_t i = 0; i < 4; i++)
{
PIN_setOutputValue(sensorTaskPinHandle, LED_RED_GPIO,
!PIN_getOutputValue(LED_RED_GPIO));
PIN_setOutputValue(sensorTaskPinHandle, LED_BLUE_GPIO,
!PIN_getOutputValue(LED_BLUE_GPIO));
wait_ms(500);
}
PIN_setOutputValue(sensorTaskPinHandle, LED_RED_GPIO, 0);
PIN_setOutputValue(sensorTaskPinHandle, LED_BLUE_GPIO, 0);
}
static uint8_t init_lsm6dsl()
{
uint8_t i2c_state = 0x01;
uint8_t txBuffer[2] = { 0x00 };
uint8_t rxBuffer[6] = { 0x00 };
I2C_Transaction i2cTransaction;
I2C_init();
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C0, &i2cParams);
if (i2c == NULL)
{
SysCtrlSystemReset();
}
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 0;
//Check LSM6DSL Address
i2cTransaction.slaveAddress = LSM6DSL_ADDRESS;
i2cTransaction.writeCount = 1;
txBuffer[0] = 0x01;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//SW Reset
i2cTransaction.writeCount = 2;
txBuffer[0] = 0x12;
txBuffer[1] = 0x01;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//Sleep 200ms
wait_ms(500);
//CTRLS3_C BDU Enable & IF_INS Enable Setting
txBuffer[0] = 0x12;
txBuffer[1] = 0x44;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//FIFO_CTRL5 FIFO Disable Setting
txBuffer[0] = 0x0A;
txBuffer[1] = 0x00;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//CTRL_6 Disable XL_HM_MODE Setting
txBuffer[0] = 0x15;
txBuffer[1] = 0b00010000;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//CTRL8_XL
txBuffer[0] = 0x17;
txBuffer[1] = 0x00;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//CTRL4_C
txBuffer[0] = 0x13;
txBuffer[1] = 0x00;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//CTRL1_XL Accel ODR Setting 12.5Hz & 2G
txBuffer[0] = 0x10;
txBuffer[1] = 0b00010000;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//CTRL7_G Gyro HM_MODE Disable Setting
txBuffer[0] = 0x16;
txBuffer[1] = 0b10000000;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//CTRL2_G Gyro ODR Setting 12.5Hz * 250dps
txBuffer[0] = 0x11;
txBuffer[1] = 0x10; // Gyro 0x00 Off / 0x10 On
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
//Sleep 200ms
wait_ms(200);
return i2c_state;
}
static uint8_t update_lsm6dsl(int16_t *ax, int16_t *ay, int16_t *az,
int16_t *gx, int16_t *gy, int16_t *gz)
{
uint8_t i2c_state = 0x01;
uint8_t txBuffer[2] = { 0x00 };
uint8_t rxBuffer[12] = { 0x00 };
I2C_Transaction i2cTransaction;
txBuffer[0] = 0x22;
i2cTransaction.slaveAddress = LSM6DSL_ADDRESS;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readCount = 12;
i2c_state = i2c_state & I2C_transfer(i2c, &i2cTransaction);
*gx = (int16_t) (rxBuffer[0] | (rxBuffer[1] << 8)) * GYRO_SCALE_VALUE;
*gy = (int16_t) (rxBuffer[2] | (rxBuffer[3] << 8)) * GYRO_SCALE_VALUE;
*gz = (int16_t) (rxBuffer[4] | (rxBuffer[5] << 8)) * GYRO_SCALE_VALUE;
*ax = (int16_t) (rxBuffer[6] | (rxBuffer[7] << 8)) * ACCEL_SCALE_VALUE;
*ay = (int16_t) (rxBuffer[8] | (rxBuffer[9] << 8)) * ACCEL_SCALE_VALUE;
*az = (int16_t) (rxBuffer[10] | (rxBuffer[11] << 8)) * ACCEL_SCALE_VALUE;
return i2c_state;
}
static uint8_t init_ms5607()
{
uint8_t i2c_state = 0x01;
int16_t temperature = 0;
int32_t pressure = 0;
i2c_state = 0x01;
set_ms560702ba03_i2c_instance(i2c);
i2c_state = i2c_state & init_ms560702ba03();
wait_ms(100);
uint32_t D1 = 0;
uint32_t D2 = 0;
set_ms560702ba03_OSR(4096);
//Read Pressure
i2c_state = i2c_state & set_ms560702ba03_conversion_pressure();
wait_ms(10);
i2c_state = i2c_state & set_ms560702ba03_measure_pressure();
wait_ms(10);
i2c_state = i2c_state & get_ms560702ba03_pressure(&D1);
//Read Temperature
i2c_state = i2c_state & set_ms560702ba03_conversion_temperature();
wait_ms(10);
i2c_state = i2c_state & set_ms560702ba03_measure_temperature();
wait_ms(10);
i2c_state = i2c_state & get_ms560702ba03_temperature(&D2);
set_ms560702ba03_convert_temperature_pressure(D2, D1);
temperature = get_ms560702ba03_convert_temperature();
pressure = get_ms560702ba03_convert_pressure();
if (temperature == 0 || pressure == 0)
{
i2c_state = 0x00;
}
return i2c_state;
}
static uint8_t update_ms5607(int16_t *temperature, int32_t *air_pressure)
{
uint8_t i2c_state = 0x01;
uint32_t D1 = 0;
uint32_t D2 = 0;
//Read Pressure
i2c_state = i2c_state & set_ms560702ba03_conversion_pressure();
wait_ms(10);
i2c_state = i2c_state & set_ms560702ba03_measure_pressure();
wait_ms(10);
i2c_state = i2c_state & get_ms560702ba03_pressure(&D1);
//Read Temperature
i2c_state = i2c_state & set_ms560702ba03_conversion_temperature();
wait_ms(10);
i2c_state = i2c_state & set_ms560702ba03_measure_temperature();
wait_ms(10);
i2c_state = i2c_state & get_ms560702ba03_temperature(&D2);
set_ms560702ba03_convert_temperature_pressure(D2, D1);
*temperature = get_ms560702ba03_convert_temperature();
*air_pressure = get_ms560702ba03_convert_pressure();
return i2c_state;
}
void gps_callback_quectel(quectel_gps_data_t data)
{
quectel_gps_data = data;
}
static uint8_t init_GPS()
{
uint8_t error = 0x00;
UART_Params uartParams;
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readMode = UART_MODE_CALLBACK;
uartParams.readCallback = uartReadCallback;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uart = UART_open(Board_UART0, &uartParams);
if (uart == NULL)
{
SysCtrlSystemReset();
}
set_quectel_gps_callback(gps_callback_quectel);
set_quectel_gps_uart_instance(uart);
set_quectel_gps_gpio_instance(sensorTaskPinHandle);
UART_read(uart, &uart_input_buf, 1);
if (set_quectel_gps_power_on(10))
{
set_quectel_gps_nmea_off_gga_only(10);
set_quectel_gps_sbas_disable(10);
error = 0x01;
}
set_quectel_gps_power_off();
UART_close(uart);
return error;
}
static void update_GPS()
{
UART_Params uartParams;
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readMode = UART_MODE_CALLBACK;
uartParams.readCallback = uartReadCallback;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uart = UART_open(Board_UART0, &uartParams);
if (uart == NULL)
{
SysCtrlSystemReset();
}
set_quectel_gps_callback(gps_callback_quectel);
set_quectel_gps_uart_instance(uart);
set_quectel_gps_gpio_instance(sensorTaskPinHandle);
UART_read(uart, &uart_input_buf, 1);
if (set_quectel_gps_power_on(10))
{
set_quectel_gps_nmea_off_gga_only(10);
set_quectel_gps_sbas_disable(10);
for (uint8_t i = 0; i < GPS_COLLEECTION_TIME; i++)
{
latitude = quectel_gps_data.latitude;
longitude = quectel_gps_data.longitude;
HDOP = quectel_gps_data.HDOP;
if (quectel_gps_data.navigation_statue > 0
&& quectel_gps_data.HDOP < 40)
{
break;
}
wait_ms(1000);
}
}
set_quectel_gps_power_off();
UART_close(uart);
}
static uint8_t update_battery_voltage()
{
uint16_t adc_value = 0;
ADC_Params_init(&ADCParams);
adc = ADC_open(CC1310_LAUNCHXL_ADC1, &ADCParams);
PIN_setOutputValue(sensorTaskPinHandle, BAT_EN_GPIO, 1);
wait_ms(100);
int_fast16_t result = ADC_convert(adc, &adc_value);
ADC_close(adc);
PIN_setOutputValue(sensorTaskPinHandle, BAT_EN_GPIO, 0);
if (result == ADC_STATUS_SUCCESS)
{
uint32_t microVolt = ADC_convertRawToMicroVolts(adc, adc_value);
microVolt *= 3;
microVolt /= 100000;
return (uint8_t) microVolt;
}
return 0;
}
static void sensorTaskFunction(UArg arg0, UArg arg1)
{
uint8_t on_off_count = 0;
int16_t ax = 0;
int16_t ay = 0;
int16_t az = 0;
int16_t gx = 0;
int16_t gy = 0;
int16_t gz = 0;
ADC_init();
I2C_init();
UART_init();
sensorTaskPinHandle = PIN_open(&sensorTaskPinState, sensorTaskPinTable);
PIN_setOutputValue(sensorTaskPinHandle, LED_RED_GPIO, 0);
PIN_setOutputValue(sensorTaskPinHandle, LED_BLUE_GPIO, 0);
PIN_setOutputValue(sensorTaskPinHandle, BAT_EN_GPIO, 0);
PIN_setOutputValue(sensorTaskPinHandle, GPS_POWER_EN_GPIO, 0);
if (!init_lsm6dsl())
{
initErrorUpdate();
}
if (!init_ms5607())
{
initErrorUpdate();
}
if (!init_GPS())
{
initErrorUpdate();
}
battery_voltage = update_battery_voltage();
PIN_setOutputValue(sensorTaskPinHandle, LED_RED_GPIO, 1);
PIN_setOutputValue(sensorTaskPinHandle, LED_BLUE_GPIO, 1);
while (1)
{
if (!PIN_getInputValue(HALL_SENSOR_GPIO))
{
if (on_off_mode == 0x01)
{
PIN_setOutputValue(sensorTaskPinHandle, LED_RED_GPIO, 0);
PIN_setOutputValue(sensorTaskPinHandle, LED_BLUE_GPIO, 1);
}
else
{
PIN_setOutputValue(sensorTaskPinHandle, LED_RED_GPIO, 1);
PIN_setOutputValue(sensorTaskPinHandle, LED_BLUE_GPIO, 0);
}
on_off_count += 1;
if (on_off_count > ON_OFF_WAIT_COUNT)
{
on_off_mode = !on_off_mode;
on_off_count = 0;
PIN_setOutputValue(sensorTaskPinHandle, LED_RED_GPIO, 0);
PIN_setOutputValue(sensorTaskPinHandle, LED_BLUE_GPIO, 0);
wait_ms(500);
PIN_setOutputValue(sensorTaskPinHandle, LED_RED_GPIO, 1);
PIN_setOutputValue(sensorTaskPinHandle, LED_BLUE_GPIO, 1);
}
}
else
{
PIN_setOutputValue(sensorTaskPinHandle, LED_RED_GPIO, 1);
PIN_setOutputValue(sensorTaskPinHandle, LED_BLUE_GPIO, 1);
on_off_count = 0;
}
if (on_off_mode == 0x01)
{
update_lsm6dsl(&ax, &ay, &az, &gx, &gy, &gz);
uint32_t vector = powf(ax, 2);
vector += powf(ay, 2);
vector += powf(az, 2);
vector = sqrtf(vector);
uint32_t max_vector = powf(max_ax, 2);
max_vector += powf(max_ay, 2);
max_vector += powf(max_az, 2);
max_vector = sqrtf(max_vector);
if (vector > max_vector)
{
max_ax = ax;
max_ay = ay;
max_az = az;
max_gx = gx;
max_gy = gy;
max_gz = gz;
}
if (start_gps_state)
{
update_GPS();
start_gps_state = 0x00;
}
if (start_radio_tx_state)
{
battery_voltage = update_battery_voltage();
update_ms5607(&temperature, &air_pressure);
payload_buffer_size = 0;
memset(payload_buffer, 0x00, sizeof(payload_buffer));
payload_buffer_size = sprintf((char*) payload_buffer, "%d.%d,",
(battery_voltage / 10),
(battery_voltage % 10));
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%d,",
max_ax);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%d,",
max_ay);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%d,",
max_az);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%d,",
max_gx);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%d,",
max_gy);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%d,",
max_gz);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%d,",
temperature);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%ld,",
air_pressure);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%d,",
HDOP);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%ld,",
latitude);
payload_buffer_size += sprintf(
(char*) payload_buffer + payload_buffer_size, "%ld",
longitude);
if (packetSendRequestCallback)
{
packetSendRequestCallback(payload_buffer,
payload_buffer_size);
}
max_ax = 0;
max_ay = 0;
max_az = 0;
max_gx = 0;
max_gy = 0;
max_gz = 0;
start_radio_tx_state = 0x00;
}
}
wait_ms(1000);
}
}
void SensorTask_init(void)
{
Event_Params eventParam;
Event_Params_init(&eventParam);
Event_construct(&sensorTaskEvent, &eventParam);
sensorTaskEventHandle = Event_handle(&sensorTaskEvent);
Task_Params_init(&sensorTaskParams);
sensorTaskParams.stackSize = SENSOR_TASK_STACK_SIZE;
sensorTaskParams.priority = SENSOR_TASK_TASK_PRIORITY;
sensorTaskParams.stack = &sensorTaskStack;
Task_construct(&sensorTask, sensorTaskFunction, &sensorTaskParams, NULL);
Clock_Params clockParams;
Clock_Params_init(&clockParams);
clockParams.period = TIMER_TIMEOUT * 1000 / Clock_tickPeriod;
clockParams.startFlag = TRUE;
Clock_construct(&sensorTimerClock, sensorTimerClockCallBack,
TIMER_TIMEOUT * 1000 / Clock_tickPeriod,
&clockParams);
}
void SensorTask_registerPacketSendRequestCallback(
PacketSendRequestCallback callback)
{
packetSendRequestCallback = callback;
}
static void uartReadCallback(UART_Handle handle, void *rxBuf, size_t size)
{
char *data = (char*) rxBuf;
quectel_gps_nmea_input(data[0]);
UART_read(handle, &uart_input_buf, 1);
}