You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.5 KiB
Python

5 years ago
from modulators.OOKModulator import OOKModulator
import numpy as np
"""
Nexus Temperature & Humidity Protocol
"""
class Nexus_TempHumidity:
def __init__(self):
5 years ago
pass
5 years ago
def generateData(self, id=244, channel=1, temp=30, humidity=100):
nibbles = self.generatePacket(id, channel, temp, humidity)
data = []
for i in range(9):
mask = 0x08
for j in range(4):
if (nibbles[i] & mask):
data.append(1)
else:
data.append(0)
mask >>= 1
return data
5 years ago
def generateSamples(self, baseband_samplerate=2e6, id=244, channel=1, temp=30, humidity=100, numpyType=np.complex64):
modulator = OOKModulator(baseband_samplerate=baseband_samplerate, am_frequency=22.471e3)
bits = self.generateData(id, channel, temp, humidity)
5 years ago
for repeat in range(0, 4):
for j in bits:
modulator.addModulation(500)
modulator.addPadding(1000 * (1 + int(j)))
5 years ago
modulator.addModulation(500)
5 years ago
modulator.addPadding(4000)
5 years ago
return modulator.getSamplesAndReset(numpyType)
5 years ago
def generatePacket(self, id=244, channel=1, temp=30, humidity=100):
5 years ago
temp = int(temp * 10)
packet = [
(id >> 4) & 0x0f,
id & 0x0f,
7 + channel,
(temp >> 8) & 0x0f,
(temp >> 4) & 0x0f,
temp & 0x0f,
0x0f,
(humidity >> 4) & 0x0f,
humidity & 0x0f
]
return packet