kopia lustrzana https://github.com/projecthorus/wenet
Added SSDV upload feature, more TX unit debugging.
rodzic
9a37c5ba12
commit
72a1e00678
|
@ -33,6 +33,11 @@ class BinaryDebug(object):
|
|||
def close(self):
|
||||
self.f.close()
|
||||
|
||||
def write_debug_message(message, debug_file = "tx_idle_message.txt"):
|
||||
f = open(debug_file,'w')
|
||||
f.write(message)
|
||||
f.close()
|
||||
print("DEBUG MSG: %s" % message)
|
||||
|
||||
class PacketTX(object):
|
||||
txqueue = Queue.Queue(4096) # Up to 1MB of 256 byte packets
|
||||
|
@ -83,7 +88,7 @@ class PacketTX(object):
|
|||
# Try and read in a message from a file.
|
||||
try:
|
||||
f = open("tx_idle_message.txt")
|
||||
idle_data = f.read()
|
||||
idle_data = "DE %s: \t%s" % (self.callsign,f.read())
|
||||
f.close()
|
||||
except:
|
||||
idle_data = "DE %s Wenet High-Speed FSK Transmitter" % self.callsign
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#!/usr/bin/env python2.7
|
||||
#
|
||||
# SSDV Upload Library
|
||||
# SSDV Upload Script.
|
||||
#
|
||||
# Watches the rx_images directory for new images, and uploads the latest image it sees.
|
||||
#
|
||||
#
|
||||
|
||||
import base64, requests, datetime, os
|
||||
import base64, requests, datetime, os, glob, time
|
||||
|
||||
ssdv_url = "http://ssdv.habhub.org/api/v0/packets"
|
||||
|
||||
|
@ -35,7 +37,10 @@ def ssdv_upload_multiple(packet_array,callsign="N0CALL"):
|
|||
"type": "packets",
|
||||
"packets": encoded_array
|
||||
}
|
||||
r = requests.post(ssdv_url,json=packet_dict)
|
||||
try:
|
||||
r = requests.post(ssdv_url,json=packet_dict)
|
||||
except Exception as e:
|
||||
print(e.strerror)
|
||||
return r
|
||||
|
||||
|
||||
|
@ -48,6 +53,7 @@ def ssdv_upload_file(filename,callsign="N0CALL", blocksize=16):
|
|||
|
||||
packet_count = file_size/256
|
||||
print("Uploading %d packets." % packet_count)
|
||||
start_time = datetime.datetime.now()
|
||||
|
||||
f = open(filename,"rb")
|
||||
|
||||
|
@ -68,11 +74,46 @@ def ssdv_upload_file(filename,callsign="N0CALL", blocksize=16):
|
|||
print("%d packets remaining." % packet_count)
|
||||
|
||||
f.close()
|
||||
stop_time = datetime.datetime.now()
|
||||
upload_time = (stop_time-start_time).total_seconds()
|
||||
print("Upload Completed in %.2f Seconds." % upload_time)
|
||||
|
||||
def ssdv_dir_watcher(glob_string="./rx_images/*.bin", check_time = 0.5, callsign="N0CALL"):
|
||||
# Check what's there now..
|
||||
rx_images = glob.glob(glob_string)
|
||||
print("Starting directory watch...")
|
||||
|
||||
while True:
|
||||
time.sleep(check_time)
|
||||
|
||||
# Check directory again.
|
||||
rx_images_temp = glob.glob(glob_string)
|
||||
if len(rx_images_temp) == 0:
|
||||
continue
|
||||
# Sort list. Image filenames are timestamps, so the last element in the array will be the latest image.
|
||||
rx_images_temp.sort()
|
||||
# Is there an new image?
|
||||
if rx_images_temp[-1] not in rx_images:
|
||||
# New image! Wait a little bit in case we're still writing to that file, then upload.
|
||||
time.sleep(0.5)
|
||||
filename = rx_images_temp[-1]
|
||||
print("Found new image! Uploading: %s " % filename)
|
||||
ssdv_upload_file(filename,callsign=callsign,blocksize=256)
|
||||
|
||||
rx_images = rx_images_temp
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
filename = sys.argv[1]
|
||||
callsign = sys.argv[2]
|
||||
print("Uploading: %s with Callsign: %s" % (filename,callsign))
|
||||
try:
|
||||
callsign = sys.argv[1]
|
||||
if len(callsign)>6:
|
||||
callsign = callsign[:6]
|
||||
except:
|
||||
print("Usage: python ssdv_upload.py CALLSIGN &")
|
||||
sys.exit(1)
|
||||
|
||||
ssdv_upload_file(filename,callsign=callsign,blocksize=256)
|
||||
print("Using callsign: %s" % callsign)
|
||||
|
||||
ssdv_dir_watcher(callsign=callsign)
|
|
@ -7,7 +7,8 @@
|
|||
#
|
||||
|
||||
import PacketTX, sys, os, datetime
|
||||
from picam_wrapper import *
|
||||
from PacketTX import write_debug_message
|
||||
from wenet_util import *
|
||||
|
||||
try:
|
||||
callsign = sys.argv[1]
|
||||
|
@ -26,7 +27,7 @@ def transmit_file(filename, tx_object):
|
|||
file_size = os.path.getsize(filename)
|
||||
|
||||
if file_size % 256 > 0:
|
||||
print("File size not a multiple of 256 bytes!")
|
||||
write_debug_message("File size not a multiple of 256 bytes!")
|
||||
return
|
||||
|
||||
print("Transmitting %d Packets." % (file_size/256))
|
||||
|
@ -42,7 +43,7 @@ def transmit_file(filename, tx_object):
|
|||
tx_object.wait()
|
||||
|
||||
|
||||
tx = PacketTX.PacketTX(debug=debug_output)
|
||||
tx = PacketTX.PacketTX(debug=debug_output, callsign=callsign)
|
||||
tx.start_tx()
|
||||
|
||||
image_id = 0
|
||||
|
@ -55,7 +56,7 @@ try:
|
|||
capture_multiple(filename="./tx_images/%s.jpg"%capture_time)
|
||||
#os.system("raspistill -t 100 -o ./tx_images/%s.jpg -vf -hf -w 1024 -h 768" % capture_time)
|
||||
# Resize using convert
|
||||
print("Processing...")
|
||||
write_debug_message("Converting Image to SSDV...")
|
||||
#os.system("convert temp.jpg -resize %s\! temp.jpg" % tx_resolution)
|
||||
# SSDV'ify the image.
|
||||
os.system("ssdv -e -n -c %s -i %d ./tx_images/%s.jpg temp.ssdv" % (callsign,image_id,capture_time))
|
||||
|
|
|
@ -1,27 +1,35 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# PiCam Wrapper Functions
|
||||
# Wenet Utility Functions
|
||||
#
|
||||
|
||||
import os,glob
|
||||
from PacketTX import write_debug_message
|
||||
|
||||
picam_str = "raspistill -t 100 -ex auto -o %s -vf -hf -w 1600 -h 1200"
|
||||
#
|
||||
# PiCam Wrapper Functions
|
||||
#
|
||||
|
||||
# Adjust this line to suit your needs (resolution, image flip, etc)
|
||||
picam_str = "raspistill -t 3000 -ex auto -mm matrix -o %s -vf -hf -w 2592 -h 1936"
|
||||
temp_file_prefix = "./temp_pic"
|
||||
|
||||
|
||||
def capture_single(filename="temp.jpg"):
|
||||
os.system(picam_str % filename)
|
||||
|
||||
def capture_multiple(filename="output.jpg", n=10, temp_prefix=temp_file_prefix):
|
||||
def capture_multiple(filename="output.jpg", n=5, temp_prefix=temp_file_prefix):
|
||||
# Remove any existing temporary images
|
||||
os.system("rm %s*.jpg"%temp_prefix)
|
||||
|
||||
# Capture n images
|
||||
for pic_num in range(n):
|
||||
write_debug_message("Capturing Image %d of %d..." % (pic_num, n))
|
||||
capture_single("%s_%d.jpg"%(temp_prefix,pic_num))
|
||||
|
||||
# Super high-tech image quality recognition filter
|
||||
# (pick the largest image... thanks daveake!)
|
||||
write_debug_message("Choosing Best Image...")
|
||||
pic_list = glob.glob("%s*.jpg"%temp_prefix)
|
||||
pic_sizes = []
|
||||
for pic in pic_list:
|
Ładowanie…
Reference in New Issue