From f45ea468976a3c0ea7925617cafebe1d128d2d18 Mon Sep 17 00:00:00 2001 From: darksidelemm Date: Fri, 1 Jan 2016 04:48:00 +0000 Subject: [PATCH] Added Habitat Telemetry Upload git-svn-id: https://svn.code.sf.net/p/freetel/code@2600 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/fsk_horus_stream.m | 25 ++++- codec2-dev/octave/telem_upload.py | 157 +++++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 codec2-dev/octave/telem_upload.py diff --git a/codec2-dev/octave/fsk_horus_stream.m b/codec2-dev/octave/fsk_horus_stream.m index 968331ac..9f63b5a9 100755 --- a/codec2-dev/octave/fsk_horus_stream.m +++ b/codec2-dev/octave/fsk_horus_stream.m @@ -9,6 +9,10 @@ % usage: % $ chmod 777 fsk_horus_stream.m % $ rec -t raw -r 8000 -s -2 -c 1 - -q | ./fsk_horus_stream.m +% or (for those of us that avoid alsa like the plague) +% $ arecord -D pulse -r 8000 -c 1 -f S16_LE - | ./fsk_horus_stream.m +% and use the 'pavucontrol' utility to select a sound device for arecord. +% % % OR to test with a stored file (8kHz 16-bit shorts): % $ cat ~/Desktop/vk5arg-3.wav | ./fsk_horus_stream.m @@ -22,6 +26,11 @@ fsk_horus; gps_log = "~/Desktop/gps_log.txt" system_command = "echo -n \"/home/david/Desktop/gps_log.txt\" | nc -u -q1 127.0.0.1 21234"; +% Upload Telemetry to Habitat (http://tracker.habhub.org/) +telem_upload_enabled = false; +% Update this command with your own callsign. +telem_upload_command = "python telem_upload.py -c N0CALL_Octave"; + more off; states = fsk_horus_init(8000, 100); %states = fsk_horus_init_rtty_uw(states); @@ -83,6 +92,13 @@ while c end if crc_ok + if telem_upload_enabled + % Upload to Habitat. + ascii_upload_cmd = sprintf("%s %s",telem_upload_command,str); + printf("Uploading ASCII to Habitat...\n"); + system(ascii_upload_cmd,false,"async"); + end + strok = sprintf("%s CRC OK", str); else strok = sprintf("%s CRC BAD", str); @@ -142,7 +158,14 @@ while c % compile with: % codec2-dev/src$ gcc horus_l2.c -o horus_l2 -Wall -DDEC_RX_BITS -DHORUS_L2_RX - system("../src/horus_l2"); + system("../src/horus_l2"); + if telem_upload_enabled + % Upload binary payload data to Habitat. + binary_upload_addition = "`cat horus_rx_bits_hex.txt`"; + binary_upload_cmd = sprintf("%s %s",telem_upload_command,binary_upload_addition); + printf("Uploading Binary to Habitat...\n"); + system(binary_upload_cmd,type="async"); + end % throw out used bits in buffer. We're not sure where the next packet starts % so lets remove everything up to just after the UW we just used to force diff --git a/codec2-dev/octave/telem_upload.py b/codec2-dev/octave/telem_upload.py new file mode 100644 index 00000000..e368b421 --- /dev/null +++ b/codec2-dev/octave/telem_upload.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python +# +# Horus Binary (and oldschool) Telemetry Uploader +# +# Mark Jessop 2015-12-31 +# +# +# This script takes either a hex representation of the binary payload, or +# a 'classic' ASCII sentence, and uploads it to Habitat. +# +# Currently this script tells the two apart by looking for 'HORUS' at the start +# of the argument to determine if it's an ASCII sentence. +# +# It's designed to be called from fsk_horus_stream.m, and is tailored for it's output. +# +# Dependencies: +# - Python 2.7 (Will probably break in Python 3) +# - crcmod (pip install crcmod) +# + +import time, struct, json, socket, httplib, crcmod, argparse, sys +from base64 import b64encode +from hashlib import sha256 +from datetime import datetime + +def crc16_ccitt(data): + """ + Calculate the CRC16 CCITT checksum of *data*. + + (CRC16 CCITT: start 0xFFFF, poly 0x1021) + """ + crc16 = crcmod.predefined.mkCrcFun('crc-ccitt-false') + return crc16(data) + +# Binary packet format, from https://github.com/darksidelemm/PicoHorusBinary/tree/master/PicoPayloadGPS +# struct TBinaryPacket +# { +# uint8_t PayloadID; +# uint16_t Counter; +# uint8_t Hours; +# uint8_t Minutes; +# uint8_t Seconds; +# float Latitude; +# float Longitude; +# uint16_t Altitude; +# uint8_t Speed; // Speed in Knots (1-255 knots) +# uint8_t Sats; +# int8_t Temp; // Twos Complement Temp value. +# uint8_t BattVoltage; // 0 = 0.5v, 255 = 2.0V, linear steps in-between. +# uint16_t Checksum; // CRC16-CCITT Checksum. +# }; // __attribute__ ((packed)); + +def decode_horus_binary_telemetry(payload): + + horus_format_struct = "