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 diff --git a/Message/HistoryStore.cpp b/Message/HistoryStore.cpp index 2e8a08cc..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; @@ -102,7 +103,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 +154,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); };