1. 增加磅单补打功能。

2. 增加拦车器锁定状态。
main
baocm 8 months ago
parent 8e849a12e1
commit 25c7483055

@ -309,6 +309,8 @@ extern std::string mqtt_topic_id;
void PublisherApp::run(std::shared_ptr<mqtt::async_client> dev) void PublisherApp::run(std::shared_ptr<mqtt::async_client> dev)
{ {
std::map<std::string, std::string> print_msg;
while (!is_stopped()) while (!is_stopped())
{ {
//dds msg //dds msg
@ -425,6 +427,51 @@ void PublisherApp::run(std::shared_ptr<mqtt::async_client> dev)
} }
} }
} }
else if (!DdsMsgData::WeightInfoOk_queue_.empty())
{
WeighingSystem::WeightInfoOk info = std::move(DdsMsgData::WeightInfoOk_queue_.front());
DdsMsgData::WeightInfoOk_queue_.pop();
dds_lock.unlock();
auto formatFloat = [](float value) -> std::string
{
std::ostringstream oss;
oss << std::fixed << std::setprecision(2) << value;
return oss.str();
};
// if (info.IsPrintTicker() == true)
// {
print_msg.clear();
print_msg["Title"] = "过衡单";
print_msg["GrossDeviceID"] = std::to_string(info.GrossDeviceID());
print_msg["GrossDeviceName"] = info.GrossDeviceName();
print_msg["TareDeviceID"] = std::to_string(info.TareDeviceID());
print_msg["TareDeviceName"] = info.TareDeviceName();
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_msg["Tips"] = info.Tips();
print_msg["TicketType"] = info.TicketType();
// }
}
else else
{ {
dds_lock.unlock(); dds_lock.unlock();
@ -446,7 +493,7 @@ void PublisherApp::run(std::shared_ptr<mqtt::async_client> dev)
json cmd = json::parse(payload); json cmd = json::parse(payload);
if (topic.find("barrier/frontup") != std::string::npos) if (topic == ("pound/" + mqtt_topic_id + "/barrier/frontup"))
{ {
if (cmd["value"] == 1) if (cmd["value"] == 1)
{ {
@ -455,7 +502,7 @@ void PublisherApp::run(std::shared_ptr<mqtt::async_client> dev)
bar_ctrl(ctrl); bar_ctrl(ctrl);
} }
} }
else if (topic.find("barrier/frontdown") != std::string::npos) else if (topic == ("pound/" + mqtt_topic_id + "/barrier/frontdown"))
{ {
if (cmd["value"] == 1) if (cmd["value"] == 1)
{ {
@ -464,18 +511,28 @@ void PublisherApp::run(std::shared_ptr<mqtt::async_client> dev)
bar_ctrl(ctrl); bar_ctrl(ctrl);
} }
} }
else if (topic.find("barrier/frontlock") != std::string::npos) else if (topic == ("pound/" + mqtt_topic_id + "/barrier/frontlock"))
{ {
if (cmd["value"] == 1) if (cmd["value"] == 1)
{ {
std::ofstream(getExeDir() / "frontbar.lock") << getpid(); std::ofstream(getExeDir() / "frontbar.lock");
std::string payload = "{\"value\": 1}";
auto mqtt_msg = mqtt::make_message("pound/" + std::string(mqtt_topic_id) + "/barrier/frontlockstatus", payload);
mqtt_msg->set_qos(0);
mqtt_msg->set_retained(true);
dev->publish(mqtt_msg);
} }
else else
{ {
std::filesystem::remove(getExeDir() / "frontbar.lock"); std::filesystem::remove(getExeDir() / "frontbar.lock");
std::string payload = "{\"value\": 0}";
auto mqtt_msg = mqtt::make_message("pound/" + std::string(mqtt_topic_id) + "/barrier/frontlockstatus", payload);
mqtt_msg->set_qos(0);
mqtt_msg->set_retained(true);
dev->publish(mqtt_msg);
} }
} }
else if (topic.find("light/frontsignal") != std::string::npos) else if (topic == ("pound/" + mqtt_topic_id + "/light/frontsignal"))
{ {
if (cmd["value"] == 1) if (cmd["value"] == 1)
{ {
@ -490,6 +547,10 @@ void PublisherApp::run(std::shared_ptr<mqtt::async_client> dev)
light_ctrl(ctrl); light_ctrl(ctrl);
} }
} }
else if (topic == ("pound/" + mqtt_topic_id + "/businessok/reprint"))
{
print_receipt(print_msg);
}
} }
else else
{ {

@ -62,6 +62,9 @@ SubscriberApp::SubscriberApp(
, scaleinfo_topic_(nullptr) , scaleinfo_topic_(nullptr)
, scaleinfo_reader_(nullptr) , scaleinfo_reader_(nullptr)
, scaleinfo_type_(new WeighingSystem::ScaleInfoPubSubType()) , scaleinfo_type_(new WeighingSystem::ScaleInfoPubSubType())
, weightinfook_topic_(nullptr)
, weightinfook_reader_(nullptr)
, weightinfook_type_(new WeighingSystem::WeightInfoOkPubSubType())
, samples_received_(0) , samples_received_(0)
, stop_(false) , stop_(false)
{ {
@ -84,6 +87,7 @@ SubscriberApp::SubscriberApp(
infraredcommand_type_.register_type(participant_); infraredcommand_type_.register_type(participant_);
license_type_.register_type(participant_); license_type_.register_type(participant_);
scaleinfo_type_.register_type(participant_); scaleinfo_type_.register_type(participant_);
weightinfook_type_.register_type(participant_);
// Create the subscriber // Create the subscriber
SubscriberQos sub_qos = SUBSCRIBER_QOS_DEFAULT; SubscriberQos sub_qos = SUBSCRIBER_QOS_DEFAULT;
@ -255,6 +259,33 @@ SubscriberApp::SubscriberApp(
{ {
throw std::runtime_error("WeighingSystem::ScaleInfo DataReader initialization failed"); throw std::runtime_error("WeighingSystem::ScaleInfo DataReader initialization failed");
} }
// Create the topic
topic_qos = TOPIC_QOS_DEFAULT;
participant_->get_default_topic_qos(topic_qos);
weightinfook_topic_ = participant_->create_topic("WeightInfoOk", weightinfook_type_.get_type_name(), topic_qos);
if (weightinfook_topic_ == nullptr)
{
throw std::runtime_error("WeighingSystem::WeightInfoOk Topic initialization failed");
}
// Create the reader
reader_qos = DATAREADER_QOS_DEFAULT;
subscriber_->get_default_datareader_qos(reader_qos);
reader_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
reader_qos.reliability().max_blocking_time = Duration_t(1, 0);
reader_qos.durability().kind = DurabilityQosPolicyKind::VOLATILE_DURABILITY_QOS;
reader_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
reader_qos.history().depth = 1;
reader_qos.resource_limits().max_samples = 200;
reader_qos.resource_limits().max_instances = 1;
reader_qos.resource_limits().max_samples_per_instance = 100;
reader_qos.data_sharing().off();
weightinfook_reader_ = subscriber_->create_datareader(weightinfook_topic_, reader_qos, this, StatusMask::all());
if (weightinfook_reader_ == nullptr)
{
throw std::runtime_error("WeighingSystem::WeightInfoOk DataReader initialization failed");
}
} }
SubscriberApp::~SubscriberApp() SubscriberApp::~SubscriberApp()
@ -384,6 +415,21 @@ void SubscriberApp::on_data_available(
} }
} }
} }
else if (topic_name == "WeightInfoOk")
{
WeighingSystem::WeightInfoOk sample_;
while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&sample_, &info)))
{
if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data)
{
{
std::unique_lock<std::mutex> lock(DdsMsgData::queue_cv_mtx_);
DdsMsgData::WeightInfoOk_queue_.push(std::move(sample_));
lock.unlock();
}
}
}
}
} }
void SubscriberApp::run(std::shared_ptr<mqtt::async_client> dev) void SubscriberApp::run(std::shared_ptr<mqtt::async_client> dev)

@ -122,6 +122,7 @@ std::queue<WeighingSystem::InfraredUpdate> DdsMsgData::InfraredUpdate_queue_;
std::queue<WeighingSystem::InfraredCommandUpdate> DdsMsgData::InfraredCommandUpdate_queue_; std::queue<WeighingSystem::InfraredCommandUpdate> DdsMsgData::InfraredCommandUpdate_queue_;
std::queue<WeighingSystem::LicenseSnapUpdate> DdsMsgData::LicenseSnapUpdate_queue_; std::queue<WeighingSystem::LicenseSnapUpdate> DdsMsgData::LicenseSnapUpdate_queue_;
std::queue<WeighingSystem::ScaleInfo> DdsMsgData::ScaleInfo_queue_; std::queue<WeighingSystem::ScaleInfo> DdsMsgData::ScaleInfo_queue_;
std::queue<WeighingSystem::WeightInfoOk> DdsMsgData::WeightInfoOk_queue_;
std::mutex DdsMsgData::queue_cv_mtx_; std::mutex DdsMsgData::queue_cv_mtx_;
std::queue<mqtt::const_message_ptr> MqttMsgData::Mqtt_msg_queue_; std::queue<mqtt::const_message_ptr> MqttMsgData::Mqtt_msg_queue_;
std::mutex MqttMsgData::queue_cv_mtx_; std::mutex MqttMsgData::queue_cv_mtx_;

@ -13,6 +13,7 @@ public:
static std::queue<WeighingSystem::InfraredCommandUpdate> InfraredCommandUpdate_queue_; static std::queue<WeighingSystem::InfraredCommandUpdate> InfraredCommandUpdate_queue_;
static std::queue<WeighingSystem::LicenseSnapUpdate> LicenseSnapUpdate_queue_; static std::queue<WeighingSystem::LicenseSnapUpdate> LicenseSnapUpdate_queue_;
static std::queue<WeighingSystem::ScaleInfo> ScaleInfo_queue_; static std::queue<WeighingSystem::ScaleInfo> ScaleInfo_queue_;
static std::queue<WeighingSystem::WeightInfoOk> WeightInfoOk_queue_;
static std::mutex queue_cv_mtx_; static std::mutex queue_cv_mtx_;
}; };

Loading…
Cancel
Save