Merge branch 'master' of http://git.wslink.cn/Embed/SmartOS
This commit is contained in:
commit
32e48cb5e4
|
@ -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();
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
|
@ -24,6 +24,7 @@ HistoryStore::HistoryStore()
|
||||||
MaxCache = 16 * 1024;
|
MaxCache = 16 * 1024;
|
||||||
MaxReport = 1024;
|
MaxReport = 1024;
|
||||||
|
|
||||||
|
OnWrite = nullptr;
|
||||||
OnReport = nullptr;
|
OnReport = nullptr;
|
||||||
OnStore = nullptr;
|
OnStore = nullptr;
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ void HistoryStore::RenderTask(void* param)
|
||||||
void HistoryStore::Reader()
|
void HistoryStore::Reader()
|
||||||
{
|
{
|
||||||
//ds_printf("HistoryStore::Reader %d/%d/%d \r\n", Size, Cache.Position(), Cache.Length);
|
//ds_printf("HistoryStore::Reader %d/%d/%d \r\n", Size, Cache.Position(), Cache.Length);
|
||||||
|
Process(OnWrite);
|
||||||
// 生成历史数据
|
// 生成历史数据
|
||||||
Buffer bs(Data, Size);
|
Buffer bs(Data, Size);
|
||||||
Write(bs);
|
Write(bs);
|
||||||
|
@ -153,6 +154,12 @@ void HistoryStore::Store()
|
||||||
Process(len, OnStore);
|
Process(len, OnStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HistoryStore::Process(EventHandler handler)
|
||||||
|
{
|
||||||
|
if (!handler) return;
|
||||||
|
handler(this, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
void HistoryStore::Process(int len, DataHandler handler)
|
void HistoryStore::Process(int len, DataHandler handler)
|
||||||
{
|
{
|
||||||
if (!len || !handler) return;
|
if (!len || !handler) return;
|
||||||
|
|
|
@ -21,6 +21,8 @@ public:
|
||||||
DataHandler OnReport;
|
DataHandler OnReport;
|
||||||
// 数据存储句柄
|
// 数据存储句柄
|
||||||
DataHandler OnStore;
|
DataHandler OnStore;
|
||||||
|
// 数据写入句柄
|
||||||
|
EventHandler OnWrite;
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
HistoryStore();
|
HistoryStore();
|
||||||
|
@ -52,6 +54,7 @@ private:
|
||||||
void Report();
|
void Report();
|
||||||
void Store();
|
void Store();
|
||||||
|
|
||||||
|
void Process(EventHandler handler);
|
||||||
void Process(int len, DataHandler handler);
|
void Process(int len, DataHandler handler);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue