【技术干货】TuyaOS(NB-IoT)新平台移植指导:适配tkl_nbiot_ril.c
本章介绍对tkl_nbiot_ril.c的接口相关适配
Code: Select all
/** * @brief ril驱动初始化 * * @param[in] null * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_init(VOID) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
ril层驱动初始化,在这里可以初始化后续需要用到的互斥锁及相关的一些信息
Code: Select all
/** * @brief 注册事件回调 * * @param[in] evt_cb :注册的相关事件回调函数 * @param[in] evt_id :事件定义 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_register_event_callback(TKL_RIL_EVENT_SEND_T evt_cb, TKL_RIL_EVENT_ID_T *evt_id) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
ril层相关事件回调注册,主要包括成功识别及未识别到sim卡,网络附着成功及网络断开,网络附着被基站拒绝等事件,具体事件类型参考枚举TKL_RIL_EVENT_ID_T。
Code: Select all
/** * @brief 查询ril层网络附着状态(建议异步处理) * * @param[in] null * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_attach_event_inquire(VOID) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- } /** * @brief 查询ril层网络附着状态(建议异步处理) * * @param[in] null * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_attach_event_inquire(VOID) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
由于有些情况下平台侧不会主动上报基站附着成功事件,所以SDK需要主动查询是否已经成功附着上基站。建议不要做任何等待,立即返回,通过发送事件异步处理。
Code: Select all
/** * @brief 获取当前设备是否识别到sim卡 * * @return BOOL_T true: 识别到卡 false: 未识别到卡 */ BOOL_T tkl_nbiot_ril_is_sim_ready(VOID) { // --- BEGIN: user implements --- return 0; // --- END: user implements --- }
由于有些情况下平台侧不会主动上报成功识别到SIM事件,所以SDK需要主动查询是否已经成功识别SIM。
Code: Select all
/** * @brief 获取当前设备cesq相关参数(建议阻塞处理) * * @param[inout] info :获取当前设备cesq相关参数 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_cesq(TKL_RIL_CESQ_T *info) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
查询CESQ相关参数
Code: Select all
/** * @brief 获取设备的T3324时间(建议阻塞处理) * * @param[inout] t3324:返回获取的设备的T3324值,单位:s * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_t3324(UINT_T *t3324) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
查询当前active time T3324的值,换算成为秒为单位的值返回
Code: Select all
/** * @brief 获取设备的T3412时间(建议阻塞处理) * * @param[inout] t3412:返回获取的设备的T3412值,单位:s * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_t3412(UINT_T *t3412) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
查询当前周期TAU T3412的值,换算成为秒为单位的值返回
Code: Select all
/** * @brief 设置设备的T3412时间(建议阻塞处理) * * @param[in] req_time :待设置设备的T3412时间,单位:s * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_set_t3412(UINT_T req_time) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
设置当前周期TAU T3412的值,输入req_time是以秒为单位的指定值
Code: Select all
/** * @brief 设置设备的T3324时间(建议阻塞处理) * * @param[in] req_time :待设置设备的T3324时间,单位:s * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_set_t3324(UINT_T req_time) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
设置当前active time T3324的值,输入req_time是以秒为单位的指定值
Code: Select all
/** * @brief 设置当前的网络接入APN名称(建议阻塞处理) * * @param[in] apn_name :设置当前的网络接入APN名称. * @param[in] pdp_type : 分组数据协议的类型,"IP",IPV6","IPV4V6","Non-IP" * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_set_apn(PCHAR_T apn_name, PCHAR_T pdp_type) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
设置当前的网络接入APN名称及分组数据协议类型
Code: Select all
/** * @brief 获取当前的网络接入APN名称(建议阻塞处理) * * @param[inout] apn 返回获取的当前的网络接入APN名称 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_apn(PCHAR_T apn) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
输出参数apn为已经提供内存空间的字符指针起始地址
Code: Select all
/** * @brief 获取设备接收信号强度值rssi(建议阻塞处理) * * @param[inout] out_rssi 返回的信号强度(为带符号的整型,理论上0为最强,一般为负值) * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_rssi(INT_T *out_rssi) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
获取当前的RSSI,建议从获取CESQ的rsrp中转换,得到dBm单位的RSSI返回值。
Code: Select all
/** * @brief 获取当前设备的IMSI(建议阻塞处理) * * @param[inout] imsi 获取当前设备的IMSI * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_imsi(PCHAR_T imsi) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
输出参数imsi为已经提供内存空间的字符指针起始地址
Code: Select all
/** * @brief 获取当前设备的iccid(建议阻塞处理) * * @param[inout] iccid 获取当前设备的iccid * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_iccid(PCHAR_T iccid) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
输出参数iccid为已经提供内存空间的字符指针起始地址
Code: Select all
/** * @brief 获取相关的国家码及运营商信息(建议阻塞处理) * * @param[in] plmn_info 获取到的plmn信息 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_plmn_info(TKL_RIL_PLMN_T *plmn_info) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
附着上基站后,SDK读取当前的MCC及MNC信息
Code: Select all
/** * @brief AT CFUN设置(建议阻塞处理) * * @param[in] val :待设置的CFUN的参数,参考AT CFUN * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_set_cfun(UCHAR_T val) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
输入val符合标准3GPP协议
Code: Select all
/** * @brief 获取当前AT CFUN参数(建议阻塞处理) * * @param[inout] val:返回的当前CFUN参数 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_cfun(INT_T *val) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
输出val符合标准3GPP协议
Code: Select all
/** * @brief 获取当前rf是否校准(建议阻塞处理) * * @param[inout] flag:返回的flag,1 已校准,否则未校准 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_rf_flag(INT_T *flag) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
产测用于判断RF是否校准
Code: Select all
/** * @brief 将IMEI写入原厂NV * * @param[in] imei :将设置的IMEI字符串指针 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_set_imei(PCHAR_T imei) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
设置imei
Code: Select all
/** * @brief 从原厂NV获取实际的IMEI * * @param[inout] buf : imei string buffer * @param[in] len : buffer length * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_imei(PCHAR_T buf, UCHAR_T len) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
输出参数buf为已经提供内存空间的字符指针起始地址
Code: Select all
/** * @brief 根据3GPP标准释放RRC,提前退出网络连接态 * * @param[in] null * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_release_rrc(VOID) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
根据3GPP标准释放RRC,提前退出网络连接态
目前默认是SDK发送完一个上行包后就立刻释放RRC
Code: Select all
/** * @brief 设置频点(建议阻塞处理) * * @param[in] band_array_str :待设置的频带,格式举例:'3,5,8' * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_set_band(PCHAR_T band_array_str) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
设置当前设备支持的所有频段,注意band_array_str格式
Code: Select all
/** * @brief 获取设备当前的频点(建议阻塞处理) * * @param[inout] pbuf : string buffer,输出格式举例:'3,5,8' * @param[in] len : buffer length * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_band(PCHAR_T pbuf, UCHAR_T len) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
len小于8时,获取当前的工作频段;否则获取设备支持的所有频段
Code: Select all
/** * @brief PSM模式配置,效果参考at+cpsms中psm开关(建议阻塞处理) * * @param[in] enable : 1,使能;0,失能 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_psm_mode_enable(UCHAR_T enable) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
是否开启设备psm模式
Code: Select all
/** * @brief EDRX使能/失能, 效果参考AT+CEDRXS(建议阻塞处理) * * @param[in] enable : 1,使能;0,失能 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_edrx_mode_enable(UCHAR_T enable) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
是否开启设备edrx模式
Code: Select all
/** * @brief 设置指定地区网络附着的相关信息 * * @param[in] operator :地区网络附着相关信息 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_set_area_attach_info(TKL_RIL_ATTACH_INFO_T *operator) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
用于国内的模组可直接返回OPRT_NOT_SUPPORTED,该功能主要用于海外模组配置PLMN/BAND/APN等信息
Code: Select all
/** * @brief 获取当前基站的id(建议阻塞处理) * * @param[inout] pbuf : 返回当前连接基站id 字符缓存 * @param[in] len : buffer length * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_serving_cellid(PCHAR_T pbuf, UCHAR_T len) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
获取当前已经连接基站cellid,pbuf为已经提供内存空间的字符指针起始地址
Code: Select all
/** * @brief 获取设备附近基站信息(建议阻塞处理) * * @param[inout] pbuf : 返回附近基站信息 * @param[inout] out_num : 附近基站总数 * * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h */ OPERATE_RET tkl_nbiot_ril_get_neightbor_cellid(TKL_RIL_NEIGHBOR_CELL_INFO_T **pbuf, INT_T *out_num) { // --- BEGIN: user implements --- return OPRT_NOT_SUPPORTED; // --- END: user implements --- }
返回附近临近基站信息