Skip to content

Commit 8809aa3

Browse files
committed
Read lua input buffer until empty
1 parent 9992b5d commit 8809aa3

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

src/SCRIPTS/BF/MSP/common.lua

+8-9
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,24 @@ function mspReceivedReply(payload)
100100
end
101101
if idx > protocol.maxRxBufferSize then
102102
mspRemoteSeq = seq
103-
return true
103+
return false
104104
end
105105
mspStarted = false
106106
-- check CRC
107107
if mspRxCRC ~= payload[idx] and version == 0 then
108108
return nil
109109
end
110-
return mspRxBuf
110+
return true
111111
end
112112

113113
function mspPollReply()
114114
while true do
115-
local ret = protocol.mspPoll()
116-
if type(ret) == "table" then
115+
local mspData = protocol.mspPoll()
116+
if mspData == nil then
117+
return nil
118+
elseif mspReceivedReply(mspData) then
117119
mspLastReq = 0
118-
return mspRxReq, ret
119-
else
120-
break
121-
end
120+
return mspRxReq, mspRxBuf
121+
end
122122
end
123-
return nil
124123
end

src/SCRIPTS/BF/MSP/crsf.lua

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local CRSF_FRAMETYPE_MSP_REQ = 0x7A -- response request using msp
66
local CRSF_FRAMETYPE_MSP_RESP = 0x7B -- reply with 60 byte chunked binary
77
local CRSF_FRAMETYPE_MSP_WRITE = 0x7C -- write with 60 byte chunked binary
88

9-
crsfMspCmd = 0
9+
local crsfMspCmd = 0
1010

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

2929
protocol.mspPoll = function()
30-
local command, data = crossfireTelemetryPop()
31-
if command == CRSF_FRAMETYPE_MSP_RESP then
32-
if data[1] == CRSF_ADDRESS_RADIO_TRANSMITTER and data[2] == CRSF_ADDRESS_BETAFLIGHT then
30+
while true do
31+
local cmd, data = crossfireTelemetryPop()
32+
if cmd == CRSF_FRAMETYPE_MSP_RESP and data[1] == CRSF_ADDRESS_RADIO_TRANSMITTER and data[2] == CRSF_ADDRESS_BETAFLIGHT then
3333
local mspData = {}
34-
for i=3, #(data) do
35-
mspData[i-2] = data[i]
34+
for i = 3, #data do
35+
mspData[i - 2] = data[i]
3636
end
37-
return mspReceivedReply(mspData)
37+
return mspData
38+
elseif cmd == nil then
39+
return nil
3840
end
3941
end
40-
return nil
4142
end

src/SCRIPTS/BF/MSP/ghst.lua

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ protocol.mspWrite = function(cmd, payload)
2020
end
2121

2222
protocol.mspPoll = function()
23-
local type, data = ghostTelemetryPop()
24-
if type == GHST_FRAMETYPE_MSP_RESP then
25-
return mspReceivedReply(data)
23+
while true do
24+
local type, data = ghostTelemetryPop()
25+
if type == GHST_FRAMETYPE_MSP_RESP then
26+
return data
27+
elseif type == nil then
28+
return nil
29+
end
2630
end
27-
return nil
2831
end

src/SCRIPTS/BF/MSP/sp.lua

+18-15
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,23 @@ local function smartPortTelemetryPop()
4242
end
4343

4444
protocol.mspPoll = function()
45-
local sensorId, frameId, dataId, value = smartPortTelemetryPop()
46-
if (sensorId == SMARTPORT_REMOTE_SENSOR_ID or sensorId == FPORT_REMOTE_SENSOR_ID) and frameId == REPLY_FRAME_ID then
47-
local payload = {}
48-
payload[1] = bit32.band(dataId,0xFF)
49-
dataId = bit32.rshift(dataId,8)
50-
payload[2] = bit32.band(dataId,0xFF)
51-
payload[3] = bit32.band(value,0xFF)
52-
value = bit32.rshift(value,8)
53-
payload[4] = bit32.band(value,0xFF)
54-
value = bit32.rshift(value,8)
55-
payload[5] = bit32.band(value,0xFF)
56-
value = bit32.rshift(value,8)
57-
payload[6] = bit32.band(value,0xFF)
58-
return mspReceivedReply(payload)
45+
while true do
46+
local sensorId, frameId, dataId, value = smartPortTelemetryPop()
47+
if (sensorId == SMARTPORT_REMOTE_SENSOR_ID or sensorId == FPORT_REMOTE_SENSOR_ID) and frameId == REPLY_FRAME_ID then
48+
local payload = {}
49+
payload[1] = bit32.band(dataId, 0xFF)
50+
dataId = bit32.rshift(dataId, 8)
51+
payload[2] = bit32.band(dataId, 0xFF)
52+
payload[3] = bit32.band(value, 0xFF)
53+
value = bit32.rshift(value, 8)
54+
payload[4] = bit32.band(value, 0xFF)
55+
value = bit32.rshift(value, 8)
56+
payload[5] = bit32.band(value, 0xFF)
57+
value = bit32.rshift(value, 8)
58+
payload[6] = bit32.band(value, 0xFF)
59+
return payload
60+
elseif sensorId == nil then
61+
return nil
62+
end
5963
end
60-
return nil
6164
end

0 commit comments

Comments
 (0)