Add files via upload

This commit is contained in:
DJ2LS 2020-12-15 18:11:53 +01:00 committed by GitHub
parent 42c8eda4bc
commit c0a1b32ed0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 13 13:45:58 2020
@author: DJ2LS
"""
@ -11,40 +10,17 @@ from ctypes import *
import pathlib
import binascii #required for string.to_bytes() function
#import crcengine # required for CRC checksum
import sys
#sys.stdout.reconfigure(encoding='utf-8')
def main():
modem = FreeDV() #Load FreeDV Class as "modem"
data = b'TEST' #byte string which will be send
#data = bytes(62) #byte string with XX of zeros
modulated_data = modem.Modulate(data) #Call Modulate function, which modulates data and prints it to the terminal
###################### try: / except necessary beacuse of error 32 - BrokenPipeError while piping data
##try:
#print(bytes(8)) #additional zero bytes before modulated data
#sys.stdout.buffer.write(modulated_data) # the normal way of piping data
#sys.stdout.flush() # flushing data
#print(modulated_data, flush=True) #print modulated data with print function
##except (BrokenPipeError, IOError):
##print ('TEST BrokenPipeError caught', file = sys.stderr)
##sys.stderr.close()
class FreeDV():
def __init__(self):
@ -56,15 +32,12 @@ 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.payload_per_frame = self.bytes_per_frame -2 #get frame payload because of 2byte CRC16 checksum
#print(self.c_lib.freedv_get_n_nom_modem_samples(self.freedv))
self.n_tx_modem_samples = self.c_lib.freedv_get_n_tx_modem_samples(self.freedv)*2
# MODULATION-OUT OBJECT
def ModulationOut(self):
#return (c_short * self.c_lib.freedv_get_n_nom_modem_samples(self.freedv)) ## all other modes
#return (c_ubyte * self.c_lib.freedv_get_n_nom_modem_samples(self.freedv)) ## DATA modes ## Fails with n_nom_modem_samples(880) for some reason
return (c_ubyte * 1024) ## DATA modes another test
return (c_short * self.n_tx_modem_samples) ##
# Pointer for changing buffer data type
def FrameBytes(self):
return (ctypes.c_ubyte * self.bytes_per_frame)
@ -72,11 +45,6 @@ class FreeDV():
# Modulate function which returns modulated data
def Modulate(self,data_out):
## #self.freedv_rawdatapreambletx(self.freedv, mod_out) # SEND PREAMBLE
##########################################
mod_out = self.ModulationOut()() # new modulation object and get pointer to it
data_list = [data_out[i:i+self.payload_per_frame] for i in range(0, len(data_out), self.payload_per_frame)] # split incomming bytes to size of 30bytes, create a list and loop through it
@ -90,22 +58,12 @@ class FreeDV():
crc = crc.value.to_bytes(2, byteorder='big') # convert buffer to 2 byte hex string
buffer += crc # append crc16 to buffer
#print(buffer)
data = self.FrameBytes().from_buffer_copy(buffer) #change data format form bytearray to ctypes.u_byte
#print(len(data))
##return bytes(mod_out) #return modulated data as byte string
#self.c_lib.freedv_rawdatapreambletx(self.freedv, mod_out) # SEND PREAMBLE
#print(bytes(mod_out), flush=True)
self.c_lib.freedv_rawdatatx(self.freedv,mod_out,data) # modulate DATA
print(bytes(mod_out), flush=True)
sys.stdout.buffer.write(mod_out) # the normal way of piping data
sys.stdout.flush() # flushing data
main()