diff --git a/Link/LinkClient.cpp b/Link/LinkClient.cpp
index d71a8b1b..dccebc14 100644
--- a/Link/LinkClient.cpp
+++ b/Link/LinkClient.cpp
@@ -175,6 +175,10 @@ void LinkClient::OnReceive(LinkMessage& msg)
OnLogin(msg);
else if (act == "Device/Ping")
OnPing(msg);
+ else if (act == "Read")
+ OnRead(msg);
+ else if (act == "Write")
+ OnWrite(msg);
// 外部公共消息事件
//Received(msg, *this);
@@ -217,6 +221,37 @@ bool LinkClient::Invoke(const String& action, const Json& args) {
return Send(msg);
}
+bool LinkClient::Reply(const String& action, int seq, int code, const Json& result) {
+ // 消息缓冲区,跳过头部
+ char cs[512];
+
+ // 格式化消息
+ auto& msg = *(LinkMessage*)cs;
+ msg.Init();
+ msg.Reply = true;
+ msg.Error = code != 0;
+ msg.Seq = seq;
+
+ auto js = msg.Create(sizeof(cs));
+ js.Add("action", action);
+ js.Add("code", code);
+ js.Add("result", result);
+
+ auto str = js.ToString();
+
+ // 长度
+ msg.Length = str.Length();
+ msg.Code = 1;
+
+#if DEBUG
+ debug_printf("Link => ");
+ msg.Show(true);
+#endif
+
+ // 发送
+ return Send(msg);
+}
+
// 登录
void LinkClient::Login()
{
@@ -361,3 +396,48 @@ void LinkClient::OnPing(LinkMessage& msg)
int serverTime = js["ServerSeconds"].AsInt();
if (serverTime > 1000) ((TTime&)Time).SetTime(serverTime);
}
+
+void LinkClient::OnRead(LinkMessage& msg)
+{
+ TS("LinkClient::OnRead");
+ if (msg.Reply) return;
+
+ auto js = msg.Create();
+ auto args = js["args"];
+ int start = args["start"].AsInt();
+ auto data = args["data"].AsString().ToHex();
+
+ Store.Write(start, data);
+ auto& bs = Store.Data;
+
+ // 响应
+ Json rs;
+ rs.Add("start", 0);
+ rs.Add("size", bs.Length());
+ rs.Add("data", bs.ToHex());
+
+ Reply(js["action"].AsString(), msg.Seq, 0, rs);
+}
+
+void LinkClient::OnWrite(LinkMessage& msg)
+{
+ TS("LinkClient::OnWrite");
+ if (msg.Reply) return;
+
+ auto js = msg.Create();
+ auto args = js["args"];
+ int start = args["start"].AsInt();
+ int size = args["size"].AsInt();
+
+ ByteArray bs(size);
+ int len = Store.Read(start, bs);
+ bs.SetLength(len);
+
+ // 响应
+ Json rs;
+ rs.Add("start", 0);
+ rs.Add("size", bs.Length());
+ rs.Add("data", bs.ToHex());
+
+ Reply(js["action"].AsString(), msg.Seq, 0, rs);
+}
diff --git a/Link/LinkClient.h b/Link/LinkClient.h
index 1e9253e6..9f715bc9 100644
--- a/Link/LinkClient.h
+++ b/Link/LinkClient.h
@@ -36,7 +36,7 @@ public:
// 发送消息
bool Invoke(const String& action, const Json& args);
- bool Reply(String& action, int code, String& result, int seq);
+ bool Reply(const String& action, int seq, int code, const Json& result);
// 收到功能消息时触发
//MessageHandler Received;
@@ -57,6 +57,9 @@ private:
void OnLogin(LinkMessage& msg);
void OnPing(LinkMessage& msg);
+ void OnRead(LinkMessage& msg);
+ void OnWrite(LinkMessage& msg);
+
private:
uint _task;
diff --git a/vs/SmartOS.vcxproj b/vs/SmartOS.vcxproj
index 27b7b17d..b6d97819 100644
--- a/vs/SmartOS.vcxproj
+++ b/vs/SmartOS.vcxproj
@@ -107,6 +107,7 @@
+
diff --git a/vs/SmartOS.vcxproj.filters b/vs/SmartOS.vcxproj.filters
index cf3b64df..1aceecad 100644
--- a/vs/SmartOS.vcxproj.filters
+++ b/vs/SmartOS.vcxproj.filters
@@ -590,5 +590,8 @@
Link
+
+ Link
+
\ No newline at end of file