![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pissa pepper
Fork of Nucleo by
Revision 0:a9ea0137c16b, committed 2018-04-20
- Comitter:
- donghuoyinzi
- Date:
- Fri Apr 20 02:49:37 2018 +0000
- Commit message:
- pissa pepper
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Apr 20 02:49:37 2018 +0000 @@ -0,0 +1,28 @@ +#include "mbed.h" + +/****my头文件*****/ +#include "main.h" +/******************************* +Desc.:whattime/where setting/clearing all Flag/Stat/Sequ +Auth.:ZY +Date.:2017.7.2 +*******************************/ +int main() +{ + f401Act::init(); //映射硬件初始化 + bc95Act::init(); + f401Act::ready(); + //f401Act::reiwdg(); //Refresh iwdg + + while(1){ + + /****非节拍任务响应*****/ + /****节拍任务响应*****/ + if(F401script::poC_ticisrS==1){ + F401script::poC_ticisrS=0; + bc95Act::put(); + } + } +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Fri Apr 20 02:49:37 2018 +0000 @@ -0,0 +1,26 @@ +#include "mybc95.h" +#include "myf401.h" + +#ifndef main_H +#define main_H + +//******注入变量分配标号**********// + + int F401script::poL=1; + int F401script::poC_initF=0; int F401script::poC_initS=0; + int F401script::poC_rdyF=0; int F401script::poC_rdyS=0; int F401script::poC_revokF=0; int F401script::poC_revokS=0; + int F401script::poC_getF=0; int F401script::poC_getS=0; int F401script::poC_putF=0; int F401script::poC_putS=0; + int F401script::poC_putcallF=0; int F401script::poC_putcallS=0; + int F401script::poC_ticisrF=0; int F401script::poC_ticisrS=0; int F401script::poC_ticisr1F=0; int F401script::poC_ticisr1S=0; + int F401script::poC_isrF=0; int F401script::poC_isrS=0; int F401script::poC_step=0; + + int bc95script::poL=2; + int bc95script::poC_initF=0; int bc95script::poC_initS=0; int bc95script::poC_redyF=0; int bc95script::poC_redyS=0; + int bc95script::poC_revokF=0; int bc95script::poC_revokS=0; int bc95script::poC_getimF=0; int bc95script::poC_getimS=0; + int bc95script::poC_putF=0; int bc95script::poC_putS=0; + int bc95script::poC_setrtcF=0; int bc95script::poC_setrtcS=0; int bc95script::poC_cntlink=0; int bc95script::poC_cntche=0; + int bc95script::poC_stpSe=0; int bc95script::poC_cntSe=0; int bc95script::poC_isrS=0; int bc95script::poC_year=0; + int bc95script::poC_mon=0; int bc95script::poC_day=0; + int bc95script::poC_hour=0; int bc95script::poC_min=0; int bc95script::poC_sec=0; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Apr 20 02:49:37 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/994bdf8177cb \ No newline at end of file
--- /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(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mybc95.h Fri Apr 20 02:49:37 2018 +0000 @@ -0,0 +1,30 @@ +#ifndef mybc95_H +#define mybc95_H + class bc95script + { + public: + static int poL; + static int poC_initF; static int poC_initS; static int poC_redyF; static int poC_redyS; + static int poC_revokF; static int poC_revokS; static int poC_getimF; static int poC_getimS; + static int poC_putF; static int poC_putS; + static int poC_setrtcF; static int poC_setrtcS; + static int poC_stpSe; static int poC_cntSe; static int poC_cntlink; static int poC_cntche; + static int poC_isrS; static int poC_year; static int poC_mon; static int poC_day; + static int poC_hour; static int poC_min; static int poC_sec; + }; + extern bc95script bc95scpt; + + class bc95Act + { + public: + static void init(void); //bc95 initialization + static void put(void); + + private: + + //static DigitalOut pow; + static DigitalOut reset; + static Serial uart; + }; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myf401.cpp Fri Apr 20 02:49:37 2018 +0000 @@ -0,0 +1,144 @@ +//#include "mbedOS.h" +#include "mbed.h" + +#include "myf401.h" + +#include "vector" +int f401Act::f401cnt=0; +int f401Act::datacnt=0; +/******iwdg instance*********/ +//IWDG_HandleTypeDef f401Act::hiwdg; //????? +/******pc uart instance*********/ +Serial f401Act::uart(DEBUG_TX, DEBUG_RX); //PA_9, PA_10 to pc debug +/******led instance*********/ +DigitalOut f401Act::led2(LED2); //PC_8 +DigitalOut f401Act::led3(LED3); //PC_9 +/**** time1 intance*****/ +Ticker f401Act::time1; +Ticker f401Act::timerone; +Timer f401Act::outtime; + +extern string send_udp3; + +char f401Act::buf[512]={0x00}; +char bufz[512]=""; +/******************************* +Desc.: f401pc initializations,include iwdg\system tick\key interrupt +Auth.:ZY +Vesion:2017.7.2 +*******************************/ +void f401Act::init(void) +{ + /*******iwdg init*******/ + //hiwdg.Instance=IWDG;//?? + //hiwdg.Init.Prescaler=IWDG_PRESCALER_16;//??? 分频因子[4,8,16,32,64,128,256,256] + //hiwdg.Init.Reload=4095;//??? 递减计数0~0XFFF + //HAL_IWDG_Init(&hiwdg); //??? + //set_time(1514806505);//自1970年1月1日0时0分0秒到2018年1月1日11时35分05秒 + f401Act::time1.attach(&isr_tick,1.0); //定时器中断设置 + f401Act::timerone.attach_us(&isr_tick1,1000); //定时器中断配置 +} + +/***************************************** +Desc.: pc ready +Auth.:ZY +Vesion:2017.7.2 +*****************************************/ +void f401Act::ready(void) +{ + uart.baud(9600); + uart.attach(&isr_pc,SerialBase::RxIrq); +} + +/***************************************** +Desc.: pc get +Auth.:ZY +Vesion:2017.7.2 +*****************************************/ +void f401Act::get(void) +{ + uart.putc(0x31); //接受母钟数据请求(协议) + wait_ms(500); + //for(int i=0;i<datacnt;i++) bufCom[i]=buf[i]; + //for(int i=0;i<datacnt;i++){ + //uart.putc(buf[i]); + //buf[i]=0; + //} + F401script::poC_getS=1; +} + +/***************************************** +Desc.: 呼叫母钟,五次 +Auth.:ZY +Vesion:2017.7.2 +*****************************************/ +void f401Act::put_call(void) +{ + outtime.start(); + outtime.reset(); + while(F401script::poC_isrS==0||outtime.read_ms()<=50){ + uart.putc(0x53); + wait_ms(1); + } + outtime.stop(); + if(F401script::poC_isrS==1){ + F401script::poC_isrS=0; + + F401script::poC_putcallS=1; + } +} + +/***************************************** +Desc.:reflesh iwdg +Auth.:ZY +Vesion:2017.7.2 +*****************************************/ +//void f401Act::reiwdg(void) +//{ + //HAL_IWDG_Refresh(&hiwdg); //???? //reflesh iwdg +//} +void f401Act::isr_tick(void) +{ + F401script::poC_ticisrS=1; + +} +/***************************************** +Desc.: system ticker ISR +Auth.:ZY +Vesion:2017.7.2 +*****************************************/ +void f401Act::isr_tick1(void) +{ + if(F401script::poC_step>0) F401script::poC_step--; + + if(F401script::poC_step==1){ + datacnt=f401cnt; //获取数据个数 + send_udp3.clear(); + //for(int i=0;i<f401cnt;i++) send_udp3.push_back(buf[i]); + send_udp3=bufz; + f401cnt=0; //数据缓存个数清零 + memset(bufz,0,sizeof(buf)); + memset(buf,0,sizeof(buf)); + } +} +/***************************************** +Desc.: pc getc ISR +Auth.:ZY +Vesion:2017.7.2 +*****************************************/ +void f401Act::isr_pc(void) +{ + F401script::poC_step=20; //计时3ms + char bufx; + char bufy[40]=""; + bufx=uart.getc(); + buf[f401cnt]=bufx; + sprintf(bufy,"%02X",bufx); + strcat(bufz,bufy); + //if(buf[0]==0x41) F401script::poC_isrS=1; //打印测试发送"AT+QWERTY=1" buf[10]=1 + f401cnt++; + if(f401cnt>512) f401cnt=0; //防止溢出 +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myf401.h Fri Apr 20 02:49:37 2018 +0000 @@ -0,0 +1,61 @@ +#ifndef myf401_H +#define myf401_H +#include "string" + /****引脚重定义*****/ + + #define LED2 PC_8 //user LED test pin LED2 + #define LED3 PC_9 //user LED test pin LED3 + #define RESET PC_13 //BC95 reset pin(CPU) + #define DEBUG_TX PA_9 //PC debug + #define DEBUG_RX PA_10 //PC debug + #define BC95_TX PA_2 //BC95 TX(CPU) + #define BC95_RX PA_3 //BC95 RX(CPU) + + class F401script + { + public: + static int poL; + static int poC_initF; static int poC_initS; + static int poC_revokF; static int poC_revokS; static int poC_rdyF; static int poC_rdyS; + static int poC_getF; static int poC_getS; static int poC_putF; static int poC_putS; + static int poC_putcallF; static int poC_putcallS; + static int poC_ticisrF; static int poC_ticisrS; static int poC_ticisr1F; static int poC_ticisr1S; + static int poC_isrF; static int poC_isrS; + static int poC_step; + }; + extern F401script f401scpt; + + class f401Act + { + public: + /*******public method***********/ + static void init(void); //f401 cpu initialization; + static void ready(void); + static void get(void); + static void put(void); + static void put_call(void); + //static void reiwdg(void); + + static Serial uart; + + static DigitalOut led2; + static DigitalOut led3; + + static Ticker time1; //定时器1 + static Ticker timerone; //定时器1 + /*******public middle variable***********/ + static int datacnt; //接受数据计数 + private: + /******* private method***********/ + //static IWDG_HandleTypeDef hiwdg; //?????????? + //static AnalogIn powAD; + static Timer outtime; // + static void isr_tick(void); + static void isr_tick1(void); + static void isr_pc(void); //get interrupt buffer + /******* private middle variable***********/ + static int f401cnt; + static char buf[512]; + }; + +#endif