84 lines
2.6 KiB
C++
84 lines
2.6 KiB
C++
#include "SimMsg.h"
|
|
#include "ObcHS.h"
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
|
|
using namespace std;
|
|
|
|
void ObcHSWriteLog(const std::string &msg)
|
|
{
|
|
std::cout << msg<<std::endl;
|
|
}
|
|
|
|
string topic_name_cmd = "Command";
|
|
string topic_name_tlm = "Telemetry";
|
|
|
|
SimMsg* ObcHS_part = nullptr;
|
|
string servername = "Obc_Hardware_Service";
|
|
|
|
//初始化
|
|
void ObcHS_init(uint8_t domainid, std::string appname)
|
|
{
|
|
std::vector<std::string> parameters;
|
|
string expression = "dest = '"+ servername + "'";
|
|
if (nullptr == ObcHS_part)
|
|
{
|
|
ObcHS_part=new SimMsg(domainid, 3000, appname, ObcHSWriteLog);
|
|
ObcHS_part->create_pub(topic_name_cmd);
|
|
ObcHS_part->create_pub(topic_name_tlm);
|
|
|
|
ObcHS_part->create_sub(topic_name_cmd, command_callback, expression, parameters);
|
|
ObcHS_part->create_sub(topic_name_tlm, telemetry_callback, expression, parameters);
|
|
}
|
|
}
|
|
|
|
// 遥控接收回调函数
|
|
void command_callback(std::string src, std::string dest, std::string type,
|
|
std::string reserve1, std::string reserve2,
|
|
std::vector<uint8_t>& data) {
|
|
// 打印接收到的数据
|
|
std::cout << "Command received from " << src << " to " << dest << std::endl;
|
|
std::cout << "Type: " << type << std::endl;
|
|
std::cout << "Data (" << data.size() << " bytes): ";
|
|
for (size_t i = 0; i < data.size(); ++i) {
|
|
std::cout << std::hex << std::uppercase << (int)data[i];
|
|
if (i < data.size() - 1) {
|
|
std::cout << ", ";
|
|
}
|
|
}
|
|
std::cout << std::dec << std::endl;
|
|
}
|
|
|
|
// 遥测接收回调函数
|
|
void telemetry_callback(std::string src, std::string dest, std::string type,
|
|
std::string reserve1, std::string reserve2,
|
|
std::vector<uint8_t>& data) {
|
|
// 打印接收到的数据
|
|
std::cout << "Telemetry received from " << src << " to " << dest << std::endl;
|
|
std::cout << "Type: " << type << std::endl;
|
|
std::cout << "Data (" << data.size() << " bytes): ";
|
|
for (size_t i = 0; i < data.size(); ++i) {
|
|
std::cout << std::hex << std::uppercase << (int)data[i];
|
|
if (i < data.size() - 1) {
|
|
std::cout << ", ";
|
|
}
|
|
}
|
|
std::cout << std::dec << std::endl;
|
|
}
|
|
|
|
|
|
// 星务硬件服务化遥控发布
|
|
void ObcHS_command_Pub(uint8_t* data, string dest, uint16_t len)
|
|
{
|
|
ObcHS_part->publish(topic_name_cmd, "Obc_Hardware_Service", dest, "command", data, len);
|
|
}
|
|
|
|
// 星务硬件服务化遥测发布
|
|
void ObcHS_telemetry_Pub(uint8_t* data, string dest, uint16_t len)
|
|
{
|
|
ObcHS_part->publish(topic_name_tlm, "Obc_Hardware_Service", dest, "telemetry", data, len);
|
|
}
|