mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Add files via upload
This commit is contained in:
parent
37c367c7b8
commit
90785dee85
112
test/TEST_RX.py
112
test/TEST_RX.py
|
@ -13,25 +13,20 @@ import pathlib
|
||||||
|
|
||||||
import binascii #required for string.to_bytes() function
|
import binascii #required for string.to_bytes() function
|
||||||
import sys
|
import sys
|
||||||
import audioop
|
|
||||||
|
|
||||||
|
|
||||||
|
import base64
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
modem = FreeDV() #Load FreeDV Class as "modem"
|
modem = FreeDV() #Load FreeDV Class as "modem"
|
||||||
|
|
||||||
#data = b'TEST' #byte string which will be send
|
modem.Demodulate()
|
||||||
|
|
||||||
#data = sys.stdin.read()
|
|
||||||
#for line in sys.stdin.buffer:
|
#for line in sys.stdin.buffer:
|
||||||
# print(line)
|
# #print(line)
|
||||||
# data = sys.stdin.buffer.read()
|
# modem.Demodulate(line)
|
||||||
#data = sys.stdin.flush()
|
|
||||||
#data = audioop.ratecv(data,2,1,48000, 8000, None)
|
|
||||||
#print(data)
|
|
||||||
# demodulated_data = modem.Demodulate(data) #Call Modulate function, which modulates data and prints it to the terminal
|
|
||||||
|
|
||||||
data = sys.stdin.buffer.read()
|
|
||||||
demodulated_data = modem.Demodulate(data)
|
|
||||||
|
|
||||||
|
|
||||||
class FreeDV():
|
class FreeDV():
|
||||||
|
@ -45,11 +40,13 @@ class FreeDV():
|
||||||
|
|
||||||
self.bytes_per_frame = int(self.c_lib.freedv_get_bits_per_modem_frame(self.freedv)/8) #get bytes per frame from selected waveform
|
self.bytes_per_frame = int(self.c_lib.freedv_get_bits_per_modem_frame(self.freedv)/8) #get bytes per frame from selected waveform
|
||||||
self.payload_per_frame = self.bytes_per_frame -2 #get frame payload because of 2byte CRC16 checksum
|
self.payload_per_frame = self.bytes_per_frame -2 #get frame payload because of 2byte CRC16 checksum
|
||||||
self.n_max_modem_samples = self.c_lib.freedv_get_n_max_modem_samples(self.freedv)
|
self.n_max_modem_samples = self.c_lib.freedv_get_n_max_modem_samples(self.freedv)
|
||||||
|
self.nin = self.c_lib.freedv_nin(self.freedv)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("N MAX MODEM SAMPLES: " + str(self.n_max_modem_samples))
|
||||||
|
print("NIN: " + str(self.nin))
|
||||||
|
print("BYTES PER FRAME: " + str(self.bytes_per_frame))
|
||||||
|
|
||||||
# MODULATION-IN OBJECT
|
# MODULATION-IN OBJECT
|
||||||
def ModulationIn(self):
|
def ModulationIn(self):
|
||||||
return (c_short * self.n_max_modem_samples) ##
|
return (c_short * self.n_max_modem_samples) ##
|
||||||
|
@ -58,36 +55,55 @@ class FreeDV():
|
||||||
# Pointer for changing buffer data type
|
# Pointer for changing buffer data type
|
||||||
def FrameBytes(self):
|
def FrameBytes(self):
|
||||||
return (c_ubyte * self.bytes_per_frame)
|
return (c_ubyte * self.bytes_per_frame)
|
||||||
# Modulate function which returns modulated data
|
#return (c_ubyte * 2)
|
||||||
def Demodulate(self,data_in):
|
|
||||||
|
|
||||||
buffer = bytearray(len(self.ModulationIn()())*sizeof(c_short)) # create empty byte array
|
|
||||||
#buffer = bytearray(40000)
|
|
||||||
buffer[:len(data_in)] = data_in # copy across what we have
|
|
||||||
|
|
||||||
modulation = self.ModulationIn() # get an empty modulation array
|
|
||||||
modulation = modulation.from_buffer_copy(buffer) # copy buffer across and get a pointer to it.
|
|
||||||
|
|
||||||
#print(bytes(modulation))
|
|
||||||
bytes_out = self.FrameBytes()() # initilize a pointer to where bytes will be outputed
|
|
||||||
#print(data_in)
|
|
||||||
nbytes = self.c_lib.freedv_rawdatarx(self.freedv, bytes_out, data_in)
|
|
||||||
|
|
||||||
nin = self.c_lib.freedv_nin(self.freedv)
|
|
||||||
|
|
||||||
#print(len(modulation))
|
|
||||||
#print(len(data_in))
|
|
||||||
#print(len(buffer))
|
|
||||||
#print(self.n_max_modem_samples)
|
|
||||||
|
|
||||||
#print(nin)
|
|
||||||
|
|
||||||
print(self.c_lib.freedv_get_sync(self.freedv))
|
|
||||||
if nbytes != 0:
|
|
||||||
print(bytes(bytes_out))
|
|
||||||
|
|
||||||
print(bytes(bytes_out))
|
# Modulate function which returns modulated data
|
||||||
#print(nbytes)
|
def Demodulate(self):
|
||||||
#print(self.c_lib.freedv_get_total_bits_coded(self.freedv))
|
|
||||||
#print(self.c_lib.freedv_get_total_bit_errors_coded(self.freedv))
|
|
||||||
main()
|
nin = self.c_lib.freedv_nin(self.freedv)
|
||||||
|
|
||||||
|
while self.c_lib.freedv_nin(self.freedv) == nin:
|
||||||
|
#nin = self.c_lib.freedv_nin(self.freedv)
|
||||||
|
#print(nin)
|
||||||
|
samples = self.c_lib.freedv_nin(self.freedv) ### MIT DER *2 funktioniert das irgendwie recht zuverlässig bei mode 5!
|
||||||
|
print(samples)
|
||||||
|
data_in = sys.stdin.buffer.read(samples)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#buffer = bytearray(len(self.ModulationIn()())*sizeof(c_short)) # create empty byte array
|
||||||
|
#buffer = bytearray(len(self.ModulationIn()())*self.n_max_modem_samples) # create empty byte array
|
||||||
|
buffer = bytearray(1848) # N MAX SAMPLES * 2
|
||||||
|
print("BUFFER LENGTH: " + str(len(buffer)))
|
||||||
|
buffer[:len(data_in)] = data_in # copy across what we have
|
||||||
|
|
||||||
|
modulation = self.ModulationIn() # get an empty modulation array
|
||||||
|
modulation = modulation.from_buffer_copy(buffer) # copy buffer across and get a pointer to it.
|
||||||
|
|
||||||
|
print("MODULATION LENGTH: " + str(len(modulation)))
|
||||||
|
bytes_out = self.FrameBytes()() # initilize a pointer to where bytes will be outputed
|
||||||
|
|
||||||
|
nbytes = self.c_lib.freedv_rawdatarx(self.freedv, bytes_out, data_in)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if nbytes > 0:
|
||||||
|
print(bytes(bytes_out))
|
||||||
|
#print(nbytes)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in a new issue