mirror of
https://github.com/n5ac/smartsdr-dsp.git
synced 2026-01-21 07:40:21 +01:00
Transmit of SYNC bits working. Very dirty state
This commit is contained in:
parent
13d4d64014
commit
fe678569b4
|
|
@ -208,6 +208,9 @@ static GMSK_DEMOD _gmsk_demod = NULL;
|
|||
static GMSK_MOD _gmsk_mod = NULL;
|
||||
static DSTAR_MACHINE _dstar = NULL;
|
||||
|
||||
static BOOL write_dat = TRUE;
|
||||
static uint32 data_i = 0;
|
||||
|
||||
#define FREEDV_NSAMPLES 160
|
||||
|
||||
static void* _sched_waveform_thread(void* param)
|
||||
|
|
@ -244,6 +247,8 @@ static void* _sched_waveform_thread(void* param)
|
|||
float tx_float_in_24k[DV_PACKET_SAMPLES * DECIMATION_FACTOR + FILTER_TAPS];
|
||||
float tx_float_out_24k[DV_PACKET_SAMPLES * DECIMATION_FACTOR ];
|
||||
|
||||
|
||||
|
||||
// ======================= Initialization Section =========================
|
||||
|
||||
thumbDV_init("/dev/ttyUSB0", &_dv_serial_fd);
|
||||
|
|
@ -338,6 +343,7 @@ static void* _sched_waveform_thread(void* param)
|
|||
|
||||
// Set the transmit 'initial' flag
|
||||
initial_tx = TRUE;
|
||||
write_dat = TRUE;
|
||||
|
||||
// Check for new receiver input packet & move to RX1_cb.
|
||||
// TODO - If transmit packet, discard here?
|
||||
|
|
@ -503,49 +509,126 @@ static void* _sched_waveform_thread(void* param)
|
|||
/* DECODE */
|
||||
uint32 decode_out = 0;
|
||||
decode_out = thumbDV_encode(_dv_serial_fd, speech_in, (unsigned char * )mod_out, DV_PACKET_SAMPLES);
|
||||
//decode_out = thumbDV_decode(_dv_serial_fd, NULL, mod_out, 160);
|
||||
|
||||
for( i = 0 ; i < DV_PACKET_SAMPLES ; i++)
|
||||
{
|
||||
//cbWriteShort(TX3_cb, mod_out[i]);
|
||||
cbWriteShort(TX3_cb, speech_in[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for >= 128 samples in TX3_cb, convert to floats
|
||||
// and spin the upsampler. Move output to TX4_cb.
|
||||
FILE * dat = NULL;
|
||||
|
||||
if(csbContains(TX3_cb) >= DV_PACKET_SAMPLES)
|
||||
{
|
||||
for( i=0 ; i< DV_PACKET_SAMPLES ; i++)
|
||||
{
|
||||
tx_float_in_8k[i+MEM_8] = ((float) (cbReadShort(TX3_cb) / SCALE_TX_OUT));
|
||||
}
|
||||
if ( write_dat ) {
|
||||
dat = fopen("gmsk_txNew2.dat", "a");
|
||||
}
|
||||
if ( initial_tx ) {
|
||||
|
||||
fdmdv_8_to_24(tx_float_out_24k, &tx_float_in_8k[MEM_8], DV_PACKET_SAMPLES);
|
||||
initial_tx = FALSE;
|
||||
float buf[5];
|
||||
uint32 j = 0;
|
||||
/* Create Sync */
|
||||
for ( i = 0 ; i < 64 * 2 ; i += 2 ) {
|
||||
gmsk_encode(_gmsk_mod, TRUE, buf, DSTAR_RADIO_BIT_LENGTH);
|
||||
|
||||
for( i=0 ; i< DV_PACKET_SAMPLES * DECIMATION_FACTOR ; i++)
|
||||
{
|
||||
cbWriteFloat(TX4_cb, tx_float_out_24k[i]);
|
||||
}
|
||||
//Sig2Noise = (_freedvS->fdmdv_stats.snr_est);
|
||||
}
|
||||
for ( j = 0 ; j < DSTAR_RADIO_BIT_LENGTH ; j++ ) {
|
||||
cbWriteFloat(TX4_cb, buf[j]);
|
||||
}
|
||||
|
||||
// Check for >= 128 samples in RX4_cb. Form packet and
|
||||
// export.
|
||||
gmsk_encode(_gmsk_mod, FALSE, buf, DSTAR_RADIO_BIT_LENGTH);
|
||||
|
||||
for ( j = 0 ; j < DSTAR_RADIO_BIT_LENGTH ; j++ ) {
|
||||
cbWriteFloat(TX4_cb, buf[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for ( i = 0 ; i < FRAME_SYNC_LENGTH_BITS ; i++ ) {
|
||||
gmsk_encode(_gmsk_mod, FRAME_SYNC_BITS[i], buf, DSTAR_RADIO_BIT_LENGTH);
|
||||
|
||||
for ( j = 0 ; j < DSTAR_RADIO_BIT_LENGTH ; j++ ) {
|
||||
cbWriteFloat(TX4_cb, buf[j]);
|
||||
}
|
||||
}
|
||||
|
||||
// fclose(dat);
|
||||
|
||||
// dstar_header tmp_h;
|
||||
// tmp_h.flag1 = 0;
|
||||
// tmp_h.flag2 = 0;
|
||||
// tmp_h.flag3 = 0;
|
||||
//
|
||||
// strncpy((char*)tmp_h.destination_rptr, "DIRECT", 9);
|
||||
// strncpy((char*)tmp_h.departure_rptr, "DIRECT", 9);
|
||||
// strncpy((char*)tmp_h.companion_call, "CQCQCQ", 9);
|
||||
// strncpy((char*)tmp_h.own_call1, "K5SDR", 9);
|
||||
// strncpy((char*)tmp_h.own_call1, "K5SDR", 9);
|
||||
//
|
||||
// dstar_pfcs pfcs;
|
||||
// pfcs.crc16 = 0xFFFF;
|
||||
// dstar_pfcsUpdateBuffer(&pfcs, (unsigned char * ) &tmp_h, 312);
|
||||
// dstar_pfcsResult(&pfcs, (unsigned char * )&(tmp_h.p_fcs));
|
||||
//
|
||||
// BOOL bits[FEC_SECTION_LENGTH_BITS] = {0};
|
||||
//
|
||||
// gmsk_bytesToBits((unsigned char *) &tmp_h, bits, 328);
|
||||
// BOOL encoded[330*2] = {0};
|
||||
// BOOL interleaved[330*2] = {0};
|
||||
// BOOL scrambled[330*2] = {0};
|
||||
// uint32 outLen = 0;
|
||||
// dstar_FECencode(bits, encoded, 330, &outLen);
|
||||
// //output("Encode outLen = %d\n", outLen);
|
||||
//
|
||||
// outLen = 660;
|
||||
// dstar_interleave(encoded, interleaved, outLen);
|
||||
//
|
||||
// uint32 count = 0;
|
||||
// dstar_scramble(interleaved, scrambled, outLen, &count);
|
||||
//output("Count = %d\n", count);
|
||||
// for ( i = 0 ; i < count ; i++ ) {
|
||||
// gmsk_encode(_gmsk_mod, scrambled[i], buf, DSTAR_RADIO_BIT_LENGTH);
|
||||
// for ( j = 0 ; j < DSTAR_RADIO_BIT_LENGTH ; j++ ) {
|
||||
// cbWriteFloat(TX4_cb, buf[j]);
|
||||
// //fprintf(dat, "%d %.12f\n", data_i++, buf[j]);
|
||||
// }
|
||||
// }
|
||||
|
||||
//fclose(dat);
|
||||
|
||||
}
|
||||
|
||||
uint32 tx_check_samples = PACKET_SAMPLES;
|
||||
|
||||
if(initial_tx)
|
||||
tx_check_samples = PACKET_SAMPLES * 3;
|
||||
if ( !initial_tx && cfbContains(TX4_cb) < PACKET_SAMPLES * 5) {
|
||||
for ( i = 0 ; i < 13 ; i++ ) {
|
||||
float buf[5];
|
||||
uint32 j = 0;
|
||||
gmsk_encode(_gmsk_mod, TRUE, buf, DSTAR_RADIO_BIT_LENGTH);
|
||||
|
||||
for ( j = 0 ; j < DSTAR_RADIO_BIT_LENGTH ; j++ ) {
|
||||
cbWriteFloat(TX4_cb, buf[j]);
|
||||
// if ( write_dat ) fprintf(dat, "%d %.12f\n", data_i++, buf[j]);
|
||||
}
|
||||
|
||||
gmsk_encode(_gmsk_mod, FALSE, buf, DSTAR_RADIO_BIT_LENGTH);
|
||||
|
||||
for ( j = 0 ; j < DSTAR_RADIO_BIT_LENGTH ; j++ ) {
|
||||
cbWriteFloat(TX4_cb, buf[j]);
|
||||
// if ( write_dat ) fprintf(dat, "%d %.12f\n", data_i++, buf[j]);
|
||||
}
|
||||
}
|
||||
|
||||
// if ( write_dat ) {
|
||||
// fclose(dat);
|
||||
//
|
||||
// sync();
|
||||
// write_dat = FALSE;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(cfbContains(TX4_cb) >= tx_check_samples )
|
||||
{
|
||||
for( i = 0 ; i < PACKET_SAMPLES ; i++)
|
||||
{
|
||||
//output("Fetching from end buffer \n");
|
||||
//output("Fetching from end buffer \n");
|
||||
// Set up the outbound packet
|
||||
fsample = cbReadFloat(TX4_cb);
|
||||
|
||||
// put the fsample into the outbound packet
|
||||
((Complex*)buf_desc->buf_ptr)[i].real = fsample;
|
||||
((Complex*)buf_desc->buf_ptr)[i].imag = fsample;
|
||||
|
|
@ -555,10 +638,11 @@ static void* _sched_waveform_thread(void* param)
|
|||
|
||||
memset( buf_desc->buf_ptr, 0, PACKET_SAMPLES * sizeof(Complex));
|
||||
|
||||
if(initial_tx)
|
||||
initial_tx = FALSE;
|
||||
|
||||
}
|
||||
|
||||
initial_tx = FALSE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -586,6 +670,7 @@ void sched_waveform_Init(void)
|
|||
|
||||
_gmsk_demod = gmsk_createDemodulator();
|
||||
_gmsk_mod = gmsk_createModulator();
|
||||
_gmsk_mod->m_invert = TRUE;
|
||||
|
||||
pthread_rwlock_init(&_list_lock, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -711,6 +711,14 @@ BOOL dstar_stateMachine(DSTAR_MACHINE machine, BOOL in_bit, unsigned char * ambe
|
|||
return have_audio_packet;
|
||||
}
|
||||
|
||||
void dstar_pfcsUpdateBuffer(DSTAR_PFCS pfcs, unsigned char * bytes, uint32 length)
|
||||
{
|
||||
uint32 i = 0;
|
||||
for ( i = 0 ; i < length ; i++ ) {
|
||||
pfcs->crc16 = (uint16)(pfcs->crc8[1]) ^ ccittTab[pfcs->crc8[0] ^ bytes[i]];
|
||||
}
|
||||
}
|
||||
|
||||
void dstar_pfcsUpdate(DSTAR_PFCS pfcs, BOOL * bits )
|
||||
{
|
||||
unsigned char byte;
|
||||
|
|
@ -719,7 +727,16 @@ void dstar_pfcsUpdate(DSTAR_PFCS pfcs, BOOL * bits )
|
|||
pfcs->crc16 = (uint16)pfcs->crc8[1] ^ ccittTab[ pfcs->crc8[0] ^ byte ];
|
||||
}
|
||||
|
||||
void dstar_pfcsResult( DSTAR_PFCS pfcs, BOOL * bits )
|
||||
void dstar_pfcsResult( DSTAR_PFCS pfcs, unsigned char * chksum )
|
||||
{
|
||||
pfcs->crc16 = ~ pfcs->crc16;
|
||||
|
||||
chksum[0] = pfcs->crc8[0];
|
||||
chksum[1] = pfcs->crc8[1];
|
||||
|
||||
}
|
||||
|
||||
void dstar_pfcsResultBits( DSTAR_PFCS pfcs, BOOL * bits )
|
||||
{
|
||||
pfcs->crc16 = ~pfcs->crc16;
|
||||
|
||||
|
|
@ -739,7 +756,7 @@ BOOL dstar_pfcsCheck(DSTAR_PFCS pfcs, BOOL * bits )
|
|||
{
|
||||
uint32 i = 0;
|
||||
BOOL sum[16];
|
||||
dstar_pfcsResult(pfcs, sum);
|
||||
dstar_pfcsResultBits(pfcs, sum);
|
||||
|
||||
for ( i = 0 ; i < 16 ; i++ ) {
|
||||
if ( sum[i] != bits[i] ) {
|
||||
|
|
|
|||
|
|
@ -98,10 +98,14 @@ BOOL dstar_stateMachine(DSTAR_MACHINE machine, BOOL in_bit, unsigned char * ambe
|
|||
|
||||
void dstar_pfcsUpdate(DSTAR_PFCS pfcs, BOOL * bits );
|
||||
BOOL dstar_pfcsCheck(DSTAR_PFCS pfcs, BOOL * bits );
|
||||
void dstar_pfcsResult(DSTAR_PFCS pfcs, unsigned char * chksum);
|
||||
void dstar_pfcsResultBits( DSTAR_PFCS pfcs, BOOL * bits );
|
||||
void dstar_pfcsUpdateBuffer(DSTAR_PFCS pfcs, unsigned char * bytes, uint32 length);
|
||||
|
||||
void dstar_FECTest(void);
|
||||
void dstar_scramble(BOOL * in, BOOL * out, uint32 length, uint32 * scramble_count);
|
||||
void dstar_interleave(const BOOL * in, BOOL * out, unsigned int length);
|
||||
void dstar_deinterleave(const BOOL * in, BOOL * out, unsigned int length);
|
||||
BOOL dstar_FECdecode(DSTAR_FEC fec, const BOOL * in, BOOL * out, unsigned int inLen, unsigned int * outLen);
|
||||
void dstar_FECencode(const BOOL * in, BOOL * out, unsigned int inLen, unsigned int * outLen);
|
||||
#endif /* THUMBDV_DSTAR_H_ */
|
||||
|
|
|
|||
|
|
@ -95,20 +95,20 @@ void gmsk_bytesToBits(unsigned char * bytes, BOOL * bits, uint32 num_bits)
|
|||
byte_idx++;
|
||||
bits_left -= 8;
|
||||
}
|
||||
|
||||
uint32 i = 0;
|
||||
output("Bytes: ");
|
||||
for ( i = 0 ; i < num_bits / 8U ; i++ ) {
|
||||
output(" 0x%02X", bytes[i]);
|
||||
}
|
||||
output("\nBits: ");
|
||||
for ( i = 0 ; i < num_bits ; i++ ) {
|
||||
output("%s ", bits[i] ? "1":"0");
|
||||
if ( (i+1) % 4 == 0 ) {
|
||||
output(" ");
|
||||
}
|
||||
}
|
||||
output("\n");
|
||||
//
|
||||
// uint32 i = 0;
|
||||
// output("Bytes: ");
|
||||
// for ( i = 0 ; i < num_bits / 8U ; i++ ) {
|
||||
// output(" 0x%02X", bytes[i]);
|
||||
// }
|
||||
// output("\nBits: ");
|
||||
// for ( i = 0 ; i < num_bits ; i++ ) {
|
||||
// output("%s ", bits[i] ? "1":"0");
|
||||
// if ( (i+1) % 4 == 0 ) {
|
||||
// output(" ");
|
||||
// }
|
||||
// }
|
||||
// output("\n");
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -307,9 +307,9 @@ uint32 gmsk_encode(GMSK_MOD mod, BOOL bit, float * buffer, unsigned int length)
|
|||
|
||||
for (i = 0; i < DSTAR_RADIO_BIT_LENGTH; i++) {
|
||||
if (bit) {
|
||||
buffer[i] = gmsk_FilterProcessSingle(mod->filter, -0.5f);
|
||||
buffer[i] = gmsk_FilterProcessSingle(mod->filter, -1.0f);
|
||||
} else {
|
||||
buffer[i] = gmsk_FilterProcessSingle(mod->filter, 0.5f);
|
||||
buffer[i] = gmsk_FilterProcessSingle(mod->filter, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -387,7 +387,7 @@ int thumbDV_processSerial(int serial_fd)
|
|||
} else if ( packet_type == AMBE3000_CHAN_PKT_TYPE ) {
|
||||
desc = hal_BufferRequest(respLen, sizeof(unsigned char) );
|
||||
memcpy(desc->buf_ptr, buffer, respLen);
|
||||
thumbDV_dump(ANSI_BLUE "Coded Packet" ANSI_WHITE, buffer, respLen);
|
||||
//thumbDV_dump(ANSI_BLUE "Coded Packet" ANSI_WHITE, buffer, respLen);
|
||||
/* Encoded data */
|
||||
_thumbDVEncodedList_LinkTail(desc);
|
||||
} else if ( packet_type == AMBE3000_SPEECH_PKT_TYPE ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue