From 968e25c863ef798e117838f8886b28bc1282d3f3 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Sat, 15 Jan 2011 19:56:40 +0100 Subject: [PATCH] [fluksod] spi half-duplex logic is now handled in the kernel driver --- mote/v2/openwrt/package/flukso/luasrc/flukso/spi.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mote/v2/openwrt/package/flukso/luasrc/flukso/spi.lua b/mote/v2/openwrt/package/flukso/luasrc/flukso/spi.lua index 728b5f4..630c32a 100644 --- a/mote/v2/openwrt/package/flukso/luasrc/flukso/spi.lua +++ b/mote/v2/openwrt/package/flukso/luasrc/flukso/spi.lua @@ -30,6 +30,8 @@ local getfenv, setmetatable = module (...) local modenv = getfenv() +local SPI_MAX_READ_BYTES = 256 + --- Create a new spi message object. -- -- Attributes: @@ -103,16 +105,18 @@ end function tx(msg, cdev) if msg.to == 'ctrl' or msg.to == 'delta' then - cdev:write('l' .. msg.encoded .. '.\0\0') + cdev:write('l' .. msg.encoded .. '.') elseif msg.to == 'uart' then - cdev:write('u' .. msg.encoded .. '\0\0') + cdev:write('u' .. msg.encoded) end end function rx(msg, cdev) msg.received = {} - msg.received.raw = cdev:spiread() + msg.received.raw = cdev:read(SPI_MAX_READ_BYTES) msg.received.l, msg.received.u = msg.received.raw:match('^l(%w*)%.?u(%w*)%.?$') + -- protect against nil values when match should fail + msg.received.l, msg.received.u = msg.received.l or '', msg.received.u or '' if msg.received.l ~= '' and msg.received.l:sub(1, 2) == msg.parsed[1] then msg.received.crc = msg.received.l:sub(-2, -1)