📄 gps_module.lst
字号:
262 {
263 1 uchar comma=9;
264 1 uchar i=0;
265 1 uchar date_array[10];
266 1 uchar *gps_date_data=date_array;
267 1
268 1 if(GPS_OK==get_sub_str(gps_buff, comma, gps_date_data))
269 1 {
270 2 for (i=0;i<3;i++)
271 2 {
272 3 gps_bcd_date[i]=((*gps_date_data)-'0')*10+*(gps_date_data+1)-'0';
273 3
274 3 gps_date_data+=2;
275 3 }
276 2
277 2 return GPS_OK;
278 2 }
279 1
280 1 else
281 1 {
282 2 return GPS_ERROR;
283 2 }
284 1 }
285 /******************************************************************************
286 *
287 *函数功能:取出GPS天线的短路、开路状态
288 *
289 ******************************************************************************/
290
291 /********************************************************************************
292 *
293 * 函数功能:将纬度数据转换成以‘分’为单位的数值
294 * 输入 :纬度字符串
295 * 输出 :以‘分’为单位的数值,乘以10000后,并去除小数点后的一位
296 * 数据包 :GPRMC
297 *
298 ********************************************************************************/
299
300 /********************************************************************************
301 *
C51 COMPILER V7.09 GPS_MODULE 09/25/2008 11:56:18 PAGE 6
302 * 函数功能:将经度数据转换成以‘分’为单位的数值
303 * 输入 :经度字符串
304 * 输出 :以‘分’为单位的数值,乘以10000后,并去除小数点后的一位
305 * 数据包 :GPRMC
306 *
307 ********************************************************************************/
308
309 /********************************************************************************
310 *
311 * 函数功能:根据GPS数据判断当前方向值
312 * 输入 :GPS方向数据
313 * 输出 :方向值
314 * 数据包 :GPRMC
315 *
316 ********************************************************************************/
317
318 int get_direction(uchar *gps_buff, uint *gps_direction)
319 {
320 1 uchar comma=8;
321 1 uchar i=0;
322 1 int point=0;
323 1 uchar n=0;
324 1 uchar direction_array[10];
325 1 uchar *gps_direction_data=direction_array;
326 1
327 1 if(GPS_OK==get_sub_str(gps_buff, comma, gps_direction_data))
328 1
329 1 {
330 2 if(*gps_direction_data==0) /*当两个逗号之间是空时,赋值为0,防止赋随机值*/
331 2
332 2 {
333 3 *gps_direction='\0';
334 3 }
335 2
336 2 else /*当两个逗号之间是正确数据时,正常处理*/
337 2
338 2 {
339 3 for(i=0;i<6;i++)
340 3 {
341 4 if (*gps_direction_data=='.')
342 4 {
343 5 point=1;
344 5
345 5 gps_direction_data++;
346 5
347 5 continue;
348 5 }
349 4
350 4 if (!point)
351 4 {
352 5 *gps_direction=((*gps_direction)*10)+((*gps_direction_data)-0x30);
353 5 }
354 4
355 4 else
356 4 {
357 5 if (n<1)
358 5 {
359 6 *gps_direction=((*gps_direction)*10)+((*gps_direction_data)-0x30);
360 6
361 6 n++;
362 6 }
363 5 }
C51 COMPILER V7.09 GPS_MODULE 09/25/2008 11:56:18 PAGE 7
364 4
365 4 gps_direction_data++;
366 4 }
367 3 }
368 2
369 2 return GPS_OK;
370 2 }
371 1
372 1 else
373 1
374 1 {
375 2 return GPS_ERROR;
376 2 }
377 1 }
378
379 /********************************************************************************
380 *
381 * 函数功能:输出高度数值
382 * 输入 :GPS高度数据
383 * 输出 :高度值
384 * 数据包 :GPGGA
385 *
386 ********************************************************************************/
387
388 int get_altitude(uchar *gps_buff, uint *gps_altitude)
389 {
390 1 uchar comma=9;
391 1 uchar i=0;
392 1 int point=0;
393 1 uchar n=0;
394 1 uchar altitude_array[10];
395 1 uchar *gps_altitude_data=altitude_array;
396 1
397 1 if(GPS_OK==get_sub_str(gps_buff, comma, gps_altitude_data))
398 1 {
399 2 if(*gps_altitude_data==0) /*当两个逗号之间是空时,赋值为0,防止赋随机值*/
400 2
401 2 {
402 3 *gps_altitude='\0';
403 3 }
404 2
405 2 else /*当两个逗号之间是正确数据时,正常处理*/
406 2 {
407 3 for(i=0;i<4;i++) /*高度数值最多由4个字符组成*/
408 3 {
409 4 if (*gps_altitude_data=='.') /*当遇到小数点时*/
410 4 {
411 5 point=1;
412 5
413 5 gps_altitude_data++;
414 5
415 5 continue;
416 5 }
417 4
418 4 if (!point) /*遇到小数点前的计算*/
419 4 {
420 5 *gps_altitude=((*gps_altitude)*10)+((*gps_altitude_data)-0x30);
421 5 }
422 4
423 4 else if (n<1) /*遇到小数点后并保留一位小数的计算*/
424 4 {
425 5 *gps_altitude=((*gps_altitude)*10)+((*gps_altitude_data)-0x30);
C51 COMPILER V7.09 GPS_MODULE 09/25/2008 11:56:18 PAGE 8
426 5 n++;
427 5 }
428 4
429 4 gps_altitude_data++;
430 4 }
431 3 }
432 2 return GPS_OK;
433 2 }
434 1
435 1 else
436 1 {
437 2 return GPS_ERROR;
438 2 }
439 1 }
440
441
442 /********************************************************************************
443 *
444 * 函数功能:取出GPS字符串中卫星数量部分
445 * 输入 :GPS字符串数据
446 * 输出 :卫星个数
447 * 数据包 :GPGGA
448 *
449 ********************************************************************************/
450
451 int get_satelt_num(uchar *gps_buff, uchar *satelt_number)
452 {
453 1 uchar comma=7;
454 1 uchar i=0;
455 1 uchar satellite_array[10];
456 1 uchar *satelt_number_data=satellite_array;
457 1
458 1 if(GPS_OK==get_sub_str(gps_buff, comma, satelt_number_data))
459 1 {
460 2 for (i=0;i<2;i++)
461 2 {
462 3 *satelt_number=(*satelt_number)*10+((*satelt_number_data)-0x30);
463 3
464 3 satelt_number_data++;
465 3 }
466 2 return GPS_OK;
467 2 }
468 1 else
469 1 {
470 2 return GPS_ERROR;
471 2 }
472 1 }
473
474 /****************************************************************************************
475 *
476 * 函数功能:提取速度数据
477 * 输入 :GPS速度数据
478 * 输出 :海里/小时的速度值
479 * 数据包 :GPRMC
480 * 修改日期:2006-5-8
481 * 修改内容:将速度单位 厘米/秒(最大误差36米/小时)又转换成(节/小时),即保持数据的原始单位
-
482 ****************************************************************************************/
483
484 int get_speed(uchar *gps_buff, uint *gps_speed)
485 {
486 1 uchar comma=7;
C51 COMPILER V7.09 GPS_MODULE 09/25/2008 11:56:18 PAGE 9
487 1 int point=0;
488 1 uchar i=0;
489 1 uchar n=0;
490 1 // ulong mid_speed=0;
491 1 uchar speed_array[10];
492 1 uchar *gps_speed_data=speed_array;
493 1
494 1 if(GPS_OK==get_sub_str(gps_buff, comma, gps_speed_data))
495 1 {
496 2 if(*gps_speed_data==0) /*当两个逗号之间是空时,赋值为0,防止赋随机值*/
497 2
498 2 {
499 3 *gps_speed='\0';
500 3 }
501 2
502 2 else /*当两个逗号之间是正确数据时,正常处理*/
503 2 {
504 3 for(i=0;i<6;i++)
505 3 {
506 4 if (*gps_speed_data=='.')
507 4 {
508 5 point=1;
509 5
510 5 gps_speed_data++;
511 5
512 5 continue;
513 5 }
514 4
515 4 if (!point) /*小数点前的运算*/
516 4 {
517 5 *gps_speed=((*gps_speed)*10)+((*gps_speed_data)-0x30);
518 5 }
519 4 else /*小数点后的运算*/
520 4 {
521 5 if (n<2) /*对小数点后两位小数进行处理*/
522 5 {
523 6 *gps_speed=((*gps_speed)*10)+((*gps_speed_data)-0x30);
524 6
525 6 n++;
526 6 }
527 5 }
528 4
529 4 gps_speed_data++;
530 4 }
531 3
532 3 // mid_speed=(mid_speed)*514/1000; /*先除以100回复两位小数,再乘以(514/10)转换为厘米/秒*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -