Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
* Added v1.0.0
  • Loading branch information
Eshco93 authored Mar 3, 2023
1 parent 1c77e9b commit 4eccda4
Show file tree
Hide file tree
Showing 18 changed files with 1,614 additions and 0 deletions.
78 changes: 78 additions & 0 deletions SondeHubUploader/SondeHubUploader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# SondeHubUploader.py - SondeHubUploader class with init and close functions
#
# Copyright (C) Simon Schäfer <[email protected]>
#
# Released under GNU GPL v3 or later


# Modules
import logging
import threading
import queue


class SondeHubUploader:

import SondeHubUploader.shuConfig as shuConfig
import SondeHubUploader.logger as logger
import SondeHubUploader.threads as threads
import SondeHubUploader.handleData as handleData
import SondeHubUploader.conversions as conversions
import SondeHubUploader.printData as printData
import SondeHubUploader.writeData as writeData
import SondeHubUploader.telemetryChecks as telemetryChecks
import SondeHubUploader.uploader as uploader
import SondeHubUploader.utils as utils

# Init function
def __init__(self, args):
# Save the provided configuration parameters
self.__dict__.update(args)

# Define a logger object
self.loggerObj = logging.getLogger('logger')
# Configure the logger
self.logger.configure_logger(self, self.loggerObj, self.loglevelp, self.loglevelw, self.writel)

# Used to break out of while-loops when the SondeHubUploader is terminated
self.running = True

# Queue for storing the received APRS packages after receiving and before parsing
self.aprs_queue = queue.Queue(self.qaprs)
# Queue for storing the telemetry packages after parsing and before uploading
self.upload_queue = queue.Queue(self.qupl)

# Stores the last time the station was uploaded
self.last_station_upload = 0
# Stores the last time the telemetry was uploaded
self.last_telemetry_upload = 0

# Create a thread for receiving the APRS packages
self.udp_receive_thread = threading.Thread(target=self.threads.udp_receive, args=(self,))
self.udp_receive_thread.start()
self.loggerObj.debug('udp_receive thread started')

# Create a thread for processing the received APRS packages
self.process_aprs_queue_thread = threading.Thread(target=self.threads.process_aprs_queue, args=(self,))
self.process_aprs_queue_thread.start()
self.loggerObj.debug('process_aprs_queue thread started')

# Create a thread for uploading the station
self.upload_station_thread = threading.Thread(target=self.threads.upload_station, args=(self,))
self.upload_station_thread.start()
self.loggerObj.debug('upload_station thread started')

# Create a thread for uploading the telemetry
self.process_upload_queue_thread = threading.Thread(target=self.threads.process_upload_queue, args=(self,))
self.process_upload_queue_thread.start()
self.loggerObj.debug('process_upload_queue thread started')

# Close function
def close(self):
# Setting running to 'False' will cause breaking out of the while-loops in the threads
self.running = False
# Join the threads
self.udp_receive_thread.join()
self.process_aprs_queue_thread.join()
self.upload_station_thread.join()
self.process_upload_queue_thread.join()
126 changes: 126 additions & 0 deletions SondeHubUploader/conversions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# conversions.py - Functions for converting units
#
# Copyright (C) Simon Schäfer <[email protected]>
#
# Released under GNU GPL v3 or later


import datetime


# Convert an address to a readable hex string
def address_to_string(address):
addr_str = '0x'
for i in range(len(address)):
addr_str += hex(address[i])[2:]
return addr_str


# Convert a framenumber to an uptime in hms
def frame_to_hms(frame, framerate):
hms = str(datetime.timedelta(seconds=frame * framerate)).split(':')
return {'hour': hms[0], 'minute': hms[1], 'second': hms[2]}


# Convert an uptime in hms to a framenumber
def hms_to_frame(hour, minute, second, framerate):
return (hour * 3600 + minute * 60 + second) * framerate


# Convert a length in feet to meter
def feet_to_meter(feet, precision):
return round(feet * 0.3048, precision)


# Convert a length in meter to feet
def meter_to_feet(meters, precision):
return round(meters * 3.28084, precision)


# Convert a speed in knot to kph
def knot_to_kph(knots, precision):
return round(knots * 1.852, precision)


# Convert a speed in kph to knot
def kph_to_knot(kph, precision):
return round(kph * 0.539957, precision)


# Convert a speed in knot to m/s
def knot_to_ms(knots, precision):
return round(knots * 0.514444, precision)


# Convert a speed in m/s to knot
def ms_to_knot(ms, precision):
return round(ms * 1.94384, precision)


# Convert a speed in kph to m/s
def kph_to_ms(kph, precision):
return round(kph * 0.277778, precision)


# Convert a speed in m/s to kph
def ms_to_kph(ms, precision):
return round(ms * 3.6, precision)


# Convert coordinates in GMS to DG
def gms_to_dg(degree, minute, second, direction, precision):
dg = round(degree + (minute * 60 + second) / 3600, precision)
if direction in ['S', 'W']:
dg *= -1
return dg


# Convert coordinates in DG to GMS
def dg_to_gms(dg, latlon, precision):
degree = int(dg)
minute = int((dg - degree) * 60)
second = round(round((dg - degree) * 3600) % 60, precision)
if dg > 0:
if latlon:
direction = 'N'
else:
direction = 'E'
else:
if latlon:
direction = 'S'
else:
direction = 'W'
return {'degree': degree, 'minute': minute, 'second': second, 'direction': direction}


# Convert coordinates in GMM to DG
def gmm_to_dg(degree, minute, direction, precision):
dg = round(degree + (minute * 60) / 3600, precision)
if direction in ['S', 'W']:
dg *= -1
return dg


# Convert coordinates in DG to GMM
def dg_to_gmm(dg, latlon, precision):
degree = int(dg)
minute = round((dg - degree) * 60, precision)
if dg > 0:
if latlon:
direction = 'N'
else:
direction = 'E'
else:
if latlon:
direction = 'S'
else:
direction = 'W'
return {'degree': degree, 'minute': minute, 'direction': direction}

# Convert coordinates in GMS to GMM
def gms_to_gmm(degree, minute, second, direction, precision):
return {'degree': degree, 'minute': minute + round(second / 60, precision), 'direction': direction}

# Convert coordinates in GMM to GMS
def gmm_to_gms(degree, minute, direction, precision):
return {'degree': degree, 'minute': int(minute), 'second': round((minute - int(minute)) * 60, precision), 'direction': direction}
Loading

0 comments on commit 4eccda4

Please sign in to comment.