蜜袋鼯 第⑩贴 基于RSL10的蜜袋鼯健康监测系统-上位机设计
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">前言</span></span></p><p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">在项目简介一贴中介绍了本项目的目标,其中第二个和第三个分别为</span><span lang="en-US" style="font-family:Calibri">:</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> 2、运动健康数据分析:由于小蜜活动时间都是在夜里,这时候我们都是在睡觉的,那么想要知道它一晚上玩的开心与否,那么就可以通过手机上位机的形式,连接RSL10传感器板来接收汇总数据,形成数据表,记录下小蜜一天的运动量~ </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> 3、健康运动奖励机制:结合1中的运动数据来分析小蜜是否运动达标~如果达标的话通过RSL10无线SoC评估板来控制投食奖励器,给小蜜投个最爱吃的玉米虫来作为奖励。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">在前面几贴中,完成了对运动奖励子系统和运动数据监测系统的设计与实现。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">本帖将对本项目的最后一个部分进行设计说明--上位机系统。</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">上位机系统可以与运动奖励系统和运动数据监测系统进行通讯,接收运动数据监测系统的环境和运动数据,控制奖励系统给小蜜投递奖励。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">可能有人会问,为啥不直接把两个板子连接起来,然后自动监测数据、投食呢?</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">当然可以咯,但我不,我要把奖励的权限握在手中!为啥,不为啥~就是玩。哈哈</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">在写上位机之前,需要根据前面几个帖子中设计的功能,对手机与模块间通讯协议进行制定。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">首先,运动奖励子系统中主要就实现了单向的</span><span lang="en-US" style="font-family:Calibri">IO</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">控制,协议相对简单:</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">如上图,上位机端发送两字节指令,第一个字节为指令,固定为</span><span lang="en-US" style="font-family:Calibri">0</span><span lang="en-US" style="font-family:"Microsoft YaHei"">xff</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">,第二个字节为要打开的弹窗索引号,索引号见可以或操作,也就是可以一条指令弹出任意个弹窗。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">接下来,运动数据监测系统则需要双向通讯,以传输各个状态信息,而</span><span lang="en-US" style="font-family:Calibri">BLE</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">协议中稳定传输时,每帧中最多</span><span lang="en-US" style="font-family:Calibri">20</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">字节,而运动监测子系统中有些数据量很大,需要多包传输,所以协议相对复杂些,具体如下。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">上位机端的协议如下:</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">下位机端的上发协议如下:</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">协议格式为: 指令 + 数据长度 + 数据的方式</span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">手机端一共</span><span lang="en-US" style="font-family:Calibri">12</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">条协议,</span><span lang="en-US" style="font-family:Calibri">3</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">个设置项,</span><span lang="en-US" style="font-family:Calibri">9</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">个获取项</span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">下位机端一共</span><span lang="en-US" style="font-family:Calibri">12</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">条协议,分别对应上位机端的</span><span lang="en-US" style="font-family:Calibri">12</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">条进行回应。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">制定好了协议包内容,就可以分别实现上下位机的协议处理了,</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">下位机端结合上一贴中的数据内存管理实现了协议,具体代码如下:</span></span></p>
<pre>
<code class="language-cpp">protocol.c
#include <data_manage2.h>
#include <protocol.h>
extern uint16_t round_count;
extern float angle_front;
extern float angle_back;
extern uint8_t ava_gyro;
extern data_manage_t temperature_dm;
extern data_manage_t light_dm;
extern data_manage_t noise_dm;
extern data_manage_t feeder_dm;
extern data_manage_t activity_dm;
extern data_manage_t rotation_dm;
uint8_t recv_protocol(uint8_t * data, uint8_t length)
{
uint8_t send_data = {0};
uint16_t cnt = 0;
if(length >= 2)
{
switch(data)
{
case CMD_CLEAN_ROUND:
round_count = 0;
angle_front = 0;
angle_back = 0;
ava_gyro = 0;
send_data = CMD_CLEAN_ROUND;
send_data = 0x01;
send_data = 0x11;
BLE_send(send_data, 3);
break;
case CMD_CLEAN_BUFF:
data_empty(&temperature_dm);
data_empty(&light_dm);
data_empty(&noise_dm);
data_empty(&feeder_dm);
data_empty(&activity_dm);
data_empty(&rotation_dm);
send_data = CMD_CLEAN_BUFF;
send_data = 0x01;
send_data = 0x11;
BLE_send(send_data, 3);
break;
case CMD_SET_TIME:
send_data = CMD_SET_TIME;
send_data = 0x01;
send_data = 0x11;
BLE_send(send_data, 3);
break;
case CMD_SET_FEETER:
send_data = CMD_SET_FEETER;
send_data = 0x01;
send_data = 0x11;
BLE_send(send_data, 3);
break;
case CMD_GET_COUND_AVAGYRO:
send_data = CMD_GET_COUND_AVAGYRO;
send_data = 0x03;
send_data = round_count >> 8 & 0xff;
send_data = round_count & 0xff;
send_data = (int8_t)ava_gyro;
BLE_send(send_data, 5);
break;
case CMD_GET_TEMP_PKG_CNT:
cnt = get_data_pkg_cnt(&temperature_dm);
send_data = CMD_GET_TEMP_PKG_CNT;
send_data = 0x02;
send_data = cnt >> 8 & 0xff;
send_data = cnt & 0xff;
BLE_send(send_data, 4);
break;
case CMD_GET_TEMP_PKG:
cnt = data << 8 | data;
send_data = CMD_GET_TEMP_PKG;
send_data = 0x14;
data_read(&temperature_dm,cnt,&send_data);
BLE_send(send_data, 20);
break;
case CMD_GET_LIGHT_PKG_CNT:
cnt = get_data_pkg_cnt(&light_dm);
send_data = CMD_GET_LIGHT_PKG_CNT;
send_data = 0x02;
send_data = cnt >> 8 & 0xff;
send_data = cnt & 0xff;
BLE_send(send_data, 4);
break;
case CMD_GET_LIGHT_PKG:
cnt = data << 8 | data;
send_data = CMD_GET_LIGHT_PKG;
send_data = 0x14;
data_read(&light_dm,cnt,&send_data);
BLE_send(send_data, 20);
break;
case CMD_GET_NOISE_PKG_CNT:
cnt = get_data_pkg_cnt(&noise_dm);
send_data = CMD_GET_NOISE_PKG_CNT;
send_data = 0x02;
send_data = cnt >> 8 & 0xff;
send_data = cnt & 0xff;
BLE_send(send_data, 4);
break;
case CMD_GET_NOISE_PKG:
cnt = data << 8 | data;
send_data = CMD_GET_NOISE_PKG;
send_data = 0x14;
data_read(&noise_dm,cnt,&send_data);
BLE_send(send_data, 20);
break;
case CMD_GET_ACT_PKG_CNT:
cnt = get_data_pkg_cnt(&rotation_dm);
send_data = CMD_GET_ACT_PKG_CNT;
send_data = 0x02;
send_data = cnt >> 8 & 0xff;
send_data = cnt & 0xff;
BLE_send(send_data, 4);
break;
case CMD_GET_ACT_PKG:
cnt = data << 8 | data;
send_data = CMD_GET_ACT_PKG;
send_data = 0x14;
data_read(&rotation_dm,cnt,&send_data);
BLE_send(send_data, 20);
break;
}
}
return 0 ;
}
</code></pre>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">上位机端采用手机软件的方式,在手机端实现上位机,可以有很多种方式,比如坛友有用Android/ios直接编的,也有用针对少年开发的Scratch图形化编程的,还有用微信小程序开发的。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">因为之前有申请过微信开发账号,所以这个项目 我也选择的微信小程序来 实现的上位机。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">小程序上分为三个界面,第一个是欢迎界面,如下图所示,其中是项目标题、”小果冻“照片和两个功能索引按钮,第一个按钮为”来呀,点我看看“实现的是本项目的主要功能,第二个按钮为“或者,调试一下”实现的本项目中需要设置或者调试的功能,接下来分别介绍这两个界面。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""><span style="font-weight:bold">一、调试界面</span></span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">首先介绍下调试界面,点击“或者,调试一下”就可以进入到调试界面。</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">在这个界面中,分别设置了数据检测器调试区和奖励器弹出调试区,每个区域中默认状态下只要一个按钮,后台蓝牙处于扫描阶段,当扫描到了对应的设备后,界面将会编程如下样子:</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">点击连接,并且连接成功后,则会显示出各项调试功能。在这里可以清空总圈数,清空数据缓冲区,设置当前时间,获取各项数据,如下图所示:</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">点击连接奖励器,则会显示出弹窗按钮,按下相应的按钮,奖励器就会弹出相应的窗口:</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""><span style="font-weight:bold">二、主界面</span></span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">接下来是主界面,“来呀,点我看看”,进入该界面后,可以看到两个按钮,一个是get,一个是clean,同时左边会显示进度条。</span></span></p>
<p> </p>
<p><span style="font-size:11.0pt"><span style="font-family:Calibri"> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">在一点进界面后,后台就会自动搜索设备,当显示设备注册成功后,就可以点击get来获取数据了,</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">此时等待进度条走满后,数据就会加载到下面图表中,图表是采用的eschart for weixin的开源库,图表中会显示出温度、亮度、噪音、和运动角速度的数据,这样小果冻一晚上的环境和他的运动情况我们就了如指掌了~</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">系统也会自动根据数据来显示出小果冻一晚上的运动情况,并显示“要不要奖励一下?”的功能按钮,此时,如果我们核对了各项数据,觉得没问题了呢,就可以点击该按钮,来进行奖励。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">当然了,如果系统都没检测到小果冻跑了,你要是强行开后门给奖励,系统可是不同意的哦,会显示如下界面。</span></span></p>
<p> </p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">以上就是小程序上位机的功能介绍了,具体功能实现代码有些长,我就不贴在帖子中了,放在了git上,有兴趣的可以关注一波。</span></span></p>
<p><span lang="en-US" style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">Github:</span></span><a href="https://gitee.com/zealerlu/hmsof-glider">hmsof-glider</a></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">至此,本项目的设计内容全部介绍完毕,可以展示并提交作品了~~撒花</span></span></p>
页:
[1]