From 0000a66827439d2b6e07352b5d602e6cc48ee3e0 Mon Sep 17 00:00:00 2001 From: LQF Date: Wed, 23 Aug 2017 16:36:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=89=E8=BD=A6?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=B2=E5=8F=A3=E5=8F=8A=E9=98=88=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/AnChe.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ App/AnChe.h | 38 ++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 App/AnChe.cpp create mode 100644 App/AnChe.h diff --git a/App/AnChe.cpp b/App/AnChe.cpp new file mode 100644 index 00000000..89e9d1c6 --- /dev/null +++ b/App/AnChe.cpp @@ -0,0 +1,70 @@ +#include "Kernel\Sys.h" + +#include "Device/Pwm.h" + +#include "Config.h" + +#include "AnChe.h" + +AnCheConfig::AnCheConfig() +{ + _Name = "AnChe"; + _Start = &Anche; + _End = &TagEnd; + Init(); + + Serial1Power = true; // 串口2开关状态 + BaudRate1 = 9600; // 串口2波特率 + DataBits1 = 8; // 串口2数据位 + Parity1 = 0; // 串口2奇偶校验位 + StopBits1 = 1; // 串口2停止位 + Serial2Power = true; // 串口3开关状态 + BaudRate2 = 9600; // 串口3波特率 + DataBits2 = 8; // 串口3数据位 + Parity2 = 0; // 串口3奇偶校验位 + StopBits2 = 1; // 串口3停止位 + IsInfrare=false; // 是否红外控制 + InitWeight[0] = 80; // 初始重量变化阈值 + InitWeight[1] = 80; // 初始重量变化阈值 + StableWeight[0] = 80; // 稳定重量变化阈值 + StableWeight[1] = 80; // 稳定重量变化阈值 + +} + +static AnCheConfig* _cfg = nullptr; +static ByteArray _bak; +static uint _saveTask = 0; + +static void SaveTask(void* param) +{ + if (!_cfg) return; + + // 比较数据,如果不同则保存 + auto bs = _cfg->ToArray(); + if (_bak.Length() == 0 || bs != _bak) + { + _bak = bs; + _cfg->Save(); + } +} + +static AnCheConfig* InitConfig() +{ + static AnCheConfig cfg; + if (!_cfg) + { + _cfg = &cfg; + _cfg->Load(); + + _bak = cfg.ToArray(); + if (!_saveTask) _saveTask = Sys.AddTask(SaveTask, nullptr, 1000, 10000, "保存配置"); + } + + return _cfg; +} + +void AnChe::GetConfig() +{ + Config = InitConfig(); +} + diff --git a/App/AnChe.h b/App/AnChe.h new file mode 100644 index 00000000..86cfbe02 --- /dev/null +++ b/App/AnChe.h @@ -0,0 +1,38 @@ +#ifndef __AnChe_H_ +#define __AnChe_H_ + +#include "Kernel\Sys.h" +#include "Platform\Pin.h" +class AnCheConfig; + +class AnChe +{ +public : + AnCheConfig* Config; + void GetConfig(); +}; + +// 配置 +class AnCheConfig : public ConfigBase +{ +public: + byte Anche; + bool Serial1Power; // 串口2开关状态 + int BaudRate1; // 串口2波特率 + byte DataBits1; // 串口2数据位 + byte Parity1; // 串口2奇偶校验位 + byte StopBits1; // 串口2停止位 + bool Serial2Power; // 串口3开关状态 + int BaudRate2; // 串口3波特率 + byte DataBits2; // 串口3数据位 + byte Parity2; // 串口3奇偶校验位 + byte StopBits2; // 串口3停止位 + bool IsInfrare; // 是否红外控制 + ushort InitWeight[2]; // 初始重量变化阈值 + ushort StableWeight[2]; // 稳定重量变化阈值 + byte TagEnd; + + AnCheConfig(); +}; + +#endif From edbcc43b35a4aa693b186eb205acdee1b9375fb4 Mon Sep 17 00:00:00 2001 From: LQF Date: Sun, 27 Aug 2017 23:53:34 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=94=B1=E4=BA=8E=E5=AE=89=E8=BD=A6?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=AF=8F10ms=E9=87=87=E9=9B=86=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=95=B0=E6=8D=AE=EF=BC=8C=E6=97=B6=E9=97=B4=E6=9E=81?= =?UTF-8?q?=E7=9F=AD=EF=BC=8C=E9=87=87=E9=9B=86=E4=BB=BB=E5=8A=A1=E4=B8=8E?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E4=BB=BB=E5=8A=A1=E4=B8=8D=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=EF=BC=8C=E9=80=A0=E6=88=90=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=80=E6=A0=B7=EF=BC=8C=E7=8E=B0=E5=A2=9E=E5=8A=A0=E6=AF=8F?= =?UTF-8?q?=E6=AC=A1=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E5=9C=A8=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=97=B6=E6=89=A7=E8=A1=8C=E4=B8=80=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=87=87=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Message/HistoryStore.cpp | 8 +++++++- Message/HistoryStore.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Message/HistoryStore.cpp b/Message/HistoryStore.cpp index 2e8a08cc..e21707c7 100644 --- a/Message/HistoryStore.cpp +++ b/Message/HistoryStore.cpp @@ -102,7 +102,7 @@ void HistoryStore::RenderTask(void* param) void HistoryStore::Reader() { //ds_printf("HistoryStore::Reader %d/%d/%d \r\n", Size, Cache.Position(), Cache.Length); - + Process(OnWrite); // 生成历史数据 Buffer bs(Data, Size); Write(bs); @@ -153,6 +153,12 @@ void HistoryStore::Store() Process(len, OnStore); } +void HistoryStore::Process(EventHandler handler) +{ + if (!handler) return; + handler(this, nullptr); +} + void HistoryStore::Process(int len, DataHandler handler) { if (!len || !handler) return; diff --git a/Message/HistoryStore.h b/Message/HistoryStore.h index 79ab6b98..146fcdb8 100644 --- a/Message/HistoryStore.h +++ b/Message/HistoryStore.h @@ -21,6 +21,8 @@ public: DataHandler OnReport; // 数据存储句柄 DataHandler OnStore; + // 数据写入句柄 + EventHandler OnWrite; // 初始化 HistoryStore(); @@ -52,6 +54,7 @@ private: void Report(); void Store(); + void Process(EventHandler handler); void Process(int len, DataHandler handler); }; From 651f6512603b493f3cf1cbb7f2f859ecea5f27f4 Mon Sep 17 00:00:00 2001 From: LQF Date: Mon, 28 Aug 2017 11:52:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=9D=E5=A7=8BOnWrite=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Message/HistoryStore.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Message/HistoryStore.cpp b/Message/HistoryStore.cpp index e21707c7..0196d3fc 100644 --- a/Message/HistoryStore.cpp +++ b/Message/HistoryStore.cpp @@ -24,6 +24,7 @@ HistoryStore::HistoryStore() MaxCache = 16 * 1024; MaxReport = 1024; + OnWrite = nullptr; OnReport = nullptr; OnStore = nullptr;