helvar
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
helvar [2023/05/21 17:37] – emozolyak | helvar [2023/09/22 14:33] (current) – emozolyak | ||
---|---|---|---|
Line 19: | Line 19: | ||
*Lua script monitors scenes ids written and converts them to the strings according to the HelvarNet protocol and application logic | *Lua script monitors scenes ids written and converts them to the strings according to the HelvarNet protocol and application logic | ||
- | <WRAP center round important | + | <WRAP center round important |
- | Please be informed this protocol relays your HelvarNet string to the TCP address: | + | Please be informed this protocol relays your HelvarNet string to the TCP address: |
</ | </ | ||
Line 39: | Line 39: | ||
PARTIAL_ETX = ' | PARTIAL_ETX = ' | ||
FULL_ETX | FULL_ETX | ||
+ | |||
function onScanStart () | function onScanStart () | ||
now = os.time() | now = os.time() | ||
Line 47: | 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 = buf |
- | | + | |
- | end | + | |
- | readBuffer = table.concat(readBuffer) | + | |
- | end | + | |
- | + | return true | |
- | return true | + | |
end | end | ||
+ | |||
-------------------------- Helpers -------------------------- | -------------------------- Helpers -------------------------- | ||
+ | |||
function sendString_(s) -- new sendString version | function sendString_(s) -- new sendString version | ||
+ | |||
local sendBuf = {} | local sendBuf = {} | ||
Line 94: | 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.1684690661.txt.gz · Last modified: 2023/05/21 17:37 by emozolyak