helvar
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
helvar [2023/05/19 13:14] – created emozolyak | helvar [2023/09/22 14:32] – emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Helvar light control | + | ====== Helvar light control |
+ | |||
+ | Please refer to the [[https:// | ||
+ | This protocol is using ASCII messaging. According to the documentation the routers in the lighting system support either ASCII or RAW format. | ||
+ | |||
+ | <WRAP center round box 80%> | ||
+ | **Message Format** | ||
+ | Any message sent to, or received from, a router can be in either ASCII or raw binary form (see | ||
+ | Command Format for more information). | ||
+ | Messages must not exceed the maximum length of 1500 bytes. | ||
+ | The format of the data contained within messages is defined by the protocol. | ||
+ | A query reply message from the router will be in the same format as the query command message | ||
+ | sent i.e. if a query message is sent in ASCII form then the reply will also be in ASCII. | ||
+ | </ | ||
+ | |||
+ | The usage of this protocol is as follows: | ||
+ | |||
+ | *Your application logic, e.g. recipe selection boxes on the dashboards chooses scenario id and writes it to the register | ||
+ | *Lua script monitors scenes ids written and converts them to the strings according to the HelvarNet protocol and application logic | ||
+ | |||
+ | <WRAP center round important 80%> | ||
+ | Please be informed this protocol relays your HelvarNet string to the TCP address: | ||
+ | </ | ||
+ | |||
+ | |||
+ | <WRAP center round box 80%> | ||
+ | For example, in the command Recall Group 1234, Block 5, Scene 6, Fade Time 32 s, the string is | ||
+ | sent as follows, including the delimiters and the start character '>' | ||
+ | "> | ||
+ | </ | ||
+ | |||
+ | *So the string like "> | ||
+ | *Once the string is written to the CMD0 register, it is sent to the remote device to the TCP port assigned in the connection settings. | ||
+ | *The response (which can be multipart) is stored in the same register | ||
<code lua> | <code lua> | ||
Line 5: | Line 39: | ||
PARTIAL_ETX = ' | PARTIAL_ETX = ' | ||
FULL_ETX | FULL_ETX | ||
+ | |||
function onScanStart () | function onScanStart () | ||
now = os.time() | now = os.time() | ||
Line 13: | Line 47: | ||
| | ||
end | end | ||
+ | |||
function readRegister (reg, device, unitId) | function readRegister (reg, device, unitId) | ||
- | |||
if (not readBuffer) then | if (not readBuffer) then | ||
readBuffer = 'no data' | readBuffer = 'no data' | ||
end | end | ||
- | | + | return readBuffer |
- | | + | |
end | end | ||
+ | |||
function writeRegister (reg, device, unitId, newValue) | function writeRegister (reg, device, unitId, newValue) | ||
- | | + | |
- | sendString_(newValue) -- expects string to be written externally | + | |
- | + | ||
local buf = {} | local buf = {} | ||
+ | local tryCount = 0 | ||
| | ||
+ | | ||
+ | |||
local currentFrame = readUntil(PARTIAL_ETX, | local currentFrame = readUntil(PARTIAL_ETX, | ||
- | local lastChar | ||
if currentFrame then | if currentFrame then | ||
| | ||
| | ||
| | ||
- | + | | |
- | until (not lastChar or (lastChar == FULL_ETX)) | + | |
- | if (#buf > 0) then | + | |
- | readBuffer = table.concat(buf) | + | readBuffer = buf |
- | | + | |
- | + | | |
- | | + | |
+ | | ||
+ | | ||
end | end | ||
+ | |||
-------------------------- Helpers -------------------------- | -------------------------- Helpers -------------------------- | ||
+ | |||
function sendString_(s) -- new sendString version | function sendString_(s) -- new sendString version | ||
+ | |||
local sendBuf = {} | local sendBuf = {} | ||
Line 57: | Line 92: | ||
sendBytes(sendBuf) | sendBytes(sendBuf) | ||
end | end | ||
+ | |||
function readUntil(endByte1, | function readUntil(endByte1, | ||
+ | DEBUG(" | ||
+ | | ||
local ONE_BYTE = 1 | local ONE_BYTE = 1 | ||
- | local buf = {} | + | local buf, rb = {}, nil |
+ | | ||
repeat | repeat | ||
- | | + | rb = readBytes(ONE_BYTE) |
if rb then | if rb then | ||
- | rb = rb[ONE_BYTE] | + | rb = rb[ONE_BYTE] |
table.insert(buf, | table.insert(buf, | ||
end | end | ||
until (not rb or (rb == endByte1 or rb == endByte2)) | until (not rb or (rb == endByte1 or rb == endByte2)) | ||
- | + | | |
- | | + | |
+ | DEBUG(' | ||
+ | |||
+ | if (#buf > 0) and (buf[#buf == endByte1] | ||
+ | DEBUG(' | ||
+ | else | ||
+ | DEBUG(' | ||
+ | end | ||
end | end | ||
</ | </ | ||
helvar.txt · Last modified: 2023/09/22 14:33 by emozolyak