123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- #ifndef __BC95_H__
- #define __BC95_H__
- #include "boards.h"
- #include "user_uart.h"
- #define BC95_AT_TIMEOUT_COUNT 60000
- #define BC95_OPEN_TIMEOUT 12*3600
- #define BC95_Send_String UartSendString
- #define BC95_Send_Hex UartSendHex
- #define BC95_RST_LOW nrf_gpio_pin_write(BC95_RST, 0);
- #define BC95_RST_HIGH nrf_gpio_pin_write(BC95_RST, 1);
- #ifdef BC95_POWER
- #define POWER_BC95_ENABLE nrf_gpio_pin_write(BC95_POWER, 1);
- #define POWER_BC95_DISABLE nrf_gpio_pin_write(BC95_POWER, 0);
- #endif
- #define EVENT_BOOTSTRAP_START "1"
- #define EVENT_BOOTSTRAP_SUCCESS "2"
- #define EVENT_BOOTSTRAP_FAILED "3"
- #define EVENT_CONNECT_SUCCESS "4"
- #define EVENT_CONNECT_FAILED "5"
- #define EVENT_REG_SUCCESS "6"
- #define EVENT_REG_FAILED "7"
- #define EVENT_REG_TIMEOUT "8"
- #define EVENT_LIFETIME_TIMEOUT "9"
- #define EVENT_STATUS_HALT "10"
- #define EVENT_UPDATE_SUCCESS "11"
- #define EVENT_UPDATE_FAILED "12"
- #define EVENT_UPDATE_TIMEOUT "13"
- #define EVENT_UPDATE_NEED "14"
- #define EVENT_DEREG_DONE "15"
- #define EVENT_RESPONSE_FAILED "20"
- #define EVENT_RESPONSE_SUCCESS "21"
- #define EVENT_NOTIFY_FAILED "25"
- #define EVENT_NOTIFY_SUCCESS "26"
- #define EVENT_FIRMWARE_DOWNLOADING "40"
- #define EVENT_FIRMWARE_DOWNLOAD_FAILED "41"
- #define EVENT_FIRMWARE_DOWNLOADED "42"
- #define EVENT_FIRMWARE_UPDATING "43"
- #define EVENT_FIRMWARE_UPDATE_SUCCESS "44"
- #define EVENT_FIRMWARE_UPDATE_FAILED "45"
- #define EVENT_FIRMWARE_UPDATE_OVER "46"
- #define EVENT_FIRMWARE_DOWNLOAD_DISCONNECT "47"
- #define EVENT_FIRMWARE_ERASE_SUCCESS "48"
- #define EVENT_FIRMWARE_ERASE_FAIL "49"
- #define UART_FRAME_ERROR "523"
- #define TUP_NOT_REG "513"
- typedef enum {
- #ifdef BC95_POWER
- BC95_OFF=0, //硬件电源关机
- BC95_ON=1, //硬件电源开机
- #endif
- BC95_BOOT=2, //硬件复位
- BC95_NRB=3, //软件复位
- BC95_NO_REG=4, //未激活
- BC95_AT=5, //检查AT指令是否正常
- BC95_NATSPEED_CHECK=6, //检查波特率
- BC95_NATSPEED=7, //设置波特率
- BC95_ATI=8, //查询估计版本
- BC95_ATE=9, //回显设置
- BC95_CMEE=10, //错误日志设置
- BC95_NPSMR=11, //设置psm模式进入显示
- BC95_PSM_CHECK=12, //查询psm设置
- BC95_PSM_SET=13, //设置psm模式
- BC95_EDRX_CHECK=14, //查询eDRX设置
- BC95_EDRX_SET=15, //设置eDRX模式
- BC95_IMEI=16, //获取IMEI号
- BC95_CCID=17, //获取CCID号
- BC95_IMSI=18, //获取IMSI号
- BC95_CSQ=19, //查询网络信号值
- BC95_NCONFIG_CHECK=20, //查询是否自动联网
- BC95_NCONFIG_SET=21, //设置自动联网
- BC95_QREGSWT_CHECK=22, //查询自动入电信网设置
- BC95_QREGSWT_SET=23, //设置自动入电信网
- BC95_NCDP_CHECK=24, //查询NB服务器设置
- BC95_NCDP_SET=25, //设置NB服务器
- BC95_CFUN_CHECK=26, //查询当前功能模式
- BC95_CFUN_MINI=27, //设置最小功能模式
- BC95_CFUN_ALL=28, //设置全功能模式
- BC95_NCSEARFCN=29, //清除频点
- BC95_CGATT_CHECK=30, //检查入网状态
- BC95_CGATT_ON=31, //设置入网
- BC95_CEREG_SET=32, //设置查询基站功能
- BC95_CEREG=33, //查询基站
- BC95_NUESTATS=34, //查询RSSI,RSRP和SNR
- BC95_ECL=35, //查询ECL
- BC95_TIME=36, //获取时间
- BC95_CSCON_SET=37, //使能URC上报功能
- BC95_DATA_READY=38, //数据准备
- BC95_SEND_ACT=39, //触发数据传送
- BC95_PSM_DELAY=40, //等待进入PSM
- BC95_PSM_WORKING=41, //进入PSM模式
- BC95_MIPLCONFIG_CHECK=42, //查询OneNET bootsrap设置
- BC95_MIPLCONFIG_SET=43, //设置bootsrap
- BC95_MIPLCREATE=44, //创建通讯套件
- BC95_MIPLDELETE=45, //删除通讯套件
- BC95_MIPLADDOBJ=46, //添加对象和实例
- BC95_MIPLDELOBJ=47, //删除对象和实例
- BC95_MIPLOPEN=48, //注册
- BC95_MIPLCLOSE=49, //注销
- BC95_ONENET_OPENING=50, //OneNet平台注册中
- BC95_ONENET_OPENED=51, //OneNet平台注册成功
- BC95_MIPLDISCOVERRSP=52, //资源发现操作
- BC95_MIPLDISCOVERRSPING=53, //资源发现操作中
- BC95_MIPLOBSERVERSP=54, //订阅资源发现操作
- BC95_MIPLOBSERVERSPING=55, //订阅资源发现操作中
- BC95_MIPLWAITE=56, //待网
- BC95_MIPLREADRSP=57, //读请求操作
- BC95_MIPLWRITERSP=58, //写请求操作
- BC95_MIPLEXECUTERSP=59, //执行请求操作
- BC95_MIPLPARAMETERRSP=60, //设置请求操作
- BC95_MIPLNOTIFY=61, //数据上报
- BC95_MIPLNOTIFING=62, //数据上报中
- BC95_MIPLUPDATE=63, //更新注册
- }BC95_NET_STATUS;
- typedef struct{
- uint32_t unixtime;
- uint16_t lac;
- uint32_t cellid;
- int16_t signalpower;
- int16_t signalrssi;
- uint8_t ecl;
- int16_t snr;
- uint16_t pci;
- uint8_t imei[8];
- uint8_t iccid[10];
- uint8_t imsi[8];
- }BC95_DATA;
- typedef enum{
- ONENET_OPEN_NULL=0,
- ONENET_BOOTSTRAP_START,
- ONENET_BOOTSTRAP_SUCCESS,
- ONENET_CONNECT_SUCCESS,
- ONENET_REG_SUCCESS,
- }ONENET_OPEN_STAT;
- typedef enum{
- RESULT_204=2, //2.04 Changed,indicating the correct result
- RESULT_400=11, //4.00 Bad request
- RESULT_401=12, //4.01 Unauthorized
- RESULT_404=13, //4.04 Not found
- RESULT_405=14 //4.05 Method not allowed
- }MIPLRESULT;
- typedef enum{
- MOBILE_NULL=0,
- MOBILE_CMCC,
- MOBILE_189
- }MOBILE_TYPE;
- typedef enum{
- IOT189_TYPE_AEP=0,
- IOT189_TYPE_TEST,
- IOT189_TYPE_COMMERCIAL,
- }IOT189_TYPE;
- typedef enum
- {
- BC95_QUEUE_TIME=0,
- BC95_QUEUE_INT=1,
- }BC95_QUEUE_TYPE;
- typedef void (*bc95_work_finish_func)(void);
- typedef bool (*bc95_work_continue_func)(void);
- typedef struct {
- bool app_time_start;
- bool dev_reg;
- bool alarm_stat;
- bc95_work_finish_func finish_func;
- bc95_work_continue_func continue_func;
- MOBILE_TYPE mobile_type;
- // void (*rst_out)(uint8_t x);
- // void (*power_out)(uint8_t x);
- // void (*set_data)(void);
- BC95_DATA bc95_data; //模块相关数据
- BC95_NET_STATUS bc95_status; //BC95模块当前工作状态
- BC95_NET_STATUS last_bc95_status; //执行完当前命令需返回的BC95状态
- bool set_natspeed; //设置波特率状态
- uint16_t ms_count; //时间计时器
- uint32_t time_check_count; //同步时间计时
- uint8_t Obj_ID; //ObjectID,目前=0
- uint32_t msgid; //当前MsgID
- int ob_msgid[2]; //订阅MsgID记录
- bool onenet_work; //移动onenet网络正常数据工作状态
- uint32_t last_tick; //计时器用
- uint32_t data_check_count; //onenet数据上报计时
- uint32_t discover_timeout; //资源发现超时
- ONENET_OPEN_STAT open_stat; //注册状态
- uint32_t open_lifetime; //更新操作计时
- uint32_t open_timeout; //注册超时
- uint8_t update_timeout; //更新注册信息超时
- MIPLRESULT miplresult; //coap返回结果,类似http,默认204
- IOT189_TYPE iot189type; //电信平台类型
- bool imsi_stat; //IMSI读取准备状态
- bool psm_stat; //PSM模式设置状态
- bool edrx_stat; //EDRX设置状态
- bool nconfig_stat; //查询nconfig状态
- bool rst_stat; //重启状态
- bool work_status; //电信网络正常数据工作状态
- uint8_t natspeed_type; //波特率设置类型0-3
- uint8_t naterror_count; //波特率设置错误次数
- uint32_t bc95_check_time; //模块状态检查计时
- uint8_t bc95_check_count; //模块状态检查次数
- uint8_t cfun_check_count; //功能模式超时次数
- uint8_t cfun_timeout; //cfun操作失败次数
- uint8_t send_check_count; //发送数据超时次数
- uint8_t error_count; //返回错误次数
- // uint8_t power_off_timeout; //模块超时关机
- uint8_t bc95power_status; //BC95复位拉底判断
- bool bc95_at_stat; //at指令返回状态
- uint16_t bc95_at_timeout; //at指令返回超时
- char * bc95_command_array[5]; //存放的指令字符的内存地址位置
- bool bc95_command_send_act; //AT指令发送ACT
- char bc95_send_Byte[USER_UART_SEND_LEN]; //发送的数据
- }BC95_STRUCT;
- void bc95_struct_Init(void);
- void bc95_timers_init(void);
- void BC95_GPIO_Init(void);
- void bc95_work_start(void);
- void bc95_work_stop(void);
- void BC95_Data_Check(char *str);
- void Set_Bc95_Queue(BC95_QUEUE_TYPE type);
- void Set_Bc95_Reg_Stat(bool stat);
- void Set_Bc95_189_Type(IOT189_TYPE type);
- void Set_Bc95_work_finish_func(bc95_work_finish_func func);
- void Set_Bc95_work_continue_func(bc95_work_continue_func func);
- extern BC95_STRUCT bc95_struct;
- extern uint32_t unixtime;
- #endif
|