Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Sender by CFG
- local sendSide = "back"
- local clockSide = "right"
- local parityBit = 0
- local counter = 0
- local filename = "text"
- local maxw, maxh = term.getSize()
- local function splitByChunk(text, chunkSize)
- local s = {}
- for i=1, #text, chunkSize do
- s[#s+1] = text:sub(i,i+chunkSize - 1)
- end
- return s
- end
- function string.tohex(str)
- return (str:gsub('.', function (c)
- return string.format('%02X', string.byte(c))
- end))
- end
- function hex2bin(str)
- local map = {
- ["0"]="0000",
- ["1"]="0001",
- ["2"]="0010",
- ["3"]="0011",
- ["4"]="0100",
- ["5"]="0101",
- ["6"]="0110",
- ["7"]="0111",
- ["8"]="1000",
- ["9"]="1001",
- ["a"]="1010",
- ["b"]="1011",
- ["c"]="1100",
- ["d"]="1101",
- ["e"]="1110",
- ["f"]="1111",
- ["A"]="1010",
- ["B"]="1011",
- ["C"]="1100",
- ["D"]="1101",
- ["E"]="1110",
- ["F"]="1111",
- }
- return str:gsub('[0-9A-F]', map)
- end
- if fs.exists(filename) == true then
- h = fs.open(filename, "r")
- text = h.readAll()
- h.close()
- strHex = string.tohex(text)
- strBin = hex2bin(strHex)
- else
- print("file does not exist, check path..")
- end
- local function error(errore)
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Error!!!!!")
- term.setCursorPos((maxw - #errore) / 2, 6)
- term.write(errore)
- os.sleep(5)
- os.reboot()
- end
- local function toBinary(num)
- return hexToBin_lut[num]
- end
- local function sendStartSequence()
- -- Start of TEXT: 10
- rs.setOutput(clockSide, true)
- rs.setOutput(sendSide, true)
- os.sleep(0.2)
- rs.setOutput(clockSide, false)
- rs.setOutput(sendSide, false)
- end
- local function sendStopSequence()
- -- End of TEXT: 11
- rs.setOutput(sendSide, false)
- rs.setOutput(clockSide, true)
- os.sleep(0.2)
- rs.setOutput(clockSide, false)
- if parityBit % 2 == 0 then
- rs.setOutput(sendSide, true)
- os.sleep(0.2)
- rs.setOutput(sendSide, false)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Calafrica Group -- Calaofeng UV5R+Plus\n\n")
- print("Bin to send..".. strBin)
- while true do
- os.sleep(0.1)
- sendStartSequence()
- os.sleep(0.2)
- -- Qui in poi legge il file
- for i = 1, #strBin do
- local c = strBin:sub(i,i)
- if c == "1" then
- rs.setOutput(sendSide, true)
- parityBit = parityBit + 1
- else
- rs.setOutput(sendSide, false)
- end
- os.sleep(0.2)
- end
- -- Finisce il file
- sendStopSequence()
- parityBit = 0
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement