Skip to content

Commit

Permalink
Additional fixed in 433nano
Browse files Browse the repository at this point in the history
  • Loading branch information
CurlyMoo committed Feb 11, 2020
1 parent 42a9791 commit 4b29140
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions libs/pilight/hardware/433nano.lua
Expand Up @@ -74,13 +74,14 @@ function M.send(obj, reason, data)
serial.write(code);
end

function invalid_stream(data)
pilight.log(LOG_NOTICE, "433nano: received invalid stream \'" .. data['content'] .. "'");
function invalid_stream(data, content)
pilight.log(LOG_NOTICE, "433nano: received invalid stream \'" .. content .. "'");

data['pulses'] = {};
data['length'] = 0;
data['content'] = '';
data['write'] = 2;
data['invalid'] = 1;
end

function M.callback(rw, serial, line)
Expand Down Expand Up @@ -111,8 +112,14 @@ function M.callback(rw, serial, line)
data['content'] = "";
end

if data['invalid'] == nil then
data['invalid'] = 0;
end

if line ~= '\n' then
data['content'] = data['content'] .. line;
else
data['content'] = "";
end

local a = #data['content'];
Expand All @@ -126,14 +133,15 @@ function M.callback(rw, serial, line)
end
end

if l == a then
local c = string.sub(data['content'], l, l);

if l == a and c ~= '@' then
break;
end

local c = string.sub(data['content'], l, l);
if c == '@' then
content = string.sub(data['content'], 1, l)

print('--', content);
data['content'] = string.sub(data['content'], l+1, a);
a = #data['content'];

Expand All @@ -150,10 +158,6 @@ function M.callback(rw, serial, line)
i = x + 2;
break;
end
if type(tonumber(c)) ~= 'number' then
invalid_stream(data);
return;
end
stream[#stream+1] = c;
end
else
Expand All @@ -166,25 +170,20 @@ function M.callback(rw, serial, line)
i = i + 1;
for x = i, l, 1 do
c = string.sub(content, x+1, x+1);

if c == ';' then
i = x + 2;
break;
end

if c == ',' or c == '@' then
c = string.sub(content, i+1, x);

i = x + 1;
if c == '@' or c == ';' then
pulses[#pulses+1] = tonumber(c);
print(content);
if #pulses > 9 then
invalid_stream(data, content);
serial.read();
return;
end
if c == '@' then
i = x + 1;
break;
end
if type(tonumber(c)) ~= 'number' then
invalid_stream(data);
return;
end
pulses[#pulses+1] = tonumber(c);
end
end
else
Expand All @@ -208,12 +207,16 @@ function M.callback(rw, serial, line)
if #stream > 0 then
local b = 1;
for i = 1, #stream, 1 do
if tonumber(stream[i]) ~= nil then
data['pulses'][b] = pulses[1];
b = b + 1;
data['pulses'][b] = pulses[stream[i] + 1];
b = b + 1;
end
end

data['invalid'] = 0;

data['length'] = b-1;
local tmp = data['content'];
data['content'] = nil;
Expand All @@ -224,7 +227,6 @@ function M.callback(rw, serial, line)
event.trigger(getmetatable(data)());

data['pulses'] = {};
data['length'] = 0;
data['content'] = tmp;
data['write'] = 2;
end
Expand Down Expand Up @@ -319,4 +321,4 @@ function M.info()
}
end

return M;
return M;

0 comments on commit 4b29140

Please sign in to comment.