![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
clock
Diff: myScope/mybc95.cpp
- Revision:
- 1:013b9fdc4e78
- Parent:
- 0:17e9016529cf
- Child:
- 2:e54d9d87c6cb
--- a/myScope/mybc95.cpp Tue May 08 02:13:50 2018 +0000 +++ b/myScope/mybc95.cpp Sat May 12 03:03:14 2018 +0000 @@ -1,10 +1,20 @@ #include "mybc95.h" -char bc95Act::buf[50]={0x00}; -int bc95Act::stpSe=0; int bc95Act::cnt=0; int bc95Act::cntche; int bc95Act::cntlink=0; -int bc95Act::year=0; int bc95Act::mon=0; int bc95Act::day=0; -int bc95Act::hour=0; int bc95Act::min=0; int bc95Act::sec=0; -const int mon_table[12]={31,28,31,30,31,30,31,31,30,31,30,31}; +char buf_bc95Tx[7]=""; +char bc95Act::buf[50]= {0x00}; +char bc95Act::buf_bc95Tx[buf_bc95TxSize]= {0x00}; +char bc95Act::buf_bc95Rx[buf_bc95RxSize]= {0x00}; +int bc95Act::stpSe=0; +int bc95Act::cnt=0; +int bc95Act::cntche; +int bc95Act::cntlink=0; +int bc95Act::year=0; +int bc95Act::mon=0; +int bc95Act::day=0; +int bc95Act::hour=0; +int bc95Act::min=0; +int bc95Act::sec=0; +const int mon_table[12]= {31,28,31,30,31,30,31,31,30,31,30,31}; /***************************** Fun.: base initialization of bc95。 Desc.: @@ -65,21 +75,16 @@ *****************************/ void bc95Act::get_tim(void) { - /* if(bc95Act::stpSe==1){ - uart.printf("AT+CCLK?\r\n"); - jump_Judg(2,250); - } - if(bc95Act::stpSe ==2) CheckOK(200,1,10); //10是最大的查询次数 - if(bc95Act::stpSe ==250){ //规范250是失败 - know:: polSta[5] =2; - bc95Act::stpSe =0; - } - if(bc95Act::stpSe ==200){ //规范200是成功, - bc95Act::stpSe =0; - bc95Act::setrtc(); - know:: polSta[5] =1; - } - return;*/ + tm *tim; + time_t seconds=time(NULL); + tim=localtime(&seconds); + + buf_bc95Tx[0]=char(tim->tm_year-100); + buf_bc95Tx[1]=char(tim->tm_mon); + buf_bc95Tx[2]=char(tim->tm_mday); + buf_bc95Tx[3]=char(tim->tm_hour); + buf_bc95Tx[4]=char(tim->tm_min); + buf_bc95Tx[5]=char(tim->tm_sec); } /***************************** @@ -96,13 +101,13 @@ } if(bc95Act::stpSe==2) CheckOK(200,1,10); //10是最大的查询次数 if(bc95Act::stpSe==250){ //规范250是失败 - know::polSta[6]=2; + know::polSta[15]="2"; bc95Act::stpSe=0; } if(bc95Act::stpSe==200){ //规范200是成功, bc95Act::stpSe=0; //know::magtsk(); - know::polSta[6]=1; + know::polSta[15]="1"; } return; } @@ -127,20 +132,20 @@ int i; - for(temp1=0;temp1<27;temp1++){ + for(temp1=0; temp1<27; temp1++) { year= (buf[temp1+5]-0x30)*10+(buf [temp1+6]-0x30)+2000; //年 mon = (buf[temp1+8]-0x30)*10+(buf [temp1+9]-0x30); //月 day = (buf[temp1+11]-0x30)*10+(buf [temp1+12]-0x30); //日 - + if((buf[temp1+23]== '0') && (buf [temp1+24] == '0')) //UTC - hour =(buf[temp1+14]-0x30)*10+(buf [temp1+15]-0x30)+8; //时 + hour =(buf[temp1+14]-0x30)*10+(buf [temp1+15]-0x30)+8; //时 else if((buf[temp1+23]== '0') && (buf [temp1+24] == '8')) //EAST 8 - hour=(buf[temp1+14]-0x30)*10+(buf[temp1+15]-0x30); + hour=(buf[temp1+14]-0x30)*10+(buf[temp1+15]-0x30); else hour=(buf[temp1+14]-0x30)*10+(buf[temp1+15]-0x30)+8; min=(buf[temp1+17]-0x30)*10+(buf[temp1+18]-0x30); //分 - sec= (buf[temp1+20]-0x30)*10+(buf[temp1+21]-0x30); //秒 + sec= (buf[temp1+20]-0x30)*10+(buf[temp1+21]-0x30); //秒 } - for(i=0;i<27;i++) buf[i]=0; + for(i=0; i<27; i++) buf[i]=0; } uint32_t bc95Act::changsec (void) @@ -148,20 +153,20 @@ uint16_t t; uint32_t seccount=0; - for(t=1970;t< year;t++){ + for(t=1970; t< year; t++) { if(Is_Leap_Year(t)) seccount+=31622400; - else seccount+=31536000; + else seccount+=31536000; } mon-=1; - for(t=0;t< mon;t++){ + for(t=0; t< mon; t++) { seccount+=(uint32_t) mon_table[t]*86400; - if(Is_Leap_Year(year)&&t==1) seccount+=86400; + if(Is_Leap_Year(year)&&t==1) seccount+=86400; } - seccount+=(uint32_t)( day-1)*86400; + seccount+=(uint32_t)( day-1)*86400; seccount+=(uint32_t) hour*3600; - seccount+=(uint32_t) min*60; + seccount+=(uint32_t) min*60; seccount+= sec; - return seccount; + return seccount; } /***************************************** @@ -171,12 +176,12 @@ *****************************************/ uint8_t bc95Act::Is_Leap_Year(uint16_t year) { - if(year%4==0){ - if(year%100==0){ - if(year%400==0)return 1;// - else return 0; - }else return 1; - }else return 0; + if(year%4==0) { + if(year%100==0) { + if(year%400==0)return 1;// + else return 0; + } else return 1; + } else return 0; } /***************************** @@ -210,14 +215,14 @@ void bc95Act::put(void) { - know::uart3.printf("AT+NSOCR=DGRAM,17,9090,1\r\n"); + know::uart3.printf("AT+NSOCR=DGRAM,17,9090,1\r\n"); wait_ms(50); - know::uart3.printf("%s",know::polDat[2].c_str()); + know::uart3.printf("%s",know::polDat[2].c_str()); wait_ms(50); - know::uart3.printf("AT+NSOCL=0\r\n"); + know::uart3.printf("AT+NSOCL=0\r\n"); wait_ms(50); - know::polSta[7] =1; + know::polSta[16]=1; } /*****************************