![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pissa pepper
Fork of Nucleo by
Diff: mybc95.cpp
- Revision:
- 0:a9ea0137c16b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mybc95.cpp Fri Apr 20 02:49:37 2018 +0000 @@ -0,0 +1,58 @@ +//#include "mbedOS.h" +#include "mbed.h" +#include "string" +#include "vector" +#include "mybc95.h" +#include "myf401.h" + +/*****bc95 reset intance ******/ +DigitalOut bc95Act::reset(RESET); //PC_13 bc95 reset pin +/***** bc95 uart intance******/ +Serial bc95Act::uart(BC95_TX,BC95_RX); //SERIAL_TX(D1), SERIAL_RX(D0) + +string send_udp1="AT+NSOST=0,150.138.119.138,8089,15";//201712130810210A0B0C0D + // 01234567890123456789012345678901234567890123456789012345678901234567890 + // 1 2 3 4 5 6 7 +string send_udp2=",0102030405060708090A0500000B01";//201712130810210A0B0C0D + // 01234567890123456789012345678901234567890123456789012345678901234567890 + // 1 2 3 4 5 6 7 +string send_udp3; + +string send_udp; + +/***************************** +Desc.: bc95 initialization +Auth.:ZY +Vesion:2017.7.2 +*****************************/ +void bc95Act::init(void) +{ + uart.baud(9600); + //uart.attach(&getISR,SerialBase::RxIrq); + wait(20); //上电等待50秒(给bc95自动驻网) +} + +void bc95Act::put(void) +{ + //poC_putF=0; + if(f401Act::datacnt==0) return; + else{ + char datastr1[4]=""; + char datastr2[7]=""; + sprintf(datastr1,"%d",(f401Act::datacnt+15)); + sprintf(datastr2,"%06X",f401Act::datacnt); + send_udp1=send_udp1.replace(32,2,datastr1); + send_udp2=send_udp2.replace(23,6,datastr2); + + send_udp=send_udp1+send_udp2+send_udp3; + + uart.printf("AT+NSOCR=DGRAM,17,8089,1\r\n");//MY_USART_OUT(USART2,open_udp,27); + wait_ms(50); + uart.printf("%s\r\n",send_udp.c_str());//MY_USART_OUT(USART2,send_udp,86); + wait_ms(50); + uart.printf("AT+NSOCL=0\r\n");//MY_USART_OUT(USART2,close_udp,12); + wait_ms(50); + //bc95script::poC_putS=1; + //send_udp3.clear(); + } +}