本文分享自中移OneOS微信公众号《定位功能测评+开发详解》。
本期严同学为了给大家展现
OnePos定位服务能力
复现地铁轨迹线路
坐了大半天的地铁
老辛苦了![](https://mbb.eet-china.com/static/image/smiley/comcom/28.gif)
这期视频大家一定要看看喔
![](https://static.assets-stash.eet-china.com/album/202111/29/162030hu7xzr0urd179r7l.png)
点此跳转展示视频
![](https://static.assets-stash.eet-china.com/album/202111/29/162210qvq76as78svj07c6.png)
想要一比一复原开发流程的小伙伴
可以看下面的讲解
绝对的干货
手把手教学(包会)
学不会找我哦![](https://mbb.eet-china.com/static/image/smiley/comcom/22.gif)
![](https://static.assets-stash.eet-china.com/album/202111/29/162035i6iaeiieu8bbu9ex.png)
点此跳转讲解视频
演示视频流程
![](https://static.assets-stash.eet-china.com/album/202111/29/162036devf1tkkgfgyyeyg.png)
![](https://static.assets-stash.eet-china.com/album/202111/29/162211v0o8rnzorx88r8tx.png)
OnePos定位平台简介
OnePos位置服务平台是一套为搭载OneOS的智能硬件设备提供端对云/云对云服务的高精度定位平台,可选择多种定位方式,同时支持WiFi/基站/惯性导航/GNSS解析等辅助定位手段。目前所有服务完全免费,企业用户可根据需求申请大额度的免费商用服务。
![](https://static.assets-stash.eet-china.com/album/202111/29/162037e2apsg2wgpihwptw.png)
详细了解参考开发者文档:OnePos定位-总体介绍
![](https://static.assets-stash.eet-china.com/album/202111/29/162211uvmy6yrc66xq5lur.png)
OnePos位置平台接入
OnePos位置平台创建设备的步骤包括以下几点:
1. OneOS官网注册账号
2. 登录OnePos平台
3. 进入产品管理
4. 创建产品
5. 创建设备(记录设备ID与设备Key)
6. 接入测试
![](https://static.assets-stash.eet-china.com/album/202111/29/162038w7xkilkzorlwwx1s.png)
详细的操作说明文档参考开发者文档:OnePos定位-端对云部分进行学习。
![](https://static.assets-stash.eet-china.com/album/202111/29/162211rl6quuoszpuzvisu.png)
OneOS定位应用开发
环境准备
目前OneOS代码已经开源,开发者可以前往OneOS仓库或者 OneOS官网进行下载。
![](https://static.assets-stash.eet-china.com/album/202111/29/162039segn31y5naeaegng.png)
OneOS-Cube是OneOS操作系统基于命令行的开发工具,提供系统配置、项目编译构造、包贡献下载等功能。OneOS-Cube工具的下载及使用说明可以查阅 OneOS-Cube环境搭建进行学习。
![](https://static.assets-stash.eet-china.com/album/202111/29/162039lngudi7z3u1g3w3d.png)
工程配置
OnePos定位服务依赖的组件包括:MQTT组件、cJSON组件、Molink组件;
使用图形化工具menuconfig.bat进行工程配置:
1. MQTT组件
OnePos组件与OnePos平台通信通过MQTT协议进行,开发者可以通过OneOS Cube中的menuconfig图形化界面工具的将MQTT组件集成到自己的应用中,MQTT组件的配置如下:
![](https://static.assets-stash.eet-china.com/album/202111/29/162040v4iezrr55rjyeyh4.png)
详细请查阅MQTT参考文档进行了解
2. cJSON组件
OnePos组件与OnePos平台交互数据采用JSON格式封装,OneOS操作系统通过cJSON组件提供JSON格式数据创建和解析的能力,cJSON组件的配置如下:
![](https://static.assets-stash.eet-china.com/album/202111/29/162040kz9sotuvwuu05g5u.png)
详细说明请访问cJSON进行学习
3. Molink组件
OnePos服务原理是利用周围的网络环境数据进行定位的,网络环境数据的获取以及与平台通信的能力是由Molink提供的;本文以CAT1模组ML302和WIFI模组esp8266为例进行网络数据的获取与通信。
![](https://static.assets-stash.eet-china.com/album/202111/29/162123xrpw4vook5o9v49v.png)
![](https://static.assets-stash.eet-china.com/album/202111/29/165113fmm9doqgoaxhhorg.png)
Molink的详细使用方法请参考MolinkAPI
4. OnePos组件
OnePos定位组件需要配合OnePos位置服务平台使用,可以对使用OneOS操作系统的开发者提供基础定位能力;
目前服务支持的能力有:Wi-Fi定位、基站定位、卫星定位。
![](https://static.assets-stash.eet-china.com/album/202111/29/162123icni7oovzvg9i7gk.png)
注意:在配置OnePos服务的设备密钥时需要将定位平台分配的设备Key进行MD5(32位小写加密),然后将加密后的配置为OnePos组件的密钥;OnePos组件详细使用方法请参考OnePos定位端侧文档。
完成上述MQTT、cJSON及Molink组件的配置后,在OneOS-Cube工具中使用命令scons --ide=mdk5更新MDK工程设置。
![](https://static.assets-stash.eet-china.com/album/202111/29/162124iufspnnrrewr773r.png)
![](https://static.assets-stash.eet-china.com/album/202111/29/162125nfmwzput0p6unl0v.png)
系统成功运行!
![](https://static.assets-stash.eet-china.com/album/202111/29/162126ddagq663fama6daa.png)
应用示例
编写如下示例的定位应用代码进行OnePos定位服务的试用。
源文件:main.c
1. #include <string.h>
2. #include <stdlib.h> 3. #include <stdio.h> 4. #include <os_task.h> 5. #include <os_dbg.h> 6. #include <os_errno.h> 7. #include <drv_gpio.h> 8. 9. #include <onepos_interface.h> 10. 11. #ifdef OS_USING_ST7789VW 12. #include "cmcclogo.h" 13. #include "oneposimage.h" 14. #include "st7789vw.h" 15. 16. #define CMCC_LCD_TIME_ROW_SP 65 17. #define CMCC_LCD_TIME_ROW_H 50 18. #define CMCC_LCD_TIME_LCOLUMN_SP 65 19. #define CMCC_LCD_TIME_RCOLUMN_SP 110 20. 21. #define SHOW_COLOR_RED 0xFA27 22. #define SHOW_COLOR_GREEN 0x1546 23. #define SHOW_COLOR_YELLOW 0xFD20 24. 25. static void oneos_lcd_show_startup_page(void) 26. { 27. /* show CMCC logo */ 28. lcd_show_image(20, 50, 200, 61, gImage_cmcc); 29. lcd_show_image(20, 150, 200, 52, gImage_oneos); 30. } 31. 32. static void oneos_lcd_show_position(void *arg) 33. { 34. char *str = OS_NULL; 35. char time_get_now[9] = {0,}; 36. time_t now = {0,}; 37. os_int32_t j = 0; 38. static char lat_show[20] = {0,}; 39. static char lon_show[20] = {0,}; 40. static onepos_pos_t pos_data = {0,}; 41. 42. lcd_clear(BLACK); 43. lcd_show_image(0, 0, 240, 240, gImage_onepos); 44. 45. while(1) 46. { 47. /* Get position */ 48. onepos_get_latest_position(&pos_data); 49. 50. /* Get time */ 51. now = time(OS_NULL); 52. str = ctime(&now); 53. 54. snprintf(lat_show, 24, "%f", pos_data.lat_coordinate); 55. snprintf(lon_show, 24, "%f", pos_data.lon_coordinate);\ 56. 57. for(j = 11; j < 19; j++) 58. { 59. time_get_now[j - 11] = str[j]; 60. } 61. time_get_now[8] = '\0'; 62. 63. lcd_set_color(SHOW_COLOR_RED, BLACK); 64. lcd_show_string(CMCC_LCD_TIME_LCOLUMN_SP + 30, CMCC_LCD_TIME_ROW_SP + CMCC_LCD_TIME_ROW_H * 0 + 3, 24, time_get_now); 65. lcd_set_color(SHOW_COLOR_GREEN, BLACK); 66. lcd_show_string(CMCC_LCD_TIME_LCOLUMN_SP + 30, CMCC_LCD_TIME_ROW_SP + CMCC_LCD_TIME_ROW_H * 1 + 15, 24, lat_show); 67. lcd_set_color(SHOW_COLOR_YELLOW, BLACK); 68. lcd_show_string(CMCC_LCD_TIME_LCOLUMN_SP + 30, CMCC_LCD_TIME_ROW_SP + CMCC_LCD_TIME_ROW_H * 2 + 30, 24, lon_show); 69. 70. os_task_mdelay(50); 71. } 72. } 73. #endif 74. 75. /* defined the LED0 pin: PD12 */ 76. #define LED0_PIN GET_PIN(D, 12) 77. 78. int main(void) 79. { 80. os_uint32_t count = 0; 81. os_task_t *lcd_show_task = OS_NULL; 82. 83. os_kprintf("Enter main function, here is the onepos code!\n"); 84. 85. #ifdef OS_USING_ST7789VW 86. oneos_lcd_show_startup_page(); 87. os_task_mdelay(500); 88. #endif 89. 90. #ifdef PKG_USING_NTP 91. /* wait ntp sync */ 92. extern time_t ntp_sync_to_rtc(const char *host_name); 93. ntp_sync_to_rtc(OS_NULL); 94. os_task_mdelay(500); 95. #endif 96. 97. count = 1; 98. /* set LED0 pin mode to output */ 99. os_pin_mode(LED0_PIN, PIN_MODE_OUTPUT); 100. 101. /* start onepos sever and wait once position */ 102. while(ONEPOS_CLOSING == onepos_get_server_sta()) 103. { 104. onepos_start_server(); 105. os_task_mdelay(5000); 106. } 107. /* creat lcd show task */ 108. lcd_show_task = os_task_create("lcd_show", oneos_lcd_show_position, 109. OS_NULL, 110. 2048, OS_TASK_PRIORITY_MAX / 2 - 4, 50); 111. 112. if (lcd_show_task != OS_NULL) 113. { 114. os_task_startup(lcd_show_task); 115. } 116. 117. while (count++) 118. { 119. os_pin_write(LED0_PIN, PIN_HIGH); 120. os_task_mdelay(400); 121. os_pin_write(LED0_PIN, PIN_LOW); 122. os_task_mdelay(400); 123. } 124. 125. return OS_EOK; 126. }复制代码头文件:oneposimage.h
百度网盘:
【https://pan.baidu.com/s/1ZYIirm7aA4qbFyHYB2_yWw】
【提取码:ppad】
在演示视频中直接用以上演示程序替换基础工程中的main.c;
由于演示功能包含实时时间显示的功能,需要使用NTP服务进行时间同步;
所以再配置一次工程:开启ntp服务;
![](https://static.assets-stash.eet-china.com/album/202111/29/162127fdge935l3h3htz53.png)
然后编译与烧录程序;
![](https://static.assets-stash.eet-china.com/album/202111/29/162129a2d61lo6dn1azd2l.png)
![](https://static.assets-stash.eet-china.com/album/202111/29/162133jlmkhb5rlvmpb6v6.png)
在OnePOS平台查询设备的位置信息:
![](https://static.assets-stash.eet-china.com/album/202111/29/162135r3eiendhv0slhvin.png)
![](https://static.assets-stash.eet-china.com/album/202111/29/162210qvq76as78svj07c6.png)
OneOS: OneOS是中国移动针对物联网领域推出的轻量级操作系统,具有可裁剪、跨平台、低功耗、高安全等特点,支持ARM Cortex-M/R/A、MIPS、RISC-V等主流CPU架构,兼容POSIX、CMSIS等标准接口,支持Micropython语言开发,提供图形化开发工具,能够有效提高开发效率并降低开发成本,帮助客户开发稳定可靠、安全易用的物联网应用。 官网地址:https://os.iot.10086.cn/
![](https://static.assets-stash.eet-china.com/album/202111/29/162210ygwrgrr4jjrdli7l.png)
文章评论(0条评论)
登录后参与讨论