![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
clock
myScope/mybc95.cpp@0:17e9016529cf, 2018-05-08 (annotated)
- Committer:
- donghuoyinzi
- Date:
- Tue May 08 02:13:50 2018 +0000
- Revision:
- 0:17e9016529cf
- Child:
- 1:013b9fdc4e78
CLOCK_needle_180508
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donghuoyinzi | 0:17e9016529cf | 1 | #include "mybc95.h" |
donghuoyinzi | 0:17e9016529cf | 2 | |
donghuoyinzi | 0:17e9016529cf | 3 | char bc95Act::buf[50]={0x00}; |
donghuoyinzi | 0:17e9016529cf | 4 | int bc95Act::stpSe=0; int bc95Act::cnt=0; int bc95Act::cntche; int bc95Act::cntlink=0; |
donghuoyinzi | 0:17e9016529cf | 5 | int bc95Act::year=0; int bc95Act::mon=0; int bc95Act::day=0; |
donghuoyinzi | 0:17e9016529cf | 6 | int bc95Act::hour=0; int bc95Act::min=0; int bc95Act::sec=0; |
donghuoyinzi | 0:17e9016529cf | 7 | const int mon_table[12]={31,28,31,30,31,30,31,31,30,31,30,31}; |
donghuoyinzi | 0:17e9016529cf | 8 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 9 | Fun.: base initialization of bc95。 |
donghuoyinzi | 0:17e9016529cf | 10 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 11 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 12 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 13 | void bc95Act::init(void) |
donghuoyinzi | 0:17e9016529cf | 14 | { |
donghuoyinzi | 0:17e9016529cf | 15 | know::uart3.baud(9600); |
donghuoyinzi | 0:17e9016529cf | 16 | know::uart3.attach(&getISR,SerialBase::RxIrq); |
donghuoyinzi | 0:17e9016529cf | 17 | } |
donghuoyinzi | 0:17e9016529cf | 18 | |
donghuoyinzi | 0:17e9016529cf | 19 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 20 | Fun.: initialization of bc95 start。 |
donghuoyinzi | 0:17e9016529cf | 21 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 22 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 23 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 24 | void bc95Act::start(void) |
donghuoyinzi | 0:17e9016529cf | 25 | { |
donghuoyinzi | 0:17e9016529cf | 26 | know::pow.write(1); //BC95POW_ON(); |
donghuoyinzi | 0:17e9016529cf | 27 | wait(50); |
donghuoyinzi | 0:17e9016529cf | 28 | } |
donghuoyinzi | 0:17e9016529cf | 29 | |
donghuoyinzi | 0:17e9016529cf | 30 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 31 | Fun.: initialization of bc95 data。 |
donghuoyinzi | 0:17e9016529cf | 32 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 33 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 34 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 35 | void bc95Act::data(void) |
donghuoyinzi | 0:17e9016529cf | 36 | { |
donghuoyinzi | 0:17e9016529cf | 37 | stpSe=1; |
donghuoyinzi | 0:17e9016529cf | 38 | cnt=0; |
donghuoyinzi | 0:17e9016529cf | 39 | } |
donghuoyinzi | 0:17e9016529cf | 40 | |
donghuoyinzi | 0:17e9016529cf | 41 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 42 | Fun.: initialization of bc95 ready。 |
donghuoyinzi | 0:17e9016529cf | 43 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 44 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 45 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 46 | void bc95Act::ready(void) |
donghuoyinzi | 0:17e9016529cf | 47 | { |
donghuoyinzi | 0:17e9016529cf | 48 | |
donghuoyinzi | 0:17e9016529cf | 49 | } |
donghuoyinzi | 0:17e9016529cf | 50 | |
donghuoyinzi | 0:17e9016529cf | 51 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 52 | Fun.: bc95 revoke |
donghuoyinzi | 0:17e9016529cf | 53 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 54 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 55 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 56 | void bc95Act::revok(void) |
donghuoyinzi | 0:17e9016529cf | 57 | { |
donghuoyinzi | 0:17e9016529cf | 58 | know::pow.write(0); //BC95POW_OFF(); |
donghuoyinzi | 0:17e9016529cf | 59 | } |
donghuoyinzi | 0:17e9016529cf | 60 | |
donghuoyinzi | 0:17e9016529cf | 61 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 62 | Fun.: get time。 |
donghuoyinzi | 0:17e9016529cf | 63 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 64 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 65 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 66 | void bc95Act::get_tim(void) |
donghuoyinzi | 0:17e9016529cf | 67 | { |
donghuoyinzi | 0:17e9016529cf | 68 | /* if(bc95Act::stpSe==1){ |
donghuoyinzi | 0:17e9016529cf | 69 | uart.printf("AT+CCLK?\r\n"); |
donghuoyinzi | 0:17e9016529cf | 70 | jump_Judg(2,250); |
donghuoyinzi | 0:17e9016529cf | 71 | } |
donghuoyinzi | 0:17e9016529cf | 72 | if(bc95Act::stpSe ==2) CheckOK(200,1,10); //10是最大的查询次数 |
donghuoyinzi | 0:17e9016529cf | 73 | if(bc95Act::stpSe ==250){ //规范250是失败 |
donghuoyinzi | 0:17e9016529cf | 74 | know:: polSta[5] =2; |
donghuoyinzi | 0:17e9016529cf | 75 | bc95Act::stpSe =0; |
donghuoyinzi | 0:17e9016529cf | 76 | } |
donghuoyinzi | 0:17e9016529cf | 77 | if(bc95Act::stpSe ==200){ //规范200是成功, |
donghuoyinzi | 0:17e9016529cf | 78 | bc95Act::stpSe =0; |
donghuoyinzi | 0:17e9016529cf | 79 | bc95Act::setrtc(); |
donghuoyinzi | 0:17e9016529cf | 80 | know:: polSta[5] =1; |
donghuoyinzi | 0:17e9016529cf | 81 | } |
donghuoyinzi | 0:17e9016529cf | 82 | return;*/ |
donghuoyinzi | 0:17e9016529cf | 83 | } |
donghuoyinzi | 0:17e9016529cf | 84 | |
donghuoyinzi | 0:17e9016529cf | 85 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 86 | Fun.: get know。 |
donghuoyinzi | 0:17e9016529cf | 87 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 88 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 89 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 90 | void bc95Act::get_knw(void) |
donghuoyinzi | 0:17e9016529cf | 91 | { |
donghuoyinzi | 0:17e9016529cf | 92 | if(bc95Act::stpSe==1){ |
donghuoyinzi | 0:17e9016529cf | 93 | know::uart3.printf("AT+CCLK?\r\n"); |
donghuoyinzi | 0:17e9016529cf | 94 | jump_Judg(2,250); |
donghuoyinzi | 0:17e9016529cf | 95 | |
donghuoyinzi | 0:17e9016529cf | 96 | } |
donghuoyinzi | 0:17e9016529cf | 97 | if(bc95Act::stpSe==2) CheckOK(200,1,10); //10是最大的查询次数 |
donghuoyinzi | 0:17e9016529cf | 98 | if(bc95Act::stpSe==250){ //规范250是失败 |
donghuoyinzi | 0:17e9016529cf | 99 | know::polSta[6]=2; |
donghuoyinzi | 0:17e9016529cf | 100 | bc95Act::stpSe=0; |
donghuoyinzi | 0:17e9016529cf | 101 | } |
donghuoyinzi | 0:17e9016529cf | 102 | if(bc95Act::stpSe==200){ //规范200是成功, |
donghuoyinzi | 0:17e9016529cf | 103 | bc95Act::stpSe=0; |
donghuoyinzi | 0:17e9016529cf | 104 | //know::magtsk(); |
donghuoyinzi | 0:17e9016529cf | 105 | know::polSta[6]=1; |
donghuoyinzi | 0:17e9016529cf | 106 | } |
donghuoyinzi | 0:17e9016529cf | 107 | return; |
donghuoyinzi | 0:17e9016529cf | 108 | } |
donghuoyinzi | 0:17e9016529cf | 109 | |
donghuoyinzi | 0:17e9016529cf | 110 | /***************************************** |
donghuoyinzi | 0:17e9016529cf | 111 | Fun.: rtc set。 |
donghuoyinzi | 0:17e9016529cf | 112 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 113 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 114 | *****************************************/ |
donghuoyinzi | 0:17e9016529cf | 115 | void bc95Act::setrtc(void) |
donghuoyinzi | 0:17e9016529cf | 116 | { |
donghuoyinzi | 0:17e9016529cf | 117 | uint32_t secc; |
donghuoyinzi | 0:17e9016529cf | 118 | |
donghuoyinzi | 0:17e9016529cf | 119 | changdate(); |
donghuoyinzi | 0:17e9016529cf | 120 | secc=changsec(); |
donghuoyinzi | 0:17e9016529cf | 121 | set_time(secc); |
donghuoyinzi | 0:17e9016529cf | 122 | } |
donghuoyinzi | 0:17e9016529cf | 123 | |
donghuoyinzi | 0:17e9016529cf | 124 | void bc95Act::changdate (void) |
donghuoyinzi | 0:17e9016529cf | 125 | { |
donghuoyinzi | 0:17e9016529cf | 126 | unsigned char temp1=0; |
donghuoyinzi | 0:17e9016529cf | 127 | |
donghuoyinzi | 0:17e9016529cf | 128 | int i; |
donghuoyinzi | 0:17e9016529cf | 129 | |
donghuoyinzi | 0:17e9016529cf | 130 | for(temp1=0;temp1<27;temp1++){ |
donghuoyinzi | 0:17e9016529cf | 131 | year= (buf[temp1+5]-0x30)*10+(buf [temp1+6]-0x30)+2000; //年 |
donghuoyinzi | 0:17e9016529cf | 132 | mon = (buf[temp1+8]-0x30)*10+(buf [temp1+9]-0x30); //月 |
donghuoyinzi | 0:17e9016529cf | 133 | day = (buf[temp1+11]-0x30)*10+(buf [temp1+12]-0x30); //日 |
donghuoyinzi | 0:17e9016529cf | 134 | |
donghuoyinzi | 0:17e9016529cf | 135 | if((buf[temp1+23]== '0') && (buf [temp1+24] == '0')) //UTC |
donghuoyinzi | 0:17e9016529cf | 136 | hour =(buf[temp1+14]-0x30)*10+(buf [temp1+15]-0x30)+8; //时 |
donghuoyinzi | 0:17e9016529cf | 137 | else if((buf[temp1+23]== '0') && (buf [temp1+24] == '8')) //EAST 8 |
donghuoyinzi | 0:17e9016529cf | 138 | hour=(buf[temp1+14]-0x30)*10+(buf[temp1+15]-0x30); |
donghuoyinzi | 0:17e9016529cf | 139 | else hour=(buf[temp1+14]-0x30)*10+(buf[temp1+15]-0x30)+8; |
donghuoyinzi | 0:17e9016529cf | 140 | min=(buf[temp1+17]-0x30)*10+(buf[temp1+18]-0x30); //分 |
donghuoyinzi | 0:17e9016529cf | 141 | sec= (buf[temp1+20]-0x30)*10+(buf[temp1+21]-0x30); //秒 |
donghuoyinzi | 0:17e9016529cf | 142 | } |
donghuoyinzi | 0:17e9016529cf | 143 | for(i=0;i<27;i++) buf[i]=0; |
donghuoyinzi | 0:17e9016529cf | 144 | } |
donghuoyinzi | 0:17e9016529cf | 145 | |
donghuoyinzi | 0:17e9016529cf | 146 | uint32_t bc95Act::changsec (void) |
donghuoyinzi | 0:17e9016529cf | 147 | { |
donghuoyinzi | 0:17e9016529cf | 148 | uint16_t t; |
donghuoyinzi | 0:17e9016529cf | 149 | uint32_t seccount=0; |
donghuoyinzi | 0:17e9016529cf | 150 | |
donghuoyinzi | 0:17e9016529cf | 151 | for(t=1970;t< year;t++){ |
donghuoyinzi | 0:17e9016529cf | 152 | if(Is_Leap_Year(t)) seccount+=31622400; |
donghuoyinzi | 0:17e9016529cf | 153 | else seccount+=31536000; |
donghuoyinzi | 0:17e9016529cf | 154 | } |
donghuoyinzi | 0:17e9016529cf | 155 | mon-=1; |
donghuoyinzi | 0:17e9016529cf | 156 | for(t=0;t< mon;t++){ |
donghuoyinzi | 0:17e9016529cf | 157 | seccount+=(uint32_t) mon_table[t]*86400; |
donghuoyinzi | 0:17e9016529cf | 158 | if(Is_Leap_Year(year)&&t==1) seccount+=86400; |
donghuoyinzi | 0:17e9016529cf | 159 | } |
donghuoyinzi | 0:17e9016529cf | 160 | seccount+=(uint32_t)( day-1)*86400; |
donghuoyinzi | 0:17e9016529cf | 161 | seccount+=(uint32_t) hour*3600; |
donghuoyinzi | 0:17e9016529cf | 162 | seccount+=(uint32_t) min*60; |
donghuoyinzi | 0:17e9016529cf | 163 | seccount+= sec; |
donghuoyinzi | 0:17e9016529cf | 164 | return seccount; |
donghuoyinzi | 0:17e9016529cf | 165 | } |
donghuoyinzi | 0:17e9016529cf | 166 | |
donghuoyinzi | 0:17e9016529cf | 167 | /***************************************** |
donghuoyinzi | 0:17e9016529cf | 168 | Fun.: 闰年判断。 |
donghuoyinzi | 0:17e9016529cf | 169 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 170 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 171 | *****************************************/ |
donghuoyinzi | 0:17e9016529cf | 172 | uint8_t bc95Act::Is_Leap_Year(uint16_t year) |
donghuoyinzi | 0:17e9016529cf | 173 | { |
donghuoyinzi | 0:17e9016529cf | 174 | if(year%4==0){ |
donghuoyinzi | 0:17e9016529cf | 175 | if(year%100==0){ |
donghuoyinzi | 0:17e9016529cf | 176 | if(year%400==0)return 1;// |
donghuoyinzi | 0:17e9016529cf | 177 | else return 0; |
donghuoyinzi | 0:17e9016529cf | 178 | }else return 1; |
donghuoyinzi | 0:17e9016529cf | 179 | }else return 0; |
donghuoyinzi | 0:17e9016529cf | 180 | } |
donghuoyinzi | 0:17e9016529cf | 181 | |
donghuoyinzi | 0:17e9016529cf | 182 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 183 | Fun.: 判断AT指令返回值。 |
donghuoyinzi | 0:17e9016529cf | 184 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 185 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 186 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 187 | void bc95Act::jump_Judg(int Chekstep,int Nexnexstep){ |
donghuoyinzi | 0:17e9016529cf | 188 | bc95Act::stpSe =Chekstep; |
donghuoyinzi | 0:17e9016529cf | 189 | bc95Act::cntche=0; |
donghuoyinzi | 0:17e9016529cf | 190 | bc95Act::cntlink++; |
donghuoyinzi | 0:17e9016529cf | 191 | if(bc95Act::cntlink>2){ |
donghuoyinzi | 0:17e9016529cf | 192 | bc95Act::stpSe=Nexnexstep; |
donghuoyinzi | 0:17e9016529cf | 193 | bc95Act::cntlink=0; |
donghuoyinzi | 0:17e9016529cf | 194 | } |
donghuoyinzi | 0:17e9016529cf | 195 | } |
donghuoyinzi | 0:17e9016529cf | 196 | |
donghuoyinzi | 0:17e9016529cf | 197 | void bc95Act::CheckOK(int Nexstp,int Lastp,int maxstp) |
donghuoyinzi | 0:17e9016529cf | 198 | { |
donghuoyinzi | 0:17e9016529cf | 199 | if(know::polSta[17]=="1"){ |
donghuoyinzi | 0:17e9016529cf | 200 | know::polSta[17]="0"; |
donghuoyinzi | 0:17e9016529cf | 201 | bc95Act::stpSe=Nexstp; |
donghuoyinzi | 0:17e9016529cf | 202 | bc95Act::cntlink=0; |
donghuoyinzi | 0:17e9016529cf | 203 | } |
donghuoyinzi | 0:17e9016529cf | 204 | else{ |
donghuoyinzi | 0:17e9016529cf | 205 | bc95Act::stpSe= bc95Act::stpSe; |
donghuoyinzi | 0:17e9016529cf | 206 | bc95Act::cntche++; |
donghuoyinzi | 0:17e9016529cf | 207 | if(bc95Act::cntche>maxstp) bc95Act::stpSe=Lastp; |
donghuoyinzi | 0:17e9016529cf | 208 | } |
donghuoyinzi | 0:17e9016529cf | 209 | } |
donghuoyinzi | 0:17e9016529cf | 210 | |
donghuoyinzi | 0:17e9016529cf | 211 | void bc95Act::put(void) |
donghuoyinzi | 0:17e9016529cf | 212 | { |
donghuoyinzi | 0:17e9016529cf | 213 | know::uart3.printf("AT+NSOCR=DGRAM,17,9090,1\r\n"); |
donghuoyinzi | 0:17e9016529cf | 214 | wait_ms(50); |
donghuoyinzi | 0:17e9016529cf | 215 | know::uart3.printf("%s",know::polDat[2].c_str()); |
donghuoyinzi | 0:17e9016529cf | 216 | wait_ms(50); |
donghuoyinzi | 0:17e9016529cf | 217 | know::uart3.printf("AT+NSOCL=0\r\n"); |
donghuoyinzi | 0:17e9016529cf | 218 | wait_ms(50); |
donghuoyinzi | 0:17e9016529cf | 219 | |
donghuoyinzi | 0:17e9016529cf | 220 | know::polSta[7] =1; |
donghuoyinzi | 0:17e9016529cf | 221 | } |
donghuoyinzi | 0:17e9016529cf | 222 | |
donghuoyinzi | 0:17e9016529cf | 223 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 224 | Fun.: bc95接收数据中断函数。 |
donghuoyinzi | 0:17e9016529cf | 225 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 226 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 227 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 228 | void bc95Act::getISR(void) |
donghuoyinzi | 0:17e9016529cf | 229 | { |
donghuoyinzi | 0:17e9016529cf | 230 | char buf; |
donghuoyinzi | 0:17e9016529cf | 231 | |
donghuoyinzi | 0:17e9016529cf | 232 | buf=know::uart3.getc(); |
donghuoyinzi | 0:17e9016529cf | 233 | bc95Act::buf[cnt]=buf; |
donghuoyinzi | 0:17e9016529cf | 234 | cnt++; |
donghuoyinzi | 0:17e9016529cf | 235 | if(cnt>5&&buf==0x0D) cnt=0; |
donghuoyinzi | 0:17e9016529cf | 236 | if(cnt>40) cnt=0; |
donghuoyinzi | 0:17e9016529cf | 237 | } |