Skip to content

Commit 1a0ac94

Browse files
authored
Merge pull request #4 from MiRoboticsLab/v1.3.0.0
V1.3.0.0
2 parents 9332bf5 + 015d963 commit 1a0ac94

25 files changed

Lines changed: 1701 additions & 42 deletions

connector/config/wifi.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[wifi]
2-
user_boots_first_time = false
32
[wifi.ssid]
43
password = "password"
54
provider = "provider"

connector/config/wifirecord.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[wifi]
2+
[wifi.ssid]
3+
type = "type"
4+
provider = "ip"

connector/include/connector/connector.hpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
#include <std_msgs/msg/string.hpp>
4343
#include <std_msgs/msg/bool.hpp>
4444

45+
#include <protocol/msg/wifi_info.hpp>
46+
#include <protocol/msg/notify_to_app.hpp>
47+
#include <protocol/msg/bluetooth_status.hpp>
48+
#include <protocol/msg/bledfu_progress.hpp>
49+
4550
#include <protocol/msg/audio_play.hpp>
4651
#include <protocol/msg/connector_status.hpp>
4752
#include <protocol/msg/touch_status.hpp>
@@ -68,7 +73,7 @@ namespace cyberdog
6873
namespace interaction
6974
{
7075
namespace py = pybind11;
71-
static const unsigned int LINE_MAX_SIZE {16384}; /*!< 行最大值:2kb */
76+
static const unsigned int LINE_MAX_SIZE {16384}; /*!< 行最大值:2kb */
7277

7378
/*! \file connector.hpp
7479
\brief 连接模块。
@@ -94,7 +99,13 @@ class Connector final : public rclcpp::Node
9499
using LedSrv = protocol::srv::LedExecute; /*!< [service 类型]LED 驱动服务 */
95100
using CameraSrv = protocol::srv::CameraService; /*!< [service 类型]相机 驱动服务 */
96101

97-
using TimeType = std::chrono::time_point<std::chrono::system_clock>; /*!< 超时 */
102+
using NotifyToAppMsg = protocol::msg::NotifyToApp; /*!< [topic 类型]通知APP连接状态消息 */
103+
using WIFIINFOMSG = protocol::msg::WifiInfo;
104+
using BLUETOOTHSTATUSMSG = protocol::msg::BluetoothStatus;
105+
using ConnectorStatus = std_msgs::msg::String;
106+
using BLEDfuProgressMsg = protocol::msg::BLEDFUProgress;
107+
108+
using TimeType = std::chrono::time_point<std::chrono::system_clock>; /*!< 超时 */
98109
enum ShellEnum
99110
{
100111
shell = 1993, /*!< 异常结束, 执行shell命令错误 */
@@ -110,16 +121,16 @@ class Connector final : public rclcpp::Node
110121
const std::function<uint(uint16_t)>,
111122
const std::function<uint(uint8_t)>,
112123
const std::function<uint(uint16_t)>,
113-
const std::function<uint(
114-
const std::string,
115-
const std::string)>); /*!< 初始化 */
124+
const std::function<uint(const std::string, const std::string)>,
125+
const std::function<bool(bool)>); /*!< 初始化 */
116126

117127
public:
118128
std::function<uint(uint16_t)> CtrlAudio; /*!< [客户端]控制语音 */
119129
std::function<uint(uint8_t)> CtrlCamera; /*!< [客户端]控制相机 */
120130
std::function<uint(uint16_t)> CtrlLed; /*!< [客户端]控制led */
121131
std::function<uint(const std::string, const std::string)>
122132
CtrlWifi; /*!< [客户端]控制wifi */
133+
std::function<bool(bool)> CtrlAdvertising; /*!< [客户端]控制蓝牙 */
123134

124135
private:
125136
bool InitPythonInterpreter(); /*!< 初始化 python 解释器 */
@@ -183,6 +194,28 @@ class Connector final : public rclcpp::Node
183194
rclcpp::CallbackGroup::SharedPtr touch_cb_group_ {nullptr}; /*!< [回调组] touch */
184195
rclcpp::CallbackGroup::SharedPtr img_cb_group_ {nullptr}; /*!< [回调组] img */
185196
rclcpp::CallbackGroup::SharedPtr pub_cb_group_ {nullptr}; /*!< [回调组] pub */
197+
198+
void APPSendWiFiCallback(const protocol::msg::WifiInfo::SharedPtr msg);
199+
void AppConnectState(const std_msgs::msg::Bool msg);
200+
void BtStatusCallback(const protocol::msg::BluetoothStatus::SharedPtr msg);
201+
void BledfuProgressCallback(const BLEDfuProgressMsg::SharedPtr msg);
202+
bool WriteToFile(
203+
const std::string ssid,
204+
const std::string ip,
205+
const std::string type);
206+
207+
NotifyToAppMsg notify_to_app_msg_;
208+
ConnectorStatus connector_status_msg_;
209+
rclcpp::Subscription<WIFIINFOMSG>::SharedPtr wifi_info_sub_ {nullptr};
210+
rclcpp::Publisher<NotifyToAppMsg>::SharedPtr notify_to_app_pub_ {nullptr};
211+
rclcpp::Subscription<BLUETOOTHSTATUSMSG>::SharedPtr bluetooth_status_sub_ {nullptr};
212+
rclcpp::Subscription<BLEDfuProgressMsg>::SharedPtr bledfu_progress_sub_ {nullptr};
213+
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr connector_init_pub_ {nullptr};
214+
std::string wifi_record_dir_ {""}; /*!< wifi 类型记录文件路径 */
215+
bool connect_network_status = true;
216+
int connect_code = -1;
217+
bool bledfu_progress_status = true;
218+
bool camera_callback_flag = false;
186219
}; // class Connector
187220
} // namespace interaction
188221
} // namespace cyberdog
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) 2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#ifndef CONNECTOR__CTRL_BLUETOOTH_HPP_
15+
#define CONNECTOR__CTRL_BLUETOOTH_HPP_
16+
17+
#include <unistd.h>
18+
#include <string>
19+
#include <iostream>
20+
#include <sstream>
21+
#include <regex>
22+
#include <vector>
23+
#include <cstdlib>
24+
#include <cstdio>
25+
#include "rclcpp/rclcpp.hpp"
26+
#include "rclcpp/wait_set.hpp"
27+
#include "cyberdog_common/cyberdog_log.hpp"
28+
#include "cyberdog_common/cyberdog_toml.hpp"
29+
#include "protocol/msg/audio_play.hpp"
30+
#include "protocol/msg/bluetooth_status.hpp"
31+
#include "protocol/srv/bms_cmd.hpp"
32+
#include "std_srvs/srv/trigger.hpp"
33+
34+
namespace cyberdog
35+
{
36+
namespace interaction
37+
{
38+
class CtrlBluetooth final : public rclcpp::Node
39+
{
40+
public:
41+
explicit CtrlBluetooth(const std::string name);
42+
~CtrlBluetooth();
43+
bool CtrlAdvertising(bool enable);
44+
45+
bool WriteToFile(
46+
const std::string ssid,
47+
const std::string ip,
48+
const std::string type);
49+
bool IsConnectApp();
50+
51+
private:
52+
bool Init();
53+
std::string runCommand(const std::string & cmd);
54+
std::vector<std::string> parseConnectionsOutput(const std::string & output);
55+
void BluetoothStatusCallback(
56+
const protocol::msg::BluetoothStatus::SharedPtr msg);
57+
bool DisconnectBluetooth();
58+
59+
private:
60+
int bluetooth_connect_status_ = -1;
61+
int bluetooth_advertising_status_ = -1;
62+
63+
rclcpp::Subscription<protocol::msg::BluetoothStatus>::SharedPtr bluetooth_status_sub_ {nullptr};
64+
rclcpp::Client<protocol::srv::BmsCmd>::SharedPtr control_advertise_client_ {nullptr};
65+
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr disconnect_app_bt_srv_ {nullptr};
66+
}; // class CtrlBluetooth
67+
} // namespace interaction
68+
} // namespace cyberdog
69+
#endif // CONNECTOR__CTRL_BLUETOOTH_HPP_

0 commit comments

Comments
 (0)