Conflicts:
	connair.py
	rfm69.py
This commit is contained in:
S. Seegel 2016-09-08 13:40:19 +00:00
commit d00e7c79ba
7 changed files with 151 additions and 16 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.pyc

View file

@ -2,6 +2,8 @@
import socket
import time
import rfm69
import sys
UDP_IP = "0.0.0.0"
UDP_PORT = 49880
@ -10,17 +12,62 @@ HELLO_MESSAGE = "HCGW:VC:Seegel Systeme;MC:RaspyRFM;FW:1.00;IP:192.168.2.124;;"
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
#sock.sendto("TXP:0,0,10,20000,350,25,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,17;", ("192.168.178.51", 49880))
#sys.exit(0)
rfm = rfm69.Rfm69()
rfm.SetParams(
Freq = 433.92,
TXPower = 13,
ModulationType = rfm69.OOK,
SyncPattern = [],
RssiThresh = -72
)
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
msg = str(data).split(":")
#data = "TXP:0,0,6,5950,350,25,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,17;"
#addr = ("123", 5)
print "received message:", data, "from ", addr
print "received message:", msg, "from ", addr
msg = str(data).split(":")
if msg[0] == "SEARCH HCGW":
sock.sendto(HELLO_MESSAGE, addr)
print "Hello message"
if msg[0] == "TXP":
msg[1] = msg[1].replace(";", "")
cmd = msg[1].split(",")
print "Command: ", cmd
rep = int(cmd[2])
pauselen = int(cmd[3])
steplen = int(cmd[4])
numpulse = int(cmd[5])
pulsedata = cmd[6:]
pulsedata[numpulse * 2 - 1] = int(pulsedata[numpulse * 2 - 1]) + pauselen / steplen
bindata = []
bit = True
numbit = 0
bitleft = 0
for i in range(numpulse * 2):
for bits in range(int(pulsedata[i])):
if bitleft == 0:
bitleft = 8
bindata.append(0x00)
bindata[len(bindata) - 1] <<= 1
if bit:
bindata[len(bindata) - 1] |= 0x01
bitleft -= 1
bit = not bit
for i in range(bitleft):
bindata[len(bindata) - 1] <<= 1
print "bitleft: ", bitleft
print "reps: ", rep
print "Pulse data", pulsedata
print "bin:", bindata
rfm.SetParams(Datarate = 1000.0 / steplen)
rfm.SendPacket(bindata * rep)

77
hamarx.py Executable file
View file

@ -0,0 +1,77 @@
#!/usr/bin/env python2.7
from rfm69 import Rfm69
import rfm69
import sys
import time
#import types
#import os
rfm = Rfm69()
rfm.SetParams(
Freq = 433.944,
Datarate = 4.0, #1 / 250E-06 / 1000,
Bandwidth = 24000,
SyncPattern = [0x00, 0x08, 0x00],
RssiThresh = -80,
ModulationType = rfm69.OOK
)
def staff(byte):
res = 0
res |= (byte & 1<<7) >> 4
res |= (byte & 1<<5) >> 3
res |= (byte & 1<<3) >> 2
res |= (byte & 1<<1) >> 1
return res
def decode(bindata):
netdata = [0x00, 0x00, 0x00, 0x00]
for i in range(0, 64, 2):
if (bindata[i / 8] >> (i % 8)) & 0x01 == (bindata[i / 8] >> (i % 8 + 1)) & 0x01:
print "Error", i, hex(bindata[i / 8]), hex(bindata[i / 8] >> (i % 8))
for i in range(4):
netdata[i] = staff(bindata[i * 2]) << 4 | staff(bindata[i * 2 + 1])
print "decode: ",
for i in range(4):
print "{0:{fill}2x}".format(netdata[i], fill='0'),
print ""
while True:
data = rfm.ReceivePacket(60)
zcount = 0
bindata = []
binval = 0
binmask = 0x80
for d in data:
rawmask = 0x80
while (rawmask > 0) and (len(bindata) < 8):
if (d & rawmask) > 0:
if zcount == 1:
binval |= binmask
binmask >>= 1
if zcount == 5:
binmask >>= 1
if zcount == 11:
print "Received pause"
if zcount == 41:
print "SYNC"
zcount = 0
else:
zcount += 1
rawmask >>= 1
if binmask == 0:
bindata.append(binval)
binmask = 0x80
binval = 0
if len(bindata) == 8:
decode(bindata)
break;

14
intertechno.py Normal file → Executable file
View file

@ -6,7 +6,8 @@ import sys
import time
if len(sys.argv) != 2:
print "usage: intertechno <CODE>" #12-digit code 12 * ['0', '1', 'f']
print "usage: intertechno <CODE>" #12-digit code 12 * ['0' | '1' | 'f']
print "Example: intertechno 0FF0F0F00FF0"
sys.exit(1)
rfm = Rfm69()
@ -15,13 +16,14 @@ rfm.SetParams(
Datarate = 2.666666,
TXPower = 13,
ModulationType = rfm69.OOK,
SyncPattern = [0x80, 0x00, 0x00, 0x00]
SyncPattern = []
)
#Frame generation
def MakeFrame(code, rep):
data = [0x80, 0x00, 0x00, 0x00] #sync
b = 0;
data = []
for c in code:
if c == '0':
data.append(0x88)
@ -29,11 +31,9 @@ def MakeFrame(code, rep):
data.append(0xEE)
elif c == 'F' or c == 'f':
data.append(0x8E)
data += [0x80, 0x00, 0x00, 0x00] #sync
result = []
for i in range(rep):
result += data
return result
return data * rep
data = MakeFrame(sys.argv[1], 3)
data = MakeFrame(sys.argv[1], 8)
rfm.SendPacket(data)

0
lacrosse.py Normal file → Executable file
View file

View file

@ -121,10 +121,15 @@ class Rfm69:
config[RegTestDagc] = 0x30
config[RegRssiThresh] = 0x90
config[RegFifoThresh] = 0x8F
config[RegBitrateMsb] = 0x1A
config[RegBitrateLsb] = 0x0B
for key in config:
self.__WriteReg(key, config[key])
self.__WriteReg(RegOpMode, MODE_STDBY << 2)
self.__WaitMode()
print("INIT COMPLETE")
def __RfmIrq(self, ch):

View file

@ -21,8 +21,8 @@ class rawsensor(object):
self.__raw = data
def __str__(self):
res = 'raw';
for data in self.__raw:
res = 'RAW RSSI ' + str(self.__raw[1]) + " dBm: "
for data in self.__raw[0]:
res = res + ' ' + hex(data)[2:];
return res;
@ -44,11 +44,16 @@ class rawsensor(object):
class lacross(rawsensor):
def __init__(self, data):
rawsensor.__init__(self, data)
self._data['ID'] = hex((data[0] << 4 | data[1] >> 4) & 0xFC)[2:]
self._data['T'] = (10 * ((data[1] & 0xF) - 4) + (data[2] >> 4) + (data[2] & 0xF) / 10.0, 'C')
rh = data[3] & 0x7F
id = data[0][0] << 4 | data[0][1] >> 4
print "A", hex(data[0][0])[2:], hex(data[0][1])[2:]
self._data['ID'] = hex(id & 0xFC)[2:]
self._data['init'] = bool(id & 1<<1)
self._data['T'] = (10 * ((data[0][1] & 0xF) - 4) + (data[0][2] >> 4) + (data[0][2] & 0xF) / 10.0, 'C')
rh = data[0][3] & 0x7F
if rh <= 100:
self._data['RH'] = (rh, '%')
self._data['batlo'] = bool(rh & 1<<7)
self._data['RSSI'] = data[1]
def __str__(self):
res = 'La crosse ' + str(self._data) # + ' ' + rawsensor.__str__(self);
@ -56,7 +61,7 @@ class lacross(rawsensor):
@staticmethod
def Create(data):
if len(data) >= 5 and len(data) <= 8 and crc8(data) == 0:
if len(data[0]) >= 5 and len(data[0]) <= 8 and crc8(data[0]) == 0:
return lacross(data)
class emt7110(rawsensor):