mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
removed unnecessary line
This commit is contained in:
parent
b5fc5b6275
commit
da1046605e
2 changed files with 20 additions and 25 deletions
|
@ -15,9 +15,6 @@ import binascii #required for string.to_bytes() function
|
|||
import sys
|
||||
|
||||
|
||||
|
||||
import base64
|
||||
|
||||
def main():
|
||||
|
||||
modem = FreeDV() #Load FreeDV Class as "modem"
|
||||
|
@ -28,10 +25,12 @@ class FreeDV():
|
|||
|
||||
def __init__(self):
|
||||
|
||||
self.mode = 12 # define mode
|
||||
|
||||
libname = pathlib.Path().absolute() / "libcodec2.so"
|
||||
self.c_lib = ctypes.CDLL(libname) # Load FreeDV shared libary
|
||||
|
||||
self.freedv = self.c_lib.freedv_open(12) #Set FreeDV waveform ( 10,11,12 --> DATA1-3 )
|
||||
self.freedv = self.c_lib.freedv_open(self.mode) #Set FreeDV waveform ( 10,11,12 --> DATA1-3 )
|
||||
|
||||
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
|
||||
|
@ -46,13 +45,12 @@ class FreeDV():
|
|||
# MODULATION-IN OBJECT
|
||||
def ModulationIn(self):
|
||||
return (c_short * (self.n_max_modem_samples)) ##
|
||||
#return (c_short * 40000)
|
||||
#return (c_short * (self.nin))
|
||||
|
||||
|
||||
# Pointer for changing buffer data type
|
||||
def FrameBytes(self):
|
||||
return (c_ubyte * self.bytes_per_frame)
|
||||
#return (c_ubyte * 2)
|
||||
|
||||
|
||||
# Modulate function which returns modulated data
|
||||
def Demodulate(self):
|
||||
|
@ -67,23 +65,21 @@ class FreeDV():
|
|||
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(self.n_max_modem_samples*2) # N MAX SAMPLES * 2
|
||||
buffer[:len(data_in)] = data_in # copy across what we have
|
||||
|
||||
self.ModulationIn()()
|
||||
self.ModulationIn()() #Create new ModulationIn Object
|
||||
modulation = self.ModulationIn()# get an empty modulation array
|
||||
modulation = modulation.from_buffer_copy(buffer) # copy buffer across and get a pointer to it.
|
||||
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)
|
||||
self.nin = self.c_lib.freedv_nin(self.freedv)
|
||||
nbytes = self.c_lib.freedv_rawdatarx(self.freedv, bytes_out, data_in) # Demodulated data and get number of demodulated bytes
|
||||
#self.nin = self.c_lib.freedv_nin(self.freedv)
|
||||
|
||||
|
||||
# ------------- SOME DEBUGGING OUTPUT
|
||||
print("INPUT PARSER: " + str(samples))
|
||||
print("INPUT LENGTH: " + str(len(data_in)))
|
||||
print("BUFFER LENGTH: " + str(len(buffer)))
|
||||
|
@ -92,13 +88,14 @@ class FreeDV():
|
|||
sync_state = self.c_lib.freedv_get_sync(self.freedv)
|
||||
if sync_state > 0:
|
||||
print("SYNC")
|
||||
# -------------
|
||||
|
||||
# print data to terminal if bytes have been demodulated
|
||||
|
||||
|
||||
# print data to terminal if nbytes > 0
|
||||
if nbytes > 0:
|
||||
print(bytes(bytes_out))
|
||||
#print(nbytes)
|
||||
|
||||
#print(bytes(bytes_out))
|
||||
|
||||
#Stop loop until data input is empty
|
||||
if len(data_in) == 0:
|
||||
|
|
|
@ -20,8 +20,7 @@ def main():
|
|||
|
||||
data = b'HALLO' #byte string which will be send
|
||||
|
||||
|
||||
modulated_data = modem.Modulate(data) #Call Modulate function, which modulates data and prints it to the terminal
|
||||
modem.Modulate(data) #Call Modulate function, which modulates data and prints it to the terminal
|
||||
|
||||
|
||||
class FreeDV():
|
||||
|
@ -70,9 +69,8 @@ class FreeDV():
|
|||
crc = crc.value.to_bytes(2, byteorder='big') # convert crc to 2 byte hex string
|
||||
buffer += crc # append crc16 to buffer
|
||||
|
||||
#print(self.bytes_per_frame)
|
||||
#print(buffer)
|
||||
data = self.FrameBytes().from_buffer_copy(buffer) #change data format from bytearray to ctypes.u_byte
|
||||
|
||||
data = self.FrameBytes().from_buffer_copy(buffer) #change data format from bytearray to ctypes.u_byte and copy from buffer to data
|
||||
|
||||
self.c_lib.freedv_rawdatatx(self.freedv,mod_out,data) # modulate DATA and safe it into mod_out pointer
|
||||
|
||||
|
|
Loading…
Reference in a new issue