From ab76e442ab4fb4d41ccbc211f9ac05e19aaefd4b Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 29 Apr 2024 19:36:48 +0200 Subject: connection, counter, messages and device scan --- messages.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 messages.lua (limited to 'messages.lua') diff --git a/messages.lua b/messages.lua new file mode 100644 index 0000000..69576e1 --- /dev/null +++ b/messages.lua @@ -0,0 +1,46 @@ +local json = require("json") + +Messages = { + -- Handshake + RequestServerInfo = { + RequestServerInfo = { + Id = 1, + ClientName = "Funsaac v0.0.2", + MessageVersion = 3 + } + }, + + -- Enumeration + + StartScanning = { + StartScanning = { + Id = 1 + } + } +} + +local cnt = 1; + +function GetMessage(msg) + local message = msg + message[next(msg)]["Id"] = cnt + cnt = cnt + 1 + return "[" .. json.encode(message) .. "]" +end + +function ResponseContent(message) + local msg = json.decode(message)[1] + local type = next(msg) + return type, msg[type] +end + +function HandleResponse(type, content) + if type == "ServerInfo" then + print("Connected to Server: " .. content["ServerName"]) + CONNECTED = true + elseif type == "Ok" then + print("Id: " .. content["Id"]) + elseif type == "DeviceAdded" then + print("DeviceAdded: " .. content["DeviceName"]) + end +end \ No newline at end of file -- cgit v1.2.3