Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Reciver by CFG
- local reciveSide = "back"
- local clockSide = "left"
- local listen = false
- local parityBit = 0
- local counter = 0
- local Byte = ""
- local bin2hex = {
- ["0000"] = "0",
- ["0001"] = "1",
- ["0010"] = "2",
- ["0011"] = "3",
- ["0100"] = "4",
- ["0101"] = "5",
- ["0110"] = "6",
- ["0111"] = "7",
- ["1000"] = "8",
- ["1001"] = "9",
- ["1010"] = "A",
- ["1011"] = "B",
- ["1100"] = "C",
- ["1101"] = "D",
- ["1110"] = "E",
- ["1111"] = "F"
- }
- function Bin2Hex(s)
- local l = 0
- local h = ""
- local b = ""
- local rem
- l = string.len(s)
- rem = l % 4
- l = l-1
- h = ""
- -- need to prepend zeros to eliminate mod 4
- if (rem > 0) then
- s = string.rep("0", 4 - rem)..s
- end
- for i = 1, l, 4 do
- b = string.sub(s, i, i+3)
- h = h..bin2hex[b]
- end
- return h
- end
- function fromhex(str)
- return (str:gsub('..', function (cc)
- return string.char(tonumber(cc, 16))
- end))
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Calafrica Group -- Calaofeng FrSky XM+ 1CH SBUS 2021 Full Range\n\n")
- print("Waiting for start of text")
- while true do
- if rs.getInput(clockSide) and rs.getInput(reciveSide) then
- listen = true
- print("Listening:\n")
- os.sleep(0.2)
- while listen do
- os.sleep(0.2)
- if rs.getInput(clockSide) and rs.getInput(reciveSide) ~= true then
- os.sleep(0.2)
- if rs.getInput(reciveSide) and parityBit % 2 == 0 then
- print("String validated")
- elseif not rs.getInput(reciveSide) and parityBit % 2 ~= 0 then
- print("String validated")
- else
- print("Stringa not validated")
- end
- os.sleep(0.2)
- listen = false
- else
- if rs.getInput(reciveSide) then
- byte = byte .. "1"
- parityBit = parityBit + 1
- else
- byte = byte .. "0"
- end
- counter = counter + 1
- end
- end
- hexText = Bin2Hex(byte)
- print("Recived text: "..fromhex(hexText))
- end
- parityBit = 0
- counter = 0
- byte = ""
- os.sleep(0.1)
- end
Add Comment
Please, Sign In to add comment