├── .gitignore ├── LICENSE ├── README.md ├── SConscript ├── examples ├── onenet_lwm2m_simple.c └── qsdk_callback__simple.c ├── help ├── png │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── 4.png │ ├── 5.png │ ├── 6.png │ ├── 7.png │ └── 8.png └── 骑士智能科技QSDK(API)使用说明.pdf ├── inc └── qsdk.h └── src ├── qsdk_callback.c ├── qsdk_gps.c ├── qsdk_iot.c ├── qsdk_nb.c ├── qsdk_net.c └── qsdk_onenet.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QSDK 2 | QSDK是河北骑士智能科技有限公司基于RT-THREAD RTOS编写的NB-IOT模块驱动代码,目前支持的模块型号有M5310、M5310A、M5311。 3 | 源码地址:[https://github.com/hbqs/qsdk] 作者:[longmain](https://github.com/hbqs) 4 | 5 | 6 | ## 前言 7 | 由于目前各方都在大力推动NB-IOT产业发展,我们骑士智能科技也代理了NB-IOT模组,为了让大家在使用我们代理的模组时更加方便,我们编写了QSDK(NB-IOT驱动)代码,目前该代码在使用过程中简单方便,目前适配了RTTHREAD 组件,可以图像化配置,减轻了大量的工作,可以促进产品快速开发。 8 | 在这里感谢RT-THREAD 这款好用的的物联网系统,同时更感谢广大开源的支持者。让我从中学到了很多,网络也是一个好平台,希望所有的开发者能形成良性循环,从网络中学知识,回馈到网络中去。 9 | ## qsdk简介 10 | qsdk是一个灵活的NB-IOT驱动,目前支持的模块型号有M5310、M5310A、M5311,后期将会增加更多模组支持。该代码根据不同的模块启用不同的功能,目前代码支持电信IOT平台、中移ONENET平台(LWM2M协议和MQTT协议)和UDP\TCP协议。 11 | 在qsdk_callback.c代码中是关于IOT、onenet、NET等下发处理回调函数,用户可以在相应函数中处理数据。 12 | ## 特点 13 | qsdk开放源码,nb控制块、协议处理块均采用数据结构方式,网络数据下发采用回调函数机制,单独的qsdk_callback.c可以完整的提示网络下发数据,用户可以在函数里面编写对网络下发数据的处理逻辑代码。 14 | 同时代码支持快速初始化NB模块联网,快速连接onenet平台等功能,大大简化了客户的使用方式。 15 | 16 | ## qsdk代码在env使用 17 | 目前我们将NB-IOT模块驱动代码做成软件包(packages),如果使用RT-Thread操作系统的话,可以在env中直接配置使用,使用前请开启AT组件支持! 18 | 19 | 步骤如下: 20 | 21 | 1. **选择在线软件包** 22 | 23 | ![](https://github.com/hbqs/qsdk/blob/master/help/png/1.png?raw=true) 24 | 25 | 2. **选择软件包属性为物联网相关** 26 | 27 | ![](https://github.com/hbqs/qsdk/blob/master/help/png/2.png?raw=true) 28 | 29 | 3. **选择qsdk组件** 30 | 31 | ![](https://github.com/hbqs/qsdk/blob/master/help/png/3.png?raw=true) 32 | 33 | 4. **点击进去设置模块相关信息** 34 | 35 | ![](https://github.com/hbqs/qsdk/blob/master/help/png/4.png?raw=true) 36 | 37 | 5. **选择需要支持的nb-iot模块** 38 | 39 | ![](https://github.com/hbqs/qsdk/blob/master/help/png/5.png?raw=true) 40 | 41 | 6. **设置需要模块的引脚和需要支持的协议** 42 | 43 | ![](https://github.com/hbqs/qsdk/blob/master/help/png/6.png?raw=true) 44 | 45 | 7. **更新软件包** 46 | 47 | ![](https://github.com/hbqs/qsdk/blob/master/help/png/7.png?raw=true) 48 | 49 | 8. **编译生成mdk/iar工程** 50 | 51 | ![](https://github.com/hbqs/qsdk/blob/master/help/png/8.png?raw=true) 52 | 53 | 54 | 55 | ## 联系人 56 | 57 | * 技术支持:longmain QQ:1239799850 58 | * 邮箱:[longmain@longmain.cn](mailto:longmain@longmain.cn) 59 | * 主页:[qsdk](https://github.com/hbqs) 60 | * 仓库:[Github](https://github.com/hbqs) 61 | -------------------------------------------------------------------------------- /SConscript: -------------------------------------------------------------------------------- 1 | from building import * 2 | 3 | cwd = GetCurrentDir() 4 | path = [cwd + '/inc'] 5 | 6 | src = Split(''' 7 | src/qsdk_nb.c 8 | src/qsdk_callback.c 9 | ''') 10 | 11 | if GetDepend(['QSDK_USING_NET']): 12 | src += Glob('src/qsdk_net.c') 13 | 14 | if GetDepend(['QSDK_USING_ONENET']): 15 | src += Glob('src/qsdk_onenet.c') 16 | 17 | if GetDepend(['QSDK_USING_IOT']): 18 | src += Glob('src/qsdk_iot.c') 19 | 20 | if GetDepend(['QSDK_USING_MQTT']): 21 | src += Glob('src/qsdk_mqtt.c') 22 | 23 | if GetDepend(['QSDK_USING_GPS']): 24 | src += Glob('src/qsdk_gps.c') 25 | 26 | group = DefineGroup('qsdk', src, depend = ['PKG_USING_QSDK'], CPPPATH = path) 27 | 28 | Return('group') 29 | -------------------------------------------------------------------------------- /examples/onenet_lwm2m_simple.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File : main.c 3 | * This file is part of fun in evb_iot_m1 board 4 | * Copyright (c) 2018-2030, longmain Development Team 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2019-04-14 longmain first version 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "qsdk.h" 15 | 16 | //设置ulog 参数 17 | #define LOG_TAG "[main]" 18 | //调试期间开启 19 | #define LOG_LVL LOG_LVL_DBG 20 | 21 | //正式期间开启此项,关闭上方的调试选项 22 | //#define LOG_LVL LOG_LVL_INFO 23 | #include 24 | 25 | 26 | //定义onenet stream 27 | qsdk_onenet_stream_t temp_object; 28 | qsdk_onenet_stream_t hump_object; 29 | qsdk_onenet_stream_t light0_object; 30 | qsdk_onenet_stream_t light1_object; 31 | qsdk_onenet_stream_t light2_object; 32 | 33 | int main(void) 34 | { 35 | rt_uint16_t recon_count=0,recon_onenet_count=0; 36 | rt_uint32_t event_status=0; 37 | net_recon: 38 | //nb-iot模块快快速初始化联网 39 | if(qsdk_nb_quick_connect()!=RT_EOK) 40 | { 41 | LOG_E("module init failure\r\n"); 42 | goto net_recon; 43 | } 44 | onenet_recon: 45 | //onenet stream 初始化 46 | temp_object=qsdk_onenet_object_init(3303,0,5700,1,"1",1,0,qsdk_onenet_value_float); 47 | if(temp_object==RT_NULL) 48 | { 49 | LOG_E("temp object create failure\r\n"); 50 | } 51 | hump_object=qsdk_onenet_object_init(3304,0,5700,1,"1",1,0,qsdk_onenet_value_float); 52 | if(hump_object==RT_NULL) 53 | { 54 | LOG_E("hump object create failure\r\n"); 55 | } 56 | light0_object=qsdk_onenet_object_init(3311,0,5850,3,"111",3,0,qsdk_onenet_value_bool); 57 | if(light0_object==RT_NULL) 58 | { 59 | LOG_E("light object create failure\r\n"); 60 | } 61 | light1_object=qsdk_onenet_object_init(3311,1,5850,3,"111",3,0,qsdk_onenet_value_bool); 62 | if(light1_object==RT_NULL) 63 | { 64 | LOG_E("light object create failure\r\n"); 65 | } 66 | light2_object=qsdk_onenet_object_init(3311,2,5850,3,"111",3,0,qsdk_onenet_value_bool); 67 | if(light2_object==RT_NULL) 68 | { 69 | LOG_E("light object create failure\r\n"); 70 | } 71 | //快速连接到onenet 72 | if(qsdk_onenet_quick_start()!=RT_EOK) 73 | { 74 | recon_onenet_count++; 75 | LOG_E("onenet quick start failure\r\n"); 76 | rt_thread_delay(30000); 77 | if(qsdk_onenet_open()!=RT_EOK) 78 | { 79 | qsdk_onenet_delete_instance(); 80 | goto onenet_recon; 81 | } 82 | qsdk_onenet_update_time(1); 83 | } 84 | 85 | //连接网络成功,beep提示一声 86 | qsdk_beep_on(); 87 | rt_thread_delay(500); 88 | qsdk_beep_off(); 89 | if(recon_count==0) 90 | rt_thread_startup(data_up_thread_id); 91 | else 92 | { 93 | rt_thread_resume(data_up_thread_id); 94 | recon_count=0; 95 | } 96 | qsdk_onenet_notify(light0_object,1,(qsdk_onenet_value_t)&led0.current_state,0); 97 | qsdk_onenet_notify(light1_object,1,(qsdk_onenet_value_t)&led1.current_state,0); 98 | qsdk_onenet_notify(light2_object,1,(qsdk_onenet_value_t)&led2.current_state,0); 99 | 100 | while(1) 101 | { 102 | //上报数据前首先判断当前lwm2m 协议是否正常连接 103 | if(qsdk_onenet_get_connect()==RT_EOK) 104 | { 105 | LOG_D("data UP is open\r\n"); 106 | if(qsdk_onenet_notify(temp_object,0,(qsdk_onenet_value_t)&temperature,0)!=RT_EOK) 107 | { 108 | LOG_E("onenet notify error\r\n"); 109 | } 110 | rt_thread_delay(100); 111 | if(qsdk_onenet_notify(hump_object,0,(qsdk_onenet_value_t)&humidity,0)!=RT_EOK) 112 | { 113 | LOG_E("onenet notify error\r\n"); 114 | } 115 | 116 | //每40分钟定时更新一次(设备在线时间) lwm2m lifetime 117 | if(lifetime>40) 118 | { 119 | if(qsdk_onenet_update_time(0)!=RT_EOK) 120 | { 121 | LOG_E("onenet lifetime update error"); 122 | rt_thread_delay(5000); 123 | if(qsdk_onenet_update_time(0)!=RT_EOK) 124 | { 125 | LOG_E("Two Update Errors in OneNet Lifetime"); 126 | } 127 | } 128 | lifetime=0; 129 | } 130 | } 131 | else LOG_E("Now lwm2m is no connect\r\n"); 132 | rt_memset(buf,0,sizeof(buf)); 133 | lifetime++; 134 | rt_thread_delay(60000); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /examples/qsdk_callback__simple.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/examples/qsdk_callback__simple.c -------------------------------------------------------------------------------- /help/png/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/help/png/1.png -------------------------------------------------------------------------------- /help/png/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/help/png/2.png -------------------------------------------------------------------------------- /help/png/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/help/png/3.png -------------------------------------------------------------------------------- /help/png/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/help/png/4.png -------------------------------------------------------------------------------- /help/png/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/help/png/5.png -------------------------------------------------------------------------------- /help/png/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/help/png/6.png -------------------------------------------------------------------------------- /help/png/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/help/png/7.png -------------------------------------------------------------------------------- /help/png/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/help/png/8.png -------------------------------------------------------------------------------- /help/骑士智能科技QSDK(API)使用说明.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/help/骑士智能科技QSDK(API)使用说明.pdf -------------------------------------------------------------------------------- /inc/qsdk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File : qsdk.h 3 | * This file is part of fun in qsdk 4 | * Copyright (c) 2018-2030, longmain Development Team 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2018-11-14 longmain first version 9 | * 2019-06-13 longmain add hexstring to string 10 | * 2019-06-13 longmain add net close callback 11 | * 2019-06-13 longmain del qsdk_onenet_init_environment 12 | * 2019-06-30 longmain add qsdk_nb_clear_environment 13 | * 2019-08-30 longmain Adding PSM support function 14 | * 2019-09-19 longmain Adding gps support function 15 | */ 16 | 17 | #ifndef __QSDK_H__ 18 | 19 | #define __QSDK_H__ 20 | #include 21 | #include "rtdevice.h" 22 | enum qsdk_nb_status_type 23 | { 24 | qsdk_nb_status_module_init_ok=0, 25 | qsdk_nb_status_reboot, 26 | qsdk_nb_status_fota, 27 | qsdk_nb_status_enter_psm, 28 | qsdk_nb_status_exit_psm, 29 | qsdk_nb_status_psm_run, 30 | }; 31 | 32 | struct nb_device 33 | { 34 | int sim_state; 35 | int device_ok; 36 | int reboot_open; 37 | int fota_open; 38 | int reboot_type; 39 | int net_connect_ok; 40 | int error; 41 | int csq; 42 | char imsi[16]; 43 | char imei[16]; 44 | char ip[16]; 45 | }; 46 | 47 | 48 | //qsdk_nb_fun 49 | int qsdk_nb_quick_connect(void); 50 | int qsdk_nb_reboot(void); 51 | int qsdk_nb_wait_connect(void); 52 | int qsdk_nb_sim_check(void); 53 | char *qsdk_nb_get_imsi(void); 54 | char *qsdk_nb_get_imei(void); 55 | int qsdk_nb_get_time(void); 56 | int qsdk_nb_get_csq(void); 57 | int qsdk_nb_set_net_start(void); 58 | int qsdk_nb_get_net_connect(void); 59 | int qsdk_nb_get_net_connect_status(void); 60 | int qsdk_nb_get_reboot_event(void); 61 | int qsdk_nb_set_psm_mode(int mode,char *tau_time,char *active_time); 62 | void qsdk_nb_enter_psm(void); 63 | int qsdk_nb_exit_psm(void); 64 | int qsdk_nb_get_psm_status(void); 65 | int qsdk_nb_set_edrx_mode(int mode,int act_type,char *edex_value,char *ptw_time); 66 | int qsdk_nb_exit_edrx_mode(void); 67 | int qsdk_nb_ping_ip(char *ip); 68 | 69 | #if (defined QSDK_USING_M5311)||(defined QSDK_USING_ME3616) 70 | int qsdk_nb_set_rai_mode(int rai); 71 | int qsdk_nb_open_net_light(void); 72 | int qsdk_nb_close_net_light(void); 73 | 74 | #if (defined QSDK_USING_M5311) 75 | 76 | int qsdk_nb_open_auto_psm(void); 77 | int qsdk_nb_close_auto_psm(void); 78 | #endif 79 | 80 | #elif (defined QSDK_USING_M5310)||(defined QSDK_USING_M5310A) 81 | char *qsdk_nb_query_ip(void); 82 | #endif 83 | 84 | int string_to_hex(const char *pString, int len, char *pHex); 85 | void hexstring_to_string(char * pHex,int len, char * pString); 86 | 87 | //qsdk_iot_fun 88 | 89 | 90 | #ifdef QSDK_USING_IOT 91 | 92 | #ifdef QSDK_USING_ME3616 93 | int qsdk_iot_create_new_client(void); 94 | int qsdk_iot_del_client(void); 95 | int qsdk_iot_notify(char *str); 96 | int qsdk_iot_get_connect_status(void); 97 | #elif (defined QSDK_USING_M5310A) 98 | int qsdk_iot_open_update_status(void); 99 | int qsdk_iot_open_down_date_status(void); 100 | int qsdk_iot_notify(char *str); 101 | #endif 102 | 103 | #endif //endif iot seting 104 | 105 | //qsdk_net_fun 106 | #ifdef QSDK_USING_NET 107 | 108 | enum NET_DATA_TYPE 109 | { 110 | QSDK_NET_TYPE_TCP=1, 111 | QSDK_NET_TYPE_UDP, 112 | }; 113 | 114 | struct net_stream 115 | { 116 | int type; 117 | #if (defined QSDK_USING_M5310)||(defined QSDK_USING_M5310A) 118 | int port; 119 | #endif 120 | int socket; 121 | int server_port; 122 | int revice_status; 123 | int revice_len; 124 | int user_status; 125 | int connect_status; 126 | char server_ip[16]; 127 | }; 128 | typedef struct net_stream *qsdk_net_client_t; 129 | 130 | #if (defined QSDK_USING_M5310)||(defined QSDK_USING_M5310A) 131 | qsdk_net_client_t qsdk_net_client_init(int type,int port,char *server_ip,unsigned short server_port); 132 | #elif (defined QSDK_USING_M5311) 133 | qsdk_net_client_t qsdk_net_client_init(int type,int socket,char *server_ip,unsigned short server_port); 134 | int qsdk_net_set_out_format(void); 135 | #endif 136 | int qsdk_net_create_socket(qsdk_net_client_t client); 137 | int qsdk_net_send_data(qsdk_net_client_t client,char *str); 138 | int qsdk_net_get_client_revice(qsdk_net_client_t client); 139 | int qsdk_net_get_client_connect(qsdk_net_client_t client); 140 | int qsdk_net_close_socket(qsdk_net_client_t client); 141 | #endif 142 | 143 | //qsdk_onenet_fun 144 | 145 | #ifdef QSDK_USING_ONENET 146 | 147 | enum qsdk_onenet_value_type 148 | { 149 | qsdk_onenet_value_string=1, 150 | qsdk_onenet_value_opaque, 151 | qsdk_onenet_value_integer, 152 | qsdk_onenet_value_float, 153 | qsdk_onenet_value_bool, 154 | qsdk_onenet_value_hexStr 155 | }; 156 | 157 | enum qsdk_onenet_status_type 158 | { 159 | qsdk_onenet_status_init=0, 160 | qsdk_onenet_status_run, 161 | qsdk_onenet_status_failure, 162 | qsdk_onenet_status_success=4, 163 | qsdk_onenet_status_close_init=0, 164 | qsdk_onenet_status_close_start, 165 | qsdk_onenet_status_update_init=10, 166 | qsdk_onenet_status_update_failure, 167 | qsdk_onenet_status_update_success, 168 | qsdk_onenet_status_update_timeout=14, 169 | qsdk_onenet_status_update_need=18, 170 | qsdk_onenet_status_result_read_success=1, 171 | qsdk_onenet_status_result_write_success, 172 | qsdk_onenet_status_result_Bad_Request=11, 173 | qsdk_onenet_status_result_Unauthorized, 174 | qsdk_onenet_status_result_Not_Found, 175 | qsdk_onenet_status_result_Method_Not_Allowed, 176 | qsdk_onenet_status_result_Not_Acceptable 177 | }; 178 | 179 | union qsdk_onenet_value 180 | { 181 | char *string_value; 182 | uint16_t int_value; 183 | float float_value; 184 | _Bool bool_value; 185 | }; 186 | 187 | typedef union qsdk_onenet_value *qsdk_onenet_value_t; 188 | 189 | struct onenet_stream 190 | { 191 | int objid; 192 | int inscount; 193 | char bitmap[QSDK_ONENET_INSTANCE_MAX_NUM]; 194 | int atts; 195 | int acts; 196 | int insid; 197 | int resid; 198 | int valuetype; 199 | int msgid; 200 | int read_status; 201 | int write_status; 202 | int exec_status; 203 | int user_status; 204 | }; 205 | 206 | typedef struct onenet_stream *qsdk_onenet_stream_t; 207 | 208 | qsdk_onenet_stream_t qsdk_onenet_object_init(int objid,int insid,int resid,int inscount,char *bitmap,int atts,int acts,int type); 209 | int qsdk_onenet_delete_instance(void); 210 | int qsdk_onenet_delete_object(qsdk_onenet_stream_t stream); 211 | int qsdk_onenet_open(void); 212 | int qsdk_onenet_close(void); 213 | int qsdk_onenet_update_time(int flge); 214 | int qsdk_onenet_quick_start(void); 215 | int qsdk_onenet_notify(qsdk_onenet_stream_t stream,int len,qsdk_onenet_value_t data,int flge); 216 | int qsdk_onenet_get_connect(void); 217 | int qsdk_onenet_get_object_read(qsdk_onenet_stream_t stream); 218 | int qsdk_onenet_get_object_write(qsdk_onenet_stream_t stream); 219 | int qsdk_onenet_get_object_exec(qsdk_onenet_stream_t stream); 220 | int qsdk_onenet_read_rsp(int msgid,int result,qsdk_onenet_stream_t stream,int len,qsdk_onenet_value_t data,int index,int flge); 221 | 222 | #if (defined QSDK_USING_M5310)||(defined QSDK_USING_M5310A) 223 | int qsdk_onenet_notify_and_ack(qsdk_onenet_stream_t stream,int len,qsdk_onenet_value_t data,int flge); 224 | #endif 225 | #endif 226 | 227 | 228 | #ifdef QSDK_USING_MQTT 229 | 230 | struct mqtt_stream 231 | { 232 | char topic[MQTT_TOPIC_NAME_MAX]; 233 | int qos; 234 | int retain; 235 | int dup; 236 | int mesg_type; 237 | int suback_ststus; 238 | int puback_status; 239 | int user_status; 240 | int revice_status; 241 | }; 242 | 243 | typedef struct mqtt_stream *qsdk_mqtt_topic_t; 244 | 245 | int qsdk_mqtt_config(void); 246 | int qsdk_mqtt_check_config(void); 247 | qsdk_mqtt_topic_t qsdk_mqtt_topic_init(const char *topic,int qos,int retain,int dup,int mesg_type); 248 | int qsdk_mqtt_open(void); 249 | int qsdk_mqtt_get_connect_status(void); 250 | int qsdk_mqtt_sub(qsdk_mqtt_topic_t topic); 251 | int qsdk_mqtt_check_sub(qsdk_mqtt_topic_t topic); 252 | int qsdk_mqtt_pub_topic(qsdk_mqtt_topic_t topic,char *mesg); 253 | int qsdk_mqtt_pub_stream(char *mesg,int qos); 254 | int qsdk_mqtt_set_ack_timeout(int timeout); 255 | int qsdk_mqtt_open_ack_dis(void); 256 | int qsdk_mqtt_close_ack_dis(void); 257 | int qsdk_mqtt_unsub(qsdk_mqtt_topic_t topic); 258 | int qsdk_mqtt_close(void); 259 | int qsdk_mqtt_delete(void); 260 | int qsdk_mqtt_get_connect(void); 261 | int qsdk_mqtt_get_error_type(void); 262 | #endif 263 | 264 | 265 | #ifdef QSDK_USING_GPS 266 | 267 | #ifdef QSDK_USING_ME3616_GPS 268 | int qsdk_gps_start_mode(rt_uint8_t mode); 269 | int qsdk_agps_config(void); 270 | int qsdk_gps_config(void); 271 | int qsdk_gps_set_out_time(rt_uint32_t time); 272 | int qsdk_gps_run_mode(rt_uint8_t mode); 273 | int qsdk_gps_close(void); 274 | 275 | #elif (defined QSDK_USING_AIR530_GPS) 276 | 277 | int qsdk_gps_start_mode(int type); 278 | int qsdk_gps_erase_flash(void); 279 | int qsdk_gps_enter_standby(int type); 280 | int qsdk_gps_set_nmea_out_time(int sec); 281 | int qsdk_gps_enter_low_power(int mode,int run_time,int sleep_time); 282 | int qsdk_gps_search_mode(int gps_status,int glonass_status,int beidou_status,int galieo_status); 283 | int qsdk_gps_set_nmea_dis(int status); 284 | int qsdk_gps_set_locat_info(char *lon,char *lat,int year,char month,char day,char hour,char min,char sec); 285 | #endif //endif QSDK_USING_AIR530_GPS 286 | 287 | #endif //endif QSDK_USING_GPS 288 | 289 | void qsdk_rtc_set_time_callback(int year,char month,char day,char hour,char min,char sec,char week); 290 | 291 | int qsdk_net_data_callback(char *data,int len); 292 | void qsdk_net_close_callback(void); 293 | int qsdk_iot_data_callback(char *data,int len); 294 | 295 | int qsdk_onenet_close_callback(void); 296 | int qsdk_onenet_read_rsp_callback(int msgid,int insid,int resid); 297 | int qsdk_onenet_write_rsp_callback(int len,char* value); 298 | int qsdk_onenet_exec_rsp_callback(int len,char* cmd); 299 | void qsdk_onenet_fota_callback(void); 300 | 301 | int qsdk_mqtt_data_callback(char *topic,char *mesg,int mesg_len); 302 | int qsdk_gps_data_callback(char *lon,char *lat,float speed); 303 | void qsdk_nb_reboot_callback(void); 304 | 305 | #endif //qsdk.h end 306 | 307 | -------------------------------------------------------------------------------- /src/qsdk_callback.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/src/qsdk_callback.c -------------------------------------------------------------------------------- /src/qsdk_gps.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/src/qsdk_gps.c -------------------------------------------------------------------------------- /src/qsdk_iot.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/src/qsdk_iot.c -------------------------------------------------------------------------------- /src/qsdk_nb.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/src/qsdk_nb.c -------------------------------------------------------------------------------- /src/qsdk_net.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/src/qsdk_net.c -------------------------------------------------------------------------------- /src/qsdk_onenet.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hbqs/qsdk/0561d98e415d80e116d5b471c2d33342698c34b6/src/qsdk_onenet.c --------------------------------------------------------------------------------