NCurses and NXDN Updates

NCurses Terminal in pretty good shape, good enough for testing
NXDN decodes RAN and RID now (from LEH)
This commit is contained in:
lwvmobile
2022-02-18 19:05:14 -05:00
committed by GitHub
parent 46196cf283
commit 6f2682d667
18 changed files with 3291 additions and 204 deletions

View File

@@ -71,8 +71,84 @@
*/
static volatile int exitflag;
//volatile int exitflag; //didn't work, couldn't build, multiple definitions of exitflag
//borrow from LEH
typedef struct
{
uint8_t RFChannelType;
uint8_t FunctionnalChannelType;
uint8_t Option;
uint8_t Direction;
uint8_t CompleteLich; /* 7 bits of LICH without parity */
uint8_t PreviousCompleteLich; /* 7 bits of previous LICH without parity */
} NxdnLich_t;
typedef struct
{
uint8_t StructureField;
uint8_t RAN;
uint8_t Data[18];
uint8_t CrcIsGood;
} NxdnSacchRawPart_t;
typedef struct
{
uint8_t Data[80];
uint8_t CrcIsGood;
} NxdnFacch1RawPart_t;
typedef struct
{
uint8_t Data[184];
uint8_t CrcIsGood;
} NxdnFacch2RawPart_t;
typedef struct
{
uint8_t F1;
uint8_t F2;
uint8_t MessageType;
/****************************/
/***** VCALL parameters *****/
/****************************/
uint8_t CCOption;
uint8_t CallType;
uint8_t VoiceCallOption;
uint16_t SourceUnitID;
uint16_t DestinationID; /* May be a Group ID or a Unit ID */
uint8_t CipherType;
uint8_t KeyID;
uint8_t VCallCrcIsGood;
/*******************************/
/***** VCALL_IV parameters *****/
/*******************************/
uint8_t IV[8];
uint8_t VCallIvCrcIsGood;
/*****************************/
/***** Custom parameters *****/
/*****************************/
/* Specifies if the "CipherType" and the "KeyID" parameter are valid
* 1 = Valid ; 0 = CRC error */
uint8_t CipherParameterValidity;
/* Used on DES and AES encrypted frames */
uint8_t PartOfCurrentEncryptedFrame; /* Could be 1 or 2 */
uint8_t PartOfNextEncryptedFrame; /* Could be 1 or 2 */
uint8_t CurrentIVComputed[8];
uint8_t NextIVComputed[8];
} NxdnElementsContent_t;
//end borrow from LEH
typedef struct
{
@@ -194,7 +270,8 @@ typedef struct
int maxbuf[1024];
int minbuf[1024];
int midx;
char err_str[64];
char err_str[64]; //actual error errorbars
char err_buf[64]; //make copy of err_str for comparison, only have string print when strcmp is different??
char fsubtype[16];
char ftype[16];
int symbolcnt;
@@ -248,6 +325,35 @@ typedef struct
short input_sample_buffer; //HERE HERE
short pulse_raw_out_buffer; //HERE HERE
//float *input_sample_buffer; //HERE HERE
short dibit_to_hex_buf;
// state->sr_0 shift registers
short hexbuf;
unsigned long long sr_0; //64-bit shift registers for pushing decoded binary or dibit data
unsigned long long sr_1; //384
unsigned long long sr_2; //
unsigned long long sr_3; //
unsigned long long sr_4; //
unsigned long long sr_5; //
unsigned long long sr_6; //
unsigned int dmr_color_code;
unsigned int nxdn_last_ran;
unsigned int nxdn_last_rid;
//borrow from LEH
NxdnSacchRawPart_t NxdnSacchRawPart[4];
NxdnFacch1RawPart_t NxdnFacch1RawPart[2];
NxdnFacch2RawPart_t NxdnFacch2RawPart;
NxdnElementsContent_t NxdnElementsContent;
NxdnLich_t NxdnLich;
int printNXDNAmbeVoiceSampleHex;
char ambe_ciphered[49];
char ambe_deciphered[49];
//end borrow
#ifdef TRACE_DSD
char debug_prefix;
@@ -277,34 +383,34 @@ typedef struct
#define INV_DSTAR_HD "313131313111311331313333"
#define DSTAR_SYNC "313131313133131113313111"
#define INV_DSTAR_SYNC "131313131311313331131333"
// original sync numbers which is FSW plus LICH
//bogus nxdnn data syncs to troubleshoot
/*
#define NXDN_MS_DATA_SYNC "33333313133113131111333333333111"
#define INV_NXDN_MS_DATA_SYNC "11133331313113313133331113333331"
#define INV_NXDN_BS_DATA_SYNC "33331111313113313133331313333333"
#define NXDN_BS_DATA_SYNC "11113333131331131311113133333333"
//end bogus nxdn data syncs
*/
#define NXDN_MS_DATA_SYNC "313133113131111333"
#define INV_NXDN_MS_DATA_SYNC "131311331313333111"
#define NXDN_MS_VOICE_SYNC "313133113131113133"
#define INV_NXDN_MS_VOICE_SYNC "131311331313331311"
#define INV_NXDN_BS_DATA_SYNC "131311331313333131"
#define NXDN_BS_DATA_SYNC "313133113131111313"
#define INV_NXDN_BS_VOICE_SYNC "131311331313331331"
#define NXDN_BS_VOICE_SYNC "313133113131113113"
//Try using only FSW and no LICH
/*
#define NXDN_MS_DATA_SYNC "3131331131"
#define INV_NXDN_MS_DATA_SYNC "1313113313"
#define NXDN_MS_VOICE_SYNC "313133113131113133"
#define INV_NXDN_MS_VOICE_SYNC "131311331313331311"
#define INV_NXDN_BS_DATA_SYNC "1313113313"
#define NXDN_BS_DATA_SYNC "3131331131"
#define INV_NXDN_BS_VOICE_SYNC "131311331313331331"
#define NXDN_BS_VOICE_SYNC "313133113131113113"
//how do two values equate to 4 symbol types? shouldn't it be -3, -1, 1, 3?
*/
#define DMR_BS_DATA_SYNC "313333111331131131331131"
#define DMR_BS_VOICE_SYNC "131111333113313313113313"
#define DMR_MS_DATA_SYNC "311131133313133331131113"
#define DMR_MS_VOICE_SYNC "133313311131311113313331"
//borrow extra syncs from LEH
#define DMR_DIRECT_MODE_TS1_DATA_SYNC "331333313111313133311111"
#define DMR_DIRECT_MODE_TS1_VOICE_SYNC "113111131333131311133333"
#define DMR_DIRECT_MODE_TS2_DATA_SYNC "311311111333113333133311"
#define DMR_DIRECT_MODE_TS2_VOICE_SYNC "133133333111331111311133"
//end LEH
#define INV_PROVOICE_SYNC "31313111333133133311331133113311"
#define PROVOICE_SYNC "13131333111311311133113311331133"
#define INV_PROVOICE_EA_SYNC "13313133113113333311313133133311"
@@ -374,13 +480,60 @@ short nxdn_filter(short sample);
//borrow from LEH for testing 'improved NXDN detection'
int strncmperr(const char *s1, const char *s2, size_t size, int MaxErr);
/* Global functions */ //also borrowed
uint32_t ConvertBitIntoBytes(uint8_t * BufferIn, uint32_t BitLength);
uint32_t ConvertAsciiToByte(uint8_t AsciiMsbByte, uint8_t AsciiLsbByte, uint8_t * OutputByte);
void Convert49BitSampleInto7Bytes(char * InputBit, char * OutputByte);
void Convert7BytesInto49BitSample(char * InputByte, char * OutputBit);
//
//ifdef ncurses
void ncursesOpen ();
void ncursesPrinter (dsd_opts * opts, dsd_state * state);
void ncursesClose ();
//endif ncurses
//borrow from LEH
/* NXDN frame decoding functions */
void ProcessNXDNFrame(dsd_opts * opts, dsd_state * state, uint8_t Inverted);
void ProcessNxdnRCCHFrame(dsd_opts * opts, dsd_state * state, uint8_t Inverted);
void ProcessNxdnRTCHFrame(dsd_opts * opts, dsd_state * state, uint8_t Inverted);
void ProcessNxdnRDCHFrame(dsd_opts * opts, dsd_state * state, uint8_t Inverted);
void ProcessNxdnRTCH_C_Frame(dsd_opts * opts, dsd_state * state, uint8_t Inverted);
void ProcessNXDNIdleData (dsd_opts * opts, dsd_state * state, uint8_t Inverted);
void ProcessNXDNFacch1Data (dsd_opts * opts, dsd_state * state, uint8_t Inverted);
void ProcessNXDNUdchData (dsd_opts * opts, dsd_state * state, uint8_t Inverted);
//end borrow
//borrow from LEH
/* NXDN functions */
void CNXDNConvolution_start(void);
void CNXDNConvolution_decode(uint8_t s0, uint8_t s1);
void CNXDNConvolution_chainback(unsigned char* out, unsigned int nBits);
void CNXDNConvolution_encode(const unsigned char* in, unsigned char* out, unsigned int nBits);
uint8_t NXDN_decode_LICH(uint8_t InputLich[8],
uint8_t * RFChannelType,
uint8_t * FunctionnalChannelType,
uint8_t * Option,
uint8_t * Direction,
uint8_t * CompleteLichBinaryFormat,
uint8_t Inverted);
uint8_t NXDN_SACCH_raw_part_decode(uint8_t * Input, uint8_t * Output);
void NXDN_SACCH_Full_decode(dsd_opts * opts, dsd_state * state);
uint8_t NXDN_FACCH1_decode(uint8_t * Input, uint8_t * Output);
uint8_t NXDN_UDCH_decode(uint8_t * Input, uint8_t * Output);
void NXDN_Elements_Content_decode(dsd_opts * opts, dsd_state * state,
uint8_t CrcCorrect, uint8_t * ElementsContent);
void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message);
void NXDN_decode_VCALL_IV(dsd_opts * opts, dsd_state * state, uint8_t * Message);
char * NXDN_Call_Type_To_Str(uint8_t CallType);
void NXDN_Voice_Call_Option_To_Str(uint8_t VoiceCallOption, uint8_t * Duplex, uint8_t * TransmissionMode);
char * NXDN_Cipher_Type_To_Str(uint8_t CipherType);
uint16_t CRC15BitNXDN(uint8_t * BufferIn, uint32_t BitLength);
uint16_t CRC12BitNXDN(uint8_t * BufferIn, uint32_t BitLength);
uint8_t CRC6BitNXDN(uint8_t * BufferIn, uint32_t BitLength);
void ScrambledNXDNVoiceBit(int * LfsrValue, char * BufferIn, char * BufferOut, int NbOfBitToScramble);
void NxdnEncryptionStreamGeneration (dsd_opts* opts, dsd_state* state, uint8_t KeyStream[1664]);
void processMbeFrameEncrypted (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24], char ambe_keystream[49], char imbe_keystream[88]);
//end borrow from LEH
#ifdef __cplusplus

View File

@@ -21,13 +21,88 @@ extern const int nX[36];
extern const int nY[36];
extern const int nZ[36];
extern const char nxdnpr[145];
extern const char nxdnpr2[145]; //why is this 145 but referenced later as 182 or 384
//borrow from LEH
extern const unsigned char nsW[72];
extern const int DSDNXDN_SACCH_m_Interleave[60];
extern const int DSDNXDN_SACCH_m_PunctureList[12];
extern const int DSDNXDN_FACCH1_m_Interleave[144];
extern const int DSDNXDN_FACCH1_m_PunctureList[48];
extern const int DSDNXDN_UDCH_m_Interleave[348];
extern const int DSDNXDN_UDCH_m_PunctureList[58];
//
//enum
//{
#define NXDN_VCALL 0b000001 /* VCALL = VCALL_REQ = VCALL_RESP */
#define NXDN_VCALL_IV 0b000011
#define NXDN_DCALL_HDR 0b001001 /* Header Format - NXDN_DCALL_HDR = NXDN_DCALL_REQ = NXDN_DCALL_RESP */
#define NXDN_DCALL_USR 0b001011 /* User Data Format */
#define NXDN_DCALL_ACK 0b001100
#define NXDN_REL_EX 0b000111
#define NXDN_HEAD_DLY 0b001111
#define NXDN_SDCALL_REQ_HDR 0b111000 /* Header Format */
#define NXDN_SDCALL_REQ_USR 0b111001 /* User Data Format */
#define NXDN_SDCALL_RESP 0b111011
#define NXDN_SDCALL_IV 0b111010
#define NXDN_STAT_INQ_REQ 0b110000
#define NXDN_STAT_INQ_RESP 0b110001
#define NXDN_STAT_REQ 0b110010
#define NXDN_STAT_RESP 0b110011
#define NXDN_REM_CON_REQ 0b110100
#define NXDN_REM_CON_RESP 0b110101
#define NXDN_REM_CON_E_REQ 0b110110
#define NXDN_REM_CON_E_RESP 0b110111
//NXDN_VCALL_REQ = 0b000001, /* VCALL = VCALL_REQ = VCALL_RESP */
//NXDN_VCALL_RESP = 0b000001, /* VCALL = VCALL_REQ = VCALL_RESP */
#define NXDN_VCALL_REC_REQ = 0b000010 /* NXDN_VCALL_REC_REQ = NXDN_VCALL_REC_RESP */
//NXDN_VCALL_REC_RESP = 0b000010,
#define NXDN_VCALL_CONN_REQ = 0b000011 /* NXDN_VCALL_CONN_REQ = NXDN_VCALL_CONN_RESP */
//NXDN_VCALL_CONN_RESP = 0b000011, /* NXDN_VCALL_CONN_REQ = NXDN_VCALL_CONN_RESP */
#define NXDN_VCALL_ASSGN_DUP = 0b000101
//NXDN_DCALL_REQ = 0b001001, /* NXDN_DCALL_HDR = NXDN_DCALL_REQ = NXDN_DCALL_RESP */
//NXDN_DCALL_RESP = 0b001001, /* NXDN_DCALL_HDR = NXDN_DCALL_REQ = NXDN_DCALL_RESP */
#define NXDN_DCALL_REC_REQ = 0b001010 /* NXDN_DCALL_REC_REQ = NXDN_DCALL_REC_RESP */
//NXDN_DCALL_REC_RESP = 0b001010, /* NXDN_DCALL_REC_REQ = NXDN_DCALL_REC_RESP */
#define NXDN_DCALL_ASSGN = 0b001110
#define NXDN_DCALL_ASSGN_DUP = 0b001101
#define NXDN_IDLE = 0b010000
#define NXDN_DISC_REQ = 0b010001 /* NXDN_DISC_REQ = NXDN_DISC */
#define NXDN_DISC = 0b010001 /* NXDN_DISC_REQ = NXDN_DISC */
#else
/*
* pseudorandom bit sequence
*/
const char nxdnpr[145] = { 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1 };
//const unsigned char nxdnpr2[384] =
const unsigned char nxdnpr2[182] = //is this a problem, should it be 384/2 for dibits?
{
0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0,
1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0,
0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1,
0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1,
1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1,
1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0,
0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1,
0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1,
1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1,
1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1,
1, 1, 0, 0, 0, 1//, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1,
// 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0,
// 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0,
// 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
// 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1,
// 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0,
// 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1,
// 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1,
// 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1,
// 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0,
// 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0,
// 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
// 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1
};
/*
* NXDN AMBE interleave schedule
*/
@@ -63,4 +138,120 @@ const int nZ[36] = { 5, 3, 4, 2, 3, 1,
13, 2, 12, 1, 11, 0
};
/*
* NXDN SACCH interleave
*/
const unsigned char nsW[72] = {
0, 12, 24, 36, 48, 60,
1, 13, 25, 37, 49, 61,
2, 14, 26, 38, 50, 62,
3, 15, 27, 39, 51, 63,
4, 16, 28, 40, 52, 64,
5, 17, 29, 41, 53, 65,
6, 18, 30, 42, 54, 66,
7, 19, 31, 43, 55, 67,
8, 20, 32, 44, 56, 68,
9, 21, 33, 45, 57, 69,
10,22, 34, 46, 58, 70,
11,23, 35, 47, 59, 71
};
const int DSDNXDN_SACCH_m_Interleave[60] =
{
0, 12, 24, 36, 48,
1, 13, 25, 37, 49,
2, 14, 26, 38, 50,
3, 15, 27, 39, 51,
4, 16, 28, 40, 52,
5, 17, 29, 41, 53,
6, 18, 30, 42, 54,
7, 19, 31, 43, 55,
8, 20, 32, 44, 56,
9, 21, 33, 45, 57,
10, 22, 34, 46, 58,
11, 23, 35, 47, 59,
};
const int DSDNXDN_SACCH_m_PunctureList[12] = { 5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71 };
const unsigned int DSDNXDN_FACCH1_m_Interleave[144] =
{
0, 16, 32, 48, 64, 80, 96, 112, 128,
1, 17, 33, 49, 65, 81, 97, 113, 129,
2, 18, 34, 50, 66, 82, 98, 114, 130,
3, 19, 35, 51, 67, 83, 99, 115, 131,
4, 20, 36, 52, 68, 84, 100, 116, 132,
5, 21, 37, 53, 69, 85, 101, 117, 133,
6, 22, 38, 54, 70, 86, 102, 118, 134,
7, 23, 39, 55, 71, 87, 103, 119, 135,
8, 24, 40, 56, 72, 88, 104, 120, 136,
9, 25, 41, 57, 73, 89, 105, 121, 137,
10, 26, 42, 58, 74, 90, 106, 122, 138,
11, 27, 43, 59, 75, 91, 107, 123, 139,
12, 28, 44, 60, 76, 92, 108, 124, 140,
13, 29, 45, 61, 77, 93, 109, 125, 141,
14, 30, 46, 62, 78, 94, 110, 126, 142,
15, 31, 47, 63, 79, 95, 111, 127, 143,
};
const unsigned int DSDNXDN_FACCH1_m_PunctureList[48] =
{
1U, 5U, 9U, 13U, 17U, 21U, 25U, 29U, 33U, 37U,
41U, 45U, 49U, 53U, 57U, 61U, 65U, 69U, 73U, 77U,
81U, 85U, 89U, 93U, 97U, 101U, 105U, 109U, 113U, 117U,
121U, 125U, 129U, 133U, 137U, 141U, 145U, 149U, 153U, 157U,
161U, 165U, 169U, 173U, 177U, 181U, 185U, 189U
};
const int DSDNXDN_UDCH_m_Interleave[348] = {
0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300, 312, 324, 336,
1, 13, 25, 37, 49, 61, 73, 85, 97, 109, 121, 133, 145, 157, 169, 181, 193, 205, 217, 229, 241, 253, 265, 277, 289, 301, 313, 325, 337,
2, 14, 26, 38, 50, 62, 74, 86, 98, 110, 122, 134, 146, 158, 170, 182, 194, 206, 218, 230, 242, 254, 266, 278, 290, 302, 314, 326, 338,
3, 15, 27, 39, 51, 63, 75, 87, 99, 111, 123, 135, 147, 159, 171, 183, 195, 207, 219, 231, 243, 255, 267, 279, 291, 303, 315, 327, 339,
4, 16, 28, 40, 52, 64, 76, 88, 100, 112, 124, 136, 148, 160, 172, 184, 196, 208, 220, 232, 244, 256, 268, 280, 292, 304, 316, 328, 340,
5, 17, 29, 41, 53, 65, 77, 89, 101, 113, 125, 137, 149, 161, 173, 185, 197, 209, 221, 233, 245, 257, 269, 281, 293, 305, 317, 329, 341,
6, 18, 30, 42, 54, 66, 78, 90, 102, 114, 126, 138, 150, 162, 174, 186, 198, 210, 222, 234, 246, 258, 270, 282, 294, 306, 318, 330, 342,
7, 19, 31, 43, 55, 67, 79, 91, 103, 115, 127, 139, 151, 163, 175, 187, 199, 211, 223, 235, 247, 259, 271, 283, 295, 307, 319, 331, 343,
8, 20, 32, 44, 56, 68, 80, 92, 104, 116, 128, 140, 152, 164, 176, 188, 200, 212, 224, 236, 248, 260, 272, 284, 296, 308, 320, 332, 344,
9, 21, 33, 45, 57, 69, 81, 93, 105, 117, 129, 141, 153, 165, 177, 189, 201, 213, 225, 237, 249, 261, 273, 285, 297, 309, 321, 333, 345,
10, 22, 34, 46, 58, 70, 82, 94, 106, 118, 130, 142, 154, 166, 178, 190, 202, 214, 226, 238, 250, 262, 274, 286, 298, 310, 322, 334, 346,
11, 23, 35, 47, 59, 71, 83, 95, 107, 119, 131, 143, 155, 167, 179, 191, 203, 215, 227, 239, 251, 263, 275, 287, 299, 311, 323, 335, 347,
};
const int DSDNXDN_UDCH_m_PunctureList[58] = {
3, 11,
17, 25,
31, 39,
45, 53,
59, 67,
73, 81,
87, 95,
101, 109,
115, 123,
129, 137,
143, 151,
157, 165,
171, 179,
185, 193,
199, 207,
213, 221,
227, 235,
241, 249,
255, 263,
269, 277,
283, 291,
297, 305,
311, 319,
325, 333,
339, 347,
353, 361,
367, 375,
381, 389,
395, 403,
};
//#endif /* _MAIN */
#endif

View File

@@ -28,13 +28,18 @@ processDMRdata (dsd_opts * opts, dsd_state * state)
char cachdata[13];
char cc[5];
char bursttype[5];
int dcc_buf;
#ifdef DMR_DUMP
int k;
char syncbits[49];
char cachbits[25];
#endif
cc[0]=0;
cc[1]=0;
cc[2]=0;
cc[3]=0; //initialize with zeroes to prevent segfault down below
state->dmr_color_code = 0; //reset
cc[4] = 0;
bursttype[4] = 0;
@@ -95,8 +100,14 @@ processDMRdata (dsd_opts * opts, dsd_state * state)
{
dibit = (dibit ^ 2);
}
cc[0] = (1 & (dibit >> 1)) + 48; // bit 1
cc[1] = (1 & dibit) + 48; // bit 0
//c[0] = (1 & (dibit >> 1)) + 48; // bit 1
//cc[1] = (1 & dibit) + 48; // bit 0
cc[0] = (1 & (dibit >> 1)); // bit 1
cc[1] = (1 & dibit); // bit 0
dcc_buf = 0;
//dcc_buf = (1 & (dibit >> 1)) | (1 & dibit);
dcc_buf = ((1 & (dibit >> 1)) + 48) | ((1 & dibit) + 48);
dibit = *dibit_p;
dibit_p++;
@@ -104,8 +115,20 @@ processDMRdata (dsd_opts * opts, dsd_state * state)
{
dibit = (dibit ^ 2);
}
cc[2] = (1 & (dibit >> 1)) + 48; // bit 1
cc[3] = (1 & dibit) + 48; // bit 0
//cc[2] = (1 & (dibit >> 1)) + 48; // bit 1
//cc[3] = (1 & dibit) + 48; // bit 0
cc[2] = (1 & (dibit >> 1)); // bit 1
cc[3] = (1 & dibit); // bit 0
dcc_buf = dcc_buf << 2;
//dcc_buf = (1 & (dibit >> 1)) | (1 & dibit);
dcc_buf = ((1 & (dibit >> 1)) + 48) | ((1 & dibit) + 48);
//state->dmr_color_code = dcc_buf;
state->dmr_color_code = (unsigned int)((cc[0] << 3) + (cc[1] << 2) + (cc[2] << 1) + cc[3]);
//cc[2] = (1 & (dibit >> 1)); // bit 1
//cc[3] = (1 & dibit); // bit 0
dibit = *dibit_p;
dibit_p++;

View File

@@ -358,6 +358,61 @@ static int digitize (dsd_opts* opts, dsd_state* state, int symbol)
}
state->last_dibit = dibit;
//test loading up a shift register and printing it to stderr
//di-bit shift register for hex values
//check for which dibit is equal to which half-nibble
if (dibit == 0){state->hexbuf = 0x0;} //+1
if (dibit == 1){state->hexbuf = 0x1;} //+3
if (dibit == 2){state->hexbuf = 0x2;} //-1
if (dibit == 3){state->hexbuf = 0x3;} //-3
state->sr_0 = (state->sr_0 << 2) | (state->sr_1 >> 62);
state->sr_1 = (state->sr_1 << 2) | (state->sr_2 >> 62);
state->sr_2 = (state->sr_2 << 2) | (state->sr_3 >> 62);
state->sr_3 = (state->sr_3 << 2) | (state->sr_4 >> 62);
state->sr_4 = (state->sr_4 << 2) | (state->sr_5 >> 62);
state->sr_5 = (state->sr_5 << 2) | (state->sr_6 >> 62);
state->sr_6 = state->sr_6 << 2;
state->sr_6 |= state->hexbuf;
if (1 == 2) //disable this later on
{
fprintf (stderr, "\nsr_0 = %16llX \n", state->sr_0);
fprintf (stderr, "sr_1 = %16llX \n", state->sr_1);
fprintf (stderr, "sr_2 = %16llX \n", state->sr_2);
fprintf (stderr, "sr_3 = %16llX \n", state->sr_3);
fprintf (stderr, "sr_4 = %16llX \n", state->sr_4);
fprintf (stderr, "sr_5 = %16llX \n", state->sr_5);
fprintf (stderr, "sr_6 = %16llX \n", state->sr_6);
/*
printw ("sr_0 = %16llX \n", sr_0);
printw ("sr_1 = %16llX \n", sr_1);
printw ("sr_2 = %16llX \n", sr_2);
printw ("sr_3 = %16llX \n", sr_3);
printw ("sr_4 = %16llX \n", sr_4);
printw ("sr_5 = %16llX \n", sr_5);
printw ("sr_6 = %16llX \n", sr_6);
*/
}
if ( state->sr_5 & 0xFFFFF == 0xDDF5D) //disable this later on
{
fprintf (stderr, "\nsr_0 = %16llX \n", state->sr_0);
fprintf (stderr, "sr_1 = %16llX \n", state->sr_1);
fprintf (stderr, "sr_2 = %16llX \n", state->sr_2);
fprintf (stderr, "sr_3 = %16llX \n", state->sr_3);
fprintf (stderr, "sr_4 = %16llX \n", state->sr_4);
fprintf (stderr, "sr_5 = %16llX \n", state->sr_5);
fprintf (stderr, "sr_6 = %16llX \n", state->sr_6);
/*
printw ("sr_0 = %16llX \n", sr_0);
printw ("sr_1 = %16llX \n", sr_1);
printw ("sr_2 = %16llX \n", sr_2);
printw ("sr_3 = %16llX \n", sr_3);
printw ("sr_4 = %16llX \n", sr_4);
printw ("sr_5 = %16llX \n", sr_5);
printw ("sr_6 = %16llX \n", sr_6);
*/
}
*state->dibit_buf_p = dibit;
state->dibit_buf_p++;

View File

@@ -78,10 +78,10 @@ processFrame (dsd_opts * opts, dsd_state * state)
state->minref = state->min;
}
if ((state->synctype == 8) || (state->synctype == 9)) //lets make this NOT do this...maybe...
if ((state->synctype == 8) || (state->synctype == 9)) //NXDN Voice
{
//state->rf_mod = 2; //wrong type of modulation HERE HERE
//state->nac = 0;
state->nac = 0;
state->lastsrc = 0;
state->lasttg = 0;
if (opts->errorbars == 1)
@@ -89,7 +89,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
if (opts->verbose > 0)
{
level = (int) state->max / 164;
fprintf (stderr,"inlvl: %2i%% ", level);
fprintf (stderr, "inlvl: %2i%% ", level);
}
}
state->nac = 0;
@@ -101,10 +101,10 @@ processFrame (dsd_opts * opts, dsd_state * state)
processNXDNVoice (opts, state);
return;
}
else if ((state->synctype == 16) || (state->synctype == 17))
else if ((state->synctype == 16) || (state->synctype == 17)) //NXDN Data
{
//state->rf_mod = 2;
//state->nac = 0;
state->nac = 0;
state->lastsrc = 0;
state->lasttg = 0;
if (opts->errorbars == 1)

571
src/dsd_frame.c.bkp Normal file
View File

@@ -0,0 +1,571 @@
/*
* Copyright (C) 2010 DSD Author
* GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0)
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "dsd.h"
#if !defined(NULL)
#define NULL 0
#endif
#include "p25p1_check_nid.h"
void
printFrameInfo (dsd_opts * opts, dsd_state * state)
{
int level;
level = (int) state->max / 164;
if (opts->verbose > 0)
{
fprintf (stderr,"inlvl: %2i%% ", level);
}
if (state->nac != 0)
{
fprintf (stderr,"nac: %4X ", state->nac);
}
if (opts->verbose > 1)
{
fprintf (stderr,"src: %8i ", state->lastsrc);
}
fprintf (stderr,"tg: %5i ", state->lasttg);
}
void
processFrame (dsd_opts * opts, dsd_state * state)
{
int i, j, dibit;
char duid[3];
char nac[13];
int level;
char status_0;
char bch_code[63];
int index_bch_code;
unsigned char parity;
char v;
int new_nac;
char new_duid[3];
int check_result;
nac[12] = 0;
duid[2] = 0;
j = 0;
if (state->rf_mod == 1)
{
state->maxref = (int)(state->max * 0.80F);
state->minref = (int)(state->min * 0.80F);
}
else
{
state->maxref = state->max;
state->minref = state->min;
}
if ((state->synctype == 8) || (state->synctype == 9)) //lets make this NOT do this...maybe...
{
//state->rf_mod = 2; //wrong type of modulation HERE HERE
state->nac = 0;
state->lastsrc = 0;
state->lasttg = 0;
if (opts->errorbars == 1)
{
if (opts->verbose > 0)
{
level = (int) state->max / 164;
fprintf (stderr,"inlvl: %2i%% ", level);
}
}
state->nac = 0;
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{
openMbeOutFile (opts, state);
}
sprintf (state->fsubtype, " VOICE ");
processNXDNVoice (opts, state);
return;
}
else if ((state->synctype == 16) || (state->synctype == 17))
{
//state->rf_mod = 2;
state->nac = 0;
state->lastsrc = 0;
state->lasttg = 0;
if (opts->errorbars == 1)
{
if (opts->verbose > 0)
{
level = (int) state->max / 164;
fprintf (stderr, "inlvl: %2i%% ", level);
}
}
state->nac = 0;
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{
openMbeOutFile (opts, state);
}
sprintf (state->fsubtype, " DATA ");
processNXDNData (opts, state);
return;
}
else if ((state->synctype == 6) || (state->synctype == 7))
{
state->nac = 0;
state->lastsrc = 0;
state->lasttg = 0;
if (opts->errorbars == 1)
{
if (opts->verbose > 0)
{
level = (int) state->max / 164;
fprintf (stderr,"inlvl: %2i%% ", level);
}
}
state->nac = 0;
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{
openMbeOutFile (opts, state);
}
sprintf (state->fsubtype, " VOICE ");
processDSTAR (opts, state);
return;
}
else if ((state->synctype == 18) || (state->synctype == 19))
{
state->nac = 0;
state->lastsrc = 0;
state->lasttg = 0;
if (opts->errorbars == 1)
{
if (opts->verbose > 0)
{
level = (int) state->max / 164;
fprintf (stderr,"inlvl: %2i%% ", level);
}
}
state->nac = 0;
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{
openMbeOutFile (opts, state);
}
sprintf (state->fsubtype, " DATA ");
processDSTAR_HD (opts, state);
return;
}
else if ((state->synctype >= 10) && (state->synctype <= 13))
{
state->nac = 0;
state->lastsrc = 0;
state->lasttg = 0;
if (opts->errorbars == 1)
{
if (opts->verbose > 0)
{
level = (int) state->max / 164;
fprintf (stderr,"inlvl: %2i%% ", level);
}
}
if ((state->synctype == 11) || (state->synctype == 12))
{
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{
openMbeOutFile (opts, state);
}
sprintf (state->fsubtype, " VOICE ");
processDMRvoice (opts, state);
}
else
{
closeMbeOutFile (opts, state);
state->err_str[0] = 0;
processDMRdata (opts, state);
}
return;
}
else if ((state->synctype >= 2) && (state->synctype <= 5))
{
state->nac = 0;
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
}
if ((state->synctype == 3) || (state->synctype == 4))
{
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{
openMbeOutFile (opts, state);
}
sprintf (state->fsubtype, " VOICE ");
processX2TDMAvoice (opts, state);
}
else
{
closeMbeOutFile (opts, state);
state->err_str[0] = 0;
processX2TDMAdata (opts, state);
}
return;
}
else if ((state->synctype == 14) || (state->synctype == 15))
{
state->nac = 0;
state->lastsrc = 0;
state->lasttg = 0;
if (opts->errorbars == 1)
{
if (opts->verbose > 0)
{
level = (int) state->max / 164;
fprintf (stderr,"inlvl: %2i%% ", level);
}
}
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{
openMbeOutFile (opts, state);
}
sprintf (state->fsubtype, " VOICE ");
processProVoice (opts, state);
return;
}
else
{
// Read the NAC, 12 bits
j = 0;
index_bch_code = 0;
for (i = 0; i < 6; i++)
{
dibit = getDibit (opts, state);
v = 1 & (dibit >> 1); // bit 1
nac[j] = v + '0';
j++;
bch_code[index_bch_code] = v;
index_bch_code++;
v = 1 & dibit; // bit 0
nac[j] = v + '0';
j++;
bch_code[index_bch_code] = v;
index_bch_code++;
}
state->nac = strtol (nac, NULL, 2);
// Read the DUID, 4 bits
for (i = 0; i < 2; i++)
{
dibit = getDibit (opts, state);
duid[i] = dibit + '0';
bch_code[index_bch_code] = 1 & (dibit >> 1); // bit 1
index_bch_code++;
bch_code[index_bch_code] = 1 & dibit; // bit 0
index_bch_code++;
}
// Read the BCH data for error correction of NAC and DUID
for (i = 0; i < 3; i++)
{
dibit = getDibit (opts, state);
bch_code[index_bch_code] = 1 & (dibit >> 1); // bit 1
index_bch_code++;
bch_code[index_bch_code] = 1 & dibit; // bit 0
index_bch_code++;
}
// Intermission: read the status dibit
status_0 = getDibit (opts, state) + '0';
// ... continue reading the BCH error correction data
for (i = 0; i < 20; i++)
{
dibit = getDibit (opts, state);
bch_code[index_bch_code] = 1 & (dibit >> 1); // bit 1
index_bch_code++;
bch_code[index_bch_code] = 1 & dibit; // bit 0
index_bch_code++;
}
// Read the parity bit
dibit = getDibit (opts, state);
bch_code[index_bch_code] = 1 & (dibit >> 1); // bit 1
parity = (1 & dibit); // bit 0
// Check if the NID is correct
check_result = check_NID (bch_code, &new_nac, new_duid, parity);
if (check_result) {
if (new_nac != state->nac) {
// NAC fixed by error correction
state->nac = new_nac;
state->debug_header_errors++;
}
if (strcmp(new_duid, duid) != 0) {
// DUID fixed by error correction
//fprintf (stderr,"Fixing DUID %s -> %s\n", duid, new_duid);
duid[0] = new_duid[0];
duid[1] = new_duid[1];
state->debug_header_errors++;
}
} else {
// Check of NID failed and unable to recover its value
//fprintf (stderr,"NID error\n");
duid[0] = 'E';
duid[1] = 'E';
state->debug_header_critical_errors++;
}
}
if (strcmp (duid, "00") == 0)
{
// Header Data Unit
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," HDU\n");
}
if (opts->mbe_out_dir[0] != 0)
{
closeMbeOutFile (opts, state);
openMbeOutFile (opts, state);
}
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
state->lastp25type = 2;
sprintf (state->fsubtype, " HDU ");
processHDU (opts, state);
}
else if (strcmp (duid, "11") == 0)
{
// Logical Link Data Unit 1
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," LDU1 ");
}
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f == NULL)
{
openMbeOutFile (opts, state);
}
}
state->lastp25type = 1;
sprintf (state->fsubtype, " LDU1 ");
state->numtdulc = 0;
processLDU1 (opts, state);
}
else if (strcmp (duid, "22") == 0)
{
// Logical Link Data Unit 2
if (state->lastp25type != 1)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," Ignoring LDU2 not preceeded by LDU1\n");
}
state->lastp25type = 0;
sprintf (state->fsubtype, " ");
}
else
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," LDU2 ");
}
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f == NULL)
{
openMbeOutFile (opts, state);
}
}
state->lastp25type = 2;
sprintf (state->fsubtype, " LDU2 ");
state->numtdulc = 0;
processLDU2 (opts, state);
}
}
else if (strcmp (duid, "33") == 0)
{
// Terminator with subsequent Link Control
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," TDULC\n");
}
if (opts->mbe_out_dir[0] != 0)
{
closeMbeOutFile (opts, state);
}
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
state->lasttg = 0;
state->lastsrc = 0;
state->lastp25type = 0;
state->err_str[0] = 0;
sprintf (state->fsubtype, " TDULC ");
state->numtdulc++;
if ((opts->resume > 0) && (state->numtdulc > opts->resume))
{
resumeScan (opts, state);
}
processTDULC (opts, state);
state->err_str[0] = 0;
}
else if (strcmp (duid, "03") == 0)
{
// Terminator without subsequent Link Control
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," TDU\n");
}
if (opts->mbe_out_dir[0] != 0)
{
closeMbeOutFile (opts, state);
}
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
state->lasttg = 0;
state->lastsrc = 0;
state->lastp25type = 0;
state->err_str[0] = 0;
sprintf (state->fsubtype, " TDU ");
processTDU (opts, state);
}
else if (strcmp (duid, "13") == 0)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," TSDU\n");
}
if (opts->resume > 0)
{
resumeScan (opts, state);
}
state->lasttg = 0;
state->lastsrc = 0;
state->lastp25type = 3;
sprintf (state->fsubtype, " TSDU ");
// Now processing NID
skipDibit (opts, state, 328-25);
}
else if (strcmp (duid, "30") == 0)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," PDU\n");
}
if (opts->resume > 0)
{
resumeScan (opts, state);
}
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f == NULL)
{
openMbeOutFile (opts, state);
}
}
state->lastp25type = 4;
sprintf (state->fsubtype, " PDU ");
}
// try to guess based on previous frame if unknown type
else if (state->lastp25type == 1)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr,"(LDU2) ");
}
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f == NULL)
{
openMbeOutFile (opts, state);
}
}
//state->lastp25type = 0;
// Guess that the state is LDU2
state->lastp25type = 2;
sprintf (state->fsubtype, "(LDU2) ");
state->numtdulc = 0;
processLDU2 (opts, state);
}
else if (state->lastp25type == 2)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr,"(LDU1) ");
}
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f == NULL)
{
openMbeOutFile (opts, state);
}
}
//state->lastp25type = 0;
// Guess that the state is LDU1
state->lastp25type = 1;
sprintf (state->fsubtype, "(LDU1) ");
state->numtdulc = 0;
processLDU1 (opts, state);
}
else if (state->lastp25type == 3)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," (TSDU)\n");
}
//state->lastp25type = 0;
// Guess that the state is TSDU
state->lastp25type = 3;
sprintf (state->fsubtype, "(TSDU) ");
// Now processing NID
skipDibit (opts, state, 328-25);
}
else if (state->lastp25type == 4)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," (PDU)\n");
}
state->lastp25type = 0;
}
else
{
state->lastp25type = 0;
sprintf (state->fsubtype, " ");
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," duid:%s *Unknown DUID*\n", duid);
}
}
}

View File

@@ -185,10 +185,13 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
while (sync == 0)
{
//fprintf (stderr,"now=%d\n", now); //okay, so this is incrementing as expected
if (opts->use_ncurses_terminal == 1)
{
ncursesPrinter(opts, state);
}
if ( opts->monitor_input_audio == 1 && (time(NULL) - now) > 1 ) //okay, still something going on, still doing the read part for some reason
{
playRawAudio(opts, state); //this is on line 21 in dsd_audio.c
//fprintf( stderr, "Farts");
}
t++;
@@ -406,7 +409,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, " P25 Phase 1 ");
sprintf (state->ftype, "P25 Phase 1");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +P25p1 ", synctest_pos + 1, modulation);
@@ -421,7 +424,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, " P25 Phase 1 ");
sprintf (state->ftype, "P25 Phase 1");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -P25p1 ", synctest_pos + 1, modulation);
@@ -442,7 +445,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
if (opts->inverted_x2tdma == 0)
{
// data frame
sprintf (state->ftype, " X2-TDMA ");
sprintf (state->ftype, "X2-TDMA");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +X2-TDMA ", synctest_pos + 1, modulation);
@@ -453,7 +456,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
else
{
// inverted voice frame
sprintf (state->ftype, " X2-TDMA ");
sprintf (state->ftype, "X2-TDMA");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -X2-TDMA ", synctest_pos + 1, modulation);
@@ -476,7 +479,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
if (opts->inverted_x2tdma == 0)
{
// voice frame
sprintf (state->ftype, " X2-TDMA ");
sprintf (state->ftype, "X2-TDMA");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +X2-TDMA ", synctest_pos + 1, modulation);
@@ -491,7 +494,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
else
{
// inverted data frame
sprintf (state->ftype, " X2-TDMA ");
sprintf (state->ftype, "X2-TDMA");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -X2-TDMA ", synctest_pos + 1, modulation);
@@ -503,7 +506,8 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
}
if (opts->frame_dmr == 1)
{
if ((strcmp (synctest, DMR_MS_DATA_SYNC) == 0) || (strcmp (synctest, DMR_BS_DATA_SYNC) == 0))
if ((strcmp (synctest, DMR_MS_DATA_SYNC) == 0) || (strcmp (synctest, DMR_BS_DATA_SYNC) == 0) )//try this
//if ((strncmperr (synctest, DMR_MS_DATA_SYNC, 24, 1) == 0) || (strncmperr (synctest, DMR_MS_DATA_SYNC, 24, 1) == 0))
{
now = time(NULL);
state->carrier = 1;
@@ -513,7 +517,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
if (opts->inverted_dmr == 0)
{
// data frame
sprintf (state->ftype, " DMR ");
sprintf (state->ftype, "DMR");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +DMR ", synctest_pos + 1, modulation);
@@ -524,7 +528,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
else
{
// inverted voice frame
sprintf (state->ftype, " DMR ");
sprintf (state->ftype, "DMR");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -DMR ", synctest_pos + 1, modulation);
@@ -538,6 +542,8 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
}
}
if ((strcmp (synctest, DMR_MS_VOICE_SYNC) == 0) || (strcmp (synctest, DMR_BS_VOICE_SYNC) == 0))
//if ( strcmp (synctest, DMR_MS_VOICE_SYNC) == 0 || strcmp (synctest, DMR_BS_VOICE_SYNC) == 0 || strcmp (synctest, DMR_DIRECT_MODE_TS1_VOICE_SYNC) == 0 || strcmp (synctest, DMR_DIRECT_MODE_TS2_VOICE_SYNC) == 0 )
//if ((strncmperr (synctest, DMR_MS_VOICE_SYNC, 24, 1) == 0) || (strncmperr (synctest, DMR_BS_VOICE_SYNC, 24, 1) == 0))
{
now = time(NULL);
state->carrier = 1;
@@ -547,7 +553,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
if (opts->inverted_dmr == 0)
{
// voice frame
sprintf (state->ftype, " DMR ");
sprintf (state->ftype, "DMR");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +DMR ", synctest_pos + 1, modulation);
@@ -562,7 +568,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
else
{
// inverted data frame
sprintf (state->ftype, " DMR ");
sprintf (state->ftype, "DMR");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -DMR ", synctest_pos + 1, modulation);
@@ -582,7 +588,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, " ProVoice ");
sprintf (state->ftype, "ProVoice");
if (opts->errorbars == 1)
//if (opts->errorbars == 1 && (time(NULL) - now) > 2 )
{
@@ -602,7 +608,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, " ProVoice ");
sprintf (state->ftype, "ProVoice");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -ProVoice ", synctest_pos + 1, modulation);
@@ -634,15 +640,17 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
if (state->samplesPerSymbol == 20)
{
sprintf (state->ftype, " NXDN48 ");
//sprintf (state->ftype, " NXDN48 ");
sprintf (state->ftype, "NXDN48"); //get rid of spaces
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +NXDN48 ", synctest_pos + 1, modulation);
//printFrameSync (opts, state, " +NXDN48 ", synctest_pos + 1, modulation);
printFrameSync (opts, state, " +NXDN48", synctest_pos + 1, modulation);
}
}
else
{
sprintf (state->ftype, " NXDN96 ");
sprintf (state->ftype, "NXDN96");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +NXDN96 ", synctest_pos + 1, modulation);
@@ -675,15 +683,17 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->min = ((state->min) + lmin) / 2;
if (state->samplesPerSymbol == 20)
{
sprintf (state->ftype, " NXDN48 ");
//sprintf (state->ftype, " NXDN48 ");
sprintf (state->ftype, "NXDN48");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -NXDN48 ", synctest_pos + 1, modulation);
//printFrameSync (opts, state, " -NXDN48 ", synctest_pos + 1, modulation);
printFrameSync (opts, state, " -NXDN48", synctest_pos + 1, modulation);
}
}
else
{
sprintf (state->ftype, " NXDN96 ");
sprintf (state->ftype, "NXDN96");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -NXDN96 ", synctest_pos + 1, modulation);
@@ -714,15 +724,17 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->min = ((state->min) + lmin) / 2;
if (state->samplesPerSymbol == 20)
{
sprintf (state->ftype, " NXDN48 ");
//sprintf (state->ftype, " NXDN48 ");
sprintf (state->ftype, "NXDN48");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +NXDN48 ", synctest_pos + 1, modulation);
//printFrameSync (opts, state, " +NXDN48 ", synctest_pos + 1, modulation);
printFrameSync (opts, state, " +NXDN48", synctest_pos + 1, modulation);
}
}
else
{
sprintf (state->ftype, " NXDN96 ");
sprintf (state->ftype, "NXDN96");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +NXDN96 ", synctest_pos + 1, modulation);
@@ -751,10 +763,12 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, " NXDN ");
//sprintf (state->ftype, " NXDN ");
sprintf (state->ftype, "NXDN");
if (state->samplesPerSymbol == 20)
{
sprintf (state->ftype, " NXDN48 ");
sprintf (state->ftype, "NXDN48");
//sprintf (state->ftype, "NXDN48");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -NXDN48 ", synctest_pos + 1, modulation);
@@ -762,7 +776,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
}
else
{
sprintf (state->ftype, " NXDN96 ");
sprintf (state->ftype, "NXDN96");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -NXDN96 ", synctest_pos + 1, modulation);
@@ -792,7 +806,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, " D-STAR ");
sprintf (state->ftype, "D-STAR");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +D-STAR ", synctest_pos + 1, modulation);
@@ -811,7 +825,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, " D-STAR ");
sprintf (state->ftype, "D-STAR");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -D-STAR ", synctest_pos + 1, modulation);
@@ -830,7 +844,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, " D-STAR_HD ");
sprintf (state->ftype, "D-STAR_HD");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " +D-STAR_HD ", synctest_pos + 1, modulation);
@@ -849,7 +863,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, " D-STAR_HD ");
sprintf (state->ftype, "D-STAR_HD");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, " -D-STAR_HD ", synctest_pos + 1, modulation);
@@ -927,7 +941,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, "(X2-TDMA) ");
sprintf (state->ftype, "(X2-TDMA)");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, "(+X2-TDMA) ", synctest_pos + 1, modulation);
@@ -945,7 +959,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
state->offset = synctest_pos;
state->max = ((state->max) + lmax) / 2;
state->min = ((state->min) + lmin) / 2;
sprintf (state->ftype, "(DMR) ");
sprintf (state->ftype, "(DMR)");
if (opts->errorbars == 1)
{
printFrameSync (opts, state, "(-DMR) ", synctest_pos + 1, modulation);

View File

@@ -293,6 +293,8 @@ initState (dsd_state * state)
state->debug_header_errors = 0;
state->debug_header_critical_errors = 0;
state->nxdn_last_ran = 0;
#ifdef TRACE_DSD
state->debug_sample_index = 0;
state->debug_label_file = NULL;
@@ -787,7 +789,7 @@ main (int argc, char **argv)
opts.frame_x2tdma = 1;
opts.frame_p25p1 = 1;
opts.frame_nxdn48 = 0; //turn it on, doesn't work due to symbol rate difference
opts.frame_nxdn96 = 0; //causes false positives, leave on 0
opts.frame_nxdn96 = 0; //causes false positives, leave on 0
opts.frame_dmr = 1;
opts.frame_provoice = 0; //turn it on, doesn't work due to symbol rate difference
}
@@ -877,7 +879,6 @@ main (int argc, char **argv)
opts.mod_qpsk = 0;
opts.mod_gfsk = 0; //was 1
state.rf_mod = 0; //was 2
//fprintf (stderr,"Enabling only GFSK modulation optimizations.\n");
fprintf (stderr,"Enabling only C4FM modulation optimizations.\n");
fprintf (stderr,"Decoding only NXDN 9600 baud frames.\n");
}
@@ -890,6 +891,9 @@ main (int argc, char **argv)
opts.frame_nxdn96 = 0;
opts.frame_dmr = 1;
opts.frame_provoice = 0;
opts.mod_c4fm = 1; //just a test
opts.mod_qpsk = 0;
opts.mod_gfsk = 0; //was 1
fprintf (stderr,"Decoding only DMR/MOTOTRBO frames.\n");
}
break;

View File

@@ -17,6 +17,8 @@
#include "dsd.h"
static void DecipherData(char * Input, char * KeyStream, char * Output, int NbData);
void
playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv)
{
@@ -73,12 +75,14 @@ playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv)
void
processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24])
{
//comment out line below should return print back to normal
//strncpy (state->err_buf, state->err_str, sizeof(state->err_str)); //right at the very top before err_str gets returned?
int i;
char imbe_d[88];
char ambe_d[49];
#ifdef AMBE_PACKET_OUT
char ambe_d_str[50];
#ifdef AMBE_PACKET_OUT
#endif
for (i = 0; i < 88; i++)
@@ -117,6 +121,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
{
mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
#ifdef AMBE_PACKET_OUT
for(i=0; i<49; i++) {
ambe_d_str[i] = ambe_d[i] + '0';
}
@@ -124,7 +129,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
// print binary string
fprintf (stderr, "\n?\t?\t%s\t", ambe_d_str);
// print error data
fprintf (stderr, "E1: %d; E2: %d; S: %s", state->errs, state->errs2, state->err_str);
fprintf (stderr, "E1: %d; E2: %d; S: %s", state->errs, state->errs2, state->err_str);}
#endif
if (opts->mbe_out_f != NULL)
{
@@ -134,8 +139,10 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
if (opts->errorbars == 1)
{
fprintf (stderr, "%s", state->err_str);
//printw("%s", state->err_str);
//state->err_buf = state->err_str; //make comy to compare, and only print when comparison differs?? THIS HERE HERE
//strncpy (state->err_buf, state->err_str, sizeof(state->err_str)); //is this the correct placement for this? want it just before err_str is set?
fprintf (stderr, "%s", state->err_str); //this the actual error 'bar' ==== printer, find way to keep this entire string from printing constantly unless err_str changes
//fprintf (stderr, "%s", state->err_buf);
}
state->debug_audio_errors += state->errs2;
@@ -151,3 +158,128 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
playSynthesizedVoice (opts, state);
}
}
void processMbeFrameEncrypted (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24], char ambe_keystream[49], char imbe_keystream[88])
{
int i;
char imbe_d[88];
char ambe_d[49];
#ifdef AMBE_PACKET_OUT
char ambe_d_str[50];
#endif
for (i = 0; i < 88; i++)
{
imbe_d[i] = 0;
}
if ((state->synctype == 0) || (state->synctype == 1))
{
// 0 +P25p1
// 1 -P25p1
mbe_processImbe7200x4400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe_fr, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
DecipherData(imbe_d, imbe_keystream, imbe_d, 88);
if (opts->mbe_out_f != NULL)
{
saveImbe4400Data (opts, state, imbe_d);
}
}
else if ((state->synctype == 14) || (state->synctype == 15))
{
mbe_processImbe7100x4400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe7100_fr, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
DecipherData(imbe_d, imbe_keystream, imbe_d, 88);
if (opts->mbe_out_f != NULL)
{
saveImbe4400Data (opts, state, imbe_d);
}
}
else if ((state->synctype == 6) || (state->synctype == 7))
{
//mbe_processAmbe3600x2400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
state->errs = 0;
state->errs2 = 0;
state->errs = mbe_eccAmbe3600x2400C0 (ambe_fr);
mbe_demodulateAmbe3600x2400Data (ambe_fr);
state->errs2 = state->errs;
state->errs2 += mbe_eccAmbe3600x2400Data (ambe_fr, ambe_d);
memcpy(state->ambe_ciphered, ambe_d, sizeof(state->ambe_ciphered));
DecipherData(ambe_d, ambe_keystream, ambe_d, 49);
memcpy(state->ambe_deciphered, ambe_d, sizeof(state->ambe_deciphered));
mbe_processAmbe2400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
if (opts->mbe_out_f != NULL)
{
saveAmbe2450Data (opts, state, ambe_d);
}
}
else
{
//mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
state->errs = 0;
state->errs2 = 0;
state->errs = mbe_eccAmbe3600x2450C0 (ambe_fr);
mbe_demodulateAmbe3600x2450Data (ambe_fr);
state->errs2 = state->errs;
state->errs2 += mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d);
memcpy(state->ambe_ciphered, ambe_d, sizeof(state->ambe_ciphered));
DecipherData(ambe_d, ambe_keystream, ambe_d, 49);
memcpy(state->ambe_deciphered, ambe_d, sizeof(state->ambe_deciphered));
mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
#ifdef AMBE_PACKET_OUT
for(i=0; i<49; i++) {
ambe_d_str[i] = ambe_d[i] + '0';
}
ambe_d_str[49] = '\0';
// print binary string
fprintf(stderr, "\n?\t?\t%s\t", ambe_d_str);
// print error data
fprintf(stderr, "E1: %d; E2: %d; S: %s", state->errs, state->errs2, state->err_str);
#endif
if (opts->mbe_out_f != NULL)
{
saveAmbe2450Data (opts, state, ambe_d);
}
}
if (opts->errorbars == 1)
{
fprintf(stderr, "%s", state->err_str);
}
state->debug_audio_errors += state->errs2;
processAudio (opts, state);
if (opts->wav_out_f != NULL)
{
writeSynthesizedVoice (opts, state);
}
if (opts->audio_out == 1)
{
playSynthesizedVoice (opts, state);
}
}
/* This function decipher/decrypt data */
static void DecipherData(char * Input, char * KeyStream, char * Output, int NbData)
{
int i;
for(i = 0; i < NbData; i++)
{
Output[i] = Input[i] ^ KeyStream[i];
}
}

View File

@@ -27,7 +27,28 @@
#include "dsd.h"
#include "git_ver.h"
/*
short hexbuf;
unsigned long long sr_0 = 0; //64-bit shift registers for pushing decoded binary or dibit data
unsigned long long sr_1 = 0; //384
unsigned long long sr_2 = 0; //
unsigned long long sr_3 = 0; //
unsigned long long sr_4 = 0; //
unsigned long long sr_5 = 0; //
unsigned long long sr_6 = 0; //
*/
int tg; //last tg
int rd; //last rid
int rn; //last ran
int nc; //nac
int src; //last rid? double?
int lls = -1; //last last sync type
int dcc = 0; //initialize with 0 to prevent core dump
int i = 0;
char * s0last = " ";
char * s1last = " ";
char versionstr[25];
unsigned long long int call_matrix[33][6]; //0 - sync type; 1 - tg/ran; 2 - rid; 3 - slot; 4 - cc; 5 - time(NULL) ;
char * FM_bannerN[9] = {
" CTRL + C twice to exit",
" ██████╗ ██████╗██████╗    ███████╗███╗ ███╗███████╗",
@@ -48,16 +69,16 @@ char * SyncTypes[20] = {
"INV_X2TDMA_BS/MS_VOICE_SYNC",
"DSTAR_SYNC",
"INV_DSTAR_SYNC",
"NXDN_BS_VOICE_SYNC", //8
"INV_NXDN_BS_VOICE_SYNC", //9
"DMR_BS/MS_DATA_SYNC",
"INV_DMR_BS/MS_DATA_SYNC",
"DMR_BS/MS_VOICE_SYNC",
"INV_DMR_BS/MS_VOICE_SYNC",
"PROVOICE_SYNC", //14
"INV_PROVOICE_SYNC", //15
"NXDN_BS_DATA_SYNC", //16
"INV_NXDN_BS_DATA_SYNC", //17
"NXDN_BS_VOICE_SYNC", //8
"INV_NXDN_BS_VOICE_SYNC", //9
"DMR_BS/MS_DATA_SYNC", //10
"DMR_MS/BS_VOICE_SYNC", //11
"DMR_MS/BS_DATA_SYNC", //12
"INV_DMR_BS/MS_VOICE_SYNC", //13
"PROVOICE_SYNC", //14
"INV_PROVOICE_SYNC", //15
"NXDN_BS_DATA_SYNC", //16
"INV_NXDN_BS_DATA_SYNC", //17
"DSTAR_HD",
"INV_DSTAR_HD"
@@ -82,7 +103,7 @@ char * getTimeN(void) //get pretty hh:mm:ss timestamp
void ncursesOpen ()
{
mbe_printVersion (versionstr);
setlocale(LC_ALL, "");
//setlocale(LC_ALL, "");
initscr(); //Initialize NCURSES screen window
start_color();
init_pair(1, COLOR_YELLOW, COLOR_BLACK); //Yellow/Amber for frame sync/control channel, NV style
@@ -92,93 +113,339 @@ void ncursesOpen ()
init_pair(5, COLOR_MAGENTA, COLOR_BLACK); //Magenta for no frame sync/signal
noecho();
cbreak();
fprintf (stderr, "Opening NCurses Terminal. \n");
//call_matrix[5-i][0] = 0;
//call_matrix[5-i][1] = 0;
//call_matrix[5-i][2] = 0;
//call_matrix[5-i][3] = 0;
//call_matrix[5-i][4] = 0;
//call_matrix[5-i][5] = time(NULL);
}
void
ncursesPrinter (dsd_opts * opts, dsd_state * state)
{
int level;
level = (int) state->max / 164;
//level = (int) state->max / 164;
level = 0; //start each cycle with 0
erase();
//disabling until wide support can be built for LM, etc. $(ncursesw5-config --cflags --libs)
//printw ("%s \n", FM_bannerN[0]); //top line in white
//attron(COLOR_PAIR(4));
//for (short int i = 1; i < 7; i++) { //following lines in cyan
//printw("%s \n", FM_bannerN[i]); }
//attroff(COLOR_PAIR(4));
printw ("%s \n", FM_bannerN[7]); //http link
printw ("Digital Speech Decoder: Florida Man Edition\n");
printw ("Github Build Version: %s \n", GIT_TAG);
printw ("mbelib version %s\n", versionstr);
printw ("Time: ");
printw ("%s ", getTimeN());
if (SyncTypes[state->lastsynctype] != NULL)
attron(COLOR_PAIR(4));
//for (short int i = 1; i < 7; i++)
//{ //following lines in cyan
//printw("%s \n", FM_bannerN[i]);
//}
attroff(COLOR_PAIR(4));
printw ("--Build Info------------------------------------------------------------------\n");
//printw ("| %s \n", FM_bannerN[7]); //http link
printw ("| Digital Speech Decoder: Florida Man Edition\n");
printw ("| Github Build Version: %s \n", GIT_TAG);
printw ("| mbelib version %s\n", versionstr);
printw ("------------------------------------------------------------------------------\n");
if ( (state->lastsynctype == 14 || state->lastsynctype == 15) ) //honestly have no idea how to do this for pV
{
printw ("%s \n", SyncTypes[state->lastsynctype]);
//printw("%s ", state->ftype); //moved to front, some ftype strings have spaces in front of them, and others dont
/* Not sure if I'm going to use the error bars yet
if (opts->errorbars == 1)
{
printw("-"); //AFAIK, errorbars==1 is the internal value for if a system has inverted signal types, not at all misleading
}
else
{
printw("+");
}
call_matrix[5][0] = lls;
call_matrix[5][1] = 1;
call_matrix[5][2] = 1;
call_matrix[5][3] = 1;
call_matrix[5][4] = 1;
call_matrix[5][5] = time(NULL);
}
if ( (state->nxdn_last_rid != src && src > 0) || (state->nxdn_last_ran != rn && rn > 0) ) //find condition to make this work well, probably if last != local last variables
{
/* //save just in case
call_matrix[0][0] = call_matrix[1][0];
call_matrix[0][1] = call_matrix[1][1];
call_matrix[0][2] = call_matrix[1][2];
call_matrix[0][3] = call_matrix[1][3];
call_matrix[0][4] = call_matrix[1][4];
call_matrix[0][5] = call_matrix[1][5];
call_matrix[1][0] = call_matrix[2][0];
call_matrix[1][1] = call_matrix[2][1];
call_matrix[1][2] = call_matrix[2][2];
call_matrix[1][3] = call_matrix[2][3];
call_matrix[1][4] = call_matrix[2][4];
call_matrix[1][5] = call_matrix[2][5];
call_matrix[2][0] = call_matrix[3][0];
call_matrix[2][1] = call_matrix[3][1];
call_matrix[2][2] = call_matrix[3][2];
call_matrix[2][3] = call_matrix[3][3];
call_matrix[2][4] = call_matrix[3][4];
call_matrix[2][5] = call_matrix[3][5];
call_matrix[3][0] = call_matrix[4][0];
call_matrix[3][1] = call_matrix[4][1];
call_matrix[3][2] = call_matrix[4][2];
call_matrix[3][3] = call_matrix[4][3];
call_matrix[3][4] = call_matrix[4][4];
call_matrix[3][5] = call_matrix[4][5];
call_matrix[4][0] = call_matrix[5][0];
call_matrix[4][1] = call_matrix[5][1];
call_matrix[4][2] = call_matrix[5][2];
call_matrix[4][3] = call_matrix[5][3];
call_matrix[4][4] = call_matrix[5][4];
call_matrix[4][5] = call_matrix[5][5];
*/
if (1 == 1){ //figure out method that will tell me when is active and when not active, maybe carrier but this doesn't print anyways unless activity
attron(COLOR_PAIR(3));
}
printw ("%s %s\n", state->ftype, state->fsubtype); //some ftype strings have extra spaces in them
if (state->lasttg < 0) //triggers compiler warning: comparison between pointer and integer
for (short int k = 0; k < 5; k++)
{
//sprintf(state->ftype, )
//state->lasttg = state->ftype; //warning: assignment to ‘int’ from ‘char *
state->lasttg = 0;
}
printw ("TG [%7i] RID [%12i] \n", state->lasttg, state->lastsrc); //variables to fill with info from other system types too
//printw ("TG [%s] \n", state->lasttg);
//printw ("TDMA activity: %s %s \n", state->slot0light, state->slot1light);
printw("In Level: [%2i%%] ", level);
printw ("Voice Error [%s] \n", state->err_str); //no idea if this shows anything outside of TDMA or P1 or what
if (1 == 1){ //same as above
attroff(COLOR_PAIR(3));
call_matrix[k][0] = call_matrix[k+1][0];
call_matrix[k][1] = call_matrix[k+1][1];
call_matrix[k][2] = call_matrix[k+1][2];
call_matrix[k][3] = call_matrix[k+1][3];
call_matrix[k][4] = call_matrix[k+1][4];
call_matrix[k][5] = call_matrix[k+1][5];
}
call_matrix[5][0] = lls;
call_matrix[5][1] = rn;
call_matrix[5][2] = src;
call_matrix[5][3] = 0;
call_matrix[5][4] = 0;
call_matrix[5][5] = time(NULL);
}
/*
if (state->lastsynctype == 8 ||state->lastsynctype == 9 ||state->lastsynctype == 16 ||state->lastsynctype == 17)
if ( (lls == 0 || lls == 1) && state->lastsrc != rd && state->lastsrc > 0) //find condition to make this work well, probably if last != local last variables
{
if (state->samplesPerSymbol == 20)
{
//sprintf (state->ftype, " NXDN48 ");
if (opts->errorbars == 1)
{
//printFrameSync (opts, state, " -NXDN48 ", synctest_pos + 1, modulation);
printw("NXDN48 ");
printw("%s \n", SyncTypes[state->lastsynctype]);
printw("%s ", state->ftype);
}
}
else
{
//sprintf (state->ftype, " NXDN96 ");
if (opts->errorbars == 1)
{
//printFrameSync (opts, state, " -NXDN96 ", synctest_pos + 1, modulation);
printw("NXDN96 ");
printw("%s ", SyncTypes[state->lastsynctype]);
printw("%s ", state->ftype);
}
}
for (short int k = 0; k < 5; k++)
{
call_matrix[k][0] = call_matrix[k+1][0];
call_matrix[k][1] = call_matrix[k+1][1];
call_matrix[k][2] = call_matrix[k+1][2];
call_matrix[k][3] = call_matrix[k+1][3];
call_matrix[k][4] = call_matrix[k+1][4];
call_matrix[k][5] = call_matrix[k+1][5];
}
call_matrix[5][0] = lls;
call_matrix[5][1] = tg;
call_matrix[5][2] = rd;
call_matrix[5][3] = 0;
call_matrix[5][4] = nc;
call_matrix[5][5] = time(NULL);
//i++;
}
//printw ("Time: ");
//printw ("%s \n", getTimeN());
attron(COLOR_PAIR(4));
printw ("--Input Output----------------------------------------------------------------\n");
if (opts->audio_in_type == 0)
{
printw ("| Pulse Audio Input [%i] kHz [%i] Channel\n", opts->pulse_digi_rate_in, opts->pulse_digi_in_channels);
}
if (opts->audio_in_type == 1)
{
printw ("| STDIN - Input\n");
}
if (opts->audio_in_type == 3)
{
printw ("| RTL2838 Device #[%d]", opts->rtl_dev_index);
printw (" [%i] dB", opts->rtl_gain_value);
printw (" [%i] Sq", opts->rtl_squelch_level);
printw (" [%i] kHz VFO\n", opts->rtl_bandwidth);
printw ("| Freq: [%lld] Hz", opts->rtlsdr_center_freq);
printw (" - Tuning available on UDP Port [%i]\n", opts->rtl_udp_port);
}
if (opts->audio_out_type == 0)
{
printw ("| Pulse Audio Output [%i] kHz [%i] Channel\n", opts->pulse_digi_rate_out, opts->pulse_digi_out_channels);
}
if (opts->mbe_out_dir[0] != 0)
{
printw ("| Writing MBE data files to directory %s\n", opts->mbe_out_dir);
}
if (opts->wav_out_file[0] != 0)
{
printw ("| Writing audio wav to file %s\n", opts->wav_out_file);
}
*/
printw("\n"); //line return
printw ("------------------------------------------------------------------------------\n");
attroff(COLOR_PAIR(4));
if (state->carrier == 1){ //figure out method that will tell me when is active and when not active, maybe carrier but this doesn't print anyways unless activity
attron(COLOR_PAIR(3));
level = (int) state->max / 164; //only update on carrier present
}
//if (state->carrier == 0){ //figure out method that will tell me when is active and when not active, maybe carrier but this doesn't print anyways unless activity
//attron(COLOR_PAIR(1));
//0 - sync type; 1 - tg/ran; 2 - rid; 3 - slot; 4 - dcc; 5 - time(NULL) ;
//}
printw ("--Audio Decode----------------------------------------------------------------\n");
printw ("| In Level: [%3i%%] \n", level);
printw ("| Voice Error: [%i][%i] \n| Error Bars: [%s] \n", state->errs, state->errs2, state->err_str); //
printw ("------------------------------------------------------------------------------\n");
printw ("--Call Info-------------------------------------------------------------------\n");
if (state->lastsynctype != -1) //not sure if this will be okay
{
lls = state->lastsynctype;
}
if (state->nxdn_last_rid > 0 && state->nxdn_last_rid != src);
{
src = state->nxdn_last_rid;
//rn = state->nxdn_last_ran;
}
if (state->nxdn_last_ran > 0 && state->nxdn_last_rid != rn);
{
//src = state->nxdn_last_rid;
rn = state->nxdn_last_ran;
}
//if (state->lastsynctype == 8 || state->lastsynctype == 9 || state->lastsynctype == 16 || state->lastsynctype == 17) //change this to NXDN syncs later on
if (lls == 8 || lls == 9 || lls == 16 || lls == 17)
{
//printw ("| RAN: [%02d] \n", state->nxdn_last_ran);
printw ("| RAN: [%02d] \n", rn);
printw ("| RID: [%d] \n", src); //maybe change to nxdn_last_rid
}
//printw ("Error?: [%i] [%i] \n", state->errs, state->errs2); //what are these?
if (state->lasttg > 0 && state->lastsrc > 0)
{
tg = state->lasttg;
rd = state->lastsrc;
}
if (state->nac > 0)
{
nc = state->nac;
}
if ((lls == 0 || lls == 1)) //1 for P25 P1 Audio
{
printw("| TID:[%i] \n| RID:[%i] \n", tg, rd);
printw("| NAC: [0x%X] \n", nc);
}
//if (state->lastsynctype == 12 || state->lastsynctype == 13) //DMR Voice Types
if (lls == 11 || lls == 13) //DMR Voice Types
{
printw ("| DCC: [%i]\n", state->dmr_color_code);
//printw ("%s ", state->slot0light);
printw ("| SLOT 0 ");
if (state->currentslot == 0) //find out how to tell when slot0 has voice
{
s0last = "Voice";
//printw("Voice");
}
printw ("%s ", s0last);
//printw ("%s ", state->slot1light);
printw ("SLOT 1 ");
if (state->currentslot == 1) //find out how to tell when slot1 has voice
{
s1last = "Voice";
//printw("Voice");
}
printw ("%s \n", s1last);
}
if (state->dmr_color_code > 0 && (lls == 11 || lls == 13) ) //DMR VOice
{
dcc = state->dmr_color_code;
}
//if (state->lastsynctype == 10 || state->lastsynctype == 11) //DMR Data Types
if (lls == 10 || lls == 11) //DMR Data Types
{
printw ("| DCC: [%i]\n", dcc);
//printw ("%s ", state->slot0light);
printw ("| SLOT 0 ");
if (state->currentslot == 0) //find out how to tell when slot0 has voice
{
s0last = "Data ";
if (strcmp (state->fsubtype, " Slot idle ") == 0)
{
s0last = "Idle ";
}
}
printw ("%s ", s0last);
//printw ("%s ", state->slot1light);
printw ("SLOT 1 ");
if (state->currentslot == 1) //find out how to tell when slot1 has voice
{
s1last = "Data ";
if (strcmp (state->fsubtype, " Slot idle ") == 0)
{
s1last = "Idle ";
}
}
printw ("%s \n", s1last);
}
if (lls != -1) //is there a synctype 0?
{
printw ("| %s \n", SyncTypes[lls]);
}
printw ("------------------------------------------------------------------------------\n");
//colors off
if (state->carrier == 1){ //same as above
attroff(COLOR_PAIR(3));
}
//if (state->carrier == 0){ //same as above
//attroff(COLOR_PAIR(1));
//}
attron(COLOR_PAIR(4)); //cyan for history
//add other interesting info to put here
//make Call_Matrix
//0 - sync type; 1 - tg/ran; 2 - rid; 3 - slot; 4 - cc; 5 - time(NULL) ;
printw ("--Call History----------------------------------------------------------------\n");
for (short int j = 0; j < 6; j++)
{
if ( (time(NULL) - call_matrix[j][5]) < 9999)
//if (1 == 1)
{
printw ("| #%d %s ", 6-j, SyncTypes[call_matrix[j][0]]);
if (lls == 8 || lls == 9 || lls == 16 || lls == 17)
{
printw ("RAN [%2d] ", call_matrix[j][1]);
}
if (lls == 0 || lls == 1 || lls == 11 || lls == 13) //P25 P1 and DMR Voice
{
printw ("TID [%2d] ", call_matrix[j][1]);
}
printw ("RID [%4d] ", call_matrix[j][2]);
//printw ("S %d - ", call_matrix[j][3]);
if (call_matrix[j][0] == 0 || call_matrix[j][0] == 1) //P25P1 Voice
{
printw ("NAC [0x%X] ", call_matrix[j][4]);
}
if (call_matrix[j][0] == 12 || call_matrix[j][0] == 13) //DMR Voice Types
{
printw ("DCC [%d] ", call_matrix[j][4]);
}
printw ("%d secs ago\n", time(NULL) - call_matrix[j][5]);
}
//printw("\n");
}
printw ("------------------------------------------------------------------------------");
attroff(COLOR_PAIR(4)); //cyan for history
//put sync type at very bottom
//printw ("%s %s\n", state->ftype, state->fsubtype); //some ftype strings have extra spaces in them
//if (state->lastsynctype != -1) //is there a synctype 0?
//debug sr printw
if (1==2) //disable this later on
{
printw ("sr_0 = %16llX \n", state->sr_0);
printw ("sr_1 = %16llX \n", state->sr_1);
printw ("sr_2 = %16llX \n", state->sr_2);
printw ("sr_3 = %16llX \n", state->sr_3);
printw ("sr_4 = %16llX \n", state->sr_4);
printw ("sr_5 = %16llX \n", state->sr_5);
printw ("sr_6 = %16llX \n", state->sr_6);
}
refresh();
}
void ncursesClose ()

View File

@@ -27,7 +27,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
sum = 0;
count = 0;
for (i = 0; i < state->samplesPerSymbol; i++) //right HERE, this is how many samples it will grab, depending on samplesPerSymbol and also rf_mod messing with it too
for (i = 0; i < state->samplesPerSymbol; i++) //right HERE
{
// timing control

View File

@@ -1,36 +1,105 @@
#include "dsd.h"
#include "nxdn_const.h"
void
processNXDNData (dsd_opts * opts, dsd_state * state)
//don't know why this doesn't work right in LEH, need to figure that out for him
//works just fien when ripped from his and into mine
//must be some random thing, I'll look at his when I have a chance
void processNXDNData (dsd_opts * opts, dsd_state * state)
{
int i, dibit;
int i, dibit = 0;
unsigned char sacch_raw[72] = {0};
unsigned char sacch_decoded[32] = {0}; /* 26 bit + 6 bit CRC */
unsigned char *pr;
uint8_t CrcIsGood = 0;
uint8_t StructureField = 0;
uint8_t RAN = 0;
uint8_t PartOfFrame = 0;
/* Remove compiler warning */
//UNUSED_VARIABLE(dibit);
if (opts->errorbars == 1)
{
fprintf (stderr, "DATA ");
}
{
fprintf(stderr, "DATA - ");
}
/* Start pseudo-random NXDN sequence after
* LITCH = 16 bit = 8 dibit
* ==> Index 8 */
pr = (unsigned char *)(&nxdnpr2[8]);
for (i = 0; i < 30; i++)
{
dibit = getDibit (opts, state);
{
dibit = getDibit (opts, state);
/* Store and de-interleave directly SACCH bits */
sacch_raw[(2*i)] = ((*pr) & 1) ^ (1 & (dibit >> 1)); // bit 1
sacch_raw[(2*i)+1] = (1 & dibit); // bit 0
pr++;
#ifdef NXDN_DUMP
fprintf (stderr, "%c", dibit + 48);
fprintf(stderr, "%c", dibit + 48);
#endif
}
}
#ifdef NXDN_DUMP
fprintf (stderr, " ");
fprintf(stderr, " ");
#endif
/* Decode the SACCH fields */
CrcIsGood = NXDN_SACCH_raw_part_decode(sacch_raw, sacch_decoded);
StructureField = (sacch_decoded[0]<<1 | sacch_decoded[1]<<0) & 0x03; /* Compute the Structure Field (remove 2 first bits of the SR Information in the SACCH) */
RAN = (sacch_decoded[2]<<5 | sacch_decoded[3]<<4 | sacch_decoded[4]<<3 | sacch_decoded[5]<<2 | sacch_decoded[6]<<1 | sacch_decoded[7]<<0) & 0x3F; /* Compute the RAN (6 last bits of the SR Information in the SACCH) */
/* Compute the Part of Frame according to the structure field */
if (StructureField == 3) PartOfFrame = 0;
else if(StructureField == 2) PartOfFrame = 1;
else if(StructureField == 1) PartOfFrame = 2;
else if(StructureField == 0) PartOfFrame = 3;
else PartOfFrame = 0; /* Normally we should never go here */
/* Fill the SACCH structure */
state->NxdnSacchRawPart[PartOfFrame].CrcIsGood = CrcIsGood;
state->NxdnSacchRawPart[PartOfFrame].StructureField = StructureField;
state->NxdnSacchRawPart[PartOfFrame].RAN = RAN;
memcpy(state->NxdnSacchRawPart[PartOfFrame].Data, &sacch_decoded[8], 18); /* Copy the 18 bits of SACCH content */
//fprintf(stderr, "RAN=%02d - Part %d/4 ", RAN, PartOfFrame + 1);
if(CrcIsGood)
{
fprintf (stderr, "RAN=%02d - Part %d/4 ", RAN, PartOfFrame + 1);
fprintf (stderr, " (OK) - ");
state->nxdn_last_ran = RAN; //disable, try to grab this in voice instead
}
else fprintf (stderr, "(CRC ERR) - ");
/* Decode the SACCH only when all 4 voice frame
* SACCH spare parts have been received */
if(PartOfFrame == 3)
{
/* Decode the entire SACCH content */
NXDN_SACCH_Full_decode(opts, state);
}
for (i = 0; i < 144; i++)
{
dibit = getDibit (opts, state);
{
dibit = getDibit (opts, state);
#ifdef NXDN_DUMP
fprintf (stderr, "%c", dibit + 48);
fprintf(stderr, "%c", dibit + 48);
#endif
}
}
if (opts->errorbars == 1)
{
fprintf (stderr, "\n");
}
}
{
fprintf(stderr, "\n");
}
/* Reset the SACCH CRCs when all 4 voice frame
* SACCH spare parts have been received */
if(PartOfFrame == 3)
{
/* Reset all CRCs of the SACCH */
for(i = 0; i < 4; i++) state->NxdnSacchRawPart[i].CrcIsGood = 0;
}
} /* End processNXDNData() */

41
src/nxdn_data.c.bkp Normal file
View File

@@ -0,0 +1,41 @@
#include "dsd.h"
#include "nxdn_const.h"//going to test pushing data frames through, but not throught he processMBE portion, want to get those get frames
void
processNXDNData (dsd_opts * opts, dsd_state * state)
{
int i, dibit;
//dibit = getDibit (opts, state);
//fprintf (stderr, "D %c \n", dibit + 48); //adding to see what dumps exactly
if (opts->errorbars == 1)
{
fprintf (stderr, "DATA ");
//dibit = getDibit (opts, state);
//fprintf (stderr, "DE %c \n", dibit + 48); //adding to see what dumps exactly
}
for (i = 0; i < 30; i++)
{
dibit = getDibit (opts, state);
#ifdef NXDN_DUMP
fprintf (stderr, "%c", dibit + 48);
#endif
}
#ifdef NXDN_DUMP
fprintf (stderr, " ");
#endif
for (i = 0; i < 144; i++)
{
dibit = getDibit (opts, state);
//fprintf (stderr, "%c", dibit + 48);
#ifdef NXDN_DUMP
fprintf (stderr, "%c", dibit + 48);
#endif
}
if (opts->errorbars == 1)
{
fprintf (stderr, "\n");
}
}

72
src/nxdn_data.c.bkp2 Normal file
View File

@@ -0,0 +1,72 @@
#include "dsd.h"
#include "nxdn_const.h" //test making this just like voice, but not processing MBEframes
void
processNXDNData (dsd_opts * opts, dsd_state * state)
{
int i, j, dibit, k, l;
char ambe_fr2[4][24];
const int *w, *x, *y, *z;
const char *pr;
if (opts->errorbars == 1)
{
fprintf (stderr,"DATA e:");
}
for (i = 0; i < 30; i++)
{
dibit = getDibit (opts, state);
#ifdef NXDN_DUMP
fprintf (stderr,"%c", dibit + 48);
#endif
}
#ifdef NXDN_DUMP
fprintf (stderr," ");
#endif
pr = nxdnpr;
for (j = 0; j < 4; j++)
{
w = nW;
x = nX;
y = nY;
z = nZ;
for (i = 0; i < 36; i++)
{
dibit = getDibit (opts, state);
//fprintf (stderr,"%c", dibit + 48); //remove later
#ifdef NXDN_DUMP
fprintf (stderr,"%c", dibit + 48);
#endif
ambe_fr2[*w][*x] = *pr ^ (1 & (dibit >> 1)); // bit 1
pr++;
ambe_fr2[*y][*z] = (1 & dibit); // bit 0
w++;
x++;
y++;
z++;
//dump this whole lot, figure out what it all means
//fprintf (stderr, "%s\n%s\n", ambe_fr, pr);
}
for (k = 0; k < 36; k++) //was 36
{
for (l = 0; l < 36; l++) //was 36
{
//fprintf (stderr, "%X%X", ambe_fr[k][l]);
//fprintf (stderr, "%X", ambe_fr2[k][l]);
}
//fprintf (stderr, "\n");
}
//processMbeFrame (opts, state, NULL, ambe_fr, NULL);
#ifdef NXDN_DUMP
fprintf (stderr," ");
#endif
}
//fprintf (stderr, "\nD%s\n%s\n", ambe_fr, pr);
if (opts->errorbars == 1)
{
fprintf (stderr,"\n");
}
}

1084
src/nxdn_lib.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,59 +1,181 @@
#include "dsd.h"
#include "nxdn_const.h"
void
processNXDNVoice (dsd_opts * opts, dsd_state * state)
//don't know why this doesn't work right in LEH, need to figure that out for him
//works just fien when ripped from his and into mine
//must be some random thing, I'll look at his when I have a chance
void processNXDNVoice (dsd_opts * opts, dsd_state * state)
{
int i, j, dibit;
char ambe_fr[4][24];
unsigned char sacch_raw[72] = {0};
unsigned char sacch_decoded[32] = {0}; /* 26 bit + 6 bit CRC */
const int *w, *x, *y, *z;
const char *pr;
unsigned char *pr;
uint8_t CrcIsGood = 0;
uint8_t StructureField = 0;
uint8_t RAN = 0;
uint8_t PartOfFrame = 0;
uint8_t KeyStream[1664] = {0};
char ambe7bytesArray[7] = {0};
int PartOfEncryptedSuperFrame = 0;
if (opts->errorbars == 1)
{
fprintf (stderr,"VOICE e:");
}
{
fprintf(stderr, "VOICE - ");
}
/* Start pseudo-random NXDN sequence after
* LITCH = 16 bit = 8 dibit
* ==> Index 8 */
pr = (unsigned char *)(&nxdnpr2[8]);
for (i = 0; i < 30; i++)
{
dibit = getDibit (opts, state);
/* Store and de-interleave directly SACCH bits */
sacch_raw[(2*i)] = ((*pr) & 1) ^ (1 & (dibit >> 1)); // bit 1
sacch_raw[(2*i)+1] = (1 & dibit); // bit 0
// TODO : Deinterleave is done in the "NXDN_SACCH_decode" function
// /* Store and de-interleave directly SACCH bits */
// sacch_raw[nsW[2*i]] = *pr ^ (1 & (dibit >> 1)); // bit 1
// sacch_raw[nsW[2*i+1]] = (1 & dibit); // bit 0
pr++;
#ifdef NXDN_DUMP
fprintf(stderr, "%c", dibit + 48);
#endif
}
#ifdef NXDN_DUMP
fprintf(stderr, " ");
#endif
// TODO : Unpuncture is done in the "NXDN_SACCH_decode" function
// /* For the sake of simplicity, handle the re-insertion of punctured bits here.
// * This makes the actual Viterbi decoder code a LOT simpler. */
// for (i = 30; i < 36; i++)
// {
// sacch_raw[nsW[2*i]] = 0;
// sacch_raw[nsW[2*i+1]] = 0;
// }
/* Decode the SACCH fields */
CrcIsGood = NXDN_SACCH_raw_part_decode(sacch_raw, sacch_decoded);
StructureField = (sacch_decoded[0]<<1 | sacch_decoded[1]<<0) & 0x03; /* Compute the Structure Field (remove 2 first bits of the SR Information in the SACCH) */
RAN = (sacch_decoded[2]<<5 | sacch_decoded[3]<<4 | sacch_decoded[4]<<3 | sacch_decoded[5]<<2 | sacch_decoded[6]<<1 | sacch_decoded[7]<<0) & 0x3F; /* Compute the RAN (6 last bits of the SR Information in the SACCH) */
/* Compute the Part of Frame according to the structure field */
if (StructureField == 3) PartOfFrame = 0;
else if(StructureField == 2) PartOfFrame = 1;
else if(StructureField == 1) PartOfFrame = 2;
else if(StructureField == 0) PartOfFrame = 3;
else PartOfFrame = 0; /* Normally we should never go here */
/* Fill the SACCH structure */
state->NxdnSacchRawPart[PartOfFrame].CrcIsGood = CrcIsGood;
state->NxdnSacchRawPart[PartOfFrame].StructureField = StructureField;
state->NxdnSacchRawPart[PartOfFrame].RAN = RAN;
memcpy(state->NxdnSacchRawPart[PartOfFrame].Data, &sacch_decoded[8], 18); /* Copy the 18 bits of SACCH content */
//fprintf(stderr, "RAN=%02d - Part %d/4 ", RAN, PartOfFrame + 1);
//if(CrcIsGood) fprintf(stderr, " (OK) - ");
if(CrcIsGood)
{
fprintf (stderr, "RAN=%02d - Part %d/4 ", RAN, PartOfFrame + 1);
fprintf (stderr, " (OK) - ");
state->nxdn_last_ran = RAN; //disable, try to grab this in voice instead
}
else fprintf(stderr, "(CRC ERR) - ");
/* Generate the key stream */
NxdnEncryptionStreamGeneration(opts, state, KeyStream);
//fprintf(stderr, "\nKeyStream = ");
//for(i = 0; i < 49; i++) fprintf(stderr, "%d", KeyStream[i]);
//fprintf(stderr, "\n");
/* Determine the current part of superframe
* (in an AES or DES encrypted frame, two superframes
* are used with the same IV, so to decipher the sound
* correctly we must know the current superframe part) */
if(state->NxdnElementsContent.PartOfNextEncryptedFrame == 1) PartOfEncryptedSuperFrame = 0;
else if(state->NxdnElementsContent.PartOfNextEncryptedFrame == 2) PartOfEncryptedSuperFrame = 1;
else PartOfEncryptedSuperFrame = 0;
/* Decode the SACCH only when all 4 voice frame
* SACCH spare parts have been received */
if(PartOfFrame == 3)
{
/* Decode the entire SACCH content */
NXDN_SACCH_Full_decode(opts, state);
}
if (opts->errorbars == 1)
{
fprintf(stderr, "e:");
}
/* Start pseudo-random NXDN sequence after
* LITCH = 16 bit = 8 dibit +
* SACCH = 60 bit = 30 dibit
* = 76 bit = 38 dibit
* ==> Index 38 */
pr = (unsigned char *)(&nxdnpr2[38]);
for (j = 0; j < 4; j++)
{
w = nW;
x = nX;
y = nY;
z = nZ;
for (i = 0; i < 36; i++)
{
dibit = getDibit (opts, state);
#ifdef NXDN_DUMP
fprintf (stderr,"%c", dibit + 48);
#endif
}
#ifdef NXDN_DUMP
fprintf (stderr," ");
fprintf(stderr, "%c", dibit + 48);
#endif
ambe_fr[*w][*x] = *pr ^ (1 & (dibit >> 1)); // bit 1
pr++;
ambe_fr[*y][*z] = (1 & dibit); // bit 0
pr = nxdnpr;
for (j = 0; j < 4; j++)
{
w = nW;
x = nX;
y = nY;
z = nZ;
for (i = 0; i < 36; i++)
{
dibit = getDibit (opts, state);
#ifdef NXDN_DUMP
fprintf (stderr,"%c", dibit + 48);
#endif
ambe_fr[*w][*x] = *pr ^ (1 & (dibit >> 1)); // bit 1
pr++;
ambe_fr[*y][*z] = (1 & dibit); // bit 0
w++;
x++;
y++;
z++;
}
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
#ifdef NXDN_DUMP
fprintf (stderr," ");
#endif
w++;
x++;
y++;
z++;
}
//processMbeFrame (opts, state, NULL, ambe_fr, NULL);
processMbeFrameEncrypted(opts, state, NULL, ambe_fr, NULL, (char *)&KeyStream[(PartOfEncryptedSuperFrame * 4 * 4 * 49) + (PartOfFrame * 4 * 49) + (j * 49)], NULL);
#ifdef BUILD_DSD_WITH_FRAME_CONTENT_DISPLAY
if(state->printNXDNAmbeVoiceSampleHex)
{
/* Display AMBE frame content */
/* Convert the 49 bit AMBE frame into 7 bytes */
Convert49BitSampleInto7Bytes(state->ambe_deciphered, ambe7bytesArray);
fprintf(stderr, "\nVoice Frame %d/4 : ", j + 1);
fprintf(stderr, "E1 = %d ; E2 = %d ; Content = ", state->errs, state->errs2);
for(i = 0; i < 7; i++) fprintf(stderr, "0x%02X, ", ambe7bytesArray[i] & 0xFF);
//fprintf(stderr, "\n");
}
#endif /* BUILD_DSD_WITH_FRAME_CONTENT_DISPLAY */
#ifdef NXDN_DUMP
fprintf(stderr, " ");
#endif
} /* End for (j = 0; j < 4; j++) */
if (opts->errorbars == 1)
{
fprintf (stderr,"\n");
}
}
{
fprintf(stderr, "\n");
}
/* Reset the SACCH CRCs when all 4 voice frame
* SACCH spare parts have been received */
if(PartOfFrame == 3)
{
/* Reset all CRCs of the SACCH */
for(i = 0; i < 4; i++) state->NxdnSacchRawPart[i].CrcIsGood = 0;
}
} /* End processNXDNVoice() */

118
src/nxdn_voice.c.bkp3 Normal file
View File

@@ -0,0 +1,118 @@
#include "dsd.h"
#include "nxdn_const.h"
void
processNXDNVoice (dsd_opts * opts, dsd_state * state)
{
int i, j, dibit, k, l;
char ambe_fr[4][24];
const int *w, *x, *y, *z;
const char *pr;
//borrow from LEH data
unsigned char sacch_raw[72] = {0};
unsigned char sacch_decoded[32] = {0}; /* 26 bit + 6 bit CRC */
unsigned char *pr2; //change this to pr2 to differentiate
uint8_t CrcIsGood = 0;
uint8_t StructureField = 0;
uint8_t RAN = 0;
uint8_t PartOfFrame = 0;
if (opts->errorbars == 1)
{
fprintf (stderr,"VOICE e:");
}
for (i = 0; i < 30; i++)
{
dibit = getDibit (opts, state);
#ifdef NXDN_DUMP
fprintf (stderr,"%c", dibit + 48);
#endif
}
#ifdef NXDN_DUMP
fprintf (stderr," ");
#endif
pr = nxdnpr;
pr2 = (unsigned char *)(&nxdnpr2[8]); //from LEH data
for (j = 0; j < 4; j++)
{
w = nW;
x = nX;
y = nY;
z = nZ;
for (i = 0; i < 36; i++)
{
dibit = getDibit (opts, state);
//fprintf (stderr,"%c", dibit + 48); //remove later
if (i < 30){
sacch_raw[(2*i)] = ((*pr2) & 1) ^ (1 & (dibit >> 1)); // bit 1
sacch_raw[(2*i)+1] = (1 & dibit); // bit 0
}
#ifdef NXDN_DUMP
fprintf (stderr,"%c", dibit + 48);
#endif
ambe_fr[*w][*x] = *pr ^ (1 & (dibit >> 1)); // bit 1
pr++;
ambe_fr[*y][*z] = (1 & dibit); // bit 0
w++;
x++;
y++;
z++;
}
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
//from LEH data
/* Decode the SACCH fields */
CrcIsGood = NXDN_SACCH_raw_part_decode(sacch_raw, sacch_decoded);
StructureField = (sacch_decoded[0]<<1 | sacch_decoded[1]<<0) & 0x03; /* Compute the Structure Field (remove 2 first bits of the SR Information in the SACCH) */
RAN = (sacch_decoded[2]<<5 | sacch_decoded[3]<<4 | sacch_decoded[4]<<3 | sacch_decoded[5]<<2 | sacch_decoded[6]<<1 | sacch_decoded[7]<<0) & 0x3F; /* Compute the RAN (6 last bits of the SR Information in the SACCH) */
/* Compute the Part of Frame according to the structure field */
if (StructureField == 3) PartOfFrame = 0;
else if(StructureField == 2) PartOfFrame = 1;
else if(StructureField == 1) PartOfFrame = 2;
else if(StructureField == 0) PartOfFrame = 3;
else PartOfFrame = 0; /* Normally we should never go here */
/* Fill the SACCH structure */
state->NxdnSacchRawPart[PartOfFrame].CrcIsGood = CrcIsGood;
state->NxdnSacchRawPart[PartOfFrame].StructureField = StructureField;
state->NxdnSacchRawPart[PartOfFrame].RAN = RAN;
memcpy(state->NxdnSacchRawPart[PartOfFrame].Data, &sacch_decoded[8], 18); /* Copy the 18 bits of SACCH content */
//fprintf(stderr, "RAN=%02d - Part %d/4 ", RAN, PartOfFrame + 1);
if(CrcIsGood)
{
//fprintf (stderr, "RAN=%02d - Part %d/4 ", RAN, PartOfFrame + 1);
//fprintf (stderr, " (OK) - ");
state->nxdn_last_ran = RAN; //disable, try to grab this in voice instead
}
else fprintf (stderr, "(CRC ERR) - ");
if(PartOfFrame == 3)
{
/* Decode the entire SACCH content */
NXDN_SACCH_Full_decode(opts, state);
}
/* Reset the SACCH CRCs when all 4 voice frame
* SACCH spare parts have been received */
if(PartOfFrame == 3)
{
/* Reset all CRCs of the SACCH */
for(i = 0; i < 4; i++) state->NxdnSacchRawPart[i].CrcIsGood = 0;
}
#ifdef NXDN_DUMP
fprintf (stderr," ");
#endif
}
//fprintf (stderr, "\nV%c\n%c\n", ambe_fr, pr);
if (opts->errorbars == 1)
{
fprintf (stderr,"\n");
}
}

171
src/nxdnconvolution.c Normal file
View File

@@ -0,0 +1,171 @@
/*
* Copyright (C) 2009-2016,2018 by Jonathan Naylor G4KLX
*
* Copyright (C) 2018 by Edouard Griffiths F4EXB:
* - Cosmetic changes to integrate with DSDcc
*
* Copyright (C) 2018 by Louis HERVE F4HUZ:
* - Transform C++ lib into C lib to integrate with DSD
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Include ------------------------------------------------------------------*/
//#include "nxdnconvolution.h"
#include <stdio.h>
//#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
/* Define -------------------------------------------------------------------*/
/* Global variables ---------------------------------------------------------*/
static const uint8_t CNXDNConvolution_BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U};
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | CNXDNConvolution_BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~CNXDNConvolution_BIT_MASK_TABLE[(i)&7])
#define READ_BIT1(p,i) (p[(i)>>3] & CNXDNConvolution_BIT_MASK_TABLE[(i)&7])
static const uint8_t CNXDNConvolution_BRANCH_TABLE1[] = {0U, 0U, 0U, 0U, 2U, 2U, 2U, 2U};
static const uint8_t CNXDNConvolution_BRANCH_TABLE2[] = {0U, 2U, 2U, 0U, 0U, 2U, 2U, 0U};
static const unsigned int CNXDNConvolution_NUM_OF_STATES_D2 = 8U;
static const unsigned int CNXDNConvolution_NUM_OF_STATES = 16U;
static const uint32_t CNXDNConvolution_M = 4U;
static const unsigned int CNXDNConvolution_K = 5U;
static uint16_t m_metrics1[16U] = {0};
static uint16_t m_metrics2[16U] = {0};
static uint64_t m_decisions[300U] = {0};
static uint16_t * m_oldMetrics = NULL;
static uint16_t * m_newMetrics = NULL;
static uint64_t * m_dp = NULL;
/* Functions ----------------------------------------------------------------*/
void CNXDNConvolution_start(void)
{
memset(m_metrics1, 0x00U, CNXDNConvolution_NUM_OF_STATES * sizeof(uint16_t));
memset(m_metrics2, 0x00U, CNXDNConvolution_NUM_OF_STATES * sizeof(uint16_t));
m_oldMetrics = m_metrics1;
m_newMetrics = m_metrics2;
m_dp = m_decisions;
}
void CNXDNConvolution_decode(uint8_t s0, uint8_t s1)
{
uint8_t i = 0;
uint8_t j = 0;
uint8_t decision0 = 0;
uint8_t decision1 = 0;
uint16_t metric = 0;
uint16_t m0 = 0;
uint16_t m1 = 0;
uint16_t * tmp = NULL;
*m_dp = 0U;
for (i = 0U; i < CNXDNConvolution_NUM_OF_STATES_D2; i++)
{
j = i * 2U;
metric = abs(CNXDNConvolution_BRANCH_TABLE1[i] - s0) + abs(CNXDNConvolution_BRANCH_TABLE2[i] - s1);
m0 = m_oldMetrics[i] + metric;
m1 = m_oldMetrics[i + CNXDNConvolution_NUM_OF_STATES_D2] + (CNXDNConvolution_M - metric);
decision0 = (m0 >= m1) ? 1U : 0U;
m_newMetrics[j + 0U] = decision0 != 0U ? m1 : m0;
m0 = m_oldMetrics[i] + (CNXDNConvolution_M - metric);
m1 = m_oldMetrics[i + CNXDNConvolution_NUM_OF_STATES_D2] + metric;
decision1 = (m0 >= m1) ? 1U : 0U;
m_newMetrics[j + 1U] = decision1 != 0U ? m1 : m0;
*m_dp |= ((uint64_t)(decision1) << (j + 1U)) | ((uint64_t)(decision0) << (j + 0U));
}
++m_dp;
//assert((m_dp - m_decisions) <= 300);
tmp = m_oldMetrics;
m_oldMetrics = m_newMetrics;
m_newMetrics = tmp;
}
void CNXDNConvolution_chainback(unsigned char* out, unsigned int nBits)
{
//assert(out != 0);
uint32_t state = 0U;
uint32_t i = 0;
uint8_t bit = 0;
while (nBits-- > 0)
{
--m_dp;
i = state >> (9 - CNXDNConvolution_K);
bit = (uint8_t)(*m_dp >> i) & 1;
state = (bit << 7) | (state >> 1);
WRITE_BIT1(out, nBits, bit != 0U);
}
}
void CNXDNConvolution_encode(const unsigned char* in, unsigned char* out, unsigned int nBits)
{
//assert(in != 0);
//assert(out != 0);
//assert(nBits > 0U);
uint8_t g1 = 0U;
uint8_t g2 = 0U;
uint8_t d = 0U;
uint8_t d1 = 0U;
uint8_t d2 = 0U;
uint8_t d3 = 0U;
uint8_t d4 = 0U;
uint32_t k = 0U;
unsigned int i = 0U;
for (i = 0U; i < nBits; i++)
{
d = READ_BIT1(in, i) ? 1U : 0U;
g1 = (d + d3 + d4) & 1;
g2 = (d + d1 + d2 + d4) & 1;
d4 = d3;
d3 = d2;
d2 = d1;
d1 = d;
WRITE_BIT1(out, k, g1 != 0U);
k++;
WRITE_BIT1(out, k, g2 != 0U);
k++;
}
}