Advertisement
cyjyj_0524

nmea

May 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. // ConsoleApplication1.cpp : 此檔案包含 'main' 函式。程式會於該處開始執行及結束執行。
  2. //
  3.  
  4. //#include "pch.h"
  5. #include "stdafx.h"
  6. #include <iostream>
  7. #include <fstream>
  8. #include <string>
  9. using namespace std;
  10.  
  11.  
  12.  
  13. void main()
  14. {
  15. fstream nmea_new("d:\\nmea_new.txt", ios_base::out);
  16. fstream file("d:\\nmea_sample.txt", ios_base::in);
  17.  
  18. if (!file)
  19. cout << "smple檔案開啟失敗" << endl;
  20. else if (!nmea_new)
  21. cout << "new檔案開啟失敗" << endl;
  22.  
  23. else {
  24. string s;
  25. string target = "GPGGA";
  26. int pos = 0;
  27. while (!file.eof()) {
  28. file >> s;
  29.  
  30. if (s.find(target) != string::npos) {
  31.  
  32. nmea_new << s << endl;
  33.  
  34. for (int i = 1; s[i] != '*'; i++) {
  35. cout << s[i];
  36. }
  37. cout << ' ' << s[s.find('*') + 1] << s[s.find('*') + 2] << endl;
  38.  
  39. int cknum = 0;
  40. if (s[s.find('*') + 1] >= 'A' && s[s.find('*') + 1] <= 'Z')
  41. cknum += (s[s.find('*') + 1] - 'A' + 10) * 16;
  42. else
  43. cknum += (s[s.find('*') + 1] - '0') * 16;
  44. if (s[s.find('*') + 2] >= 'A' && s[s.find('*') + 2] <= 'Z')
  45. cknum += s[s.find('*') + 2] - 'A' + 10;
  46. else
  47. cknum += s[s.find('*') + 2] - '0';
  48.  
  49. int cksum = 0;
  50. for (int i = 1; s[i] != '*'; i++) {
  51. cksum ^= s[i];
  52. }
  53.  
  54. // cout << "***cknum= " << cknum << endl;
  55. // cout << "***cksum= " << cksum << endl;
  56. if (cksum == cknum)
  57. cout << "PASS" << endl;
  58. else
  59. cout << "WRONG" << endl;
  60.  
  61. unsigned int j, cnt = 0, pos = 0;
  62. if ((j = s.find(',')) != string::npos) {
  63. // cout << "***j= " << j << endl;
  64. // cout << "***pos= " << pos << endl;
  65. cout << "Time : " << s[s.find(',') + 1] << s[s.find(',') + 2] << " : " << s[s.find(',') + 3] << s[s.find(',') + 4] << " : " << s[s.find(',') + 5] << s[s.find(',') + 6] << endl;
  66. pos = j + 6;
  67. // cout << "***j= " << j << endl;
  68. // cout << "***pos= " << pos << endl;
  69. cout << "緯度 : " << s[s.find(',', pos) + 1] << s[s.find(',', pos) + 2] << ' ' << s[s.find(',', pos) + 3] << s[s.find(',', pos) + 4] << '.' << s[s.find('.') + 1] << s[s.find('.') + 2] << ' ' << s[s.find('.') + 3] << s[s.find('.') + 4];
  70. pos += 10;
  71. // cout << "***j= " << j << endl;
  72. // cout << "***pos= " << pos << endl;
  73. cout << ' ' << s[s.find(',', pos) + 1] << endl;
  74. pos += 2;
  75. // cout << "***j= " << j << endl;
  76. // cout << "***pos= " << pos << endl;
  77. cout << "經度 : " << s[s.find(',', pos) + 1] << s[s.find(',', pos) + 2] << s[s.find(',', pos) + 3] << ' ' << s[s.find(',', pos) + 4] << s[s.find(',', pos) + 5] << '.' << s[s.find(',', pos) + 7] << s[s.find(',', pos) + 8] << ' ' << s[s.find(',', pos) + 9] << s[s.find(',', pos) + 10];
  78. pos += 11;
  79. // cout << "***j= " << j << endl;
  80. // cout << "***pos= " << pos << endl;
  81. cout << ' ' << s[s.find(',', pos) + 1] << endl;
  82. pos += 2;
  83. // cout << "***j= " << j << endl;
  84. // cout << "***pos= " << pos << endl;
  85. }
  86.  
  87.  
  88. }
  89. }
  90.  
  91.  
  92. cout << "寫入完畢" << endl;
  93.  
  94.  
  95. }
  96.  
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement