You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.1 KiB
Plaintext

diff --git a/core/Publisher.cxx b/core/Publisher.cxx
index 6aba885..acf2b7c 100644
--- a/core/Publisher.cxx
+++ b/core/Publisher.cxx
@@ -333,12 +333,19 @@ bool PublisherApp::print_receipt(const std::map<std::string, std::string>& msg)
return true;
}
+#define WEIGH_IDLE 0
+#define WEIGH_LIC 1
+#define WEIGH_STABLE 2
+#define WEIGH_PRINT 3
+#define WEIGH_ERROR 4
+#define WEIGH_LEAVE 5
+
void PublisherApp::run()
{
- uint8_t send_sum = 0;
- uint8_t is_print = 0;
std::string license_no = "";
float stable_weight = 0;
+ int weigh_state = WEIGH_IDLE;
+ uint16_t weigh_timer = 0;
while (!is_stopped())
{
@@ -357,6 +364,7 @@ void PublisherApp::run()
if (license_no == "")
{
license_no = info.License();
+ weigh_state = WEIGH_LIC;
}
}
else if (!DdsMsgData::ScaleInfo_queue_.empty())
@@ -378,19 +386,18 @@ void PublisherApp::run()
else
{
stable_weight = 0;
- send_sum = 0;
}
if (info.HasVehicle() == 0)
{
license_no = "";
- if (is_print == 1)
+ if (weigh_state == WEIGH_LEAVE)
{
std::this_thread::sleep_for(std::chrono::seconds(5));
std::map<std::string, std::string> ctrl;
ctrl["FrontBar"] = "down";
bar_ctrl(ctrl);
- is_print = 0;
+ weigh_state = WEIGH_IDLE;
}
}
}
@@ -464,7 +471,7 @@ void PublisherApp::run()
print_receipt(print_msg);
- is_print = 1;
+ weigh_state = WEIGH_LEAVE;
std::map<std::string, std::string> ctrl;
ctrl["FrontBar"] = "up";
bar_ctrl(ctrl);
@@ -477,7 +484,7 @@ void PublisherApp::run()
dds_lock.unlock();
std::this_thread::sleep_for(std::chrono::seconds(3));
- send_sum = 0;
+ weigh_state = WEIGH_ERROR;
}
else
{
@@ -486,17 +493,43 @@ void PublisherApp::run()
}
// logic
- if (send_sum == 0)
+ switch (weigh_state)
{
- if ((stable_weight != 0) && (license_no != ""))
- {
- DEBUG("send summary");
- WeighingSystem::SummaryUpdate info;
- info.License() = license_no;
- info.StableValue() = stable_weight;
- summary_writer_->write(&info);
- send_sum = 1;
- }
+ case WEIGH_IDLE:
+ weigh_timer = 0;
+ break;
+ case WEIGH_LIC:
+ if (weigh_timer++ > 600)
+ {
+ DEBUG("timer reach");
+ DEBUG("license_no " << license_no);
+ DEBUG("stable_weight " << stable_weight);
+ weigh_state = WEIGH_STABLE;
+ weigh_timer = 0;
+ }
+ break;
+ case WEIGH_STABLE:
+ if ((stable_weight != 0) && (license_no != ""))
+ {
+ DEBUG("send summary");
+ WeighingSystem::SummaryUpdate info;
+ info.License() = license_no;
+ info.StableValue() = stable_weight;
+ summary_writer_->write(&info);
+ weigh_state = WEIGH_PRINT;
+ }
+ break;
+ case WEIGH_PRINT:
+ break;
+ case WEIGH_ERROR:
+ std::this_thread::sleep_for(std::chrono::seconds(3));
+ weigh_state = WEIGH_STABLE;
+ break;
+ case WEIGH_LEAVE:
+ break;
+ default:
+ weigh_state = WEIGH_IDLE;
+ break;
}
// Wait for period or stop event