极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 25911|回复: 6

尝试DIY一个空气净化器 (7) 尝试为控制器加上GPS授时

[复制链接]
发表于 2014-3-31 17:28:14 | 显示全部楼层 |阅读模式
测试程序1:


功能:小内存提取GPS中的2行数据
优点:理论可行,小于350字节一次性发送无误,实际上GPS测试也无误
缺点:严格测试(650字节)一次性发送,GPRMC收不到,估计是延迟上有问题,且没有做校验

  1. char temp1[6],GPGGA[80],GPRMC[80];

  2. String test1= "";

  3. int jsq1,jsq2,jsq3;
  4. boolean change0,change1,change2,change3;


  5. void setup() {
  6.    Serial.begin(9600);
  7. }


  8. void loop() {

  9. jsq1=0;
  10. jsq2=0;
  11. jsq3=0;

  12. change0=0;
  13. change1=0;
  14. change2=0;
  15. change3=0;

  16. while (Serial.available() > 0) {  //监听串口输入

  17. change0=1;
  18.        
  19. if(!change1){
  20.        
  21. if(jsq1<4){
  22. temp1[jsq1]=Serial.read();
  23. delayMicroseconds(1200);
  24. jsq1++; //jsq1最终值为4,temp1:0-4共计5个字节

  25. if(jsq1==4){//值得注意的是,此时,temp1[4]并没有赋值
  26. temp1[4]=Serial.read(); //为temp1[4]赋值
  27. delayMicroseconds(1200);
  28. panduan1();//此时,收集到5个字符,可以进行判断
  29. }


  30. }else{

  31. //传递过程,temp1只有5个字节
  32. temp1[0]=temp1[1];
  33. temp1[1]=temp1[2];
  34. temp1[2]=temp1[3];
  35. temp1[3]=temp1[4];
  36. temp1[4]=Serial.read();

  37. delayMicroseconds(1200);

  38. panduan1();

  39. }

  40. ///////////////////////////////////////////////////////////////////////////
  41. }else if(change2){

  42. //GPGGA
  43. GPGGA[jsq1]=Serial.read();
  44. delayMicroseconds(1200);

  45. if(GPGGA[jsq1-2]=='*'){ //GPGGA字符串的结束
  46. change1=0;//恢复以前的状态,继续由临时数组temp1判断
  47. change2=0;//不再执行这段代码
  48. jsq1=0;//计数器1还原

  49. }else jsq1++;

  50. //////////////////////////////////////////////////////////////////////////
  51. }else if(change3){
  52. //GPRMC

  53. GPRMC[jsq1]=Serial.read();
  54. delayMicroseconds(1200);

  55. if(GPRMC[jsq1-2]=='*'){
  56. change1=0;//恢复以前的状态,继续由临时数组temp1判断
  57. change2=0;//不再执行这段代码
  58. jsq1=0;//计数器1还原

  59. }else jsq1++;

  60. }



  61. }
  62.   








  63. //最后的收尾工作
  64. if(change0){

  65. Serial.print("GPGGA[jsq1]=");
  66. Serial.println(GPGGA);
  67. Serial.print("GPRMC[jsq1]=");
  68. Serial.println(GPRMC);  
  69. Serial.println("----------------------");  

  70. //置0
  71. for(int col=0;col<80;col++)GPGGA[col]=0;
  72. for(int col=0;col<80;col++)GPRMC[col]=0;
  73. }

  74. }


  75. void panduan1(){

  76. //清空字符串,且数组转字符串
  77. //神奇的地球,数组==“字符串”貌似不能成立
  78. test1 = "";
  79. test1 += temp1[0];
  80. test1 += temp1[1];
  81. test1 += temp1[2];
  82. test1 += temp1[3];
  83. test1 += temp1[4];




  84. if(test1=="GPGGA"){//字符串GPGGA

  85.    Serial.println("find GPGGA");
  86.    change1=1;
  87.    change2=1;
  88.    change3=0;

  89.    //交接工作,接下来的数据都会给GPGGA
  90. GPGGA[0]=temp1[0];
  91. GPGGA[1]=temp1[1];
  92. GPGGA[2]=temp1[2];
  93. GPGGA[3]=temp1[3];
  94. GPGGA[4]=temp1[4];
  95.    jsq1=5;
  96.    
  97. }else if(test1=="GPRMC"){//字符串GPRMC

  98.    Serial.println("find GPRMC");
  99.    change1=1;
  100.    change2=0;
  101.    change3=1;

  102. GPRMC[0]=temp1[0];
  103. GPRMC[1]=temp1[1];
  104. GPRMC[2]=temp1[2];
  105. GPRMC[3]=temp1[3];
  106. GPRMC[4]=temp1[4];   
  107.    jsq1=5;
  108. }

  109. }
复制代码
回复

使用道具 举报

发表于 2014-3-31 19:35:39 | 显示全部楼层
提个问题:空气净化器应该在屋子里使用吧?  gps 能工作正常么?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-3-31 21:52:54 | 显示全部楼层
zoologist 发表于 2014-3-31 19:35
提个问题:空气净化器应该在屋子里使用吧?  gps 能工作正常么?

空气净化器的控制模块与净化器是可以分离的,以无线进行连接,所以,控制器本身可以充当空气质量检测器~~

PS:考窗边的话,GPS可以定位~~~获得时间就更不在话下
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-3-31 21:54:05 | 显示全部楼层
程序2,加入异或校验:

  1. char temp1[6],GPGGA[80],GPRMC[80];

  2. String test1= "";


  3. int jsq1,jsq2,jsq3;
  4. boolean change1,change2,change3;

  5. int GPGGAlong,GPRMClong;//GPGGA、GPRMC的长度
  6. int yihuoyunsuan;
  7. boolean jiaoyanjieguoA,jiaoyanjieguoB;


  8. void setup() {
  9.    Serial.begin(9600);
  10. }


  11. void loop() {

  12. jsq1=0;
  13. jsq2=0;
  14. jsq3=0;


  15. change1=0;
  16. change2=0;
  17. change3=0;

  18. GPGGAlong=0;
  19. GPRMClong=0;
  20. jiaoyanjieguoA=0;
  21. jiaoyanjieguoB=0;

  22. while (Serial.available() > 0) {  //监听串口输入


  23. if(!change1){

  24. if(jsq1<4){
  25. temp1[jsq1]=Serial.read();
  26. delayMicroseconds(1200);
  27. jsq1++; //jsq1最终值为4,temp1:0-4共计5个字节

  28. if(jsq1==4){//值得注意的是,此时,temp1[4]并没有赋值
  29. temp1[4]=Serial.read(); //为temp1[4]赋值
  30. delayMicroseconds(1200);
  31. panduan1();//此时,收集到5个字符,可以进行判断
  32. }


  33. }else{

  34. //传递过程,temp1只有5个字节
  35. temp1[0]=temp1[1];
  36. temp1[1]=temp1[2];
  37. temp1[2]=temp1[3];
  38. temp1[3]=temp1[4];
  39. temp1[4]=Serial.read();

  40. delayMicroseconds(1200);

  41. panduan1();

  42. }

  43. ///////////////////////////////////////////////////////////////////////////
  44. }else if(change2){

  45. //GPGGA
  46. GPGGA[jsq1]=Serial.read();
  47. delayMicroseconds(1200);

  48. if(GPGGA[jsq1-2]=='*'){ //GPGGA字符串的结束
  49. change1=0;//恢复以前的状态,继续由临时数组temp1判断
  50. change2=0;//不再执行这段代码
  51. GPGGAlong=jsq1-2;//记录这段字符串的长度GPGGAlong=jsq1-3+1(0位有一个字节)
  52. jsq1=0;//计数器1还原

  53. }else jsq1++;

  54. //////////////////////////////////////////////////////////////////////////
  55. }else if(change3){
  56. //GPRMC

  57. GPRMC[jsq1]=Serial.read();
  58. delayMicroseconds(1200);

  59. if(GPRMC[jsq1-2]=='*'){
  60. change1=0;//恢复以前的状态,继续由临时数组temp1判断
  61. change2=0;//不再执行这段代码
  62. GPRMClong=jsq1-2;
  63. jsq1=0;//计数器1还原

  64. }else jsq1++;

  65. }



  66. }




  67. /////////////////////////////////////////////////////异或运算,验证其数据可信

  68. if(GPGGAlong>0){ //字符串GPGGA的验证

  69. for(int col=0;col<GPGGAlong;col++){
  70. if(col==0)yihuoyunsuan=GPGGA[col];
  71. else yihuoyunsuan=yihuoyunsuan ^ GPGGA[col];
  72. }

  73. panduan2();


  74. if(test1[0]==GPGGA[GPGGAlong+1] && test1[1]==GPGGA[GPGGAlong+2]){
  75. //一致,则说明数据是有效的,输出校验结果
  76. jiaoyanjieguoA=1;
  77. }else{
  78. //不一致
  79. jiaoyanjieguoA=0;
  80. }


  81. }


  82. if(GPRMClong>0){//字符串GPRMC的验证

  83. for(int col=0;col<GPRMClong;col++){
  84. if(col==0)yihuoyunsuan=GPRMC[col];
  85. else yihuoyunsuan=yihuoyunsuan ^ GPRMC[col];
  86. }

  87. panduan2();


  88. if(test1[0]==GPRMC[GPRMClong+1] && test1[1]==GPRMC[GPRMClong+2]){
  89. //一致,则说明数据是有效的,输出校验结果
  90. jiaoyanjieguoB=1;
  91. }else{
  92. //不一致
  93. jiaoyanjieguoB=0;
  94. }


  95. }


  96. /////////////////////////////////////////////////

  97. if(jiaoyanjieguoA && jiaoyanjieguoB){

  98.   Serial.print("GPGGA[jsq1]=");
  99. Serial.println(GPGGA);
  100. Serial.print("GPRMC[jsq1]=");
  101. Serial.println(GPRMC);  
  102. Serial.println("----------------------");  

  103. }




  104. //最后的收尾工作
  105. if(GPRMClong>0 || GPGGAlong>0){



  106.   



  107. //置0
  108. for(int col=0;col<80;col++)GPGGA[col]=0;
  109. for(int col=0;col<80;col++)GPRMC[col]=0;
  110. }

  111. }


  112. void panduan1(){ //找到特定字符串的开始

  113. //清空字符串,且数组转字符串
  114. //神奇的地球,数组==“字符串”貌似不能成立
  115. test1 = "";
  116. test1 += temp1[0];
  117. test1 += temp1[1];
  118. test1 += temp1[2];
  119. test1 += temp1[3];
  120. test1 += temp1[4];




  121. if(test1=="GPGGA"){//字符串GPGGA

  122.    Serial.println("find GPGGA");
  123.    change1=1;
  124.    change2=1;
  125.    change3=0;

  126.    //交接工作,接下来的数据都会给GPGGA
  127. GPGGA[0]=temp1[0];
  128. GPGGA[1]=temp1[1];
  129. GPGGA[2]=temp1[2];
  130. GPGGA[3]=temp1[3];
  131. GPGGA[4]=temp1[4];
  132.    jsq1=5;

  133. }else if(test1=="GPRMC"){//字符串GPRMC

  134.    Serial.println("find GPRMC");
  135.    change1=1;
  136.    change2=0;
  137.    change3=1;

  138. GPRMC[0]=temp1[0];
  139. GPRMC[1]=temp1[1];
  140. GPRMC[2]=temp1[2];
  141. GPRMC[3]=temp1[3];
  142. GPRMC[4]=temp1[4];   
  143.    jsq1=5;
  144. }

  145. }


  146.   void panduan2(){ //异或运算的结果转化为字符串,以便于比较
  147.   

  148.   
  149.   if(yihuoyunsuan==0){
  150. //校验数10进制为0,直接填充字符串00
  151. test1="00";

  152. }else if(yihuoyunsuan>15){
  153. //此时转换为16进制以后,天然有2位,很理想,不用处理
  154. test1 = String(yihuoyunsuan,HEX);

  155. }else{
  156. //校验数10进制为1-15时,转换为16进制就只有1位数,所以需要在前面填0
  157. test1 = "0";
  158. test1 += String(yihuoyunsuan,HEX);

  159. }
  160.   
  161. test1.toUpperCase();//将其字母转换为大写

  162.   
  163.   }
复制代码
回复 支持 反对

使用道具 举报

发表于 2014-3-31 22:01:24 | 显示全部楼层
hi55234 发表于 2014-3-31 21:52
空气净化器的控制模块与净化器是可以分离的,以无线进行连接,所以,控制器本身可以充当空气质量检测器~~ ...

有道理,不错啊
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-4-1 23:01:12 | 显示全部楼层

GPStest:14/4/1 22:55:12

altitude= 255

weixingshu= 5

latitude= latitude:xxxx.xxxx N

longitude= longitude:xxxxx.xxxx E

仅适用于经纬度小数点后4位的情况,如果是5位的,则要做相应的修改
至于通用的又要复杂一点,要判断逗号的位置,类似于提取年月日的过程(部分数据长度不确定),所以,这里以节约资源的名义偷工减料了


  1. char temp1[6],GPGGA[80],GPRMC[80];

  2. String test1= "";

  3. String latitude = ""; //纬度
  4. String longitude = ""; //经度
  5.   

  6. int jsq1,jsq2,jsq3;
  7. boolean change1,change2,change3;

  8. int GPGGAlong,GPRMClong;//GPGGA、GPRMC的长度
  9. int yihuoyunsuan;
  10. boolean jiaoyanjieguoA,jiaoyanjieguoB;


  11. //UTC +8(北京时间)时、分、秒、年、月、日
  12. int utc8s,utc8f,utc8m,utc8n,utc8y,utc8r;
  13. //小月的数组
  14. int xiaoyue[5]={4,6,9,11};
  15. //日进位,月进位,年进位,大小月判断值
  16. boolean rijinwei,yuejinwei,nianjinwei,xiaoyueok;

  17. boolean dingweiok;//定位ok

  18. int weixingshu;//有效卫星数
  19. int altitude; //海拔


  20. void setup() {
  21.    Serial.begin(9600);
  22. }


  23. void loop() {

  24. jsq1=0;
  25. jsq2=0;
  26. jsq3=0;


  27. change1=0;
  28. change2=0;
  29. change3=0;

  30. GPGGAlong=0;
  31. GPRMClong=0;
  32. jiaoyanjieguoA=0;
  33. jiaoyanjieguoB=0;


  34.    //日进位,月进位
  35. rijinwei=0;
  36. yuejinwei=0;
  37. nianjinwei=0;
  38. xiaoyueok=0;

  39. dingweiok=0;//默认未定位

  40. weixingshu=0;//有效卫星数
  41. altitude=0; //海拔

  42. while (Serial.available() > 0) {  //监听串口输入


  43. if(!change1){

  44. if(jsq1<4){
  45. temp1[jsq1]=Serial.read();
  46. delayMicroseconds(1200);
  47. jsq1++; //jsq1最终值为4,temp1:0-4共计5个字节

  48. if(jsq1==4){//值得注意的是,此时,temp1[4]并没有赋值
  49. temp1[4]=Serial.read(); //为temp1[4]赋值
  50. delayMicroseconds(1200);
  51. panduan1();//此时,收集到5个字符,可以进行判断
  52. }


  53. }else{

  54. //传递过程,temp1只有5个字节
  55. temp1[0]=temp1[1];
  56. temp1[1]=temp1[2];
  57. temp1[2]=temp1[3];
  58. temp1[3]=temp1[4];
  59. temp1[4]=Serial.read();

  60. delayMicroseconds(1200);

  61. panduan1();

  62. }

  63. ///////////////////////////////////////////////////////////////////////////
  64. }else if(change2){

  65. //GPGGA
  66. GPGGA[jsq1]=Serial.read();
  67. delayMicroseconds(1200);

  68. if(GPGGA[jsq1-2]=='*'){ //GPGGA字符串的结束
  69. change1=0;//恢复以前的状态,继续由临时数组temp1判断
  70. change2=0;//不再执行这段代码
  71. GPGGAlong=jsq1-2;//记录这段字符串的长度GPGGAlong=jsq1-3+1(0位有一个字节)
  72. jsq1=0;//计数器1还原

  73. }else jsq1++;

  74. //////////////////////////////////////////////////////////////////////////
  75. }else if(change3){
  76. //GPRMC

  77. GPRMC[jsq1]=Serial.read();
  78. delayMicroseconds(1200);

  79. if(GPRMC[jsq1-2]=='*'){
  80. change1=0;//恢复以前的状态,继续由临时数组temp1判断
  81. change2=0;//不再执行这段代码
  82. GPRMClong=jsq1-2;
  83. jsq1=0;//计数器1还原

  84. }else jsq1++;

  85. }



  86. }




  87. /////////////////////////////////////////////////////异或运算,验证其数据可信

  88. if(GPGGAlong>0){ //字符串GPGGA的验证

  89. for(int col=0;col<GPGGAlong;col++){
  90. if(col==0)yihuoyunsuan=GPGGA[col];
  91. else yihuoyunsuan=yihuoyunsuan ^ GPGGA[col];
  92. }

  93. panduan2();


  94. if(test1[0]==GPGGA[GPGGAlong+1] && test1[1]==GPGGA[GPGGAlong+2]){
  95. //一致,则说明数据是有效的,输出校验结果
  96. jiaoyanjieguoA=1;
  97. }else{
  98. //不一致
  99. jiaoyanjieguoA=0;
  100. }


  101. }


  102. if(GPRMClong>0){//字符串GPRMC的验证

  103. for(int col=0;col<GPRMClong;col++){
  104. if(col==0)yihuoyunsuan=GPRMC[col];
  105. else yihuoyunsuan=yihuoyunsuan ^ GPRMC[col];
  106. }

  107. panduan2();


  108. if(test1[0]==GPRMC[GPRMClong+1] && test1[1]==GPRMC[GPRMClong+2]){
  109. //一致,则说明数据是有效的,输出校验结果
  110. jiaoyanjieguoB=1;
  111. }else{
  112. //不一致
  113. jiaoyanjieguoB=0;
  114. }


  115. }


  116. /////////////////////////////////////////////////

  117. if(jiaoyanjieguoA && jiaoyanjieguoB){ //要求GPGGA、GPRMC同时通过奇偶验证才能进行下一步


  118. gpstime(); //gps时间提取,日月年、时分秒、转为北京时间
  119. Serial.println(test1);//这个字符串是gpstime

  120. jingduweidu();//拾取经度、维度

  121. if(dingweiok)haiba();//在定位有效的情况下拾取海拔、有效卫星数




  122. Serial.print("altitude= ");
  123. Serial.println(altitude);

  124.   Serial.print("weixingshu= ");
  125. Serial.println(weixingshu);


  126. Serial.print("latitude= ");
  127. Serial.println(latitude);

  128. Serial.print("longitude= ");
  129.   Serial.println(longitude);

  130. Serial.print("GPGGA[jsq1]=");
  131. Serial.println(GPGGA);
  132. Serial.print("GPRMC[jsq1]=");
  133. Serial.println(GPRMC);  
  134. Serial.println("----------------------");  

  135. }




  136. //最后的收尾工作
  137. if(GPRMClong>0 || GPGGAlong>0){
  138. //置0
  139. for(int col=0;col<80;col++)GPGGA[col]=0;
  140. for(int col=0;col<80;col++)GPRMC[col]=0;
  141. }

  142. }


  143. void panduan1(){ //找到特定字符串的开始

  144. //清空字符串,且数组转字符串
  145. //神奇的地球,数组==“字符串”貌似不能成立

  146. test1 = String(temp1[0]);
  147. test1 += temp1[1];
  148. test1 += temp1[2];
  149. test1 += temp1[3];
  150. test1 += temp1[4];




  151. if(test1=="GPGGA"){//字符串GPGGA

  152.   // Serial.println("find GPGGA");
  153.    change1=1;
  154.    change2=1;
  155.    change3=0;

  156.    //交接工作,接下来的数据都会给GPGGA
  157. GPGGA[0]=temp1[0];
  158. GPGGA[1]=temp1[1];
  159. GPGGA[2]=temp1[2];
  160. GPGGA[3]=temp1[3];
  161. GPGGA[4]=temp1[4];
  162.    jsq1=5;

  163. }else if(test1=="GPRMC"){//字符串GPRMC

  164. //  Serial.println("find GPRMC");
  165.    change1=1;
  166.    change2=0;
  167.    change3=1;

  168. GPRMC[0]=temp1[0];
  169. GPRMC[1]=temp1[1];
  170. GPRMC[2]=temp1[2];
  171. GPRMC[3]=temp1[3];
  172. GPRMC[4]=temp1[4];   
  173.    jsq1=5;
  174. }

  175. }


  176.   void panduan2(){ //异或运算的结果转化为字符串,以便于比较
  177.   

  178.   
  179.   if(yihuoyunsuan==0){
  180. //校验数10进制为0,直接填充字符串00
  181. test1="00";

  182. }else if(yihuoyunsuan>15){
  183. //此时转换为16进制以后,天然有2位,很理想,不用处理
  184. test1 = String(yihuoyunsuan,HEX);

  185. }else{
  186. //校验数10进制为1-15时,转换为16进制就只有1位数,所以需要在前面填0
  187. test1 = "0";
  188. test1 += String(yihuoyunsuan,HEX);

  189. }
  190.   
  191. test1.toUpperCase();//将其字母转换为大写

  192.   
  193.   }
  194.   
  195.   void gpstime(){
  196.   
  197.   
  198.   //时间部分:UTC转为UTC+8,北京时间(时:分:秒)
  199. //时:
  200. test1 =  String(GPRMC[6]);//复用test1这个数组来节约内存
  201. test1 +=  GPRMC[7];
  202. utc8s=test1.toInt()+8;
  203. if(utc8s>23)rijinwei=1;//提示后面程序换算为北京时间的时候,日要+1天
  204. utc8s=utc8s%24;//字符串转换为整数,参与运算

  205. //分:
  206. test1 =  String(GPRMC[8]);//复用test1这个数组来节约内存
  207. test1 +=  GPRMC[9];
  208. utc8f=test1.toInt();//字符串转换为整数,参与运算

  209. //秒:
  210. test1 =  String(GPRMC[10]);//复用test1这个数组来节约内存
  211. test1 +=  GPRMC[11];
  212. utc8m=test1.toInt();//字符串转换为整数,参与运算

  213. ////////////////////////////////////////////////
  214. //提取UTC日期(日、月、年),这个日期位于GPRMC第9个数据中,所以定位第九个逗号的位置即可


  215. jsq2=0;
  216. jsq3=0;
  217.   for(int col=0;col<80;col++){
  218.   if(GPRMC[col]==',')jsq2++;
  219. if(jsq2==9){
  220. jsq3=col;//找到9第个逗号的前一个位置,循环0开始,0的时候就已经后推了一位置
  221. col=80;//找到9个逗号就跳出循环
  222. }
  223. }  

  224. //日
  225. test1 =  String(GPRMC[jsq3+1]);//复用test1这个数组来节约内存,9第个逗号前一位后推2个位置
  226. test1 +=  GPRMC[jsq3+2];
  227. utc8r=test1.toInt();//字符串转换为整数,参与运算

  228. //月
  229. test1 =  String(GPRMC[jsq3+3]);//复用test1这个数组来节约内存
  230. test1 +=  GPRMC[jsq3+4];
  231. utc8y=test1.toInt();//字符串转换为整数,参与运算

  232. //年
  233. test1 =  String(GPRMC[jsq3+5]);//复用test1这个数组来节约内存
  234. test1 +=  GPRMC[jsq3+6];
  235. utc8n=test1.toInt();//字符串转换为整数,参与运算


  236. jsq2=0; //防止以后会用,先行清零
  237. jsq3=0;

  238. //讨论日、月、年进位(大月、小月、平年、闰年的问题)
  239. if(rijinwei){

  240. //先讨论2月的问题
  241. if(utc8y==2 && utc8r==28){
  242. if(utc8n%4==0)utc8r=29;//闰年可加一天
  243. else {
  244. utc8r=1;
  245. yuejinwei=1;
  246. }

  247. }else{

  248. //判断大小月
  249. for(int col=0;col<4;col++){
  250. if(xiaoyue[col]==utc8y)xiaoyueok=1;
  251. }

  252. if(xiaoyueok && utc8r==30){ //小月最后一天
  253. utc8r=1;
  254. yuejinwei=1;
  255. }else if(!xiaoyueok && utc8r==31){ //大月最后一天
  256. utc8r=1;
  257. yuejinwei=1;
  258. }else{
  259. utc8r++;//剩下的情况自加1就可以了
  260. }
  261. }

  262. }

  263. if(yuejinwei && utc8y==12){ //最后一月
  264. utc8y=1;
  265. nianjinwei=1;
  266. }else if(yuejinwei){
  267. utc8y++;
  268. }

  269. if(nianjinwei)utc8n++;

  270. ////////////////
  271. test1 = "GPStest:";
  272. test1 += utc8n;
  273. test1 += "/";
  274. test1 += utc8y;
  275. test1 += "/";
  276. test1 += utc8r;
  277. test1 += " ";
  278. test1 += utc8s;
  279. test1 += ":";
  280. test1 += utc8f;
  281. test1 += ":";
  282. test1 += utc8m;

  283.   
  284.   }
  285.   
  286.   
  287.   void jingduweidu(){
  288.   
  289.   if(GPRMC[17]=='A'){//已定位
  290.   dingweiok=1;//已定位
  291.   
  292. latitude = "latitude:"; //纬度
  293. for(int col=19;col<28;col++) latitude += GPRMC[col];
  294. latitude += " ";
  295. latitude += GPRMC[29];
  296.   
  297.   longitude = "longitude:"; //经度
  298. for(int col=31;col<41;col++)  longitude += GPRMC[col];
  299. longitude += " ";
  300. longitude += GPRMC[42];
  301.   
  302.   }
  303.   
  304.   }
  305.   
  306.   
  307.   void haiba(){
  308.   
  309.   //有效卫星数

  310.   test1 =  String(GPGGA[44]);
  311.   test1 +=  GPGGA[45];
  312.   weixingshu=test1.toInt();//字符串转换为整数,参与运算
  313.   
  314.   //海拔
  315.   //找到开始的逗号,与结束的逗号位置
  316.   for(int col=47;col<64;col++){
  317.   if(GPGGA[col]==',' && jsq2==0)jsq2=col;//海拔开始的逗号
  318.   if(col>jsq2){
  319.   if(GPGGA[col]==','){
  320.   jsq3=col;//海拔结束的逗号
  321.   col=64;//跳出循环
  322.   }
  323.   }
  324.   }
  325.   
  326.   //拾取海拔高度
  327.   for(int col=jsq2+1;col<jsq3;col++){
  328.   if(col==jsq2+1)test1 =  String(GPGGA[col]);
  329.   else test1 +=  GPGGA[col];
  330.   }
  331.   
  332.   altitude=test1.toInt();//字符串转换为整数,参与运算;
  333.   }

  334.   
  335.   
  336.   
  337.   
  338.   
  339.   
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-4-19 17:44:52 | 显示全部楼层











可以在蓝牙gps、空气检测模块之间切换

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-19 15:35 , Processed in 0.045399 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表