diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b7fccb3 --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +CC := gcc +CCFLAG := -Wall -O2 -std=c99 +DBGFLAG := -g +CCOBJFLAG := $(CCFLAG) -c + +BIN_PATH := bin +OBJ_PATH := obj +SRC_PATH := src +DBG_PATH := debug + +TARGET_NAME := m17enc +TARGET := $(BIN_PATH)/$(TARGET_NAME) +TARGET_DEBUG := $(DBG_PATH)/$(TARGET_NAME) +MAIN_SRC := src/M17_RF_streamgen.c + +SRC := $(foreach x, $(SRC_PATH), $(wildcard $(addprefix $(x)/*,.c*))) +OBJ := $(addprefix $(OBJ_PATH)/, $(addsuffix .o, $(notdir $(basename $(SRC))))) +OBJ_DEBUG := $(addprefix $(DBG_PATH)/, $(addsuffix .o, $(notdir $(basename $(SRC))))) + +DISTCLEAN_LIST := $(OBJ) $(OBJ_DEBUG) +CLEAN_LIST := $(TARGET) $(TARGET_DEBUG) $(DISTCLEAN_LIST) + +default: all + +$(TARGET): $(OBJ) + $(CC) $(CCFLAG) -o $@ $? + +$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c* + $(CC) $(CCOBJFLAG) -o $@ $< + +$(DBG_PATH)/%.o: $(SRC_PATH)/%.c* + $(CC) $(CCOBJFLAG) $(DBGFLAG) -o $@ $< + +$(TARGET_DEBUG): $(OBJ_DEBUG) + $(CC) $(CCFLAG) $(DBGFLAG) $? -o $@ + +.PHONY: all +all: $(TARGET) + +.PHONY: debug +debug: $(TARGET_DEBUG) + +.PHONY: clean +clean: + @echo CLEAN $(CLEAN_LIST) + @rm -f $(CLEAN_LIST) + +.PHONY: distclean +distclean: + @echo CLEAN $(DISTCLEAN_LIST) + @rm -f $(DISTCLEAN_LIST) diff --git a/README.md b/README.md index 20ed3ac..7b4955e 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,20 @@ Generates an M17 RF stream for Codec2-encoded speech files ('c2enc' output). **M17_RF_streamgen.c** - main program. Just a sketch right now. **dummy.c** - can generate a pseudorandom bitstream with legitimate sync patterns. This can be used to check receivers. + +# Installation + +``` +make +``` + +# Nomenclature + +# Example +This example records local audio and generates a M17-compliant RF stream into +a file. Codec2 and SoX need to be installed. + +``` +rec -t raw -r 8000 --buffer 2048 -e signed-integer -b 16 -c 1 - | \ +c2enc 3200 - - | m17enc DL1FROM DL1TO - out.raw +``` diff --git a/bin/m17enc b/bin/m17enc new file mode 100755 index 0000000..d232d35 Binary files /dev/null and b/bin/m17enc differ diff --git a/dummy.c b/example/dummy.c similarity index 100% rename from dummy.c rename to example/dummy.c diff --git a/obj/M17_RF_streamgen.o b/obj/M17_RF_streamgen.o new file mode 100644 index 0000000..905a80b Binary files /dev/null and b/obj/M17_RF_streamgen.o differ diff --git a/obj/main.o b/obj/main.o new file mode 100644 index 0000000..cda7c3c Binary files /dev/null and b/obj/main.o differ diff --git a/M17_RF_streamgen.c b/src/M17_RF_streamgen.c similarity index 79% rename from M17_RF_streamgen.c rename to src/M17_RF_streamgen.c index d72f8d5..5c22693 100644 --- a/M17_RF_streamgen.c +++ b/src/M17_RF_streamgen.c @@ -2,6 +2,7 @@ #include #include #include +#include #define LEAD_PREAM 40 //first (lead) preamble length in ms @@ -33,12 +34,13 @@ const uint8_t sync_1[2]={0x32, 0x43}; //SYNC for the link setup frame const uint8_t sync_2[2]={0x2B, 0x7E}; //SYNC for all subsequent frames uint8_t ConvolLUT[32]; //a look-up table for convolutional encoder -uint8_t type_1[30]; //type-1 packed bits +uint8_t type_1[30]; //type-1 packed bits uint8_t type_1_u[300]; //type-1 unpacked bits uint8_t type_2[500]; //type-2 unpacked bits uint8_t type_3[384]; uint8_t type_4[384]; FILE *f_out; +FILE *f_in; //Takes an ASCII callsign in a null terminated char* and encodes it using base 40. //Returns -1 (all Fs) if the provided callsign is longer than 9 characters, which @@ -164,16 +166,17 @@ int main(int argc, char *argv[]) { uint16_t type=(1<<0)|(0b10<<1); //type indicator - stream, voice, codec2 3200bps, no encryption uint8_t nonce[16]={0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; - - if(argc==4) + + if(argc==5) { - dest_addr.val=encode_callsign_base40(argv[2]); - src_addr.val=encode_callsign_base40(argv[3]); + // link setup + dest_addr.val=encode_callsign_base40(argv[1]); + src_addr.val=encode_callsign_base40(argv[2]); printf("DEST\t0x%012llX\n", dest_addr.val); printf("SRC \t0x%012llX\n", src_addr.val); - f_out=fopen(argv[1], "wb"); + f_out=fopen(argv[4], "wb"); //preamble for(uint16_t i=0; i<(LEAD_PREAM*9600)/1000; i++) @@ -206,14 +209,42 @@ int main(int argc, char *argv[]) //convolutionally encode type-1 to type-2 ; - - fclose(f_out); - + + // frames + if(!strcmp(argv[3], "-")) + { + f_in = stdin; + } else { + f_in = fopen(argv[1], "rb"); + + if(f_in == NULL) + { + printf("No valid input data to work with\n"); + + return 1; + } + } + + uint8_t payload[16]; + size_t bytes = 0; + + while(1) + { + bytes = fread(payload, 1, 16, f_in); + fwrite(payload, 1, 16, f_out); + + if(bytes < 16) + if(feof(f_in)) break; + } + + fclose(f_in); + fclose(f_out); + return 0; } else { - printf("Not enough params\n"); + printf("Invalid number of params\n"); return 1; }