From 3f0352daf09f1a4a126bc302823dd52130407dcd Mon Sep 17 00:00:00 2001 From: tk Date: Fri, 12 Jul 2024 14:09:16 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=09=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afactor=20=E3=80=90=E4=B8=BB=09=E9=A2=98=E3=80=91?= =?UTF-8?q?=EF=BC=9A=E5=8F=91=E9=80=81=E9=A3=9E=E6=9C=BA=E7=8A=B6=E6=80=81?= =?UTF-8?q?=20=E4=B8=8D=E5=A4=9F=E9=A2=91=E7=B9=81=20=E3=80=90=E6=8F=8F=09?= =?UTF-8?q?=E8=BF=B0=E3=80=91=EF=BC=9A=20=09[=E5=8E=9F=E5=9B=A0]=EF=BC=9A?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E6=8E=A5=E6=94=B6=E9=A3=9E=E6=9C=BA=E7=8A=B6?= =?UTF-8?q?=E6=80=81=20=E5=A4=AA=E6=97=A7=20=09[=E8=BF=87=E7=A8=8B]?= =?UTF-8?q?=EF=BC=9A=E5=92=8C=E5=BF=83=E8=B7=B3=E4=B8=80=E8=B5=B7=E9=A2=91?= =?UTF-8?q?=E7=B9=81=E5=8F=91=E9=80=81=20=E4=B8=80=E7=A7=92=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=20=09[=E5=BD=B1=E5=93=8D]=EF=BC=9A=20=E3=80=90?= =?UTF-8?q?=E7=BB=93=09=E6=9D=9F=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动 --- src/commser.cpp | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/commser.cpp b/src/commser.cpp index 8f9b51d..3a89935 100644 --- a/src/commser.cpp +++ b/src/commser.cpp @@ -16,10 +16,10 @@ static const char *MOUDLENAME = "COMMSER"; /*项目对象*/ // char* ssid = "szdot"; //wifi帐号 // char* password = "Ttaj@#*.com"; //wifi密码 -// char *ssid = "flicube"; // wifi帐号 -// char *password = "fxmf0622"; // wifi密码 -char *ssid = "fxmf_sc01"; // 4g wifi帐号 -char *password = "12345678"; // 4g wifi密码 +char *ssid = "flicube"; // wifi帐号 +char *password = "fxmf0622"; // wifi密码 +// char *ssid = "fxmf_sc01"; // 4g wifi帐号 +// char *password = "12345678"; // 4g wifi密码 char *mqttServer = "szdot.top"; // mqtt地址 int mqttPort = 1883; // mqtt端口 char *mqttName = "admin"; // mqtt帐号 @@ -628,24 +628,27 @@ void pubThread() // 遍历 有更新的数据 组成一个json对象 for (int i = 0; i < topicPubCount; i++) { - if (topicPubMsg[i] != oldMsg[i]) + if (i == 0) + { // 心跳包 每每向心跳主题发布信息 + // 启动飞控 第一次心跳 ps:防止飞控 滞后启动 拿不到数据 + if (fc.getIsInit()) + { + fc.setIsInit(false); + fc.mav_request_data(); // 再向飞控请求一次 设定飞控输出数据流内容 + } + // 设置对象成员 ps:心跳 + doc[topicPub[0]] = topicPubMsg[0]; + } + else if (i == 10) { - if (i == 0) - { // 心跳包 每每向心跳主题发布信息 - // 启动飞控 第一次心跳 ps:防止飞控 滞后启动 拿不到数据 - if (fc.getIsInit()) - { - fc.setIsInit(false); - fc.mav_request_data(); // 再向飞控请求一次 设定飞控输出数据流内容 - } - // 设置对象成员 ps:心跳 - doc[topicPub[0]] = topicPubMsg[0]; - } - else - { // 非心跳 有更新 录入成员 - doc[topicPub[i]] = topicPubMsg[i]; - oldMsg[i] = topicPubMsg[i]; - } + // 设置对象成员 ps:飞机状态 state + doc[topicPub[10]] = topicPubMsg[10]; + } + else if (topicPubMsg[i] != oldMsg[i]) + { + // 非心跳 非飞机状态 有更新 录入成员 + doc[topicPub[i]] = topicPubMsg[i]; + oldMsg[i] = topicPubMsg[i]; } } // 将JSON对象序列化为JSON字符串