Skip to content

Read lua buffer until empty #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/SCRIPTS/BF/MSP/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,24 @@ function mspReceivedReply(payload)
end
if idx > protocol.maxRxBufferSize then
mspRemoteSeq = seq
return true
return false
end
mspStarted = false
-- check CRC
if mspRxCRC ~= payload[idx] and version == 0 then
return nil
end
return mspRxBuf
return true
end

function mspPollReply()
while true do
local ret = protocol.mspPoll()
if type(ret) == "table" then
local mspData = protocol.mspPoll()
if mspData == nil then
return nil
elseif mspReceivedReply(mspData) then
mspLastReq = 0
return mspRxReq, ret
else
break
end
return mspRxReq, mspRxBuf
end
end
return nil
end
17 changes: 9 additions & 8 deletions src/SCRIPTS/BF/MSP/crsf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local CRSF_FRAMETYPE_MSP_REQ = 0x7A -- response request using msp
local CRSF_FRAMETYPE_MSP_RESP = 0x7B -- reply with 60 byte chunked binary
local CRSF_FRAMETYPE_MSP_WRITE = 0x7C -- write with 60 byte chunked binary

crsfMspCmd = 0
local crsfMspCmd = 0

protocol.mspSend = function(payload)
local payloadOut = { CRSF_ADDRESS_BETAFLIGHT, CRSF_ADDRESS_RADIO_TRANSMITTER }
Expand All @@ -27,15 +27,16 @@ protocol.mspWrite = function(cmd, payload)
end

protocol.mspPoll = function()
local command, data = crossfireTelemetryPop()
if command == CRSF_FRAMETYPE_MSP_RESP then
if data[1] == CRSF_ADDRESS_RADIO_TRANSMITTER and data[2] == CRSF_ADDRESS_BETAFLIGHT then
while true do
local cmd, data = crossfireTelemetryPop()
if cmd == CRSF_FRAMETYPE_MSP_RESP and data[1] == CRSF_ADDRESS_RADIO_TRANSMITTER and data[2] == CRSF_ADDRESS_BETAFLIGHT then
local mspData = {}
for i=3, #(data) do
mspData[i-2] = data[i]
for i = 3, #data do
mspData[i - 2] = data[i]
end
return mspReceivedReply(mspData)
return mspData
elseif cmd == nil then
return nil
end
end
return nil
end
11 changes: 7 additions & 4 deletions src/SCRIPTS/BF/MSP/ghst.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ protocol.mspWrite = function(cmd, payload)
end

protocol.mspPoll = function()
local type, data = ghostTelemetryPop()
if type == GHST_FRAMETYPE_MSP_RESP then
return mspReceivedReply(data)
while true do
local type, data = ghostTelemetryPop()
if type == GHST_FRAMETYPE_MSP_RESP then
return data
elseif type == nil then
return nil
end
end
return nil
end
33 changes: 18 additions & 15 deletions src/SCRIPTS/BF/MSP/sp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ local function smartPortTelemetryPop()
end

protocol.mspPoll = function()
local sensorId, frameId, dataId, value = smartPortTelemetryPop()
if (sensorId == SMARTPORT_REMOTE_SENSOR_ID or sensorId == FPORT_REMOTE_SENSOR_ID) and frameId == REPLY_FRAME_ID then
local payload = {}
payload[1] = bit32.band(dataId,0xFF)
dataId = bit32.rshift(dataId,8)
payload[2] = bit32.band(dataId,0xFF)
payload[3] = bit32.band(value,0xFF)
value = bit32.rshift(value,8)
payload[4] = bit32.band(value,0xFF)
value = bit32.rshift(value,8)
payload[5] = bit32.band(value,0xFF)
value = bit32.rshift(value,8)
payload[6] = bit32.band(value,0xFF)
return mspReceivedReply(payload)
while true do
local sensorId, frameId, dataId, value = smartPortTelemetryPop()
if (sensorId == SMARTPORT_REMOTE_SENSOR_ID or sensorId == FPORT_REMOTE_SENSOR_ID) and frameId == REPLY_FRAME_ID then
local payload = {}
payload[1] = bit32.band(dataId, 0xFF)
dataId = bit32.rshift(dataId, 8)
payload[2] = bit32.band(dataId, 0xFF)
payload[3] = bit32.band(value, 0xFF)
value = bit32.rshift(value, 8)
payload[4] = bit32.band(value, 0xFF)
value = bit32.rshift(value, 8)
payload[5] = bit32.band(value, 0xFF)
value = bit32.rshift(value, 8)
payload[6] = bit32.band(value, 0xFF)
return payload
elseif sensorId == nil then
return nil
end
end
return nil
end