|
|
|
|
@ -54,6 +54,9 @@ PublisherApp::PublisherApp(
|
|
|
|
|
, summary_topic_(nullptr)
|
|
|
|
|
, summary_writer_(nullptr)
|
|
|
|
|
, summary_type_(new WeighingSystem::SummaryUpdatePubSubType())
|
|
|
|
|
, print_topic_(nullptr)
|
|
|
|
|
, print_writer_(nullptr)
|
|
|
|
|
, print_type_(new InternalSystem::PrintReqPubSubType())
|
|
|
|
|
, matched_(0)
|
|
|
|
|
, samples_sent_(0)
|
|
|
|
|
, stop_(false)
|
|
|
|
|
@ -76,6 +79,7 @@ PublisherApp::PublisherApp(
|
|
|
|
|
bar_type_.register_type(participant_);
|
|
|
|
|
light_type_.register_type(participant_);
|
|
|
|
|
summary_type_.register_type(participant_);
|
|
|
|
|
print_type_.register_type(participant_);
|
|
|
|
|
|
|
|
|
|
// Create the publisher
|
|
|
|
|
PublisherQos pub_qos = PUBLISHER_QOS_DEFAULT;
|
|
|
|
|
@ -166,6 +170,33 @@ PublisherApp::PublisherApp(
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("WeighingSystem::SummaryUpdate DataWriter initialization failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the topic
|
|
|
|
|
topic_qos = TOPIC_QOS_DEFAULT;
|
|
|
|
|
participant_->get_default_topic_qos(topic_qos);
|
|
|
|
|
print_topic_ = participant_->create_topic("PrintReq", print_type_.get_type_name(), topic_qos);
|
|
|
|
|
if (print_topic_ == nullptr)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("PrintReq Topic initialization failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the data writer
|
|
|
|
|
writer_qos = DATAWRITER_QOS_DEFAULT;
|
|
|
|
|
publisher_->get_default_datawriter_qos(writer_qos);
|
|
|
|
|
writer_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
|
|
|
|
|
writer_qos.reliability().max_blocking_time = Duration_t(1, 0);
|
|
|
|
|
writer_qos.durability().kind = DurabilityQosPolicyKind::VOLATILE_DURABILITY_QOS;
|
|
|
|
|
writer_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
|
|
|
|
|
writer_qos.history().depth = 1;
|
|
|
|
|
writer_qos.resource_limits().max_samples = 200;
|
|
|
|
|
writer_qos.resource_limits().max_instances = 1;
|
|
|
|
|
writer_qos.resource_limits().max_samples_per_instance = 100;
|
|
|
|
|
writer_qos.data_sharing().off();
|
|
|
|
|
print_writer_ = publisher_->create_datawriter(print_topic_, writer_qos, this, StatusMask::all());
|
|
|
|
|
if (print_writer_ == nullptr)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("InternalSystem::PrintReq DataWriter initialization failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PublisherApp::~PublisherApp()
|
|
|
|
|
@ -288,6 +319,22 @@ bool PublisherApp::light_ctrl(const std::map<std::string, std::string>& ctrl)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PublisherApp::print_receipt(const std::map<std::string, std::string>& msg)
|
|
|
|
|
{
|
|
|
|
|
InternalSystem::PrintReq req;
|
|
|
|
|
|
|
|
|
|
req.msg() = msg;
|
|
|
|
|
|
|
|
|
|
for (auto &m : req.msg())
|
|
|
|
|
{
|
|
|
|
|
std::cout << "first: " << m.first << " second: " << m.second << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print_writer_->write(&req);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PublisherApp::run(std::shared_ptr<mqtt::async_client> dev)
|
|
|
|
|
{
|
|
|
|
|
uint8_t send_sum = 0;
|
|
|
|
|
@ -418,6 +465,40 @@ void PublisherApp::run(std::shared_ptr<mqtt::async_client> dev)
|
|
|
|
|
WeighingSystem::WeightInfoOk info = std::move(DdsMsgData::WeightInfoOk_queue_.front());
|
|
|
|
|
DdsMsgData::WeightInfoOk_queue_.pop();
|
|
|
|
|
dds_lock.unlock();
|
|
|
|
|
|
|
|
|
|
std::map<std::string, std::string> print_msg;
|
|
|
|
|
auto formatFloat = [](float value) -> std::string
|
|
|
|
|
{
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
oss << std::fixed << std::setprecision(2) << value;
|
|
|
|
|
return oss.str();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
print_msg.clear();
|
|
|
|
|
print_msg["Title"] = "过衡单";
|
|
|
|
|
print_msg["DeviceID"] = std::to_string(info.DeviceID());
|
|
|
|
|
print_msg["DeviceName"] = info.DeviceName();
|
|
|
|
|
print_msg["TitleCorp"] = info.EnterpriseName();
|
|
|
|
|
print_msg["CoalNumber"] = info.BillNumber();
|
|
|
|
|
print_msg["CarNumber"] = info.CarNumber();
|
|
|
|
|
print_msg["Supplier"] = info.Supplier();
|
|
|
|
|
print_msg["GoodsType"] = info.GoodsType();
|
|
|
|
|
print_msg["GrossWeight"] = formatFloat(info.GrossWeight());
|
|
|
|
|
print_msg["GrossTime"] = info.GrossTime();
|
|
|
|
|
print_msg["GrossOperater"] = info.GrossOperater();
|
|
|
|
|
print_msg["TareWeight"] = formatFloat(info.Tare());
|
|
|
|
|
print_msg["TareTime"] = info.TareTime();
|
|
|
|
|
print_msg["TareOperater"] = info.TareOperater();
|
|
|
|
|
print_msg["SuttleWeight"] = formatFloat(info.Suttle());
|
|
|
|
|
print_msg["duduction1"] = formatFloat(info.duduction1());
|
|
|
|
|
print_msg["duduction2"] = formatFloat(info.duduction2());
|
|
|
|
|
print_msg["duduction3"] = formatFloat(info.duduction3());
|
|
|
|
|
print_msg["INCoalYard"] = info.INCoalYard();
|
|
|
|
|
print_msg["OUTCoalYard"] = info.OutCoalYard();
|
|
|
|
|
print_msg["BatchNumber"] = info.BatchNumber();
|
|
|
|
|
print_msg["Warning"] = info.Warning();
|
|
|
|
|
|
|
|
|
|
print_receipt(print_msg);
|
|
|
|
|
}
|
|
|
|
|
else if (!DdsMsgData::WeightInfoError_queue_.empty())
|
|
|
|
|
{
|
|
|
|
|
|