-
Notifications
You must be signed in to change notification settings - Fork 0
/
BMsg838.cpp
1247 lines (1089 loc) · 35.9 KB
/
BMsg838.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
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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "BMsg838.h"
#define _GPRMC_TERM "GPRMC"
#define _GPGGA_TERM "GPGGA"
#define ACK 0x02
#define NACK 0x01
fix_cb_t fix_callback = NULL; // TJS:
void BMsg838::add_callback(fix_cb_t fct_ptr){
fix_callback = fct_ptr;
}
BMsg838::BMsg838()
: _time(GPS_INVALID_TIME)
, _date(GPS_INVALID_DATE)
, _latitude(GPS_INVALID_ANGLE)
, _longitude(GPS_INVALID_ANGLE)
, _altitude(GPS_INVALID_ALTITUDE)
, _speed(GPS_INVALID_SPEED)
, _course(GPS_INVALID_ANGLE)
, _last_time_fix(GPS_INVALID_FIX_TIME)
, _last_position_fix(GPS_INVALID_FIX_TIME)
, _parity(0)
, _is_checksum_term(false)
, _sentence_type(_GPS_SENTENCE_OTHER)
, _term_number(0)
, _term_offset(0)
, _gps_data_good(false)
#ifndef _GPS_NO_STATS
, _encoded_characters(0)
, _good_sentences(0)
, _failed_checksum(0)
#endif
{
_term[0] = '\0';
}
BMsg838::~BMsg838()
{
}
//
// public methods
//
/*---------------------------------------------------------------------*/
/*================= Binary message checksum function==================*/
/* CS = 0, N=PL;
For n = 0 to N
CS = CS ^ <Payload Byte # n>*/
/*---------------------------------------------------------------------*/
uint8_t BMsg838::checksum(byte* buffer, int len)
{
uint8_t cs = 0;
while (len) {
cs ^= *buffer;
buffer++;
len--;
}
return cs;
}
//get message type among Ack, response, NAck an error
/*Make binary message of venus 838LPx GPS receiver
The sytax of the Message is shown below.
<0xA0,0xA1><PL><Message ID><Message Body><CS><0x0D,0x0A>
Payload : Binary Message String
id : message id
len: Message Payload length
subflag: message type
return total length of Binary message made
*/
uint8_t BMsg838::MakeBinaryMessage(int len){
char checkingsum=0;
char temp[128];
memcpy(temp,SendStream,128);
checkingsum=checksum(SendStream, len);
SendStream[0]=0xA0;
SendStream[1]=0xA1;
SendStream[2]=(len>>8)&0xFF;
SendStream[3]=len;
for(int j=0;j<len;j++){
SendStream[j+4]=temp[j];
}
SendStream[len+4]=checkingsum;
SendStream[len+5]=0x0D;
SendStream[len+6]=0x0A;
return len+7;
}
/*This is a request which will reset and restart the GNSS receiver. */
uint8_t BMsg838::ResetGNSS(uint8_t startmode, uint16_t year, uint8_t month, uint8_t day,uint8_t hour, uint8_t minute, uint8_t second, int16_t latitude, int16_t longitude, int16_t altitude)
{
memset(SendStream,0,128);
SendStream[0]=1;
SendStream[1]=startmode;
SendStream[2]=year>>8;
SendStream[3]=year;
SendStream[4]=month;
SendStream[5]=day;
SendStream[6]=hour;
SendStream[7]=minute;
SendStream[8]=second;
SendStream[9]=(latitude*100)>>8;
SendStream[10]=latitude*100;
SendStream[11]=(longitude*100)>>8;
SendStream[12]=longitude*100;
SendStream[13]=altitude>>8;
SendStream[14]=altitude;
return MakeBinaryMessage(15);
}
/*This is a request to configure SBAS parameters of GNSS receiver. */
uint8_t BMsg838::ConfigureSBAS(boolean en_SBAS, uint16_t ranging, uint8_t URA_mask, boolean en_corr,
uint8_t channels, uint8_t subsys_mask, uint8_t attributes)
{
memset(SendStream,0,128);
SendStream[0]=0x62;
SendStream[1]=1;
SendStream[2]=en_SBAS;
SendStream[3]=ranging;
SendStream[4]=URA_mask;
SendStream[5]=en_corr;
SendStream[6]=channels;
SendStream[7]=(1<<subsys_mask);
SendStream[8]=attributes;
return MakeBinaryMessage(9);
}
/*Make Stream to request message of Softversion*/
uint8_t BMsg838::GetSoftVersion(){
memset(SendStream,0,128);
SendStream[0]=0x02;
SendStream[1]=0x00;
return MakeBinaryMessage(2);
}
/*Get version information of GPS receiver
return : 1->get success, 0-> checksum error, -1->timeout, 3->
*/
GPSSoftVersiondata* BMsg838::ResponseSoftVersion()
{
//return SendMessage(SendStream, 1000);
if(RecVBinarybuf[4]==0x80){
softversion.type=RecVBinarybuf[5];
softversion.Kversion=(RecVBinarybuf[6]<<24)|(RecVBinarybuf[7]<<16)|(RecVBinarybuf[8]<<8)|RecVBinarybuf[9];
softversion.ODMversion=(RecVBinarybuf[10]<<24)|(RecVBinarybuf[11]<<16)|(RecVBinarybuf[12]<<8)|RecVBinarybuf[13];
softversion.revision=(RecVBinarybuf[14]<<24)|(RecVBinarybuf[15]<<16)|(RecVBinarybuf[16]<<8)|RecVBinarybuf[17];
softversion.ckecksumOK =(checksum(RecVBinarybuf+4, 14)==RecVBinarybuf[18]);
return &softversion;
}
else
return NULL;
}
/*Get SoftwareCRC information of GPS receiver
return binaysteam size in byte unit.
*/
uint8_t BMsg838::GetSoftCRC()
{
memset(SendStream,0,128);
SendStream[0]=0x03;
SendStream[1]=0x00;
return MakeBinaryMessage(2);
}
/*Response message process of SoftwareCRC information of GPS receiver
type: Software type: 0?Reserved:(1)System code
CRC:CRC value
timeout: ack waiting time
return : 1->get success, 0-> checksum error, -1->timeout, 3->NACK
Two Binary messages are used in this function
of which id are is 0x03,x81
*/
uint8_t BMsg838::ResponseSoftCRC(uint8_t*Type, uint16_t*CRCinfo){
//SendMessage(SendStream, 1000);
if(RecVBinarybuf[4]==0x81){
*Type=RecVBinarybuf[5];
*CRCinfo=(RecVBinarybuf[6]<<8)|RecVBinarybuf[7];
return (checksum(RecVBinarybuf+4, 4)==RecVBinarybuf[8]);
}
else
return -1;
}
/*Set Factory Default
timeout : response wating time
return : ack(0x02) or 0x03(Nack) or -1(timeput) , 0(checksum error)
*/
uint8_t BMsg838::SetFactoryDefalt(){
memset(SendStream,0,128);
SendStream[0]=0x04;
SendStream[1]=0x00;
return MakeBinaryMessage(2);
}
/*=================================================================/
Set SerialPort Baudrate
baudrate: com1 baudrae of GPS to set
atribute: pdatetype: 0(RAM) or 1(both fo ram and flash)
timeout : response wating time
return : ack(0x02) or 0x03(Nack) or -1(timeput) , 0(checksum error)
/====================================================================*/
uint8_t BMsg838::SetSerialPort(int Baudrate, uint8_t Atribute){
memset(SendStream,0,128);
int baudR[9]={4800,9600,19200,38400,57600,115200,230400,460800,921600};
SendStream[0]=0x05;
SendStream[1]=0x00;
for(int i=0;i<9;i++)
if(baudR[i]==Baudrate){
SendStream[2]=i;
break;
}
SendStream[3]=Atribute;
return MakeBinaryMessage(4);
}
/*=================================================================/
Set BinaryMessagetype
timeout : response wating time
return : ack(0x02) or 0x03(Nack) or -1(timeput) , 0(checksum error)
/=================================================================*/
uint8_t BMsg838::SetBinaryMessagetype(){
SendStream[0]=0x09;
SendStream[1]=0x02; //Message type : Binary message Mode
SendStream[2]=0x01; //atribute: pdatetype: 0(RAM) or 1(both fo ram and flash)
return MakeBinaryMessage(3);
}
/*Set powermode binary message steeam make
*/
uint8_t BMsg838::SetPowerMode(uint8_t mode, uint8_t Atribute)
{
memset(SendStream,0,128);
SendStream[0]=12;
SendStream[1]=mode;
SendStream[2]=Atribute;
return MakeBinaryMessage(3);
}
/*making binary message stream setting of position update rate */
uint8_t BMsg838::SetPositionRate(uint8_t Rate)
{
memset(SendStream,0,128);
SendStream[0]=0x0E;
SendStream[1]=Rate; //update rate
SendStream[2]=1; //0:Ram 1:both of RAM amd Flush
return MakeBinaryMessage(3);
}
/*Get Position update rate
return : stream length
*/
uint8_t BMsg838::GetPositionRate()
{
memset(SendStream,0,128);
SendStream[0]=0x10;
return MakeBinaryMessage(1);
}
/*Response Message process to query of Position update rate
rate: positon update rate is one of {1,2,4,5,8,10,20,25,40,50}
timout wating time of ACK
return : 1->get success, 0-> checksum error, -1->timeout, 3->nack
*/
uint8_t BMsg838::ResponsePositionRate(uint8_t* rate)
{
if(RecVBinarybuf[4]==0x86){
*rate=RecVBinarybuf[5];
return (checksum(RecVBinarybuf+4, 2)==RecVBinarybuf[6]);
}
else
return -1;
}
/*=================================================================/
Set Navigation Interval
interval: value of Navigation Interval of GPS to set
return : ack(0x02) or 0x03(Nack) or -1(timeput) , 0(checksum error)
/====================================================================*/
uint8_t BMsg838::SetNavigationInterval(uint8_t interval) //interval[7]
{
memset(SendStream,0,128);
SendStream[0]=17;
SendStream[1]=interval;
SendStream[2]=1;
return MakeBinaryMessage(3);
}
/*=================================================================/
Set Position Datum
Set parameter:
uint16_t index,
uint8_t EllipIdx,
uint16_t DeltaX,
uint16_t DeltaY,
uint16_t DeltaZ,
uint32_t Semiaxis,
uint8_t InversedFlatten
return : ack(0x02) or 0x03(Nack) or -1(timeput) , 0(checksum error)
/====================================================================*/
uint8_t BMsg838::SetPositionDatum(uint16_t index, uint8_t EllipIdx, uint16_t DeltaX, uint16_t DeltaY, uint16_t DeltaZ,uint32_t Semiaxis, uint8_t InversedFlatten)
{
memset(SendStream,0,128);
SendStream[0]=0x29;
SendStream[1]=(index>>8)&0xFF;
SendStream[2]=index&0xFF;
SendStream[3]=EllipIdx;
SendStream[4]=(DeltaX>>8)&0xFF;
SendStream[5]=DeltaX&0xFF;
SendStream[6]=(DeltaY>>8)&0xFF;
SendStream[7]=(DeltaY)&0xFF;
SendStream[8]=(DeltaZ>>8)&0xFF;
SendStream[9]=(DeltaZ)&0xFF;
SendStream[10]=(Semiaxis>>24)&0xFF;
SendStream[11]=(Semiaxis>>16)&0xFF;
SendStream[12]=(Semiaxis>>8)&0xFF;
SendStream[13]=(Semiaxis)&0xFF;
SendStream[14]=(InversedFlatten>>24)&0xFF;
SendStream[15]=(InversedFlatten>>16)&0xFF;
SendStream[16]=(InversedFlatten>>8)&0xFF;
SendStream[17]=InversedFlatten&0xFF;
SendStream[18]=1;
return MakeBinaryMessage(19);
}
/*return : 1->get success, 0-> checksum error, -1->timeout, 3->*/
uint8_t BMsg838::Getdatum(){
memset(SendStream,0,128);
SendStream[0]=0x2D;
return MakeBinaryMessage(1);
//SendMessage(SendStream, 1000);
}
/*return : 1->get success, 0-> checksum error, -1->timeout, 3->*/
uint8_t BMsg838::Responsedatum(uint16_t* Datum){
if(RecVBinarybuf[4]==0xAE){
*Datum=(RecVBinarybuf[5]<<8)|RecVBinarybuf[6];
return (checksum(RecVBinarybuf+4, 3)==RecVBinarybuf[7]);
}
else
return -1;
}
/*Enable or disable position pinning of
GNSS receiver
return : binary message length*/
uint8_t BMsg838::SetPositionPinning(uint8_t positionpinning)
{
memset(SendStream,0,128);
SendStream[0]=0x39;
SendStream[1]=positionpinning;
SendStream[2]=1;
return MakeBinaryMessage(3);
}
/*Query position pinning status of the
GNSS receiver
return : binary message length*/
uint8_t BMsg838::GetPositionPinning(){
memset(SendStream,0,128);
SendStream[0]=0x3A;
return MakeBinaryMessage(1);
}
/*return : 1->get success, 0-> checksum error, -1->timeout, 3->*/
uint8_t BMsg838::ResponsePositionPinning(uint8_t*status, uint16_t* speed, uint16_t* cnt,uint16_t* upspeed,uint16_t* upcnt,uint16_t* updsit){
//return SendMessage(SendStream, 1000);
if(RecVBinarybuf[4]==0xB4){
*status=RecVBinarybuf[5];
*speed=(RecVBinarybuf[6]<<8)|RecVBinarybuf[7];
*cnt=(RecVBinarybuf[8]<<8)|RecVBinarybuf[9];
*upspeed=(RecVBinarybuf[10]<<8)|RecVBinarybuf[11];
*upcnt=(RecVBinarybuf[12]<<8)|RecVBinarybuf[13];
*updsit=(RecVBinarybuf[14]<<8)|RecVBinarybuf[15];
return (checksum(RecVBinarybuf+4, 12)==RecVBinarybuf[16]);;
}
else
return -1;
}
/*Set position pinning parameters of GNSS
receiver
return: binary message strem length*/
uint8_t BMsg838::SetPositionPinningParam(uint16_t speed,uint16_t cnt,uint16_t upspeed,uint16_t upcnt,uint16_t updistance){
memset(SendStream,0,128);
SendStream[0]=0x3B;
SendStream[1]=(speed>>8)&0xFF;
SendStream[2]=(speed)&0xFF;
SendStream[3]=(cnt>>8)&0xFF;
SendStream[4]=(cnt)&0xFF;
SendStream[5]=(upspeed>>8)&0xFF;
SendStream[6]=(upspeed)&0xFF;
SendStream[7]=(upcnt>>8)&0xFF;
SendStream[8]=(upcnt)&0xFF;
SendStream[9]=(updistance>>8)&0xFF;
SendStream[10]=(updistance)&0xFF;
SendStream[11]=1;
return MakeBinaryMessage(12);
}
/*Query 1PPS timing of the GNSS receiver
return : binary message stream length in byte unit*/
uint8_t BMsg838::Get1PPSTiming( ){
char SendStream[128];
memset(SendStream,0,128);
SendStream[0]=0x44;
return MakeBinaryMessage(1);
}
/* processing Response message to Query 1PPS timing of the GNSS receiver
return : 1->get success, 0-> checksum error, -1->timeout, NACK->*/
uint8_t BMsg838::Response1PPSTiming(uint8_t* mode,uint32_t* len,uint32_t* standev,DPFP* savelati,DPFP* savelong,SPFP* savealti,uint8_t* runtimemode,uint32_t* runtimelen){
if(RecVBinarybuf[4]==0xC2){
*mode=RecVBinarybuf[5];
*len=(RecVBinarybuf[6]<<24)|(RecVBinarybuf[7]<<16)|(RecVBinarybuf[8]<<8)|RecVBinarybuf[9];
// *standev=(RecVBinarybuf[10]<<24)|(RecVBinarybuf[11]<<16)|(RecVBinarybuf[12]<<8)|RecVBinarybuf[13];
// *savelati=(RecVBinarybuf[14]<<56)|(RecVBinarybuf[15]<<48)|(RecVBinarybuf[16]<<40)|(RecVBinarybuf[17]<<32)|(RecVBinarybuf[18]<<24)|(RecVBinarybuf[19]<<16)|(RecVBinarybuf[20]<<8)|RecVBinarybuf[21];
// *savelong=(RecVBinarybuf[22]<<56)|(RecVBinarybuf[23]<<48)|(RecVBinarybuf[24]<<40)|(RecVBinarybuf[25]<<32)|(RecVBinarybuf[25]<<26)|(RecVBinarybuf[27]<<16)|(RecVBinarybuf[28]<<8)|RecVBinarybuf[29];
// *savealti=(RecVBinarybuf[30]<<24)|(RecVBinarybuf[31]<<16)|(RecVBinarybuf[32]<<8)|RecVBinarybuf[33];
*runtimemode=RecVBinarybuf[34];
*runtimelen=(RecVBinarybuf[35]<<24)|(RecVBinarybuf[36]<<16)|(RecVBinarybuf[37]<<8)|RecVBinarybuf[38];
return (checksum(RecVBinarybuf+4, 35)==RecVBinarybuf[39]);
}
else
return -1;
}
/*Configure cable delay of 1PPS timing*/
uint8_t BMsg838::Set1PPSCabledelay(uint32_t Cabledelay){
char SendStream[128];
memset(SendStream,0,128);
SendStream[0]=0x45;
SendStream[1]=Cabledelay>>24;
SendStream[2]=Cabledelay>>16;
SendStream[3]=Cabledelay>>8;
SendStream[4]=Cabledelay;
SendStream[5]=1;
return MakeBinaryMessage(6);
}
/*Cable delay of 1PPS timing mode . Get value in unit of 1/100 ns. edelayThe
value is stored in Cabledelay [-500000,500000]
return : 1->get success, 0-> checksum error, -1->timeout, NACK->
*/
uint8_t BMsg838::Get1PPSCabledelay(){
memset(SendStream,0,128);
SendStream[0]=0x46;
return MakeBinaryMessage(1);
//SendMessage(SendStream, 1000);
}
uint8_t BMsg838::Response1PPSCabledelay(uint32_t *Cabledelay){
if(RecVBinarybuf[4]==0xBB){
*Cabledelay=(RecVBinarybuf[5]<<24)|(RecVBinarybuf[6]<<16)|(RecVBinarybuf[7]<<8)|RecVBinarybuf[8];
return (checksum(RecVBinarybuf+4, 5)==RecVBinarybuf[9]);
}
else
return -1;
}
/*Configure the navigation mode of GNSS
receiver
return: Binary Message stream length*/
uint8_t BMsg838::SetGNSSNavigationMode(uint8_t mode){
memset(SendStream,0,128);
SendStream[0]=0x64;
SendStream[1]=0x17;
SendStream[2]=mode;
SendStream[3]=1;
return MakeBinaryMessage(4);
}
/*Query the navigation mode of GNSS
receiver
return: Binary Message stream length*/
int8_t BMsg838::GetGNSSNavigationMode(){
memset(SendStream,0,128);
SendStream[0]=0x64;
SendStream[1]=0x18;
return MakeBinaryMessage(2);
}
/*Processing response message to query the navigation mode
return : 1->get success, 0-> checksum error, -1->timeout, NACK->*/
int8_t BMsg838::ResponseGNSSNavigationMode(char* mode){
if(RecVBinarybuf[5]==0x8B){
switch (RecVBinarybuf[6])
{
case 0:
sprintf(mode, "%s","auto");//mode="auto";
break;
case 1:
//mode="prdestrain";
sprintf(mode, "%s","prdestrain");
break;
case 2:
//mode="car";
sprintf(mode, "%s","car");
break;
case 3:
//mode="marine";
sprintf(mode, "%s","marine");
break;
case 4:
//mode="ballon";
sprintf(mode, "%s","ballon");
break;
case 5:
//mode="airborne";
sprintf(mode, "%s","airborne");
break;
}
return (checksum(RecVBinarybuf+4, 3)==RecVBinarybuf[7]);
}
else
return -1;
}
/*binary message stream make for Configure the GNSS constellation type
used for navigation solution
return stream length*/
uint8_t BMsg838::SetGNSSConstelGPStype(){
memset(SendStream,0,128);
SendStream[0]=0x64;
SendStream[1]=0x19;
SendStream[2]=0;
SendStream[3]=0;
SendStream[4]=1;
return MakeBinaryMessage(5);
}
/*make binary message stream to Query the GNSS constellation type used
for navigation solution
return : binay message stream size in byte*/
uint8_t BMsg838::GetGNSSConstellationtype(){
memset(SendStream,0,128);
SendStream[0]=0x64;
SendStream[1]=0x1A;
return MakeBinaryMessage(2);
}
/*Response message processing to Query the GNSS constellation type used
for navigation solution
return : 1->get success, 0-> checksum error, -1->timeout, NACK->*/
uint8_t BMsg838::ResponseGNSSConstellationtype(char *mode){
//SendMessage(SendStream, 1000);
char Navimode[4][10]={"GPS","Glonass","Galileo","Beido"};
if(RecVBinarybuf[5]==0x8C){
if(RecVBinarybuf[7]&1){
sprintf(mode, "%s",Navimode[0]);
//mode="GPS";
}if(RecVBinarybuf[7]&2){
if(mode)
strcat(mode,Navimode[1]);
else
sprintf(mode, "%s",Navimode[1]);
}if(RecVBinarybuf[7]&4){
if(mode)
strcat(mode,Navimode[2]);
else
sprintf(mode, "%s",Navimode[2]);
}if(RecVBinarybuf[7]&8){
if(mode)
strcat(mode,Navimode[3]);
else
sprintf(mode, "%s",Navimode[3]);
}
return (checksum(RecVBinarybuf+4, 4)==RecVBinarybuf[8]);
}
else
return -1;
}
/*Make binary message stream for Configure GPS/UTC leap seconds of
GNSS receiver
return binary message stream size*/
uint8_t BMsg838::SetGPSUTCSecond(uint8_t leapsecond)
{
memset(SendStream,0,128);
SendStream[0]=0x64;
SendStream[1]=0x1F;
SendStream[2]=leapsecond;
SendStream[3]=1;
return MakeBinaryMessage(4);
}
/*Make binary message stream for Query GPS time of GNSS receiver
return binary message stream size*/
uint8_t BMsg838::GetGPSTime(){
memset(SendStream,0,128);
SendStream[0]=0x64;
SendStream[1]=0x20;
return MakeBinaryMessage(2);
//SendMessage(SendStream, timeout);
}
/*response message processing to Query GPS time of GNSS receiver
return message length*/
uint8_t BMsg838::respondGPSTime(uint32_t *Timeofweek, uint32_t *SubTimeofweek, uint16_t *weeknumber, uint8_t *Defleapsecond,int8_t *curleapsecond, uint8_t *Valid){
if(RecVBinarybuf[5]==0x8E){
*Timeofweek=(RecVBinarybuf[6]<<24)|(RecVBinarybuf[7]<<16)|(RecVBinarybuf[8]<<8)|RecVBinarybuf[9];
*SubTimeofweek=(RecVBinarybuf[10]<<24)|(RecVBinarybuf[11]<<16)|(RecVBinarybuf[12]<<8)|RecVBinarybuf[13];
*weeknumber=(RecVBinarybuf[14]<<8)|RecVBinarybuf[15];
*Defleapsecond=RecVBinarybuf[16];
*curleapsecond=RecVBinarybuf[17];
*Valid=RecVBinarybuf[18];
return (checksum(RecVBinarybuf+4, 15)==RecVBinarybuf[19]);
}
else
return -1;
}
/*Make binary message stream for Configure GNSS datum index of GNSS
receiver
return binary message stream size*/
uint8_t BMsg838::SetDatumIndex(uint8_t index){
memset(SendStream,0,128);
SendStream[0]=0x64;
SendStream[1]=0x27;
SendStream[2]=(index>>8)&0xFF;
SendStream[3]=index&0xFF;
SendStream[4]=1;
return MakeBinaryMessage(5);
}
/*Make binary message stream for Query GNSS datum index of GNSS
receiver
return binary message stream size*/
uint8_t BMsg838::GetDatumIndex(){
memset(SendStream,0,128);
SendStream[0]=0x64;
SendStream[1]=0x28;
return MakeBinaryMessage(2);
} //SendMessage(SendStream, 1000);
/*response message processing to Configure GNSS datum index of GNSS
receiver
return 1:receive ok 0:checksum error -1: Invalid message*/
uint8_t BMsg838::ResponseDatumIndex(uint16_t *datumindex)
{
if(RecVBinarybuf[5]==0x92){
*datumindex=(RecVBinarybuf[6]<<8)|RecVBinarybuf[7];
return (checksum(RecVBinarybuf+4, 4)==RecVBinarybuf[8]);
}
else
return -1;
}
/*Make binary message stream for Configure 1PPS pulse width of GNSS
receiver
return binary message stream size*/
uint8_t BMsg838::Set1PPSPulseWidth(uint32_t width ){
memset(SendStream,0,128);
SendStream[0]=0x65;
SendStream[1]=0x01;
SendStream[2]=(width>>24)&0xFF;
SendStream[3]=(width>>16)&0xFF;
SendStream[4]=(width>>8)&0xFF;
SendStream[5]=(width)&0xFF;
SendStream[6]=1;
return MakeBinaryMessage(7);
}
/*Make binary message stream for Query 1PPS pulse width of GNSS
receiver
return binary message stream size*/
uint8_t BMsg838::Get1PPSPulseWidth(){
memset(SendStream,0,128);
SendStream[128]=0x65;
SendStream[128]=0x02;
return MakeBinaryMessage(2);
}
/*
response message processing to Query 1PPS pulse width of GNSS
receiver
return : 1->get success, 0-> checksum error, -1->timeout, NACK->*/
uint8_t BMsg838::Response1PPSPulseWidth(uint32_t* Width){
if(RecVBinarybuf[5]==0x80){
*Width=(RecVBinarybuf[6]<<24)|(RecVBinarybuf[7]<<16)|(SendStream[8]<<8)|(SendStream[9]<<0);
return (checksum(RecVBinarybuf+4, 6)==RecVBinarybuf[10]);
}
else
return -1;
}
/*Make binary message stream for Configure 1PPS frequency output of
GNSS receiver
return binary message stream size*/
uint8_t BMsg838::Set1PPSFrequency(uint32_t frequency){
memset(SendStream,0,128);
SendStream[0]=0x65;
SendStream[1]=3;
SendStream[2]=(frequency>>24)&0xFF;
SendStream[3]=(frequency>>16)&0xFF;
SendStream[4]=(frequency>>8)&0xFF;
SendStream[5]=(frequency)&0xFF;
SendStream[6]=1;
return MakeBinaryMessage(7);
}
/*Make binary message stream for query 1PPS frequency output of
GNSS receiver
return binary message stream size*/
uint8_t BMsg838::Get1PPSFrequency()
{
memset(SendStream,0,128);
SendStream[0]=0x65;
SendStream[0]=0x04;
return MakeBinaryMessage(2);
}
/*
response message processing to query 1PPS frequency output of
GNSS receiver
return : 1->get success, 0-> checksum error, -1->timeout, NACK->*/
uint8_t BMsg838::Response1PPSFrequency(uint32_t *frequency)
{
if(RecVBinarybuf[5]==0x81){
*frequency=(RecVBinarybuf[6]<<24)|(RecVBinarybuf[7]<<16)|(RecVBinarybuf[8]<<8)|(RecVBinarybuf[9]<<0);
return (checksum(RecVBinarybuf+4, 6)==RecVBinarybuf[10]);
}
else
return -1;
}
/*This is a function which receive Message of user navigation date in binary format
(ID:0xA8)from the GNSS receiver .
Paramer:
position: scale 1e-7 , degree [0]-Latitude; >0 :North Hemisphere
<0:South Hemisphere
[1]-Longitude;>0 :North Hemisphere
<0:South Hemisphere
altitude: scale 0.01 , meter [0]-ellipsoid altitu;
[1]-mean sea level altitude
dilution: scale 0.01 , [0]-Geometric dilution of precision
[1]-Position dilution of precision
[2]-Horizontal dilution of precision
[3]-Vertical dilution of precision
[4]-Time dilution of precision
coordinate: scale 0.01 , meter [0]-ECEF X coordinate
[1]-ECEF Y coordinate
[2]-ECEF Z coordinate
altitude: scale 0.01 , meter/s [0]-ECEF X Veolcity
[1]-ECEF Y Veolcity
[2]-ECEF Z Veolcity
return : 1->receive success, 0-> checksum error, -1->timeout, 3->NACK
*/
uint8_t BMsg838::ReceiveNavigationData(uint8_t* modenum, uint16_t* gps_week, uint32_t* timeofweek, int32_t *position, uint32_t* altitude, uint16_t *dilution, int32_t* coordinate,int32_t* veolcity)
{
if(RecVBinarybuf[4]==0xA8){
modenum[0]=RecVBinarybuf[5];
modenum[1]=RecVBinarybuf[6];
gps_week[0]=(RecVBinarybuf[7]<<8)|(RecVBinarybuf[8]<<0);
timeofweek[0]=(RecVBinarybuf[9]<<24)|(RecVBinarybuf[10]<<16)|(RecVBinarybuf[11]<<8)|(RecVBinarybuf[12]<<0);
position[0]=(RecVBinarybuf[13]<<24)|(RecVBinarybuf[14]<<16)|(RecVBinarybuf[15]<<8)|(RecVBinarybuf[16]<<0);
position[1]=(RecVBinarybuf[17]<<24)|(RecVBinarybuf[18]<<16)|(RecVBinarybuf[19]<<8)|(RecVBinarybuf[20]<<0);
altitude[0]=(RecVBinarybuf[21]<<24)|(RecVBinarybuf[22]<<16)|(RecVBinarybuf[23]<<8)|(RecVBinarybuf[24]<<0);
altitude[1]=(RecVBinarybuf[25]<<24)|(RecVBinarybuf[26]<<16)|(RecVBinarybuf[27]<<8)|(RecVBinarybuf[28]<<0);
dilution[0]=(RecVBinarybuf[29]<<8)|(RecVBinarybuf[30]<<0);
dilution[1]=(RecVBinarybuf[31]<<8)|(RecVBinarybuf[32]<<0);
dilution[2]=(RecVBinarybuf[33]<<8)|(RecVBinarybuf[34]<<0);
dilution[3]=(RecVBinarybuf[35]<<8)|(RecVBinarybuf[36]<<0);
dilution[4]=(RecVBinarybuf[37]<<8)|(RecVBinarybuf[38]<<0);
coordinate[0]=(RecVBinarybuf[39]<<24)|(RecVBinarybuf[40]<<16)|(RecVBinarybuf[41]<<8)|(RecVBinarybuf[42]<<0);
coordinate[1]=(RecVBinarybuf[43]<<24)|(RecVBinarybuf[44]<<16)|(RecVBinarybuf[45]<<8)|(RecVBinarybuf[46]<<0);
coordinate[2]=(RecVBinarybuf[47]<<24)|(RecVBinarybuf[48]<<16)|(RecVBinarybuf[49]<<8)|(RecVBinarybuf[50]<<0);
veolcity[0]=(RecVBinarybuf[51]<<24)|(RecVBinarybuf[52]<<16)|(RecVBinarybuf[53]<<8)|(RecVBinarybuf[54]<<0);
veolcity[1]=(RecVBinarybuf[55]<<24)|(RecVBinarybuf[56]<<16)|(RecVBinarybuf[57]<<8)|(RecVBinarybuf[58]<<0);
veolcity[2]=(RecVBinarybuf[59]<<24)|(RecVBinarybuf[60]<<16)|(RecVBinarybuf[61]<<8)|(RecVBinarybuf[62]<<0);
// for (int i=0; i < 65; i++){
// Serial.print(RecVBinarybuf[i]);
// Serial.print(" ");
// }
// Serial.println();
return (checksum(RecVBinarybuf+4, 59)==RecVBinarybuf[63]);
}
else
return -1;
}
/*======================Binary message to make ============*/
//uint8_t BMsg838::SetNMEATalkId(uint8_t idtype, uint8_t Attribute);
//uint8_t BMsg838::GetNMEATalkId();
//93 char* respondNMEAtalkID(uint8_t id);
//uint8_t BMsg838::Set1PPSTiming(uint8_t timemode,uint32_t len,uint32_t standdeciation,DFDP Latitude,DFDP Longtude,DFDP Altitude,uint8_t attribute);
//uint8_t BMsg838::SetSBASParam(uint8_t Enable,uint8_t ranging,uint8_t URAmask,uint8_t correction,uint8_t channel,uint8_t subsystemmask,uint8_t attribute);
//uint8_t BMsg838::GetSBASStatus();
//6280 char* RespondSBASStatus(uint8_t Enable,uint8_t ranging,uint8_t URAmask,uint8_t correction,uint8_t channel,uint8_t subsystemmask,uint8_t *respond);
//uint8_t BMsg838::SetQZSS(uint8_t Enable,uint8_t channel,uint8_t attribute);
//uint8_t BMsg838::GetQZSS();
//6281 char* RespondQZSS(uint8_t Enable,uint8_t channel,uint8_t *respond);
//uint8_t BMsg838::SetSAEE(uint8_t Enable,uint8_t attribute);
//uint8_t BMsg838::GetSAEE();
//6380 char* RespondSAEE(uint8_t Status,uint8_t *respond);
//uint8_t BMsg838::Getbootstatus(uint8_t *respond);
//6480:4 char* respondbootstatus(uint8_t status,uint8_t type,uint8_t *respond);
//uint8_t BMsg838::SetExtendedNMEA(uint8_t interval[],uint8_t attribute);
//uint8_t BMsg838::GetExtendedNMEA();
//6481:14 char* respondExtendedNMEA(uint8_t interval[],uint8_t *respond);
//uint8_t BMsg838::SetInferenceDetection(uint8_t detectcontrol,uint8_t attribute);
//uint8_t BMsg838::GetInferenceDetection();
//6483:4 char* respondInferenceDetection(uint8_t detectcontrol,uint8_t status,uint8_t *respond);
//uint8_t BMsg838::SetParamseachNum(uint8_t num,uint8_t attributed);
//uint8_t BMsg838::GetParamseachNum();
//640A:3 char* respondParamseachNum(uint8_t num,uint8_t *respond);
//uint8_t BMsg838::Setephemeris(uint8_t **subframe);
//2E uint8_t BMsg838::GetDOPMask();
//AF uint8_t BMsg838::respondDOPMask();
//uint8_t BMsg838::GetElevaCNRMask();
// B0 char* respondElevationCNRmask(uint16_t len, uint8_t *respond);
//uint8_t BMsg838::SetDopMask(uint8_t mode,uint16_t pdopval,uint16_t hdopval,uint16_t gdopval,uint8_t Atribute);
//uint8_t BMsg838::SetElevationCnrMask(uint8_t mode,uint8_t elevamask,uint8_t cnrmask,uint8_t Atribute);
//uint8_t BMsg838::SetNMEAmessage(uint8_t *interval,uint8_t attribute){}
//uint8_t BMsg838::DownloadImage(uint8_t Baudrate, uint8_t type,uint16_t Flushid,uint8_t Index){}
//15 uint8_t BMsg838::GetPowerMode(uint8_t Atribute);
//B9 char* respondPWRModeStatus(uint16_t len, uint8_t *respond)
//uint8_t BMsg838::Getephemeris(uint8_t sv);
// B1 char* respondGPSEphemeris(uint16_t len, uint8_t *respond);
//
// public methods
//
/*====================NMEA Message Interface function=================*/
bool BMsg838::encode(char c)
{
bool valid_sentence = false;
// Serial.print(c); // TJS:
++_encoded_characters;
switch(c)
{
case ',': // term terminators
_parity ^= c;
case '\r':
case '\n':
case '*':
if (_term_offset < sizeof(_term))
{
_term[_term_offset] = 0;
valid_sentence = term_complete();
}
++_term_number;
_term_offset = 0;
_is_checksum_term = c == '*';
return valid_sentence;
case '$': // sentence begin
_term_number = _term_offset = 0;
_parity = 0;
_sentence_type = _GPS_SENTENCE_OTHER;
_is_checksum_term = false;
_gps_data_good = false;
return valid_sentence;
}
// ordinary characters
if (_term_offset < sizeof(_term) - 1)
_term[_term_offset++] = c;
if (!_is_checksum_term)
_parity ^= c;
return valid_sentence;
}
#ifndef _GPS_NO_STATS
void BMsg838::stats(unsigned long *chars, unsigned short *sentences, unsigned short *failed_cs)
{
if (chars) *chars = _encoded_characters;
if (sentences) *sentences = _good_sentences;
if (failed_cs) *failed_cs = _failed_checksum;
}
#endif
//
// internal utilities
//
int BMsg838::from_hex(char a)
{
if (a >= 'A' && a <= 'F')
return a - 'A' + 10;
else if (a >= 'a' && a <= 'f')
return a - 'a' + 10;
else
return a - '0';
}
unsigned long BMsg838::parse_decimal()
{
char *p = _term;
bool isneg = *p == '-';
if (isneg) ++p;
unsigned long ret = 100UL * gpsatol(p);
while (gpsisdigit(*p)) ++p;
if (*p == '.')
{
if (gpsisdigit(p[1]))
{
ret += 10 * (p[1] - '0');
if (gpsisdigit(p[2]))
ret += p[2] - '0';
}
}
return isneg ? -ret : ret;
}
unsigned long BMsg838::parse_degrees()
{
char *p;
unsigned long left = gpsatol(_term);
unsigned long tenk_minutes = (left % 100UL) * 10000UL;
for (p=_term; gpsisdigit(*p); ++p);
if (*p == '.')
{
unsigned long mult = 1000;
while (gpsisdigit(*++p))
{
tenk_minutes += mult * (*p - '0');
mult /= 10;
}
}
return (left / 100) * 100000 + tenk_minutes / 6;
}