RaspyRFM/fs20tx.py

84 lines
1.7 KiB
Python
Raw Normal View History

2018-02-13 15:39:12 +01:00
#!/usr/bin/env python2.7
2020-01-27 02:11:10 +01:00
from raspyrfm import *
2018-02-13 15:39:12 +01:00
import sys
import time
2020-01-27 02:11:10 +01:00
rfm = RaspyRFM(2, RFM69) #when using the RaspyRFM twin
#elif Rfm69.Test(0):
# rfm = Rfm69() #when using a single single 868 MHz RaspyRFM
#else:
# print "No RFM69 module found!"
# exit()
2018-04-24 00:15:14 +02:00
2020-01-27 02:11:10 +01:00
rfm.set_params(
2018-02-13 15:39:12 +01:00
Freq = 868.350,
Datarate = 5.0,
2020-01-27 02:11:10 +01:00
TxPower = -10,
2018-02-13 15:39:12 +01:00
ModulationType = rfm69.OOK,
SyncPattern = [0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x38],
Preamble = 0
)
data = []
bitcnt = 0
def AddBit(bit):
2020-01-27 02:11:10 +01:00
global data
2018-02-13 15:39:12 +01:00
global bitcnt
if bit:
if ((len(data) * 8) - bitcnt) < 6:
data.append(0)
data[bitcnt / 8] |= 0xE0 >> (bitcnt % 8)
if (bitcnt % 8) > 2:
data[(bitcnt / 8) + 1] |= (0xE0 << (8 - (bitcnt % 8))) & 0xFF
bitcnt += 6
else:
if ((len(data) * 8) - bitcnt) < 4:
data.append(0)
data[bitcnt / 8] |= 0xC0 >> (bitcnt % 8)
if (bitcnt % 8) > 4:
data[(bitcnt / 8) + 1] |= (0xC0 << (8 - (bitcnt % 8))) & 0xFF
bitcnt += 4
def AddByte(b):
mask = 0x80
while (mask):
AddBit(b & mask)
mask >>= 1
cnt = 0
while b:
cnt += 1
b &= b - 1
AddBit(cnt & 1)
def MakeFS20Frame(hc, adr, cmd):
q = 0
AddByte(hc >> 8)
AddByte(hc & 0xFF)
q += hc >> 8
q += hc & 0xFF
AddByte(adr)
q += adr
if (cmd > 0xFF):
AddByte(cmd >> 8)
q += cmd >> 8
AddByte(cmd & 0xFF)
q += cmd & 0xFF
q += 6
AddByte(q & 0xFF)
AddBit(0)
data = []
bitcnt = 0
MakeFS20Frame(int(sys.argv[1], 0), int(sys.argv[2], 0), int(sys.argv[3], 0))
2020-01-27 02:11:10 +01:00
print(data)
2018-02-13 15:39:12 +01:00
for x in range(3):
2020-01-27 02:11:10 +01:00
rfm.send_packet(data)