bc95.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #ifndef __BC95_H__
  2. #define __BC95_H__
  3. #include "boards.h"
  4. #include "user_uart.h"
  5. #define BC95_AT_TIMEOUT_COUNT 60000
  6. #define BC95_OPEN_TIMEOUT 12*3600
  7. #define BC95_Send_String UartSendString
  8. #define BC95_Send_Hex UartSendHex
  9. #define BC95_RST_LOW nrf_gpio_pin_write(BC95_RST, 0);
  10. #define BC95_RST_HIGH nrf_gpio_pin_write(BC95_RST, 1);
  11. #ifdef BC95_POWER
  12. #define POWER_BC95_ENABLE nrf_gpio_pin_write(BC95_POWER, 1);
  13. #define POWER_BC95_DISABLE nrf_gpio_pin_write(BC95_POWER, 0);
  14. #endif
  15. #define EVENT_BOOTSTRAP_START "1"
  16. #define EVENT_BOOTSTRAP_SUCCESS "2"
  17. #define EVENT_BOOTSTRAP_FAILED "3"
  18. #define EVENT_CONNECT_SUCCESS "4"
  19. #define EVENT_CONNECT_FAILED "5"
  20. #define EVENT_REG_SUCCESS "6"
  21. #define EVENT_REG_FAILED "7"
  22. #define EVENT_REG_TIMEOUT "8"
  23. #define EVENT_LIFETIME_TIMEOUT "9"
  24. #define EVENT_STATUS_HALT "10"
  25. #define EVENT_UPDATE_SUCCESS "11"
  26. #define EVENT_UPDATE_FAILED "12"
  27. #define EVENT_UPDATE_TIMEOUT "13"
  28. #define EVENT_UPDATE_NEED "14"
  29. #define EVENT_DEREG_DONE "15"
  30. #define EVENT_RESPONSE_FAILED "20"
  31. #define EVENT_RESPONSE_SUCCESS "21"
  32. #define EVENT_NOTIFY_FAILED "25"
  33. #define EVENT_NOTIFY_SUCCESS "26"
  34. #define EVENT_FIRMWARE_DOWNLOADING "40"
  35. #define EVENT_FIRMWARE_DOWNLOAD_FAILED "41"
  36. #define EVENT_FIRMWARE_DOWNLOADED "42"
  37. #define EVENT_FIRMWARE_UPDATING "43"
  38. #define EVENT_FIRMWARE_UPDATE_SUCCESS "44"
  39. #define EVENT_FIRMWARE_UPDATE_FAILED "45"
  40. #define EVENT_FIRMWARE_UPDATE_OVER "46"
  41. #define EVENT_FIRMWARE_DOWNLOAD_DISCONNECT "47"
  42. #define EVENT_FIRMWARE_ERASE_SUCCESS "48"
  43. #define EVENT_FIRMWARE_ERASE_FAIL "49"
  44. #define UART_FRAME_ERROR "523"
  45. #define TUP_NOT_REG "513"
  46. typedef enum {
  47. #ifdef BC95_POWER
  48. BC95_OFF=0, //硬件电源关机
  49. BC95_ON=1, //硬件电源开机
  50. #endif
  51. BC95_BOOT=2, //硬件复位
  52. BC95_NRB=3, //软件复位
  53. BC95_NO_REG=4, //未激活
  54. BC95_AT=5, //检查AT指令是否正常
  55. BC95_NATSPEED_CHECK=6, //检查波特率
  56. BC95_NATSPEED=7, //设置波特率
  57. BC95_ATI=8, //查询估计版本
  58. BC95_ATE=9, //回显设置
  59. BC95_CMEE=10, //错误日志设置
  60. BC95_NPSMR=11, //设置psm模式进入显示
  61. BC95_PSM_CHECK=12, //查询psm设置
  62. BC95_PSM_SET=13, //设置psm模式
  63. BC95_EDRX_CHECK=14, //查询eDRX设置
  64. BC95_EDRX_SET=15, //设置eDRX模式
  65. BC95_IMEI=16, //获取IMEI号
  66. BC95_CCID=17, //获取CCID号
  67. BC95_IMSI=18, //获取IMSI号
  68. BC95_CSQ=19, //查询网络信号值
  69. BC95_NCONFIG_CHECK=20, //查询是否自动联网
  70. BC95_NCONFIG_SET=21, //设置自动联网
  71. BC95_QREGSWT_CHECK=22, //查询自动入电信网设置
  72. BC95_QREGSWT_SET=23, //设置自动入电信网
  73. BC95_NCDP_CHECK=24, //查询NB服务器设置
  74. BC95_NCDP_SET=25, //设置NB服务器
  75. BC95_CFUN_CHECK=26, //查询当前功能模式
  76. BC95_CFUN_MINI=27, //设置最小功能模式
  77. BC95_CFUN_ALL=28, //设置全功能模式
  78. BC95_NCSEARFCN=29, //清除频点
  79. BC95_CGATT_CHECK=30, //检查入网状态
  80. BC95_CGATT_ON=31, //设置入网
  81. BC95_CEREG_SET=32, //设置查询基站功能
  82. BC95_CEREG=33, //查询基站
  83. BC95_NUESTATS=34, //查询RSSI,RSRP和SNR
  84. BC95_ECL=35, //查询ECL
  85. BC95_TIME=36, //获取时间
  86. BC95_CSCON_SET=37, //使能URC上报功能
  87. BC95_DATA_READY=38, //数据准备
  88. BC95_SEND_ACT=39, //触发数据传送
  89. BC95_PSM_DELAY=40, //等待进入PSM
  90. BC95_PSM_WORKING=41, //进入PSM模式
  91. BC95_MIPLCONFIG_CHECK=42, //查询OneNET bootsrap设置
  92. BC95_MIPLCONFIG_SET=43, //设置bootsrap
  93. BC95_MIPLCREATE=44, //创建通讯套件
  94. BC95_MIPLDELETE=45, //删除通讯套件
  95. BC95_MIPLADDOBJ=46, //添加对象和实例
  96. BC95_MIPLDELOBJ=47, //删除对象和实例
  97. BC95_MIPLOPEN=48, //注册
  98. BC95_MIPLCLOSE=49, //注销
  99. BC95_ONENET_OPENING=50, //OneNet平台注册中
  100. BC95_ONENET_OPENED=51, //OneNet平台注册成功
  101. BC95_MIPLDISCOVERRSP=52, //资源发现操作
  102. BC95_MIPLDISCOVERRSPING=53, //资源发现操作中
  103. BC95_MIPLOBSERVERSP=54, //订阅资源发现操作
  104. BC95_MIPLOBSERVERSPING=55, //订阅资源发现操作中
  105. BC95_MIPLWAITE=56, //待网
  106. BC95_MIPLREADRSP=57, //读请求操作
  107. BC95_MIPLWRITERSP=58, //写请求操作
  108. BC95_MIPLEXECUTERSP=59, //执行请求操作
  109. BC95_MIPLPARAMETERRSP=60, //设置请求操作
  110. BC95_MIPLNOTIFY=61, //数据上报
  111. BC95_MIPLNOTIFING=62, //数据上报中
  112. BC95_MIPLUPDATE=63, //更新注册
  113. }BC95_NET_STATUS;
  114. typedef struct{
  115. uint32_t unixtime;
  116. uint16_t lac;
  117. uint32_t cellid;
  118. int16_t signalpower;
  119. int16_t signalrssi;
  120. uint8_t ecl;
  121. int16_t snr;
  122. uint16_t pci;
  123. uint8_t imei[8];
  124. uint8_t iccid[10];
  125. uint8_t imsi[8];
  126. }BC95_DATA;
  127. typedef enum{
  128. ONENET_OPEN_NULL=0,
  129. ONENET_BOOTSTRAP_START,
  130. ONENET_BOOTSTRAP_SUCCESS,
  131. ONENET_CONNECT_SUCCESS,
  132. ONENET_REG_SUCCESS,
  133. }ONENET_OPEN_STAT;
  134. typedef enum{
  135. RESULT_204=2, //2.04 Changed,indicating the correct result
  136. RESULT_400=11, //4.00 Bad request
  137. RESULT_401=12, //4.01 Unauthorized
  138. RESULT_404=13, //4.04 Not found
  139. RESULT_405=14 //4.05 Method not allowed
  140. }MIPLRESULT;
  141. typedef enum{
  142. MOBILE_NULL=0,
  143. MOBILE_CMCC,
  144. MOBILE_189
  145. }MOBILE_TYPE;
  146. typedef enum{
  147. IOT189_TYPE_AEP=0,
  148. IOT189_TYPE_TEST,
  149. IOT189_TYPE_COMMERCIAL,
  150. }IOT189_TYPE;
  151. typedef enum
  152. {
  153. BC95_QUEUE_TIME=0,
  154. BC95_QUEUE_INT=1,
  155. }BC95_QUEUE_TYPE;
  156. typedef void (*bc95_work_finish_func)(void);
  157. typedef bool (*bc95_work_continue_func)(void);
  158. typedef struct {
  159. bool app_time_start;
  160. bool dev_reg;
  161. bool alarm_stat;
  162. bc95_work_finish_func finish_func;
  163. bc95_work_continue_func continue_func;
  164. MOBILE_TYPE mobile_type;
  165. // void (*rst_out)(uint8_t x);
  166. // void (*power_out)(uint8_t x);
  167. // void (*set_data)(void);
  168. BC95_DATA bc95_data; //模块相关数据
  169. BC95_NET_STATUS bc95_status; //BC95模块当前工作状态
  170. BC95_NET_STATUS last_bc95_status; //执行完当前命令需返回的BC95状态
  171. bool set_natspeed; //设置波特率状态
  172. uint16_t ms_count; //时间计时器
  173. uint32_t time_check_count; //同步时间计时
  174. uint8_t Obj_ID; //ObjectID,目前=0
  175. uint32_t msgid; //当前MsgID
  176. int ob_msgid[2]; //订阅MsgID记录
  177. bool onenet_work; //移动onenet网络正常数据工作状态
  178. uint32_t last_tick; //计时器用
  179. uint32_t data_check_count; //onenet数据上报计时
  180. uint32_t discover_timeout; //资源发现超时
  181. ONENET_OPEN_STAT open_stat; //注册状态
  182. uint32_t open_lifetime; //更新操作计时
  183. uint32_t open_timeout; //注册超时
  184. uint8_t update_timeout; //更新注册信息超时
  185. MIPLRESULT miplresult; //coap返回结果,类似http,默认204
  186. IOT189_TYPE iot189type; //电信平台类型
  187. bool imsi_stat; //IMSI读取准备状态
  188. bool psm_stat; //PSM模式设置状态
  189. bool edrx_stat; //EDRX设置状态
  190. bool nconfig_stat; //查询nconfig状态
  191. bool rst_stat; //重启状态
  192. bool work_status; //电信网络正常数据工作状态
  193. uint8_t natspeed_type; //波特率设置类型0-3
  194. uint8_t naterror_count; //波特率设置错误次数
  195. uint32_t bc95_check_time; //模块状态检查计时
  196. uint8_t bc95_check_count; //模块状态检查次数
  197. uint8_t cfun_check_count; //功能模式超时次数
  198. uint8_t cfun_timeout; //cfun操作失败次数
  199. uint8_t send_check_count; //发送数据超时次数
  200. uint8_t error_count; //返回错误次数
  201. // uint8_t power_off_timeout; //模块超时关机
  202. uint8_t bc95power_status; //BC95复位拉底判断
  203. bool bc95_at_stat; //at指令返回状态
  204. uint16_t bc95_at_timeout; //at指令返回超时
  205. char * bc95_command_array[5]; //存放的指令字符的内存地址位置
  206. bool bc95_command_send_act; //AT指令发送ACT
  207. char bc95_send_Byte[USER_UART_SEND_LEN]; //发送的数据
  208. }BC95_STRUCT;
  209. void bc95_struct_Init(void);
  210. void bc95_timers_init(void);
  211. void BC95_GPIO_Init(void);
  212. void bc95_work_start(void);
  213. void bc95_work_stop(void);
  214. void BC95_Data_Check(char *str);
  215. void Set_Bc95_Queue(BC95_QUEUE_TYPE type);
  216. void Set_Bc95_Reg_Stat(bool stat);
  217. void Set_Bc95_189_Type(IOT189_TYPE type);
  218. void Set_Bc95_work_finish_func(bc95_work_finish_func func);
  219. void Set_Bc95_work_continue_func(bc95_work_continue_func func);
  220. extern BC95_STRUCT bc95_struct;
  221. extern uint32_t unixtime;
  222. #endif