-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice_messages.lua
executable file
·105 lines (83 loc) · 3.5 KB
/
device_messages.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--[[=============================================================================
Get, Handle and Dispatch message functions
Copyright 2015 Control4 Corporation. All Rights Reserved.
===============================================================================]]
-- This macro is utilized to identify the version string of the driver template version used.
if (TEMPLATE_VERSION ~= nil) then
TEMPLATE_VERSION.device_messages = "2015.11.30"
end
--[[=============================================================================
GetMessage()
Description:
Used to retrieve a message from the communication buffer. Each driver is
responsible for parsing that communication from the buffer.
Parameters:
None
Returns:
A single message from the communication buffer
===============================================================================]]
function GetMessage()
local message = ""
if ((gReceiveBuffer ~= nil) and (gReceiveBuffer ~= "")) then
--TODO: Implement a routine which will parse out a single message
-- from the receive buffer(gReceiveBuffer)
message = ""
end
--TODO: Once a complete message is found in the buffer remove it and
-- return the message
gReceiveBuffer = ""
return message
end
--[[=============================================================================
HandleMessage(message)]
Description
This is where we parse the messages returned from the GetMessage()
function into a command and data. The call to 'DispatchMessage' will use the
'name' variable as a key to determine which handler routine, function, should
be called in the DEV_MSG table. The 'value' variable will then be passed as
a string parameter to that routine.
Parameters
message - Message string containing the function and value to be sent to DispatchMessage
Returns
Nothing
===============================================================================]]
function HandleMessage(message)
LogTrace("HandleMessage. Message is ==>%s<==", message)
-- TODO: Parse messages and DispatchMessage
DispatchMessage(name, value)
end
--[[=============================================================================
DispatchMessage(MsgKey, MsgData)
Description
Parse routine that will call the routines to handle the information returned
by the connected system.
Parameters
MsgKey(string) - The function to be called from within DispatchMessage
MsgData(string) - The parameters to be passed to the function found in MsgKey
Returns
Nothing
===============================================================================]]
function DispatchMessage(MsgKey, MsgData)
if (DEV_MSG[MsgKey] ~= nil and (type(DEV_MSG[MsgKey]) == "function")) then
LogInfo("DEV_MSG.%s: %s", MsgKey, MsgData)
local status, err = pcall(DEV_MSG[MsgKey], MsgData)
if (not status) then
LogError("LUA_ERROR: %s", err)
end
else
LogTrace("HandleMessage: Unhandled command = %s, data = %s", MsgKey, MsgData)
end
end
function DEV_MSG.Moving(value)
LogTrace("DEV_MSG.Moving(), value = " .. value)
local level_target = value
local ramp_rate = 1
--get the current level stored in the proxy class
local level = gBlindProxy:GetLevel()
gBlindProxy:dev_Moving(level,level_target,ramp_rate)
end
function DEV_MSG.Stopped(value)
LogTrace("DEV_MSG.Stopped(), value = " .. value)
local level = value
gBlindProxy:dev_Stopped(level)
end