123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- #include "includes.h"
- SUT_GPS_INF sutGpsInfo;
- GPS_DATA_TYPE GPS_Data_Type;
- //static unsigned char gpsInit=0;
- //
- //void GPSRestart(void){
- // gpsInit=1;
- //}
- //void GPSStop(void){
- // gpsInit=10;
- //}
- void GPSInit(void){
- memset(&sutGpsInfo,0,sizeof(SUT_GPS_INF));
- }
- void GpsTimeUpdate(void)
- {
- if(GPS_TimeTable[newPara.gpsTimeIndex])
- {
- sutGpsInfo.g_GpsEnable=1;
- }
- else{
- sutGpsInfo.g_GpsEnable=0;
- sutGpsInfo.isGpsWork=0;
- }
- MSG_INFO(1,"newPara.gpsTimeIndex===%d,%d",newPara.gpsTimeIndex,sutGpsInfo.g_GpsEnable);
-
- }
- void GpsInternalChange(unsigned int interval)
- {
- static signed char step=-1;
- static char last_g_GpsStat=-1;
- static unsigned short cnt=0;
-
- if(++cnt<(1000/interval)) return;//1秒读一次ADC即可
- cnt=0;
- if(last_g_GpsStat!=sutGpsInfo.g_GpsEnable){
- last_g_GpsStat=sutGpsInfo.g_GpsEnable;
- step=0;
- }
-
- switch(step)
- {
- case 0:
- if(sutGpsInfo.g_GpsEnable){
- msgToModem("AT+GPS=\"ON\"\r\n");
- MSG_INFO(1,"GPS open--change--r\n");
-
- }
- else {
- msgToModem("AT+GPS=\"OFF\"\r\n");
- gpsDataInit();
- MSG_INFO(1,"GPS OFF--change--r\n");
- }
- //step=1;
- break;
- case 1:
- if(sutGpsInfo.g_GpsEnable)msgToModem("AT+GPSANT=1\r\n");
- else msgToModem("AT+GPSANT=0\r\n");
- //step=2;
- break;
- case 7: //第一次查询需要延时查询
- //step=0;
- gpsCheckInfo();
- break;
- break;
- }
-
- if(step<8)step++;
-
- }
- //12345,1214
- //鑾峰彇绗�竴涓�€楀彿鍓嶆暟瀛楁湁鍑犱綅
- int getDlen(char *msg){
- int i;
- for(i=0;i<strlen(msg);i++){
- if(msg[i]>0x39 || msg[i]<0x30){
- return i;
- }
- }
- return -1;//娌℃湁閫楀彿
- }
- static unsigned char translate_digitAscii_to_bcd(char *ascii_number, unsigned char len, char *bcd_number)
- {
- int i, j;
- char temp[10] = ""; /* extra + and NULL */
- unsigned char bcd_index = 0; /* Index into output bcd_number */
-
- int num_len = len;
-
-
- /* Translate or skip over invalid characters */
- for (i = 0, j = 0; i < num_len; i++)
- {
- temp[j++] = ascii_number[i] & 0x0F;
- }
-
- ascii_number[len] = 0;
- /* Now that temp has the bcd codes in natural order... Squish them together
- * and reverse the order per bcd coding.
- */
- for (i = 0; i < j; i+=2)
- bcd_number[bcd_index++] = ((char)(temp[i] << 4)) | temp[i+1];
-
- bcd_number[len] = 0;
-
- return 0;
- }
- /*=====================================
- UTC time:hms status latitue north? longitue east? 速度(节) 方位角 UTC time 磁偏角 方向 模式 checksum
- $GPRMC hhmmss.sss A/V ddmm.mmmm N/S dddmm.mmmm E/W speed aspect ddmmyy 000-180 E/W A/D/E/N *hh
- For example: $GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,,,A*50
- */
- #define GPRMC_UTC1_TOKEN_INDEX 0
- #define GPRMC_STATUS_TOKEN_INDEX 1
- #define GPRMC_LATITUE_TOKEN_INDEX 2
- #define GPRMC_NORTH_TOKEN_INDEX 3
- #define GPRMC_longitue_TOKEN_INDEX 4
- #define GPRMC_EAST_TOKEN_INDEX 5
- #define GPRMC_SPEED_TOKEN_INDEX 6
- #define GPRMC_ASPECT_TOKEN_INDEX 7
- #define GPRMC_UTC2_TOKEN_INDEX 8
- #define GPRMC_HIGHT_TOKEN_INDEX 8
- #define GPRMC_STARTNUM_TOKEN_INDEX 6
- #define GPS_BDVISUAL_INDEX 2
-
- /*************************************************************************************
- *
- **************************************************************************************/
- void process_gps_data(char *buf,uint32_t size) //这里的buf就是从GPRMC,后开始
- {
- char tmp_char[16] = {0};
- char bcd_tmp[8] = {0};
- char *token[16] = {NULL};
- char size_each_token[16] = {0};//长度
- unsigned char hh,hl;
- unsigned char token_index = 0;
- unsigned char j;
-
- int i = 0;
- int index = 0;
- int dig_bit_num = 0;
- int ptr_each = 0;
- unsigned short speed;
- unsigned short aspect;
- double speed_jie = 0.0;
- GPS_Data_Type=GNRMC;
- sutGpsInfo.isGpsWork=1;
-
- if(GPS_Data_Type==GBGSV|| GPS_Data_Type==GPGSV)return;
- token[token_index] = buf;
- //RunMake(THIS_FILE_ID);
- while(index < size )
- {
- if(buf[index] == ',')
- {
- size_each_token[token_index] = ptr_each;
- if(ptr_each == 0) token[token_index] = NULL;
- //*(token[token_index] + ptr_each) = 0; //
- ptr_each = 0;
- token_index++;
-
- if(token_index==16)return;
-
- token[token_index] = buf+index+1; //skip this ','
- if(*(token[token_index]+1) == '*')
- {
- size_each_token[token_index] = 1; //cut of *hh\r\n
- }
- }
- else
- {
- ptr_each++;
- }
- index++;
- }
- /*
- GPS_NULL,
- GNRMC=1,
- GPVTG,
- GNGGA,
- GPGSV,
- GBGSV,
- */
- //RunMake(THIS_FILE_ID);
- switch(GPS_Data_Type){
-
- case GNRMC:
- //UTC time:hms
- if(token[GPRMC_UTC1_TOKEN_INDEX])
- {
- strncpy((char*)tmp_char,(char*)token[0],size_each_token[0]);
- translate_digitAscii_to_bcd(tmp_char,6,bcd_tmp); //去掉.xx
- //小时需要加8 因为北京是东8区
- hl=bcd_tmp[0]&0x0f;
- hh=bcd_tmp[0]&0xf0;
- hl+=8;
- if(hl>=10){
- hl-=10;
- hh+=0x10;
- //if(hh>0x20)hh=0; 处理GPS时间问题 V520_P1
- }
- sutGpsInfo.hour=(hh | hl);
- sutGpsInfo.minu = bcd_tmp[1];
- sutGpsInfo.sec = bcd_tmp[2];
- }
- //RunMake(THIS_FILE_ID);
- //Fix status
- if(token[GPRMC_STATUS_TOKEN_INDEX])
- {
- memset(tmp_char , 0 ,sizeof(tmp_char));
- strncpy((char*)tmp_char,(char*)token[1],size_each_token[1]);
- //if(*tmp_char == 'A'){
- if(*tmp_char == 'A'){
- sutGpsInfo.isGpsValid = 1;
- }else{
- sutGpsInfo.isGpsValid = 0;
- }
- }
- //RunMake(THIS_FILE_ID);
- if(sutGpsInfo.isGpsValid == 0)return;
- //latitude 纬度
- /*=====================================
- UTC time:hms status latitue north? longitue east? 速度(节) 方位角 UTC time 磁偏角 方向 模式 checksum
- $GPRMC hhmmss.ss A/V ddmm.mmmm N/S dddmm.mmmm E/W speed aspect ddmmyy 000-180 E/W A/D/E/N *hh
- For example: $GPRMC,024813.640,A,3158.4608,N,11848.3737,E,010.5,324.7,150706,,,A*50
- */
-
- if(token[GPRMC_LATITUE_TOKEN_INDEX])
- {
- char *p=token[GPRMC_LATITUE_TOKEN_INDEX];
- //ddmm.mmmmm
- int ddmm=atoi(p);
- int mmmmm=atoi((p+5));
- int dd=ddmm/100;
- int mm=ddmm%100;
- int dlen=getDlen(p+5);
- if(dlen<0){
- sutGpsInfo.isGpsValid = 0;
- return;
- }
- dlen = 6-dlen;
- //double fmm=(double)mm+(double)mmmmm/100000.0;
- //nmeaInfo.latitude=(double)dd+fmm/60.0;
- sutGpsInfo.latitue=dd*1000000;//露脠 路脜麓贸1000000卤露拢卢脮没脢媒虏驴路脰
- mm*=1000000;
- if(dlen==1) mmmmm*=10;
- else if(dlen==2) mmmmm*=100;
- else if(dlen==3) mmmmm*=1000;
- else if(dlen==4) mmmmm*=10000;
- else mmmmm*=100000;
- mm+=mmmmm;//路脰 路脜麓贸1000000卤露
- dd=mm/60;//露脠 路脜麓贸1000000卤露 脨隆脢媒虏驴路脰
- sutGpsInfo.latitue+=dd;//露脠 路脜麓贸1000000卤露
- }
- if(token[GPRMC_NORTH_TOKEN_INDEX])
- {
- strncpy((char*)tmp_char,(char*)token[3],size_each_token[3]);
- sutGpsInfo.NSFlag=*tmp_char;
-
- }
-
-
-
- //longitude 经度
- if(token[GPRMC_longitue_TOKEN_INDEX])
- {
- char *p=token[GPRMC_longitue_TOKEN_INDEX];
- int dddmm=atoi(p);
- int mmmmm=atoi((p+6));
- int ddd=dddmm/100;
- int mm=dddmm%100;
- int dlen=getDlen(p+6);
- if(dlen<0){
- sutGpsInfo.isGpsValid = 0;
- return;
- }
- dlen = 6-dlen;
-
- sutGpsInfo.longitue=ddd*1000000;//露脠 路脜麓贸1000000卤露 脮没脢媒虏驴路脰
- mm*=1000000;
- if(dlen==1) mmmmm*=10;
- else if(dlen==2) mmmmm*=100;
- else if(dlen==3) mmmmm*=1000;
- else if(dlen==4) mmmmm*=10000;
- else mmmmm*=100000;
- mm+=mmmmm;//路脰 路脜麓贸1000000卤露
- ddd=mm/60;//露脠 路脜麓贸1000000卤露 脨隆脢媒虏驴路脰
- sutGpsInfo.longitue+=ddd;
- if(token[GPRMC_EAST_TOKEN_INDEX])
- {
- strncpy((char*)tmp_char,(char*)token[5],size_each_token[5]);
- sutGpsInfo.EWFlag=*tmp_char;
-
- }
-
- }
-
- //Speed
- if(token[GPRMC_SPEED_TOKEN_INDEX])
- {
- //RunMake(THIS_FILE_ID);
- memset(tmp_char , 0 ,sizeof(tmp_char));
- strncpy((char*)tmp_char,(char*)token[GPRMC_SPEED_TOKEN_INDEX],size_each_token[GPRMC_SPEED_TOKEN_INDEX]);
- index = 0;
- while(index < size_each_token[GPRMC_SPEED_TOKEN_INDEX])
- {
- if(tmp_char[index] == '.')
- break;
- index++;
- }
- dig_bit_num = size_each_token[GPRMC_SPEED_TOKEN_INDEX]-index-1;
- //这里,index代表小数点前有多少位,dig_bit_num代表小数点后面有多少位
- //RunMake(THIS_FILE_ID);
- //ol_debug("dig_bit_num:%d,all len:%d",dig_bit_num,size_each_token[GPRMC_SPEED_TOKEN_INDEX]);
- #if 0
- if(index == 3)
- {
- speed_jie = (tmp_char[0]-0x30)*100
- + (tmp_char[1]-0x30)*10
- + (tmp_char[2]-0x30);
- }
- else if(index == 2)
- {
- speed_jie = (tmp_char[0]-0x30)*10
- + (tmp_char[1]-0x30);
- }
- else
- speed_jie = (tmp_char[0]-0x30);
- if(dig_bit_num > 0)
- speed_jie += (tmp_char[index+1]-0x30)*0.1;
- #else
- speed_jie = atoi(tmp_char);
- if(dig_bit_num>0)
- speed_jie += (tmp_char[index+1]-0x30)*0.1;
- #endif
- speed = (unsigned short)(speed_jie*1.852);
-
- sutGpsInfo.speed = ( ((speed/100)<<8) | (((speed /10)%10)<<4) | (speed %10) );
- //ol_debug("speed_jie to speed:%d,xinan speed:%d",speed,sutGpsInfo.speed);
- }
- //RunMake(THIS_FILE_ID);
- //Aspect 方向
- if(token[GPRMC_ASPECT_TOKEN_INDEX])
- {
- memset(tmp_char , 0 ,sizeof(tmp_char));
- strncpy((char*)tmp_char,(char*)token[GPRMC_ASPECT_TOKEN_INDEX],size_each_token[GPRMC_ASPECT_TOKEN_INDEX]);
- #if 0
- aspect = (unsigned short)((tmp_char[0]-0x30)*100
- + (tmp_char[1]-0x30)*10
- + (tmp_char[2]-0x30));
-
- //aspect = 150;
- sutGpsInfo.aspect= ( ((aspect/100) << 8) | (((aspect /10)%10)<<4) | (aspect %10) );
-
- #else
- aspect=atoi(tmp_char);
- aspect %=360;
- sutGpsInfo.aspect= ( ((aspect/100) << 8) | (((aspect /10)%10)<<4) | (aspect %10) );
- #endif
- }
- //RunMake(THIS_FILE_ID);
- //UTC2
- if(token[GPRMC_UTC2_TOKEN_INDEX])
- {
- memset(tmp_char , 0 ,sizeof(tmp_char));
- memset(bcd_tmp , 0 ,sizeof(bcd_tmp));
- strncpy((char*)tmp_char,(char*)token[GPRMC_UTC2_TOKEN_INDEX],size_each_token[GPRMC_UTC2_TOKEN_INDEX]);
- translate_digitAscii_to_bcd(tmp_char,6,bcd_tmp);
-
- sutGpsInfo.day = bcd_tmp[0];
- sutGpsInfo.month= bcd_tmp[1];
- sutGpsInfo.year = bcd_tmp[2];
- }
-
- break;
-
- case GPVTG:
-
- break;
- case GNGGA:
-
- if(token[GPRMC_STARTNUM_TOKEN_INDEX])
- {
-
- strncpy((char*)tmp_char,(char*)token[GPRMC_STARTNUM_TOKEN_INDEX],size_each_token[GPRMC_STARTNUM_TOKEN_INDEX]);
- if(size_each_token[GPRMC_STARTNUM_TOKEN_INDEX]<1)return;
- // bcd_tmp[0]=tmp_char[0];
- // bcd_tmp[1]=tmp_char[1];
- // bcd_tmp[2]=0;
- sutGpsInfo.startnum=atoi(tmp_char);
- }
- if(token[GPRMC_HIGHT_TOKEN_INDEX])
- {
- memset(tmp_char , 0 ,sizeof(tmp_char));
- strncpy((char*)tmp_char,(char*)token[GPRMC_HIGHT_TOKEN_INDEX],size_each_token[GPRMC_HIGHT_TOKEN_INDEX]);
- // bcd_tmp
- for(i=0,j=0;i<size_each_token[GPRMC_HIGHT_TOKEN_INDEX];i++){
-
- if(tmp_char[i]=='.'){
-
- i++;
- continue;
- }
- bcd_tmp[j]=tmp_char[i];
- i++;
- j++;
- }
- }
- sutGpsInfo.hight=atoi(bcd_tmp);
- // printf("get GPS hight--------------------%d---------\r\n",sutGpsInfo.hight);
-
- break;
- case GPGSV:
- if(token[GPS_BDVISUAL_INDEX])
- {
-
- strncpy((char*)tmp_char,(char*)token[GPS_BDVISUAL_INDEX],size_each_token[GPS_BDVISUAL_INDEX]);
- sutGpsInfo.GPSVisible_num=atoi(tmp_char);
- }
-
- break;
- case GBGSV:
- if(token[GPS_BDVISUAL_INDEX])
- {
-
- strncpy((char*)tmp_char,(char*)token[GPS_BDVISUAL_INDEX],size_each_token[GPS_BDVISUAL_INDEX]);
- sutGpsInfo.BDVisible_num=atoi(tmp_char);
- }
- break;
-
- }
-
-
- }
|