From 885cf51ecca7089948ed89088caad0b1bd9adf47 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:22:20 -0500 Subject: [PATCH 01/55] Update codecAO40.h remove cpp --- codecAO40.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/codecAO40.h b/codecAO40.h index f7f1238d..abd1b54f 100644 --- a/codecAO40.h +++ b/codecAO40.h @@ -24,11 +24,11 @@ #include "fecConstants.h" -class CCodecAO40 -{ -public: - CCodecAO40(void); - virtual ~CCodecAO40(void); +//class CCodecAO40 +//{ +//public: +// CCodecAO40(void); +// virtual ~CCodecAO40(void); int decode(unsigned char viterbi_decoded[NBITS_OUT], unsigned char *decoded_data); @@ -40,7 +40,7 @@ public: /* Compares raw input symbols to current buffer of encoded symbols and counts the errors */ int count_errors( unsigned char *raw_symbols); -private: +//private: int mod255(int x); int decode_rs_8(char *data, int *eras_pos, int no_eras); void scramble_and_encode(unsigned char c); @@ -62,4 +62,4 @@ private: unsigned char m_RS_block[RSBLOCKS][NROOTS]; /* RS parity blocks */ unsigned char m_encoded[SYMPBLOCK] ; /* encoded symbols */ -}; +//}; From 67b8eb31c04219c1d67849034355f3ab212b1639 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:26:40 -0500 Subject: [PATCH 02/55] Update codecAO40.cpp remove cpp things --- codecAO40.cpp | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/codecAO40.cpp b/codecAO40.cpp index 89073739..f1646e46 100644 --- a/codecAO40.cpp +++ b/codecAO40.cpp @@ -46,6 +46,7 @@ #define min(a,b) ((a) < (b) ? (a) : (b)) #endif +/* CCodecAO40::CCodecAO40(void) { } @@ -55,8 +56,9 @@ CCodecAO40::~CCodecAO40(void) { } - -int CCodecAO40::mod255(int x) { +*/ +//int CCodecAO40::mod255(int x) { +int mod255(int x) { while (x >= 255) { x -= 255; x = (x >> 8) + (x & 255); @@ -64,7 +66,8 @@ int CCodecAO40::mod255(int x) { return x; } -int CCodecAO40::decode_rs_8(char *data, int *eras_pos, int no_eras){ +//int CCodecAO40::decode_rs_8(char *data, int *eras_pos, int no_eras){ +int decode_rs_8(char *data, int *eras_pos, int no_eras){ int deg_lambda, el, deg_omega; int i, j, r,k; @@ -268,7 +271,8 @@ finish: /* Write one binary channel symbol into the interleaver frame and update the pointers */ -void CCodecAO40::interleave_symbol(int c) +//void CCodecAO40::interleave_symbol(int c) +void interleave_symbol(int c) { int row,col; col=m_ileaver_index/COLUMNS; @@ -281,7 +285,8 @@ void CCodecAO40::interleave_symbol(int c) } /* Convolutionally encode and interleave one byte */ -void CCodecAO40::encode_and_interleave(unsigned char c,int cnt){ +//void CCodecAO40::encode_and_interleave(unsigned char c,int cnt){ +void encode_and_interleave(unsigned char c,int cnt){ while(cnt-- != 0) { m_conv_sr = (m_conv_sr << 1) | (c >> 7); @@ -292,7 +297,8 @@ void CCodecAO40::encode_and_interleave(unsigned char c,int cnt){ } /* Scramble a byte, convolutionally encode and interleave into frame */ -void CCodecAO40::scramble_and_encode(unsigned char c){ +//void CCodecAO40::scramble_and_encode(unsigned char c){ +void scramble_and_encode(unsigned char c){ c ^= Scrambler[m_encoded_bytes]; /* Scramble byte */ encode_and_interleave(c,8); /* RS encode and place into reencode buffer */ } @@ -301,7 +307,8 @@ void CCodecAO40::scramble_and_encode(unsigned char c){ * results stored in m_encoded. * On success encoded buffer is returned, an zeroed buffer on failure */ -const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count) +//const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count) +const unsigned char *encode(unsigned char *source_bytes, int byte_count) { if(BLOCKSIZE != byte_count || NULL == source_bytes ) { @@ -333,7 +340,8 @@ encode_parity() Called 64 times to finish off */ /* This function initializes the encoder. */ -void CCodecAO40::init_encoder(void){ +//void CCodecAO40::init_encoder(void){ +void init_encoder(void){ int i,j,sr; m_encoded_bytes = 0; @@ -370,7 +378,8 @@ void CCodecAO40::init_encoder(void){ * current frame. It should be called in sequence 256 times per frame, followed * by 64 calls to encode_parity(). */ -void CCodecAO40::encode_byte(unsigned char c){ +//void CCodecAO40::encode_byte(unsigned char c){ +void encode_byte(unsigned char c){ unsigned char *rp; /* RS block pointer */ int i; unsigned char feedback; @@ -417,7 +426,8 @@ void CCodecAO40::encode_byte(unsigned char c){ * have been passed to update_encoder. Each call scrambles, encodes and * interleaves one byte of Reed-Solomon parity. */ -void CCodecAO40::encode_parity(void) { +//void CCodecAO40::encode_parity(void) { +void encode_parity(void) { unsigned char c; c = m_RS_block[m_encoded_bytes & 1][(m_encoded_bytes-256)>>1]; @@ -430,7 +440,8 @@ void CCodecAO40::encode_parity(void) { -void CCodecAO40::descramble_to_rsblocks(unsigned char viterbi_decoded[NBITS_OUT], char rsblocks[RSBLOCKS][NN]) +//void CCodecAO40::descramble_to_rsblocks(unsigned char viterbi_decoded[NBITS_OUT], char rsblocks[RSBLOCKS][NN]) +void descramble_to_rsblocks(unsigned char viterbi_decoded[NBITS_OUT], char rsblocks[RSBLOCKS][NN]) { /* interleave into Reed Solomon codeblocks */ memset(rsblocks,0,RSBLOCKS*NN); /* Zero rsblocks array */ @@ -465,7 +476,8 @@ void CCodecAO40::descramble_to_rsblocks(unsigned char viterbi_decoded[NBITS_OUT] * rserrs[x] contains -1 * Data output should not be used. */ -int CCodecAO40::decode(unsigned char vitdecdata[NBITS_OUT], unsigned char *decoded_data) +//int CCodecAO40::decode(unsigned char vitdecdata[NBITS_OUT], unsigned char *decoded_data) +int decode(unsigned char vitdecdata[NBITS_OUT], unsigned char *decoded_data) { int row, col, row_errors, total_errors; char rsblocks[RSBLOCKS][NN]; @@ -502,7 +514,8 @@ int CCodecAO40::decode(unsigned char vitdecdata[NBITS_OUT], unsigned char *decod } /* Compairs raw input symbols to current buffer of encoded symbols and counts the errors */ -int CCodecAO40::count_errors(unsigned char *raw_symbols) +//int CCodecAO40::count_errors(unsigned char *raw_symbols) +int count_errors(unsigned char *raw_symbols) { int error_count = 0; for(int i=0;i Date: Sun, 19 Jan 2025 10:26:56 -0500 Subject: [PATCH 03/55] Rename codecAO40.cpp to codecAO40.c --- codecAO40.cpp => codecAO40.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename codecAO40.cpp => codecAO40.c (100%) diff --git a/codecAO40.cpp b/codecAO40.c similarity index 100% rename from codecAO40.cpp rename to codecAO40.c From dd07e5fe2b4ca407ed63c35ea930758046166a08 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:28:33 -0500 Subject: [PATCH 04/55] Update Makefile remove cpp and g++ --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 713eacf3..49398b19 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ cubesatsim: afsk/ax5043.o cubesatsim: TelemEncoding.o cubesatsim: main.o cubesatsim: codecAO40.o - g++ -std=c++14 $(DEBUG_BEHAVIOR) -o cubesatsim -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o TelemEncoding.o codecAO40.o main.o -lwiringPi -lax5043 -lm + gcc -std=gnu99 $(DEBUG_BEHAVIOR) -o cubesatsim -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o TelemEncoding.o codecAO40.o main.o -lwiringPi -lax5043 -lm telem: telem.o gcc -std=gnu99 $(DEBUG_BEHAVIOR) -o telem -Wall -Wextra -L./ telem.o -lwiringPi @@ -52,10 +52,10 @@ TelemEncoding.o: TelemEncoding.c TelemEncoding.o: TelemEncoding.h gcc -std=gnu99 $(DEBUG_BEHAVIOR) -Wall -Wextra -c TelemEncoding.c -codecAO40.o: codecAO40.cpp +codecAO40.o: codecAO40.c codecAO40.o: codecAO40.h codecAO40.o: fecConstants.h - g++ -std=c++14 $(DEBUG_BEHAVIOR) -Wall -Wextra -c codecAO40.cpp + gcc -std=gnu99 $(DEBUG_BEHAVIOR) -Wall -Wextra -c codecAO40.c ax5043/generated/configcommon.o: ax5043/generated/configcommon.c ax5043/generated/configcommon.o: ax5043/generated/configrx.h From bbecb000645dc90cad286f6d17257ddd1bde99f3 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:29:46 -0500 Subject: [PATCH 05/55] Update main.c remove objects --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 8777a974..2255f7f3 100644 --- a/main.c +++ b/main.c @@ -2255,8 +2255,8 @@ void get_tlm_fc() { // const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count) - CCodecAO40 ao40; - encoded_bytes = ao40.encode((unsigned char*)source_bytes, byte_count); +// CCodecAO40 ao40; + encoded_bytes = encode((unsigned char*)source_bytes, byte_count); /* convert to waveform buffer */ From 62692432cb784253b377c1017a47fd04b1d8a176 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:31:08 -0500 Subject: [PATCH 06/55] Update main.c encoded_bytes --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 2255f7f3..60278612 100644 --- a/main.c +++ b/main.c @@ -2244,7 +2244,7 @@ void get_tlm_fc() { /* create data, stream, and waveform buffers */ unsigned char source_bytes[256]; - unsigned char encoded_bytes[650]; +// unsigned char encoded_bytes[650]; int byte_count = 256; memset(source_bytes, 0xa5, sizeof(source_bytes)); @@ -2256,7 +2256,7 @@ void get_tlm_fc() { // const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count) // CCodecAO40 ao40; - encoded_bytes = encode((unsigned char*)source_bytes, byte_count); + unsigned char* encoded_bytes = encode((unsigned char*)source_bytes, byte_count); /* convert to waveform buffer */ From d9a0d1e7f2933040b8997b1d234492904f370996 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:43:03 -0500 Subject: [PATCH 07/55] Update codecAO40.h added extern --- codecAO40.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codecAO40.h b/codecAO40.h index abd1b54f..0de54acf 100644 --- a/codecAO40.h +++ b/codecAO40.h @@ -24,6 +24,8 @@ #include "fecConstants.h" +extern const unsigned char ALPHA_TO[]; + //class CCodecAO40 //{ //public: From b4cd3ea74a18a68784db86ce86ba7d505113b457 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:45:19 -0500 Subject: [PATCH 08/55] Update main.h added extern --- main.h | 1 + 1 file changed, 1 insertion(+) diff --git a/main.h b/main.h index 2b123615..68cf6d1a 100644 --- a/main.h +++ b/main.h @@ -88,6 +88,7 @@ void update_rs(unsigned char parity[32], unsigned char c); void write_little_endian(unsigned int word, int num_bytes, FILE *wav_file); static int init_rf(); extern int Encode_8b10b[][256]; +extern const unsigned char ALPHA_TO[]; // const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count); void program_radio(); From b067ea74f9cd73a45502ef40ea29ab32f6894acb Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:54:34 -0500 Subject: [PATCH 09/55] Update codecAO40.c added variables --- codecAO40.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codecAO40.c b/codecAO40.c index f1646e46..5674a7b6 100644 --- a/codecAO40.c +++ b/codecAO40.c @@ -1,6 +1,12 @@ #include #include "codecAO40.h" + unsigned char m_RS_block[RSBLOCKS][NROOTS]; /* RS parity blocks */ + unsigned char m_encoded[SYMPBLOCK] ; /* encoded symbols */ + int m_encoded_bytes; /* Byte counter for encode_data() */ + int m_ileaver_index; /* Byte counter for interleaver */ + unsigned char m_conv_sr; /* Convolutional encoder shift register state */ + /* ---------------------- */ /* AO40 Encoder - Decoder */ /* ---------------------- */ From 90033f77da06a28ff5aaa11efb5aa484ac8a4bcb Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:54:44 -0500 Subject: [PATCH 10/55] Update codecAO40.h moved variables --- codecAO40.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/codecAO40.h b/codecAO40.h index 0de54acf..52585e54 100644 --- a/codecAO40.h +++ b/codecAO40.h @@ -58,10 +58,5 @@ extern const unsigned char ALPHA_TO[]; void interleave_symbol(int c); - int m_encoded_bytes; /* Byte counter for encode_data() */ - int m_ileaver_index; /* Byte counter for interleaver */ - unsigned char m_conv_sr; /* Convolutional encoder shift register state */ - unsigned char m_RS_block[RSBLOCKS][NROOTS]; /* RS parity blocks */ - unsigned char m_encoded[SYMPBLOCK] ; /* encoded symbols */ //}; From ef0608f5df50abca7b8bab39c966f7ebc6e4990d Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:55:53 -0500 Subject: [PATCH 11/55] Update codecAO40.c moved variables --- codecAO40.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/codecAO40.c b/codecAO40.c index 5674a7b6..f1646e46 100644 --- a/codecAO40.c +++ b/codecAO40.c @@ -1,12 +1,6 @@ #include #include "codecAO40.h" - unsigned char m_RS_block[RSBLOCKS][NROOTS]; /* RS parity blocks */ - unsigned char m_encoded[SYMPBLOCK] ; /* encoded symbols */ - int m_encoded_bytes; /* Byte counter for encode_data() */ - int m_ileaver_index; /* Byte counter for interleaver */ - unsigned char m_conv_sr; /* Convolutional encoder shift register state */ - /* ---------------------- */ /* AO40 Encoder - Decoder */ /* ---------------------- */ From 51d35f4b7b6cca205ce9c2f8358b0796a929dd8b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:56:27 -0500 Subject: [PATCH 12/55] Update main.h added variables --- main.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.h b/main.h index 68cf6d1a..bb9c5992 100644 --- a/main.h +++ b/main.h @@ -207,3 +207,9 @@ long int loopTime; int error_count = 0; int groundCommandCount = 0; + + unsigned char m_RS_block[RSBLOCKS][NROOTS]; /* RS parity blocks */ + unsigned char m_encoded[SYMPBLOCK] ; /* encoded symbols */ + int m_encoded_bytes; /* Byte counter for encode_data() */ + int m_ileaver_index; /* Byte counter for interleaver */ + unsigned char m_conv_sr; /* Convolutional encoder shift register state */ From 5d7c292336482f1e358516be6924c7e84b751077 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 10:57:34 -0500 Subject: [PATCH 13/55] Update codecAO40.h added extern --- codecAO40.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codecAO40.h b/codecAO40.h index 52585e54..a45151a6 100644 --- a/codecAO40.h +++ b/codecAO40.h @@ -26,6 +26,12 @@ extern const unsigned char ALPHA_TO[]; +extern unsigned char m_RS_block[RSBLOCKS][NROOTS]; /* RS parity blocks */ +extern unsigned char m_encoded[SYMPBLOCK] ; /* encoded symbols */ +extern int m_encoded_bytes; /* Byte counter for encode_data() */ +extern int m_ileaver_index; /* Byte counter for interleaver */ +extern unsigned char m_conv_sr; /* Convolutional encoder shift register state */ + //class CCodecAO40 //{ //public: From a2bc1e99f51ac36d143c57179c1eb6632c939908 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 11:01:01 -0500 Subject: [PATCH 14/55] Update main.h copy in fecConstants.h --- main.h | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/main.h b/main.h index bb9c5992..96877dc7 100644 --- a/main.h +++ b/main.h @@ -213,3 +213,135 @@ int groundCommandCount = 0; int m_encoded_bytes; /* Byte counter for encode_data() */ int m_ileaver_index; /* Byte counter for interleaver */ unsigned char m_conv_sr; /* Convolutional encoder shift register state */ + + +// from funcubeLib/common/fecConstants.h + +//#pragma once + +/* + Amsat P3 FEC Encoder/decoder system. Look-up tables + Created by Phil Karn KA9Q and James Miller G3RUH + Last modified 2003 Jun 20 +*/ + +/* Defines for Viterbi Decoder for r=1/2 k=7 (to CCSDS convention) */ +#define K 7 /* Constraint length */ +#define N 2 /* Number of symbols per data bit */ +#define CPOLYA 0x4f /* First convolutional encoder polynomial */ +#define CPOLYB 0x6d /* Second convolutional encoder polynomial */ + +#define SYNC_POLY 0x48 /* Sync vector PN polynomial */ + +#define NN 255 +#define KK 223 +#define NROOTS 32 /* NN-KK */ +#define A0 (NN) +#define FCR 112 +#define PRIM 11 +#define IPRIM 116 +#define BLOCKSIZE 256 /* Data bytes per frame */ +#define RSBLOCKS 2 /* Number of RS decoder blocks */ +#define RSPAD 95 /* Unused bytes in block (KK-BLOCKSIZE/RSBLOCKS) */ + +/* Defines for Interleaver */ +#define ROWS 80 /* Block interleaver rows */ +#define COLUMNS 65 /* Block interleaver columns */ +#define SYMPBLOCK (ROWS*COLUMNS) /* Encoded symbols per block */ + +/* Number of symbols in an FEC block that are */ +/* passed to the Viterbi decoder (320*8 + 6) */ +#define NBITS ((BLOCKSIZE+NROOTS*RSBLOCKS)*8+K-1) +/* Number of bits obtained from Viterbi decoder */ +#define NBITS_OUT (BLOCKSIZE+NROOTS*RSBLOCKS) + +const unsigned char RS_poly[] = { + 249, 59, 66, 4, 43,126,251, 97, 30, 3,213, 50, 66,170, 5, 24 +}; + +/* Tables for RS decoder */ +/* Galois field log/antilog tables */ +const unsigned char ALPHA_TO[] = +{ + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x87, 0x89, 0x95, 0xad, 0xdd, 0x3d, 0x7a, 0xf4, + 0x6f, 0xde, 0x3b, 0x76, 0xec, 0x5f, 0xbe, 0xfb, 0x71, 0xe2, 0x43, 0x86, 0x8b, 0x91, 0xa5, 0xcd, + 0x1d, 0x3a, 0x74, 0xe8, 0x57, 0xae, 0xdb, 0x31, 0x62, 0xc4, 0x0f, 0x1e, 0x3c, 0x78, 0xf0, 0x67, + 0xce, 0x1b, 0x36, 0x6c, 0xd8, 0x37, 0x6e, 0xdc, 0x3f, 0x7e, 0xfc, 0x7f, 0xfe, 0x7b, 0xf6, 0x6b, + 0xd6, 0x2b, 0x56, 0xac, 0xdf, 0x39, 0x72, 0xe4, 0x4f, 0x9e, 0xbb, 0xf1, 0x65, 0xca, 0x13, 0x26, + 0x4c, 0x98, 0xb7, 0xe9, 0x55, 0xaa, 0xd3, 0x21, 0x42, 0x84, 0x8f, 0x99, 0xb5, 0xed, 0x5d, 0xba, + 0xf3, 0x61, 0xc2, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, + 0x47, 0x8e, 0x9b, 0xb1, 0xe5, 0x4d, 0x9a, 0xb3, 0xe1, 0x45, 0x8a, 0x93, 0xa1, 0xc5, 0x0d, 0x1a, + 0x34, 0x68, 0xd0, 0x27, 0x4e, 0x9c, 0xbf, 0xf9, 0x75, 0xea, 0x53, 0xa6, 0xcb, 0x11, 0x22, 0x44, + 0x88, 0x97, 0xa9, 0xd5, 0x2d, 0x5a, 0xb4, 0xef, 0x59, 0xb2, 0xe3, 0x41, 0x82, 0x83, 0x81, 0x85, + 0x8d, 0x9d, 0xbd, 0xfd, 0x7d, 0xfa, 0x73, 0xe6, 0x4b, 0x96, 0xab, 0xd1, 0x25, 0x4a, 0x94, 0xaf, + 0xd9, 0x35, 0x6a, 0xd4, 0x2f, 0x5e, 0xbc, 0xff, 0x79, 0xf2, 0x63, 0xc6, 0x0b, 0x16, 0x2c, 0x58, + 0xb0, 0xe7, 0x49, 0x92, 0xa3, 0xc1, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0xc7, 0x09, 0x12, 0x24, + 0x48, 0x90, 0xa7, 0xc9, 0x15, 0x2a, 0x54, 0xa8, 0xd7, 0x29, 0x52, 0xa4, 0xcf, 0x19, 0x32, 0x64, + 0xc8, 0x17, 0x2e, 0x5c, 0xb8, 0xf7, 0x69, 0xd2, 0x23, 0x46, 0x8c, 0x9f, 0xb9, 0xf5, 0x6d, 0xda, + 0x33, 0x66, 0xcc, 0x1f, 0x3e, 0x7c, 0xf8, 0x77, 0xee, 0x5b, 0xb6, 0xeb, 0x51, 0xa2, 0xc3, 0x00, +}; + +const unsigned char INDEX_OF[]= +{ + 0xff, 0x00, 0x01, 0x63, 0x02, 0xc6, 0x64, 0x6a, 0x03, 0xcd, 0xc7, 0xbc, 0x65, 0x7e, 0x6b, 0x2a, + 0x04, 0x8d, 0xce, 0x4e, 0xc8, 0xd4, 0xbd, 0xe1, 0x66, 0xdd, 0x7f, 0x31, 0x6c, 0x20, 0x2b, 0xf3, + 0x05, 0x57, 0x8e, 0xe8, 0xcf, 0xac, 0x4f, 0x83, 0xc9, 0xd9, 0xd5, 0x41, 0xbe, 0x94, 0xe2, 0xb4, + 0x67, 0x27, 0xde, 0xf0, 0x80, 0xb1, 0x32, 0x35, 0x6d, 0x45, 0x21, 0x12, 0x2c, 0x0d, 0xf4, 0x38, + 0x06, 0x9b, 0x58, 0x1a, 0x8f, 0x79, 0xe9, 0x70, 0xd0, 0xc2, 0xad, 0xa8, 0x50, 0x75, 0x84, 0x48, + 0xca, 0xfc, 0xda, 0x8a, 0xd6, 0x54, 0x42, 0x24, 0xbf, 0x98, 0x95, 0xf9, 0xe3, 0x5e, 0xb5, 0x15, + 0x68, 0x61, 0x28, 0xba, 0xdf, 0x4c, 0xf1, 0x2f, 0x81, 0xe6, 0xb2, 0x3f, 0x33, 0xee, 0x36, 0x10, + 0x6e, 0x18, 0x46, 0xa6, 0x22, 0x88, 0x13, 0xf7, 0x2d, 0xb8, 0x0e, 0x3d, 0xf5, 0xa4, 0x39, 0x3b, + 0x07, 0x9e, 0x9c, 0x9d, 0x59, 0x9f, 0x1b, 0x08, 0x90, 0x09, 0x7a, 0x1c, 0xea, 0xa0, 0x71, 0x5a, + 0xd1, 0x1d, 0xc3, 0x7b, 0xae, 0x0a, 0xa9, 0x91, 0x51, 0x5b, 0x76, 0x72, 0x85, 0xa1, 0x49, 0xeb, + 0xcb, 0x7c, 0xfd, 0xc4, 0xdb, 0x1e, 0x8b, 0xd2, 0xd7, 0x92, 0x55, 0xaa, 0x43, 0x0b, 0x25, 0xaf, + 0xc0, 0x73, 0x99, 0x77, 0x96, 0x5c, 0xfa, 0x52, 0xe4, 0xec, 0x5f, 0x4a, 0xb6, 0xa2, 0x16, 0x86, + 0x69, 0xc5, 0x62, 0xfe, 0x29, 0x7d, 0xbb, 0xcc, 0xe0, 0xd3, 0x4d, 0x8c, 0xf2, 0x1f, 0x30, 0xdc, + 0x82, 0xab, 0xe7, 0x56, 0xb3, 0x93, 0x40, 0xd8, 0x34, 0xb0, 0xef, 0x26, 0x37, 0x0c, 0x11, 0x44, + 0x6f, 0x78, 0x19, 0x9a, 0x47, 0x74, 0xa7, 0xc1, 0x23, 0x53, 0x89, 0xfb, 0x14, 0x5d, 0xf8, 0x97, + 0x2e, 0x4b, 0xb9, 0x60, 0x0f, 0xed, 0x3e, 0xe5, 0xf6, 0x87, 0xa5, 0x17, 0x3a, 0xa3, 0x3c, 0xb7, +}; + +/* 8-bit parity table */ +const unsigned char Partab[] = { + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, +}; + +/* Scramble byte table */ +const unsigned char Scrambler[]= +{ + 0xff, 0x48, 0x0e, 0xc0, 0x9a, 0x0d, 0x70, 0xbc, 0x8e, 0x2c, 0x93, 0xad, 0xa7, 0xb7, 0x46, 0xce, + 0x5a, 0x97, 0x7d, 0xcc, 0x32, 0xa2, 0xbf, 0x3e, 0x0a, 0x10, 0xf1, 0x88, 0x94, 0xcd, 0xea, 0xb1, + 0xfe, 0x90, 0x1d, 0x81, 0x34, 0x1a, 0xe1, 0x79, 0x1c, 0x59, 0x27, 0x5b, 0x4f, 0x6e, 0x8d, 0x9c, + 0xb5, 0x2e, 0xfb, 0x98, 0x65, 0x45, 0x7e, 0x7c, 0x14, 0x21, 0xe3, 0x11, 0x29, 0x9b, 0xd5, 0x63, + 0xfd, 0x20, 0x3b, 0x02, 0x68, 0x35, 0xc2, 0xf2, 0x38, 0xb2, 0x4e, 0xb6, 0x9e, 0xdd, 0x1b, 0x39, + 0x6a, 0x5d, 0xf7, 0x30, 0xca, 0x8a, 0xfc, 0xf8, 0x28, 0x43, 0xc6, 0x22, 0x53, 0x37, 0xaa, 0xc7, + 0xfa, 0x40, 0x76, 0x04, 0xd0, 0x6b, 0x85, 0xe4, 0x71, 0x64, 0x9d, 0x6d, 0x3d, 0xba, 0x36, 0x72, + 0xd4, 0xbb, 0xee, 0x61, 0x95, 0x15, 0xf9, 0xf0, 0x50, 0x87, 0x8c, 0x44, 0xa6, 0x6f, 0x55, 0x8f, + 0xf4, 0x80, 0xec, 0x09, 0xa0, 0xd7, 0x0b, 0xc8, 0xe2, 0xc9, 0x3a, 0xda, 0x7b, 0x74, 0x6c, 0xe5, + 0xa9, 0x77, 0xdc, 0xc3, 0x2a, 0x2b, 0xf3, 0xe0, 0xa1, 0x0f, 0x18, 0x89, 0x4c, 0xde, 0xab, 0x1f, + 0xe9, 0x01, 0xd8, 0x13, 0x41, 0xae, 0x17, 0x91, 0xc5, 0x92, 0x75, 0xb4, 0xf6, 0xe8, 0xd9, 0xcb, + 0x52, 0xef, 0xb9, 0x86, 0x54, 0x57, 0xe7, 0xc1, 0x42, 0x1e, 0x31, 0x12, 0x99, 0xbd, 0x56, 0x3f, + 0xd2, 0x03, 0xb0, 0x26, 0x83, 0x5c, 0x2f, 0x23, 0x8b, 0x24, 0xeb, 0x69, 0xed, 0xd1, 0xb3, 0x96, + 0xa5, 0xdf, 0x73, 0x0c, 0xa8, 0xaf, 0xcf, 0x82, 0x84, 0x3c, 0x62, 0x25, 0x33, 0x7a, 0xac, 0x7f, + 0xa4, 0x07, 0x60, 0x4d, 0x06, 0xb8, 0x5e, 0x47, 0x16, 0x49, 0xd6, 0xd3, 0xdb, 0xa3, 0x67, 0x2d, + 0x4b, 0xbe, 0xe6, 0x19, 0x51, 0x5f, 0x9f, 0x05, 0x08, 0x78, 0xc4, 0x4a, 0x66, 0xf5, 0x58, 0xff, + 0x48, 0x0e, 0xc0, 0x9a, 0x0d, 0x70, 0xbc, 0x8e, 0x2c, 0x93, 0xad, 0xa7, 0xb7, 0x46, 0xce, 0x5a, + 0x97, 0x7d, 0xcc, 0x32, 0xa2, 0xbf, 0x3e, 0x0a, 0x10, 0xf1, 0x88, 0x94, 0xcd, 0xea, 0xb1, 0xfe, + 0x90, 0x1d, 0x81, 0x34, 0x1a, 0xe1, 0x79, 0x1c, 0x59, 0x27, 0x5b, 0x4f, 0x6e, 0x8d, 0x9c, 0xb5, + 0x2e, 0xfb, 0x98, 0x65, 0x45, 0x7e, 0x7c, 0x14, 0x21, 0xe3, 0x11, 0x29, 0x9b, 0xd5, 0x63, 0xfd, +}; From ec75a7d21c3f00e5d60467d1b5eb97257c39e262 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 11:03:17 -0500 Subject: [PATCH 15/55] Update codecAO40.h add externs --- codecAO40.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/codecAO40.h b/codecAO40.h index a45151a6..b3a08925 100644 --- a/codecAO40.h +++ b/codecAO40.h @@ -22,9 +22,7 @@ #pragma once -#include "fecConstants.h" - -extern const unsigned char ALPHA_TO[]; +//#include "fecConstants.h" extern unsigned char m_RS_block[RSBLOCKS][NROOTS]; /* RS parity blocks */ extern unsigned char m_encoded[SYMPBLOCK] ; /* encoded symbols */ @@ -32,6 +30,12 @@ extern int m_encoded_bytes; /* Byte counter for encode_data() extern int m_ileaver_index; /* Byte counter for interleaver */ extern unsigned char m_conv_sr; /* Convolutional encoder shift register state */ +extern const unsigned char RS_poly[]; +extern const unsigned char ALPHA_TO[]; +extern const unsigned char INDEX_OF[]; +extern const unsigned char Partab[]; +extern const unsigned char Scrambler[]; + //class CCodecAO40 //{ //public: From 8c1496fc6434056d79d396bf6972c72a9e187042 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 11:03:45 -0500 Subject: [PATCH 16/55] Update Makefile remove fec --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 49398b19..bf295216 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,6 @@ TelemEncoding.o: TelemEncoding.h codecAO40.o: codecAO40.c codecAO40.o: codecAO40.h -codecAO40.o: fecConstants.h gcc -std=gnu99 $(DEBUG_BEHAVIOR) -Wall -Wextra -c codecAO40.c ax5043/generated/configcommon.o: ax5043/generated/configcommon.c From c3df2ead757b9b7be06e6cefa4aa6c6f160a53b1 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 11:06:37 -0500 Subject: [PATCH 17/55] Update codecAO40.h added fec defines --- codecAO40.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/codecAO40.h b/codecAO40.h index b3a08925..3ca2c11c 100644 --- a/codecAO40.h +++ b/codecAO40.h @@ -24,6 +24,44 @@ //#include "fecConstants.h" + +/* + Amsat P3 FEC Encoder/decoder system. Look-up tables + Created by Phil Karn KA9Q and James Miller G3RUH + Last modified 2003 Jun 20 +*/ + +/* Defines for Viterbi Decoder for r=1/2 k=7 (to CCSDS convention) */ +#define K 7 /* Constraint length */ +#define N 2 /* Number of symbols per data bit */ +#define CPOLYA 0x4f /* First convolutional encoder polynomial */ +#define CPOLYB 0x6d /* Second convolutional encoder polynomial */ + +#define SYNC_POLY 0x48 /* Sync vector PN polynomial */ + +#define NN 255 +#define KK 223 +#define NROOTS 32 /* NN-KK */ +#define A0 (NN) +#define FCR 112 +#define PRIM 11 +#define IPRIM 116 +#define BLOCKSIZE 256 /* Data bytes per frame */ +#define RSBLOCKS 2 /* Number of RS decoder blocks */ +#define RSPAD 95 /* Unused bytes in block (KK-BLOCKSIZE/RSBLOCKS) */ + +/* Defines for Interleaver */ +#define ROWS 80 /* Block interleaver rows */ +#define COLUMNS 65 /* Block interleaver columns */ +#define SYMPBLOCK (ROWS*COLUMNS) /* Encoded symbols per block */ + +/* Number of symbols in an FEC block that are */ +/* passed to the Viterbi decoder (320*8 + 6) */ +#define NBITS ((BLOCKSIZE+NROOTS*RSBLOCKS)*8+K-1) +/* Number of bits obtained from Viterbi decoder */ +#define NBITS_OUT (BLOCKSIZE+NROOTS*RSBLOCKS) + + extern unsigned char m_RS_block[RSBLOCKS][NROOTS]; /* RS parity blocks */ extern unsigned char m_encoded[SYMPBLOCK] ; /* encoded symbols */ extern int m_encoded_bytes; /* Byte counter for encode_data() */ From 85ccf749a684b0f27b231fca22c690292f828a11 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 11:08:08 -0500 Subject: [PATCH 18/55] Update main.h remove fec const defines --- main.h | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/main.h b/main.h index 96877dc7..b3ec473f 100644 --- a/main.h +++ b/main.h @@ -217,44 +217,6 @@ int groundCommandCount = 0; // from funcubeLib/common/fecConstants.h -//#pragma once - -/* - Amsat P3 FEC Encoder/decoder system. Look-up tables - Created by Phil Karn KA9Q and James Miller G3RUH - Last modified 2003 Jun 20 -*/ - -/* Defines for Viterbi Decoder for r=1/2 k=7 (to CCSDS convention) */ -#define K 7 /* Constraint length */ -#define N 2 /* Number of symbols per data bit */ -#define CPOLYA 0x4f /* First convolutional encoder polynomial */ -#define CPOLYB 0x6d /* Second convolutional encoder polynomial */ - -#define SYNC_POLY 0x48 /* Sync vector PN polynomial */ - -#define NN 255 -#define KK 223 -#define NROOTS 32 /* NN-KK */ -#define A0 (NN) -#define FCR 112 -#define PRIM 11 -#define IPRIM 116 -#define BLOCKSIZE 256 /* Data bytes per frame */ -#define RSBLOCKS 2 /* Number of RS decoder blocks */ -#define RSPAD 95 /* Unused bytes in block (KK-BLOCKSIZE/RSBLOCKS) */ - -/* Defines for Interleaver */ -#define ROWS 80 /* Block interleaver rows */ -#define COLUMNS 65 /* Block interleaver columns */ -#define SYMPBLOCK (ROWS*COLUMNS) /* Encoded symbols per block */ - -/* Number of symbols in an FEC block that are */ -/* passed to the Viterbi decoder (320*8 + 6) */ -#define NBITS ((BLOCKSIZE+NROOTS*RSBLOCKS)*8+K-1) -/* Number of bits obtained from Viterbi decoder */ -#define NBITS_OUT (BLOCKSIZE+NROOTS*RSBLOCKS) - const unsigned char RS_poly[] = { 249, 59, 66, 4, 43,126,251, 97, 30, 3,213, 50, 66,170, 5, 24 }; From 7ac8870e29d455fdeb9955b42a4d02dcaee508d5 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 12:15:52 -0500 Subject: [PATCH 19/55] Update main.h added FC --- main.h | 1 + 1 file changed, 1 insertion(+) diff --git a/main.h b/main.h index b3ec473f..82a2b10f 100644 --- a/main.h +++ b/main.h @@ -112,6 +112,7 @@ FILE *telem_file; #define BPSK 3 #define SSTV 4 #define CW 5 +#define FC 7 #define REPEATER 11 #define TXCOMMAND 12 From 80adb03f8e8d009957147e640606932d5abd766e Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 12:19:46 -0500 Subject: [PATCH 20/55] Update config add mode j funcube --- config | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/config b/config index 104a17e3..c006a662 100755 --- a/config +++ b/config @@ -249,6 +249,8 @@ if [ "$1" = "" ]; then echo "Mode is SSTV" elif [ "$1" = "e" ]; then echo "Mode is Repeater" + elif [ "$1" = "j" ]; then + echo "Mode is FunCube" elif [ "$1" = "n" ]; then echo -n "Mode is Transmit Commands with " FILE=/home/pi/CubeSatSim/transmit_dtmf @@ -1403,6 +1405,22 @@ elif [ "$1" = "-g" ]; then echo "Not resetting" fi +elif [ "$1" = "-j" ]; then + + value=`cat /home/pi/CubeSatSim/.mode` + echo "$value" > /dev/null + set -- $value + +# if [ "$1" == "n" ]; then + +# transmit_command_bpsk + +# else + + echo "changing CubeSatSim to FunCube mode" + sudo echo "j" > /home/pi/CubeSatSim/.mode + restart=1 +# fi elif [ "$1" = "-h" ]; then @@ -1416,7 +1434,8 @@ elif [ "$1" = "-h" ]; then echo " -f Change to FSK/DUV mode" echo " -b Change to BPSK mode" echo " -s Change to SSTV mode" - echo " -n Change to Transmit Commands mode" + echo " -j Change to FunCube mode" + echo " -n Change to Transmit Commands mode" echo " -e Change to Repeater mode" echo " -i Restart CubeSatsim software" echo " -c Change the CALLSIGN in the configuration file sim.cfg" From 20a39c05aa69e7d09a243726651423f9e3215326 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 12:23:58 -0500 Subject: [PATCH 21/55] Update transmit.py add mode -j --- transmit.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/transmit.py b/transmit.py index 6932638e..f38ccc44 100644 --- a/transmit.py +++ b/transmit.py @@ -383,7 +383,7 @@ if __name__ == "__main__": # if (mode != ) and (command_tx == True): # if (command_tx == True): - if ((mode == 'a') or (mode == 'b') or (mode == 'f') or (mode == 's')) and (command_tx == True) and (skip == False): + if ((mode == 'a') or (mode == 'b') or (mode == 'f') or (mode == 's') or (mode == 'j')) and (command_tx == True) and (skip == False): # battery_saver_mode GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 GPIO.setup(txLed, GPIO.OUT) @@ -739,9 +739,12 @@ if __name__ == "__main__": # output(pd, 0) sleep(10) - elif (mode == 'b'): + elif (mode == 'b') or (mode == 'j'): # command_control_check() - print("BPSK") + if (mode == 'b'): + print("BPSK") + else + print("FunCube") print("turn on FM rx") output(pd, 1) output(ptt, 1) @@ -768,7 +771,10 @@ if __name__ == "__main__": output(txLed, txLedOn) # print(txLed) # print(txLedOn) - sleep(4.2) + if (mode == 'b'): + sleep(4.2) + else + sleep(4.6) elif (mode == 'e'): # code based on https://zr6aic.blogspot.com/2016/11/creating-2m-fm-repeater-with-raspberry.html print("Repeater") print("Stopping command and control") From 168a4f6e910f4ca1b2cf549c451cb6b00dff0bf6 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 12:35:40 -0500 Subject: [PATCH 22/55] Update main.c add mode FC same as BPSK --- main.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 60278612..2185f36c 100644 --- a/main.c +++ b/main.c @@ -190,6 +190,9 @@ int main(int argc, char * argv[]) { } else if ( * argv[1] == 'm') { mode = CW; printf("Mode is CW\n"); + } else if ( * argv[1] == 'j') { + mode = FC; + printf("Mode is FunCube\n"); } else { printf("Mode is BPSK\n"); } @@ -228,6 +231,9 @@ int main(int argc, char * argv[]) { } else if ( mode_string == 'm') { mode = CW; printf("Mode is CW\n"); + } else if ( mode_string == 'j') { + mode = FC; + printf("Mode is FunCube\n"); } else if ( mode_string == 'e') { mode = REPEATER; printf("Mode is Repeater\n"); @@ -487,6 +493,36 @@ int main(int argc, char * argv[]) { // printf(" %d", sin_map[j]); } printf("\n"); + } else if (mode == FC) { // for now copy BPSK settings + bitRate = 1200; + rsFrames = 3; + payloads = 6; + rsFrameLen = 159; + headerLen = 8; + dataLen = 78; + syncBits = 31; + syncWord = 0b1000111110011010010000101011101; + parityLen = 32; + amplitude = 32767; + samples = S_RATE / bitRate; + bufLen = (frameCnt * (syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))) * samples); + + samplePeriod = ((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))))/(float)bitRate) * 1000 - 1800; + // samplePeriod = 3000; + // sleepTime = 3.0; + //samplePeriod = 2200; // reduce dut to python and sensor querying delays + sleepTime = 2.2f; + + frameTime = ((float)((float)bufLen / (samples * frameCnt * bitRate))) * 1000; // frame time in ms + + printf("\n BPSK Mode, bufLen: %d, %d bits per frame, %d bits per second, %d ms per frame %d ms sample period\n", + bufLen, bufLen / (samples * frameCnt), bitRate, frameTime, samplePeriod); + + sin_samples = S_RATE/freq_Hz; + for (int j = 0; j < sin_samples; j++) { + sin_map[j] = (short int)(amplitude * sin((float)(2 * M_PI * j / sin_samples))); + } + printf("\n"); } memset(voltage, 0, sizeof(voltage)); @@ -496,6 +532,9 @@ int main(int argc, char * argv[]) { if (((mode == FSK) || (mode == BPSK))) // && !sim_mode) get_tlm_fox(); // fill transmit buffer with reset count 0 packets that will be ignored + else if (((mode == FC))) // && !sim_mode) + get_tlm_fc(); // fill transmit buffer with reset count 0 packets that will be ignored + firstTime = 1; // if (!sim_mode) // always read sensors, even in sim mode @@ -869,6 +908,8 @@ int main(int argc, char * argv[]) { } else if ((mode == FSK) || (mode == BPSK)) {// FSK or BPSK get_tlm_fox(); + } else if ((mode == FC)) { + get_tlm_fc(); } else { // SSTV // fprintf(stderr, "Sleeping\n"); sleep(30); @@ -879,7 +920,7 @@ int main(int argc, char * argv[]) { #endif } - if (mode == BPSK) { + if ((mode == BPSK) || (mode == FC)) { // digitalWrite(txLed, txLedOn); #ifdef DEBUG_LOGGING // printf("Tx LED On 1\n"); @@ -2257,6 +2298,11 @@ void get_tlm_fc() { // CCodecAO40 ao40; unsigned char* encoded_bytes = encode((unsigned char*)source_bytes, byte_count); + + printf("\n\n"); + for (int i=0; i<100; i++) + printf("%x", encoded_bytes[i]; + printf("\n\n"); /* convert to waveform buffer */ @@ -2272,5 +2318,8 @@ void get_tlm_fc() { CCodecAO40 ao40; const U8* encoded = ao40.encode((unsigned char*)sourceBytes, BLOCK_SIZE); */ - + + mode = BPSK; + get_tlm_fox(); // for now, do same as BPSK + mode = FC; } From 7f1d88df12b9efda4207ac2eb2afe3d6e63fe49c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 12:36:47 -0500 Subject: [PATCH 23/55] Update main.c typo --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 2185f36c..bc56212a 100644 --- a/main.c +++ b/main.c @@ -2301,7 +2301,7 @@ void get_tlm_fc() { printf("\n\n"); for (int i=0; i<100; i++) - printf("%x", encoded_bytes[i]; + printf("%x", encoded_bytes[i]); printf("\n\n"); /* convert to waveform buffer */ From 1c37ad5d4d10ba6cb15dd619718e5603b6ab9cf1 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 12:41:09 -0500 Subject: [PATCH 24/55] Update transmit.py typo --- transmit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmit.py b/transmit.py index f38ccc44..801ac33f 100644 --- a/transmit.py +++ b/transmit.py @@ -743,7 +743,7 @@ if __name__ == "__main__": # command_control_check() if (mode == 'b'): print("BPSK") - else + else: print("FunCube") print("turn on FM rx") output(pd, 1) From 335ebf5d91dd73286a7cad74aed9048739a5b50a Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 12:42:56 -0500 Subject: [PATCH 25/55] Update transmit.py another typo --- transmit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmit.py b/transmit.py index 801ac33f..9e37acf7 100644 --- a/transmit.py +++ b/transmit.py @@ -773,7 +773,7 @@ if __name__ == "__main__": # print(txLedOn) if (mode == 'b'): sleep(4.2) - else + else: sleep(4.6) elif (mode == 'e'): # code based on https://zr6aic.blogspot.com/2016/11/creating-2m-fm-repeater-with-raspberry.html print("Repeater") From 597ffcb48289d31e099d35ba8ecfa75da3a7ab28 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 12:47:10 -0500 Subject: [PATCH 26/55] Update main.c another test sequence --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index bc56212a..1abf05c8 100644 --- a/main.c +++ b/main.c @@ -2288,7 +2288,7 @@ void get_tlm_fc() { // unsigned char encoded_bytes[650]; int byte_count = 256; - memset(source_bytes, 0xa5, sizeof(source_bytes)); + memset(source_bytes, 0x5a, sizeof(source_bytes)); /* write telemetry into data buffer */ From 97eda2eab8085ea9a10ea7e398b34c1a43139aeb Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:05:31 -0500 Subject: [PATCH 27/55] Update main.c added FC code --- main.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 194 insertions(+), 19 deletions(-) diff --git a/main.c b/main.c index 1abf05c8..16be128b 100644 --- a/main.c +++ b/main.c @@ -461,6 +461,7 @@ int main(int argc, char * argv[]) { printf("\n FSK Mode, %d bits per frame, %d bits per second, %d ms per frame, %d ms sample period\n", bufLen / (samples * frameCnt), bitRate, frameTime, samplePeriod); + } else if (mode == BPSK) { bitRate = 1200; rsFrames = 3; @@ -493,30 +494,33 @@ int main(int argc, char * argv[]) { // printf(" %d", sin_map[j]); } printf("\n"); + } else if (mode == FC) { // for now copy BPSK settings bitRate = 1200; - rsFrames = 3; - payloads = 6; - rsFrameLen = 159; - headerLen = 8; - dataLen = 78; - syncBits = 31; - syncWord = 0b1000111110011010010000101011101; - parityLen = 32; +// rsFrames = 3; +// payloads = 6; +// rsFrameLen = 159; + headerLen = 768; // 8; + dataLen = 5200; // 78; + syncBits = 32; // 31; + syncWord = 0x1acffc1d; // 0b1000111110011010010000101011101; +// parityLen = 32; amplitude = 32767; samples = S_RATE / bitRate; - bufLen = (frameCnt * (syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))) * samples); + // bufLen = (frameCnt * (syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))) * samples); + bufLen = (headerLen + syncBits + dataLen)/8; - samplePeriod = ((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))))/(float)bitRate) * 1000 - 1800; + // samplePeriod = ((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))))/(float)bitRate) * 1000 - 1800; + samplePeriod = 5000; // samplePeriod = 3000; // sleepTime = 3.0; //samplePeriod = 2200; // reduce dut to python and sensor querying delays - sleepTime = 2.2f; +// sleepTime = 2.2f; frameTime = ((float)((float)bufLen / (samples * frameCnt * bitRate))) * 1000; // frame time in ms - printf("\n BPSK Mode, bufLen: %d, %d bits per frame, %d bits per second, %d ms per frame %d ms sample period\n", - bufLen, bufLen / (samples * frameCnt), bitRate, frameTime, samplePeriod); + printf("\n FC Mode, bufLen: %d, %d bits per frame, %d bits per second, %d ms per frame %d ms sample period\n", + bufLen, bufLen / samples, bitRate, frameTime, samplePeriod); sin_samples = S_RATE/freq_Hz; for (int j = 0; j < sin_samples; j++) { @@ -2306,9 +2310,180 @@ void get_tlm_fc() { /* convert to waveform buffer */ - /* open socket */ + int data; + int val; + //int offset = 0; + + for (i = 1; i <= headerLen * samples; i++) { + write_wave(ctr, buffer); + if ((i % samples) == 0) { + phase *= -1; + if ((ctr - smaller) > 0) { + for (int j = 1; j <= smaller; j++) + buffer[ctr - j] = buffer[ctr - j] * 0.4; + } + flip_ctr = ctr; + } + } + + for (i = 1; i <= syncBits * samples; i++) { + write_wave(ctr, buffer); + // printf("%d ",ctr); + if ((i % samples) == 0) { + int bit = syncBits - i / samples + 1; + val = syncWord; + data = val & 1 << (bit - 1); + // printf ("%d i: %d new frame %d sync bit %d = %d \n", + // ctr/SAMPLES, i, frames, bit, (data > 0) ); + + if (data == 0) { + phase *= -1; + if ((ctr - smaller) > 0) { + for (int j = 1; j <= smaller; j++) + buffer[ctr - j] = buffer[ctr - j] * 0.4; + } + flip_ctr = ctr; + } + } + } + + for (i = 1; i <= (dataLen * samples); i++) // 572 + { + write_wave(ctr, buffer); + if ((i % samples) == 0) { + int symbol = (int)((i - 1) / (samples * 8)); + int bit = 8 - (i - symbol * samples * 8) / samples + 1; + val = encoded_bytes[symbol]; + data = val & 1 << (bit - 1); + // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", + // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); + + if (data == 0) { + phase *= -1; + if ((ctr - smaller) > 0) { + for (int j = 1; j <= smaller; j++) + buffer[ctr - j] = buffer[ctr - j] * 0.4; + } + flip_ctr = ctr; + } + } + } + +/* open socket */ + + int error = 0; + // int count; + // for (count = 0; count < dataLen; count++) { + // printf("%02X", b[count]); + // } + // printf("\n"); + + // socket write + + if (!socket_open && transmit) { + printf("Opening socket!\n"); + // struct sockaddr_in address; + // int valread; + struct sockaddr_in serv_addr; + // char *hello = "Hello from client"; + // char buffer[1024] = {0}; + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + printf("\n Socket creation error \n"); + error = 1; + } + + memset( & serv_addr, '0', sizeof(serv_addr)); + + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(PORT); + + // Convert IPv4 and IPv6 addresses from text to binary form + if (inet_pton(AF_INET, "127.0.0.1", & serv_addr.sin_addr) <= 0) { + printf("\nInvalid address/ Address not supported \n"); + error = 1; + } + + if (connect(sock, (struct sockaddr * ) & serv_addr, sizeof(serv_addr)) < 0) { + printf("\nConnection Failed \n"); + printf("Error: %s\n", strerror(errno)); + error = 1; - /* write waveform buffer over socket */ + // try again + error = 0; + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + printf("\n Socket creation error \n"); + error = 1; + } + + memset( & serv_addr, '0', sizeof(serv_addr)); + + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(PORT); + + // Convert IPv4 and IPv6 addresses from text to binary form + if (inet_pton(AF_INET, "127.0.0.1", & serv_addr.sin_addr) <= 0) { + printf("\nInvalid address/ Address not supported \n"); + error = 1; + } + + if (connect(sock, (struct sockaddr * ) & serv_addr, sizeof(serv_addr)) < 0) { + printf("\nConnection Failed \n"); + printf("Error: %s\n", strerror(errno)); + error = 1; + } + } + if (error == 1) { + printf("Socket error count: %d\n", error_count); +// ; //transmitStatus = -1; + if (error_count++ > 5) { + printf("Restarting transmit\n"); + FILE * transmit_restartf = popen("sudo systemctl restart transmit", "r"); + pclose(transmit_restartf); + sleep(10); // was 5 // sleep if socket connection refused + } + } + else { + socket_open = 1; + error_count = 0; + } + } + +/* write waveform buffer over socket */ + + int length = (headerLen + syncBits + frameLen) * samples + + if (!error && transmit) { + // digitalWrite (0, LOW); + // printf("Sending %d buffer bytes over socket after %d ms!\n", ctr, (long unsigned int)millis() - start); + start = millis(); + int sock_ret = send(sock, buffer, length, 0); +// printf("socket send 1 %d ms bytes: %d \n\n", (unsigned int)millis() - start, sock_ret); + fflush(stdout); + + if (sock_ret < length) { + // printf("Not resending\n"); + sleep(0.5); + sock_ret = send(sock, &buffer[sock_ret], length - sock_ret, 0); +// printf("socket send 2 %d ms bytes: %d \n\n", millis() - start, sock_ret); + } + + loop_count++; + + if (sock_ret == -1) { + printf("Error: %s \n", strerror(errno)); + socket_open = 0; + } + } + if (!transmit) { + fprintf(stderr, "\nNo CubeSatSim Band Pass Filter detected. No transmissions after the CW ID.\n"); + fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); + } + + if (socket_open == 1) + firstTime = 0; + + return; +} /* from funcubeLib/common/testFec.cpp @@ -2319,7 +2494,7 @@ void get_tlm_fc() { const U8* encoded = ao40.encode((unsigned char*)sourceBytes, BLOCK_SIZE); */ - mode = BPSK; - get_tlm_fox(); // for now, do same as BPSK - mode = FC; -} +// mode = BPSK; +// get_tlm_fox(); // for now, do same as BPSK +// mode = FC; +// } From 829c62b3582d42f262232a7125099f500702dde2 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:06:58 -0500 Subject: [PATCH 28/55] Update main.c labels --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 16be128b..c12206bd 100644 --- a/main.c +++ b/main.c @@ -2291,11 +2291,11 @@ void get_tlm_fc() { unsigned char source_bytes[256]; // unsigned char encoded_bytes[650]; int byte_count = 256; + + /* write telemetry into data buffer */ memset(source_bytes, 0x5a, sizeof(source_bytes)); - /* write telemetry into data buffer */ - /* convert data buffer into stream buffer */ // const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count) From 472937c09e588d03d1525acba2984ac19600a6fb Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:08:33 -0500 Subject: [PATCH 29/55] Update main.c variable declarations --- main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index c12206bd..fea58871 100644 --- a/main.c +++ b/main.c @@ -2312,6 +2312,7 @@ void get_tlm_fc() { int data; int val; + int i; //int offset = 0; for (i = 1; i <= headerLen * samples; i++) { @@ -2450,7 +2451,7 @@ void get_tlm_fc() { /* write waveform buffer over socket */ - int length = (headerLen + syncBits + frameLen) * samples + int length = (headerLen + syncBits + dataLen) * samples if (!error && transmit) { // digitalWrite (0, LOW); From 1f81630ba969a77ee098b176b5177fab2d64813f Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:09:22 -0500 Subject: [PATCH 30/55] Update main.c missing ; --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index fea58871..6763b05c 100644 --- a/main.c +++ b/main.c @@ -2451,7 +2451,7 @@ void get_tlm_fc() { /* write waveform buffer over socket */ - int length = (headerLen + syncBits + dataLen) * samples + int length = (headerLen + syncBits + dataLen) * samples; if (!error && transmit) { // digitalWrite (0, LOW); From 96a749b57d9780728cdc82e686c03a6692bbc85f Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:19:33 -0500 Subject: [PATCH 31/55] Update main.c data zeros, zero str --- main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 6763b05c..8613a7eb 100644 --- a/main.c +++ b/main.c @@ -2294,7 +2294,7 @@ void get_tlm_fc() { /* write telemetry into data buffer */ - memset(source_bytes, 0x5a, sizeof(source_bytes)); + memset(source_bytes, 0x00, sizeof(source_bytes)); /* convert data buffer into stream buffer */ @@ -2307,6 +2307,7 @@ void get_tlm_fc() { for (int i=0; i<100; i++) printf("%x", encoded_bytes[i]); printf("\n\n"); + printf("size of encoded_bytes: %d\n\n", sizeof(encoded_bytes)); /* convert to waveform buffer */ @@ -2314,7 +2315,8 @@ void get_tlm_fc() { int val; int i; //int offset = 0; - + ctr = 0; + for (i = 1; i <= headerLen * samples; i++) { write_wave(ctr, buffer); if ((i % samples) == 0) { From d3b1fb327eb7dfc0705184114290cdb6e279730d Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:39:03 -0500 Subject: [PATCH 32/55] Update main.c add random in data block --- main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 8613a7eb..0e41bc6c 100644 --- a/main.c +++ b/main.c @@ -2291,10 +2291,12 @@ void get_tlm_fc() { unsigned char source_bytes[256]; // unsigned char encoded_bytes[650]; int byte_count = 256; - + smaller = (int) (S_RATE / (2 * freq_Hz)); + /* write telemetry into data buffer */ memset(source_bytes, 0x00, sizeof(source_bytes)); + source_byte[10] = (uint8_t) rnd_float(0,255); /* convert data buffer into stream buffer */ @@ -2304,10 +2306,10 @@ void get_tlm_fc() { unsigned char* encoded_bytes = encode((unsigned char*)source_bytes, byte_count); printf("\n\n"); - for (int i=0; i<100; i++) + for (int i=0; i<650; i++) printf("%x", encoded_bytes[i]); printf("\n\n"); - printf("size of encoded_bytes: %d\n\n", sizeof(encoded_bytes)); +// printf("size of encoded_bytes: %d\n\n", sizeof(encoded_bytes)); /* convert to waveform buffer */ @@ -2336,8 +2338,8 @@ void get_tlm_fc() { int bit = syncBits - i / samples + 1; val = syncWord; data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d sync bit %d = %d \n", - // ctr/SAMPLES, i, frames, bit, (data > 0) ); + printf ("%d i: %d new frame %d sync bit %d = %d \n", + ctr/SAMPLES, i, frames, bit, (data > 0) ); if (data == 0) { phase *= -1; From bf18748ea75d5408cc6ffe89be4ebb4b2132b8e4 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:42:27 -0500 Subject: [PATCH 33/55] Update main.c fixed printf --- main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 0e41bc6c..ced52f31 100644 --- a/main.c +++ b/main.c @@ -1708,7 +1708,7 @@ void get_tlm_fox() { val = sync; data = val & 1 << (bit - 1); // printf ("%d i: %d new frame %d sync bit %d = %d \n", - // ctr/SAMPLES, i, frames, bit, (data > 0) ); + // ctr/, i, frames, bit, (data > 0) ); if (mode == FSK) { phase = ((data != 0) * 2) - 1; // printf("Sending a %d\n", phase); @@ -1736,7 +1736,7 @@ void get_tlm_fox() { val = data10[symbol]; data = val & 1 << (bit - 1); // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", - // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); + // ctr/, i, frames, symbol, val, bit, (data > 0) ); if (mode == FSK) { phase = ((data != 0) * 2) - 1; // printf("Sending a %d\n", phase); @@ -2338,8 +2338,8 @@ void get_tlm_fc() { int bit = syncBits - i / samples + 1; val = syncWord; data = val & 1 << (bit - 1); - printf ("%d i: %d new frame %d sync bit %d = %d \n", - ctr/SAMPLES, i, frames, bit, (data > 0) ); + printf ("%d i: %d sync bit %d = %d \n", + ctr, i, bit, (data > 0) ); if (data == 0) { phase *= -1; From 529fbba34f4091df3af73f043a4b8240e4194621 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:43:30 -0500 Subject: [PATCH 34/55] Update main.c source_bytes typo --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index ced52f31..520ab75b 100644 --- a/main.c +++ b/main.c @@ -2296,7 +2296,7 @@ void get_tlm_fc() { /* write telemetry into data buffer */ memset(source_bytes, 0x00, sizeof(source_bytes)); - source_byte[10] = (uint8_t) rnd_float(0,255); + source_bytes[10] = (uint8_t) rnd_float(0,255); /* convert data buffer into stream buffer */ From 2bde5b77a88d462afde292e7ceb0c36fe49e1028 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:54:09 -0500 Subject: [PATCH 35/55] Update main.c add prints --- main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 520ab75b..79eb492a 100644 --- a/main.c +++ b/main.c @@ -2293,6 +2293,10 @@ void get_tlm_fc() { int byte_count = 256; smaller = (int) (S_RATE / (2 * freq_Hz)); + printf("\n\n"); + for (int i=0; i<256; i++) + printf("%d ", source_bytes[i]); + printf("\n\n"); /* write telemetry into data buffer */ memset(source_bytes, 0x00, sizeof(source_bytes)); @@ -2307,7 +2311,7 @@ void get_tlm_fc() { printf("\n\n"); for (int i=0; i<650; i++) - printf("%x", encoded_bytes[i]); + printf("%d ", encoded_bytes[i]); printf("\n\n"); // printf("size of encoded_bytes: %d\n\n", sizeof(encoded_bytes)); @@ -2373,6 +2377,8 @@ void get_tlm_fc() { } } } + printf("\nctr = %d\n\n", ctr); + /* open socket */ From 46fb18d6012077557c6a242e6d98a3321a370307 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 16:59:54 -0500 Subject: [PATCH 36/55] Update main.c change prints --- main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 79eb492a..661f777d 100644 --- a/main.c +++ b/main.c @@ -2293,15 +2293,17 @@ void get_tlm_fc() { int byte_count = 256; smaller = (int) (S_RATE / (2 * freq_Hz)); - printf("\n\n"); - for (int i=0; i<256; i++) - printf("%d ", source_bytes[i]); - printf("\n\n"); /* write telemetry into data buffer */ memset(source_bytes, 0x00, sizeof(source_bytes)); source_bytes[10] = (uint8_t) rnd_float(0,255); + printf("\nsource_bytes\n"); + for (int i=0; i<256; i++) + printf("%d ", source_bytes[i]); + printf("\n\n"); + + /* convert data buffer into stream buffer */ // const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count) @@ -2309,7 +2311,7 @@ void get_tlm_fc() { // CCodecAO40 ao40; unsigned char* encoded_bytes = encode((unsigned char*)source_bytes, byte_count); - printf("\n\n"); + printf("\nencoded_bytes\n"); for (int i=0; i<650; i++) printf("%d ", encoded_bytes[i]); printf("\n\n"); From 1d2e3a067a412e679d0a1f97f9f85a9b32146ecc Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 17:04:56 -0500 Subject: [PATCH 37/55] Update main.c add const --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 661f777d..ebae89b9 100644 --- a/main.c +++ b/main.c @@ -2309,7 +2309,7 @@ void get_tlm_fc() { // const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count) // CCodecAO40 ao40; - unsigned char* encoded_bytes = encode((unsigned char*)source_bytes, byte_count); + const unsigned char* encoded_bytes = encode((unsigned char*)source_bytes, byte_count); printf("\nencoded_bytes\n"); for (int i=0; i<650; i++) From 74eb0ad2f5c8ea1d9b5430ff76cd761d288ecf6f Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 17:10:37 -0500 Subject: [PATCH 38/55] Update main.c print BLOCKSIZE --- main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index ebae89b9..f17e2015 100644 --- a/main.c +++ b/main.c @@ -2295,6 +2295,8 @@ void get_tlm_fc() { /* write telemetry into data buffer */ + printf("\nBLOCKSIZE = %d\n", BLOCKSIZE); + memset(source_bytes, 0x00, sizeof(source_bytes)); source_bytes[10] = (uint8_t) rnd_float(0,255); @@ -2344,8 +2346,8 @@ void get_tlm_fc() { int bit = syncBits - i / samples + 1; val = syncWord; data = val & 1 << (bit - 1); - printf ("%d i: %d sync bit %d = %d \n", - ctr, i, bit, (data > 0) ); +// printf ("%d i: %d sync bit %d = %d \n", + // ctr, i, bit, (data > 0) ); if (data == 0) { phase *= -1; From 7feb25402226b64972127fd230f90fd1eb043171 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 17:12:59 -0500 Subject: [PATCH 39/55] Update main.c remove () --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index f17e2015..76730519 100644 --- a/main.c +++ b/main.c @@ -2311,7 +2311,7 @@ void get_tlm_fc() { // const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count) // CCodecAO40 ao40; - const unsigned char* encoded_bytes = encode((unsigned char*)source_bytes, byte_count); + const unsigned char* encoded_bytes = encode(source_bytes, byte_count); printf("\nencoded_bytes\n"); for (int i=0; i<650; i++) From a2f35f42417a88b3f491d4a1580191c881be5446 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 17:17:51 -0500 Subject: [PATCH 40/55] Update main.c print --- main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main.c b/main.c index 76730519..a7eb0fcb 100644 --- a/main.c +++ b/main.c @@ -2296,6 +2296,7 @@ void get_tlm_fc() { /* write telemetry into data buffer */ printf("\nBLOCKSIZE = %d\n", BLOCKSIZE); + printf("\nSYMPBLOCK = %d\n", SYMPBLOCK); memset(source_bytes, 0x00, sizeof(source_bytes)); source_bytes[10] = (uint8_t) rnd_float(0,255); From c76db650877447a3d4e2cc1786e18eca908254b9 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 17:24:36 -0500 Subject: [PATCH 41/55] Update main.c change from bytes to bits in encoded --- main.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index a7eb0fcb..4f459c76 100644 --- a/main.c +++ b/main.c @@ -2315,8 +2315,8 @@ void get_tlm_fc() { const unsigned char* encoded_bytes = encode(source_bytes, byte_count); printf("\nencoded_bytes\n"); - for (int i=0; i<650; i++) - printf("%d ", encoded_bytes[i]); + for (int i=0; i<5200; i++) + printf("%d", encoded_bytes[i]); printf("\n\n"); // printf("size of encoded_bytes: %d\n\n", sizeof(encoded_bytes)); @@ -2365,13 +2365,14 @@ void get_tlm_fc() { { write_wave(ctr, buffer); if ((i % samples) == 0) { - int symbol = (int)((i - 1) / (samples * 8)); - int bit = 8 - (i - symbol * samples * 8) / samples + 1; - val = encoded_bytes[symbol]; - data = val & 1 << (bit - 1); + // int symbol = (int)((i - 1) / (samples * 8)); + // int bit = 8 - (i - symbol * samples * 8) / samples + 1; +// val = encoded_bytes[symbol]; +// data = val & 1 << (bit - 1); // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); - + symbol = i / samples; + data = encoded_bytes[symbol]; if (data == 0) { phase *= -1; if ((ctr - smaller) > 0) { From 28604844dc1aa04b204d0cf9eb850e8af42af9df Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 17:25:09 -0500 Subject: [PATCH 42/55] Update main.c missing int --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 4f459c76..23f9e617 100644 --- a/main.c +++ b/main.c @@ -2371,7 +2371,7 @@ void get_tlm_fc() { // data = val & 1 << (bit - 1); // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); - symbol = i / samples; + int symbol = i / samples; data = encoded_bytes[symbol]; if (data == 0) { phase *= -1; From 6d05cce4d51ad4639dd10b2bfbd4e4db3b0a89f9 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 22:57:11 -0500 Subject: [PATCH 43/55] Update main.c added sleeps --- main.c | 58 ++++++++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/main.c b/main.c index 23f9e617..8423f980 100644 --- a/main.c +++ b/main.c @@ -511,16 +511,17 @@ int main(int argc, char * argv[]) { bufLen = (headerLen + syncBits + dataLen)/8; // samplePeriod = ((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))))/(float)bitRate) * 1000 - 1800; - samplePeriod = 5000; + samplePeriod = 5000; // samplePeriod = 3000; // sleepTime = 3.0; //samplePeriod = 2200; // reduce dut to python and sensor querying delays // sleepTime = 2.2f; - frameTime = ((float)((float)bufLen / (samples * frameCnt * bitRate))) * 1000; // frame time in ms - +// frameTime = ((float)((float)bufLen / (samples * frameCnt * bitRate))) * 1000; // frame time in ms + frameTime = 5000; + printf("\n FC Mode, bufLen: %d, %d bits per frame, %d bits per second, %d ms per frame %d ms sample period\n", - bufLen, bufLen / samples, bitRate, frameTime, samplePeriod); + bufLen, bufLen / samples, bitRate, frameTime, samplePeriod); sin_samples = S_RATE/freq_Hz; for (int j = 0; j < sin_samples; j++) { @@ -2291,42 +2292,37 @@ void get_tlm_fc() { unsigned char source_bytes[256]; // unsigned char encoded_bytes[650]; int byte_count = 256; - smaller = (int) (S_RATE / (2 * freq_Hz)); /* write telemetry into data buffer */ - printf("\nBLOCKSIZE = %d\n", BLOCKSIZE); - printf("\nSYMPBLOCK = %d\n", SYMPBLOCK); +// printf("\nBLOCKSIZE = %d\n", BLOCKSIZE); +// printf("\nSYMPBLOCK = %d\n", SYMPBLOCK); memset(source_bytes, 0x00, sizeof(source_bytes)); source_bytes[10] = (uint8_t) rnd_float(0,255); - +/* printf("\nsource_bytes\n"); for (int i=0; i<256; i++) printf("%d ", source_bytes[i]); printf("\n\n"); - +*/ /* convert data buffer into stream buffer */ -// const unsigned char *CCodecAO40::encode(unsigned char *source_bytes, int byte_count) - -// CCodecAO40 ao40; const unsigned char* encoded_bytes = encode(source_bytes, byte_count); - +/* printf("\nencoded_bytes\n"); for (int i=0; i<5200; i++) printf("%d", encoded_bytes[i]); printf("\n\n"); -// printf("size of encoded_bytes: %d\n\n", sizeof(encoded_bytes)); - +*/ /* convert to waveform buffer */ int data; int val; int i; - //int offset = 0; ctr = 0; + smaller = (int) (S_RATE / (2 * freq_Hz)); for (i = 1; i <= headerLen * samples; i++) { write_wave(ctr, buffer); @@ -2348,8 +2344,7 @@ void get_tlm_fc() { val = syncWord; data = val & 1 << (bit - 1); // printf ("%d i: %d sync bit %d = %d \n", - // ctr, i, bit, (data > 0) ); - + // ctr, i, bit, (data > 0) ); if (data == 0) { phase *= -1; if ((ctr - smaller) > 0) { @@ -2361,7 +2356,7 @@ void get_tlm_fc() { } } - for (i = 1; i <= (dataLen * samples); i++) // 572 + for (i = 1; i <= (dataLen * samples); i++) // 5200 { write_wave(ctr, buffer); if ((i % samples) == 0) { @@ -2475,7 +2470,7 @@ void get_tlm_fc() { start = millis(); int sock_ret = send(sock, buffer, length, 0); // printf("socket send 1 %d ms bytes: %d \n\n", (unsigned int)millis() - start, sock_ret); - fflush(stdout); +// fflush(stdout); if (sock_ret < length) { // printf("Not resending\n"); @@ -2496,22 +2491,17 @@ void get_tlm_fc() { fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); } + int startSleep = millis(); + if ((millis() - sampleTime) < ((unsigned int)frameTime - 750 + pi_zero_2_offset)) + sleep(1.0); + while ((millis() - sampleTime) < ((unsigned int)frameTime - 750 + pi_zero_2_offset)) + sleep(0.1); + printf("Start sleep %d Sleep period: %d while period: %d\n", startSleep, millis() - startSleep, (unsigned int)frameTime - 750 + pi_zero_2_offset); + sampleTime = (unsigned int) millis(); // resetting time for sleeping + fflush(stdout); + if (socket_open == 1) firstTime = 0; return; } - - /* from funcubeLib/common/testFec.cpp - - U8 sourceBytes[BLOCK_SIZE]; - memset(sourceBytes, 42, BLOCK_SIZE); - - CCodecAO40 ao40; - const U8* encoded = ao40.encode((unsigned char*)sourceBytes, BLOCK_SIZE); - */ - -// mode = BPSK; -// get_tlm_fox(); // for now, do same as BPSK -// mode = FC; -// } From b4c6f588f4380f63888ca92b888b47255f5497bd Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 19 Jan 2025 23:25:11 -0500 Subject: [PATCH 44/55] Update main.c fix sleep time --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 8423f980..e9e3a23e 100644 --- a/main.c +++ b/main.c @@ -2492,11 +2492,11 @@ void get_tlm_fc() { } int startSleep = millis(); - if ((millis() - sampleTime) < ((unsigned int)frameTime - 750 + pi_zero_2_offset)) + if ((millis() - sampleTime) < ((unsigned int)frameTime)) // - 750 + pi_zero_2_offset)) sleep(1.0); - while ((millis() - sampleTime) < ((unsigned int)frameTime - 750 + pi_zero_2_offset)) + while ((millis() - sampleTime) < ((unsigned int)frameTime)) // - 750 + pi_zero_2_offset)) sleep(0.1); - printf("Start sleep %d Sleep period: %d while period: %d\n", startSleep, millis() - startSleep, (unsigned int)frameTime - 750 + pi_zero_2_offset); + printf("Start sleep %d Sleep period: %d while period: %d\n", startSleep, millis() - startSleep, millis() - sampleTime); sampleTime = (unsigned int) millis(); // resetting time for sleeping fflush(stdout); From 1fb6cda81e67b69ee9d41c0b92cf074f92372728 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 09:01:50 -0500 Subject: [PATCH 45/55] Update main.c print smaller --- main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main.c b/main.c index e9e3a23e..71c805e7 100644 --- a/main.c +++ b/main.c @@ -2323,6 +2323,7 @@ void get_tlm_fc() { int i; ctr = 0; smaller = (int) (S_RATE / (2 * freq_Hz)); + printf("\n\nsmaller = %d \n\n",smaller); for (i = 1; i <= headerLen * samples; i++) { write_wave(ctr, buffer); From 83b91ee4b102507d03c00d45ba5ab4a1c8e331b9 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 09:04:10 -0500 Subject: [PATCH 46/55] Update main.c print buffer --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 71c805e7..e1b91556 100644 --- a/main.c +++ b/main.c @@ -1980,7 +1980,7 @@ void write_wave(int i, short int *buffer) else // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } -// printf("%d %d \n", i, buffer[ctr - 1]); + printf("%d %d \n", i, buffer[ctr - 1]); } From 684f1e444378df70c51e8f170a8f161a0c9d4952 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 09:11:55 -0500 Subject: [PATCH 47/55] Update main.c print * for flip_ctr --- main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index e1b91556..61ba76a6 100644 --- a/main.c +++ b/main.c @@ -1974,9 +1974,11 @@ void write_wave(int i, short int *buffer) } else { - if ((ctr - flip_ctr) < smaller) + if ((ctr - flip_ctr) < smaller) { // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples] / 2); + printf("*"); + } else // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } From 0c5c7938775ea6f39277233920e470c708e4f389 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 09:17:45 -0500 Subject: [PATCH 48/55] Update main.c only print < 1000 --- main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 61ba76a6..f8b693b4 100644 --- a/main.c +++ b/main.c @@ -1977,12 +1977,13 @@ void write_wave(int i, short int *buffer) if ((ctr - flip_ctr) < smaller) { // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples] / 2); - printf("*"); + if (ctr < 1000) printf("*"); } else // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } - printf("%d %d \n", i, buffer[ctr - 1]); + buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); + } + if (ctr < 1000) printf("%d %d \n", i, buffer[ctr - 1]); } From b6718b536f7775a213122e5f40edff9e9655521b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 09:21:36 -0500 Subject: [PATCH 49/55] Update main.c print smaller if < 1000 --- main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main.c b/main.c index f8b693b4..12f1abe3 100644 --- a/main.c +++ b/main.c @@ -2377,6 +2377,7 @@ void get_tlm_fc() { if ((ctr - smaller) > 0) { for (int j = 1; j <= smaller; j++) buffer[ctr - j] = buffer[ctr - j] * 0.4; + if (ctr < 1000) printf("# %d %d\n", ctr - j, buffer[ctr - j]); } flip_ctr = ctr; } From c640b477a908762b1a116f96b2e0ebda687136d2 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 09:24:20 -0500 Subject: [PATCH 50/55] Update main.c fix j --- main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 12f1abe3..5eac6139 100644 --- a/main.c +++ b/main.c @@ -2375,7 +2375,8 @@ void get_tlm_fc() { if (data == 0) { phase *= -1; if ((ctr - smaller) > 0) { - for (int j = 1; j <= smaller; j++) + int j; + for (j = 1; j <= smaller; j++) buffer[ctr - j] = buffer[ctr - j] * 0.4; if (ctr < 1000) printf("# %d %d\n", ctr - j, buffer[ctr - j]); } From 9e102a166e4d4bf6bff4732883a4830888b211b0 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 09:39:13 -0500 Subject: [PATCH 51/55] Update main.c fix {} --- main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 5eac6139..f6213a6c 100644 --- a/main.c +++ b/main.c @@ -1983,7 +1983,7 @@ void write_wave(int i, short int *buffer) // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } - if (ctr < 1000) printf("%d %d \n", i, buffer[ctr - 1]); + if (ctr < 1000) printf("%d %d %d \n", ctr, i, buffer[ctr - 1]); } @@ -2376,9 +2376,10 @@ void get_tlm_fc() { phase *= -1; if ((ctr - smaller) > 0) { int j; - for (j = 1; j <= smaller; j++) + for (j = 1; j <= smaller; j++) { buffer[ctr - j] = buffer[ctr - j] * 0.4; if (ctr < 1000) printf("# %d %d\n", ctr - j, buffer[ctr - j]); + } } flip_ctr = ctr; } From 81b0746c2937c69309093bf35eed1df05b75d5bd Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 09:48:43 -0500 Subject: [PATCH 52/55] Update main.c print smaller --- main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index f6213a6c..96f7df2d 100644 --- a/main.c +++ b/main.c @@ -2333,8 +2333,11 @@ void get_tlm_fc() { if ((i % samples) == 0) { phase *= -1; if ((ctr - smaller) > 0) { - for (int j = 1; j <= smaller; j++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; + int j; + for (j = 1; j <= smaller; j++) { + buffer[ctr - j] = buffer[ctr - j] * 0.4; + if (ctr < 1000) printf("# %d %d\n", ctr - j, buffer[ctr - j]); + } } flip_ctr = ctr; } From 349e2d7ca014ea281cd4667f76203e20ca984a2b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 09:53:50 -0500 Subject: [PATCH 53/55] Update main.c remove prints --- main.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index 96f7df2d..e7903a0a 100644 --- a/main.c +++ b/main.c @@ -1977,13 +1977,13 @@ void write_wave(int i, short int *buffer) if ((ctr - flip_ctr) < smaller) { // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples] / 2); - if (ctr < 1000) printf("*"); +// if (ctr < 1000) printf("*"); } else // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } - if (ctr < 1000) printf("%d %d %d \n", ctr, i, buffer[ctr - 1]); +// if (ctr < 1000) printf("%d %d %d \n", ctr, i, buffer[ctr - 1]); } @@ -2335,8 +2335,8 @@ void get_tlm_fc() { if ((ctr - smaller) > 0) { int j; for (j = 1; j <= smaller; j++) { - buffer[ctr - j] = buffer[ctr - j] * 0.4; - if (ctr < 1000) printf("# %d %d\n", ctr - j, buffer[ctr - j]); + buffer[ctr - j] = buffer[ctr - j] * 0.5; +// if (ctr < 1000) printf("# %d %d\n", ctr - j, buffer[ctr - j]); } } flip_ctr = ctr; @@ -2355,8 +2355,9 @@ void get_tlm_fc() { if (data == 0) { phase *= -1; if ((ctr - smaller) > 0) { - for (int j = 1; j <= smaller; j++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; + int j; + for (j = 1; j <= smaller; j++) + buffer[ctr - j] = buffer[ctr - j] * 0.5; } flip_ctr = ctr; } @@ -2380,8 +2381,8 @@ void get_tlm_fc() { if ((ctr - smaller) > 0) { int j; for (j = 1; j <= smaller; j++) { - buffer[ctr - j] = buffer[ctr - j] * 0.4; - if (ctr < 1000) printf("# %d %d\n", ctr - j, buffer[ctr - j]); + buffer[ctr - j] = buffer[ctr - j] * 0.5; +// if (ctr < 1000) printf("# %d %d\n", ctr - j, buffer[ctr - j]); } } flip_ctr = ctr; From 5a271f314cb0021fe73102390000052c698b0c11 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 10:19:44 -0500 Subject: [PATCH 54/55] Update main.c try sin wave --- main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index e7903a0a..60c53e7f 100644 --- a/main.c +++ b/main.c @@ -1975,13 +1975,15 @@ void write_wave(int i, short int *buffer) else { if ((ctr - flip_ctr) < smaller) { -// buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples] / 2); +// buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); + buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); +// buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples] / 2); // if (ctr < 1000) printf("*"); } else -// buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); +// buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); + buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); +// buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } // if (ctr < 1000) printf("%d %d %d \n", ctr, i, buffer[ctr - 1]); From af38f7ff002a5b69c455914a01a675afa1078b4c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 20 Jan 2025 10:24:58 -0500 Subject: [PATCH 55/55] Update main.c cleanup --- main.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 60c53e7f..82197709 100644 --- a/main.c +++ b/main.c @@ -1976,14 +1976,12 @@ void write_wave(int i, short int *buffer) { if ((ctr - flip_ctr) < smaller) { // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); -// buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples] / 2); + buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples] / 2); // if (ctr < 1000) printf("*"); } else // buffer[ctr++] = (short int)(amplitude * 0.4 * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - buffer[ctr++] = (short int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); -// buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); + buffer[ctr++] = (short int)(phase * sin_map[ctr % sin_samples]); } // if (ctr < 1000) printf("%d %d %d \n", ctr, i, buffer[ctr - 1]); @@ -2328,7 +2326,7 @@ void get_tlm_fc() { int i; ctr = 0; smaller = (int) (S_RATE / (2 * freq_Hz)); - printf("\n\nsmaller = %d \n\n",smaller); +// printf("\n\nsmaller = %d \n\n",smaller); for (i = 1; i <= headerLen * samples; i++) { write_wave(ctr, buffer);