![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pissa pepper
mybc95.cpp@0:a9ea0137c16b, 2018-04-20 (annotated)
- Committer:
- donghuoyinzi
- Date:
- Fri Apr 20 02:49:37 2018 +0000
- Revision:
- 0:a9ea0137c16b
pissa pepper
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donghuoyinzi | 0:a9ea0137c16b | 1 | //#include "mbedOS.h" |
donghuoyinzi | 0:a9ea0137c16b | 2 | #include "mbed.h" |
donghuoyinzi | 0:a9ea0137c16b | 3 | #include "string" |
donghuoyinzi | 0:a9ea0137c16b | 4 | #include "vector" |
donghuoyinzi | 0:a9ea0137c16b | 5 | #include "mybc95.h" |
donghuoyinzi | 0:a9ea0137c16b | 6 | #include "myf401.h" |
donghuoyinzi | 0:a9ea0137c16b | 7 | |
donghuoyinzi | 0:a9ea0137c16b | 8 | /*****bc95 reset intance ******/ |
donghuoyinzi | 0:a9ea0137c16b | 9 | DigitalOut bc95Act::reset(RESET); //PC_13 bc95 reset pin |
donghuoyinzi | 0:a9ea0137c16b | 10 | /***** bc95 uart intance******/ |
donghuoyinzi | 0:a9ea0137c16b | 11 | Serial bc95Act::uart(BC95_TX,BC95_RX); //SERIAL_TX(D1), SERIAL_RX(D0) |
donghuoyinzi | 0:a9ea0137c16b | 12 | |
donghuoyinzi | 0:a9ea0137c16b | 13 | string send_udp1="AT+NSOST=0,150.138.119.138,8089,15";//201712130810210A0B0C0D |
donghuoyinzi | 0:a9ea0137c16b | 14 | // 01234567890123456789012345678901234567890123456789012345678901234567890 |
donghuoyinzi | 0:a9ea0137c16b | 15 | // 1 2 3 4 5 6 7 |
donghuoyinzi | 0:a9ea0137c16b | 16 | string send_udp2=",0102030405060708090A0500000B01";//201712130810210A0B0C0D |
donghuoyinzi | 0:a9ea0137c16b | 17 | // 01234567890123456789012345678901234567890123456789012345678901234567890 |
donghuoyinzi | 0:a9ea0137c16b | 18 | // 1 2 3 4 5 6 7 |
donghuoyinzi | 0:a9ea0137c16b | 19 | string send_udp3; |
donghuoyinzi | 0:a9ea0137c16b | 20 | |
donghuoyinzi | 0:a9ea0137c16b | 21 | string send_udp; |
donghuoyinzi | 0:a9ea0137c16b | 22 | |
donghuoyinzi | 0:a9ea0137c16b | 23 | /***************************** |
donghuoyinzi | 0:a9ea0137c16b | 24 | Desc.: bc95 initialization |
donghuoyinzi | 0:a9ea0137c16b | 25 | Auth.:ZY |
donghuoyinzi | 0:a9ea0137c16b | 26 | Vesion:2017.7.2 |
donghuoyinzi | 0:a9ea0137c16b | 27 | *****************************/ |
donghuoyinzi | 0:a9ea0137c16b | 28 | void bc95Act::init(void) |
donghuoyinzi | 0:a9ea0137c16b | 29 | { |
donghuoyinzi | 0:a9ea0137c16b | 30 | uart.baud(9600); |
donghuoyinzi | 0:a9ea0137c16b | 31 | //uart.attach(&getISR,SerialBase::RxIrq); |
donghuoyinzi | 0:a9ea0137c16b | 32 | wait(20); //上电等待50秒(给bc95自动驻网) |
donghuoyinzi | 0:a9ea0137c16b | 33 | } |
donghuoyinzi | 0:a9ea0137c16b | 34 | |
donghuoyinzi | 0:a9ea0137c16b | 35 | void bc95Act::put(void) |
donghuoyinzi | 0:a9ea0137c16b | 36 | { |
donghuoyinzi | 0:a9ea0137c16b | 37 | //poC_putF=0; |
donghuoyinzi | 0:a9ea0137c16b | 38 | if(f401Act::datacnt==0) return; |
donghuoyinzi | 0:a9ea0137c16b | 39 | else{ |
donghuoyinzi | 0:a9ea0137c16b | 40 | char datastr1[4]=""; |
donghuoyinzi | 0:a9ea0137c16b | 41 | char datastr2[7]=""; |
donghuoyinzi | 0:a9ea0137c16b | 42 | sprintf(datastr1,"%d",(f401Act::datacnt+15)); |
donghuoyinzi | 0:a9ea0137c16b | 43 | sprintf(datastr2,"%06X",f401Act::datacnt); |
donghuoyinzi | 0:a9ea0137c16b | 44 | send_udp1=send_udp1.replace(32,2,datastr1); |
donghuoyinzi | 0:a9ea0137c16b | 45 | send_udp2=send_udp2.replace(23,6,datastr2); |
donghuoyinzi | 0:a9ea0137c16b | 46 | |
donghuoyinzi | 0:a9ea0137c16b | 47 | send_udp=send_udp1+send_udp2+send_udp3; |
donghuoyinzi | 0:a9ea0137c16b | 48 | |
donghuoyinzi | 0:a9ea0137c16b | 49 | uart.printf("AT+NSOCR=DGRAM,17,8089,1\r\n");//MY_USART_OUT(USART2,open_udp,27); |
donghuoyinzi | 0:a9ea0137c16b | 50 | wait_ms(50); |
donghuoyinzi | 0:a9ea0137c16b | 51 | uart.printf("%s\r\n",send_udp.c_str());//MY_USART_OUT(USART2,send_udp,86); |
donghuoyinzi | 0:a9ea0137c16b | 52 | wait_ms(50); |
donghuoyinzi | 0:a9ea0137c16b | 53 | uart.printf("AT+NSOCL=0\r\n");//MY_USART_OUT(USART2,close_udp,12); |
donghuoyinzi | 0:a9ea0137c16b | 54 | wait_ms(50); |
donghuoyinzi | 0:a9ea0137c16b | 55 | //bc95script::poC_putS=1; |
donghuoyinzi | 0:a9ea0137c16b | 56 | //send_udp3.clear(); |
donghuoyinzi | 0:a9ea0137c16b | 57 | } |
donghuoyinzi | 0:a9ea0137c16b | 58 | } |