diff --git a/Drivers/HMI.cpp b/Drivers/HMI.cpp new file mode 100644 index 00000000..f6905ea0 --- /dev/null +++ b/Drivers/HMI.cpp @@ -0,0 +1,72 @@ +#include "HMI.h" +#include "Device\SerialPort.h" +#include "Kernel\Sys.h" + +#define NET_DEBUG DEBUG +//#define NET_DEBUG 0 +#if NET_DEBUG +#define net_printf debug_printf +#else +#define net_printf(format, ...) +#endif + +/******************************** HMI ********************************/ +HMI::HMI() +{ + Port = nullptr; +} + +HMI::~HMI() +{ + delete Port; +} + +// 初始化HMI串口 +void HMI::Init(COM idx, int baudrate) +{ + auto srp = new SerialPort(idx, baudrate); + srp->Tx.SetCapacity(0x200); + srp->Rx.SetCapacity(0x200); + srp->MaxSize = 512; + + Init(srp); +} + +// 注册HMI串口的数据到达 +void HMI::Init(ITransport* port) +{ + Port = port; + if (Port) Port->Register(OnPortReceive, this); +} + +// 数据到达 +uint HMI::OnPortReceive(ITransport* sender, Buffer& bs, void* param, void* param2) +{ + auto esp = (HMI*)param; + return esp->OnReceive(bs, param2); +} + +// 解析收到的数据 +uint HMI::OnReceive(Buffer& bs, void* param) +{ + if (bs.Length() == 0) return 0; + debug_printf("HMI::收到:"); + bs.AsString().Show(true); + return 0; +} + +// 向HMI发送数据指令 +void HMI::Send(const String& cmd) +{ + Port->Write(cmd); + SenDFlag(); +} + +// 向HMI发送指令结束符 +void HMI::SenDFlag() +{ + byte by[3] = { 0xFF,0xFF,0xFF }; + Buffer bs(by, 3); + Port->Write(bs); +} + diff --git a/Drivers/HMI.h b/Drivers/HMI.h new file mode 100644 index 00000000..e8181154 --- /dev/null +++ b/Drivers/HMI.h @@ -0,0 +1,29 @@ +#ifndef __HMI_H__ +#define __HMI_H__ + +#include "Device\SerialPort.h" + +class HMI +{ +public: + ITransport* Port; // 传输口 + + HMI(); + ~HMI(); + + // 初始化串口屏的串口 + void Init(COM idx, int baudrate = 115200); + // 初始传输口 + void Init(ITransport* port); + + // 引发数据到达事件 + uint OnReceive(Buffer& bs, void* param); + static uint OnPortReceive(ITransport* sender, Buffer& bs, void* param, void* param2); + + // 发送指令到串口屏 + void Send(const String& cmd); + // 发送结束标志 + void SenDFlag(); +}; + +#endif diff --git a/Message/HistoryStore.cpp b/Message/HistoryStore.cpp index 0196d3fc..c208cf3c 100644 --- a/Message/HistoryStore.cpp +++ b/Message/HistoryStore.cpp @@ -2,6 +2,8 @@ #include "Device\Flash.h" +#include "Kernel\Task.h" + #include "HistoryStore.h" #define DS_DEBUG DEBUG @@ -61,6 +63,8 @@ bool HistoryStore::Open(bool UseThousand) p = RenderPeriod; } _task = Sys.AddTask(RenderTask, this, p, p, "鍘嗗彶鏁版嵁"); + auto task = Task::Get(_task); + task->MaxDeepth = 4; return Opened = true; }