fill in missing leading sync packet and new log_debug parameter.

pull/12/head
Tom Early 7 years ago
parent b0c0945799
commit 1eada4339a

@ -80,6 +80,11 @@ CQnetModem::~CQnetModem()
{
}
bool CQnetModem::VoicePacketIsSync(const unsigned char *text)
{
return *text==0x55U && *(text+1)==0x2DU && *(text+2)==0x16U;
}
bool CQnetModem::GetBufferSize()
{
std::this_thread::sleep_for(std::chrono::seconds(2));
@ -576,15 +581,18 @@ int CQnetModem::SendToModem(const unsigned char *buf)
bool CQnetModem::ProcessGateway(const int len, const unsigned char *raw)
{
static unsigned int sfcount = 0U;
if (29==len || 58==len) { //here is dstar data
SDSTR dstr;
memcpy(dstr.pkt_id, raw, len); // transfer raw data to SDSTR struct
if (LOG_DEBUG) {
if (58 == len)
printf("From Gateway id=%04X header='%.36s'\n", ntohs(dstr.vpkt.streamid), dstr.vpkt.hdr.flag+3);
else
printf("from Gateway id=%04X ctrl=%02X text=%02X:%02X:%02X\n", ntohs(dstr.vpkt.streamid), dstr.vpkt.ctrl, dstr.vpkt.vasd.text[0], dstr.vpkt.vasd.text[1], dstr.vpkt.vasd.text[2]);
}
SMODEM frame; // destination
frame.start = FRAME_START;
if (58 == len) { // write a Header packet
sfcount = 20U;
frame.length = 44U;
frame.type = TYPE_HEADER;
memcpy(frame.header.flag, dstr.vpkt.hdr.flag, 3);
@ -597,19 +605,11 @@ bool CQnetModem::ProcessGateway(const int len, const unsigned char *raw)
queue.push(CFrame(&frame.start));
PacketWait.start();
g2_is_active = true;
if (LOG_QSO)
if (LOG_QSO && ! LOG_DEBUG)
printf("Queued to %s flags=%02x:%02x:%02x ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s\n", MODEM_DEVICE.c_str(), frame.header.flag[0], frame.header.flag[1], frame.header.flag[2], frame.header.ur, frame.header.r1, frame.header.r2, frame.header.my, frame.header.nm);
} else { // write a voice data packet
if (g2_is_active) {
//const unsigned char sdsync[3] = { 0x55U, 0x2DU, 0x16U };
if (0U == (0x3FU & dstr.vpkt.ctrl)) {
if (sfcount != 20U)
printf("Warning: Superframe count is %u\n", sfcount);
sfcount = 0U;
if (0x55U!=dstr.vpkt.vasd.text[0] || 0x2DU!=dstr.vpkt.vasd.text[1] || 0x16U!=dstr.vpkt.vasd.text[2])
printf("Warning: Voice sync frame (ctrl=0x%02xU) contained text %02x:%02x:%02x!\n", dstr.vpkt.ctrl, dstr.vpkt.vasd.text[0], dstr.vpkt.vasd.text[1], dstr.vpkt.vasd.text[2]);
} else
sfcount++;
if (dstr.vpkt.ctrl & 0x40U) {
frame.length = 3U;
frame.type = TYPE_EOT;
@ -617,8 +617,6 @@ bool CQnetModem::ProcessGateway(const int len, const unsigned char *raw)
if (LOG_QSO)
printf("Queued modem end of transmission\n");
} else {
if (sfcount != (dstr.vpkt.ctrl & 0x3FU))
printf("Warning: frame ctrl should be %u, but it's %u!\n", sfcount, (dstr.vpkt.ctrl & 0x3FU));
frame.length = 15U;
frame.type = TYPE_DATA;
memcpy(frame.voice.ambe, dstr.vpkt.vasd.voice, 12);
@ -627,16 +625,42 @@ bool CQnetModem::ProcessGateway(const int len, const unsigned char *raw)
PacketWait.start();
}
}
} else
printf("DEBUG: ProcessGateway: unusual packet size read len=%d\n", len);
} else {
if (LOG_DEBUG)
printf("From gateway: unusual packet size len=%d\n", len);
}
return false;
}
bool CQnetModem::ProcessModem(const SMODEM &frame)
{
static bool in_stream = false;
static bool first_voice_packet = false;
static short stream_id = 0U;
static unsigned char ctrl = 0U;
if (LOG_DEBUG) {
switch (frame.type) {
case TYPE_HEADER:
printf("Header from modem: %.36s\n", frame.header.flag+3);
break;
case TYPE_DATA:
printf("Data from modem: text is %02X:%02X:%02X\n", frame.voice.text[0], frame.voice.text[1], frame.voice.text[2]);
break;
case TYPE_EOT:
printf("EOT From modem\n");
break;
case TYPE_LOST:
printf("Lost Transmission from modem\n");
break;
default:
printf("Other packet from modem: %02X", frame.start);
for (unsigned int i=0; i<frame.length; i++)
printf(":%02X", *(&frame.start + i));
printf("\n");
break;
}
}
// create a stream id if this is a header
if (frame.type == TYPE_HEADER)
stream_id = random.NewStreamID();
@ -655,7 +679,8 @@ bool CQnetModem::ProcessModem(const SMODEM &frame)
dstr.vpkt.streamid = htons(stream_id);
if (frame.type == TYPE_HEADER) { // header
ctrl = 1U;
in_stream = first_voice_packet = true;
ctrl = 0U;
dstr.remaining = 0x30U;
dstr.vpkt.ctrl = 0x80U;
@ -672,13 +697,23 @@ bool CQnetModem::ProcessModem(const SMODEM &frame)
printf("ERROR: ProcessModem: Could not write gateway header packet\n");
return true;
}
if (LOG_QSO)
if (LOG_QSO && ! LOG_DEBUG)
printf("Sent DSTR to gateway, streamid=%04x flags=%02x:%02x:%02x ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s\n", ntohs(dstr.vpkt.streamid), dstr.vpkt.hdr.flag[0], dstr.vpkt.hdr.flag[1], dstr.vpkt.hdr.flag[2], dstr.vpkt.hdr.ur, dstr.vpkt.hdr.r1, dstr.vpkt.hdr.r2, dstr.vpkt.hdr.my, dstr.vpkt.hdr.nm);
} else if (frame.type==TYPE_DATA || frame.type==TYPE_EOT || frame.type==TYPE_LOST) { // ambe
} else if (in_stream && (frame.type==TYPE_DATA || frame.type==TYPE_EOT || frame.type==TYPE_LOST)) { // ambe
dstr.remaining = 0x16U;
dstr.vpkt.ctrl = ctrl++;
if (frame.type == TYPE_DATA) {
if (0x55U==frame.voice.text[0] && 0x2DU==frame.voice.text[1] && 0x16U==frame.voice.text[2]) {
if (first_voice_packet) {
if (! VoicePacketIsSync(frame.voice.text)) { // create a quite sync voice packet, if needed
const unsigned char sync[12] = { 0x4EU,0x8DU,0x32U,0x88U,0x26U,0x1AU,0x3FU,0x61U,0xE8U,0x55U,0x2DU,0x16U };
dstr.vpkt.ctrl = 0U;
memcpy(dstr.vpkt.vasd.voice, sync, 12U);
Modem2Gate.Write(dstr.pkt_id, 29);
ctrl = 1U;
}
first_voice_packet = false;
}
if (VoicePacketIsSync(frame.voice.text)) {
dstr.vpkt.ctrl = 0U; // re-sync!
ctrl = 1U; // the frame after the sync
}
@ -693,12 +728,13 @@ bool CQnetModem::ProcessModem(const SMODEM &frame)
else
memcpy(dstr.vpkt.vasd.voice, silence, 12);
dstr.vpkt.ctrl |= 0x40U;
if (LOG_QSO) {
if (LOG_QSO && ! LOG_DEBUG) {
if (frame.type == TYPE_EOT)
printf("Sent DSTR end of streamid=%04x\n", ntohs(dstr.vpkt.streamid));
else
printf("Sent LOST end of streamid=%04x\n", ntohs(dstr.vpkt.streamid));
}
first_voice_packet = in_stream = false;
}
if (29 != Modem2Gate.Write(dstr.pkt_id, 29)) {
printf("ERROR: ProcessModem: Could not write gateway voice packet\n");
@ -805,6 +841,7 @@ bool CQnetModem::ReadConfig(const char *cfgFile)
}
cfg.GetValue("log_qso", estr, LOG_QSO);
cfg.GetValue("log_debug", estr, LOG_DEBUG);
return false;
}

@ -211,6 +211,7 @@ private:
bool g2_is_active;
// functions
bool VoicePacketIsSync(const unsigned char *);
bool Initialize(const char *cfgfile);
static void SignalCatch(const int signum);
bool ProcessGateway(const int len, const unsigned char *raw);
@ -231,7 +232,7 @@ private:
std::string MODEM_DEVICE, RPTR;
double TX_FREQUENCY, RX_FREQUENCY, TX_OFFSET, RX_OFFSET, packet_wait;
int TX_DELAY, RX_LEVEL, TX_LEVEL, PACKET_WAIT;
bool DUPLEX, RX_INVERT, TX_INVERT, PTT_INVERT, LOG_QSO;
bool DUPLEX, RX_INVERT, TX_INVERT, PTT_INVERT, LOG_QSO, LOG_DEBUG;
// parameters
HARDWARE_TYPE hardwareType;

@ -167,6 +167,7 @@ dvrptr_inverse_tx=true # if you're not hearing your system, try false
log_qso_d=false # QSO info goes into the log
log_irc_d=false # IRC debug info
log_dtmf_d=false # DTMF debug info
log_debug_d=false # WARNING, can produce a large number of log entries!
##########################################################################################################################
#

@ -143,6 +143,8 @@ FileMenu () {
echo -n "cl : Call(QSO) logging :"; EvaluateVar log_qso{,_d}
echo -n "il : IRC logging :"; EvaluateVar log_irc{,_d}
echo -n "dl : DTMF logging :"; EvaluateVar log_dtmf{,_d}
echo -n "xl : Debug logging :"; EvaluateVar log_debug{,_d}
echo " WARNING debug logging can produce large log file!"
if [ -n "$em" ]; then
echo
echo " Files and directories"
@ -172,6 +174,7 @@ FileMenu () {
elif [[ "$key" == cl* ]]; then SetBooleanValue log_qso "$value"
elif [[ "$key" == il* ]]; then SetBooleanValue log_irc "$value"
elif [[ "$key" == dl* ]]; then SetBooleanValue log_dtmf "$value"
elif [[ "$key" == xl* ]]; then SetBooleanValue log_debug "$value"
elif [[ "$key" == et* ]]; then timing_timeout_echo="$value"
elif [[ "$key" == vt* ]]; then timing_timeout_voicemail="$value"
elif [[ "$key" == gt* ]]; then timing_timeout_remote_g2="$value"
@ -188,6 +191,7 @@ FileMenu () {
elif [[ "$value" == cl* ]]; then unset log_qso
elif [[ "$value" == il* ]]; then unset log_irc
elif [[ "$value" == dl* ]]; then unset log_dtmf
elif [[ "$value" == xl* ]]; then unset log_debug
elif [[ "$value" == et* ]]; then unset timing_timeout_echo
elif [[ "$value" == vt* ]]; then unset timing_timeout_voicemail
elif [[ "$value" == gt* ]]; then unset timing_timeout_remote_g2
@ -597,6 +601,7 @@ WriteCFGFile () {
[ -z "${log_qso+x}" ] || echo "log_qso=${log_qso}" >> $outFile
[ -z "${log_irc+x}" ] || echo "log_irc=${log_irc}" >> $outFile
[ -z "${log_dtmf+x}" ] || echo "log_dtmf=${log_dtmf}" >> $outFile
[ -z "${log_debug+x}" ] || echo "log_debug=${log_debug}" >> $outFile
# dplus_ section
[ -z "${dplus_authorize+x}" ] || echo "dplus_authorize=${dplus_authorize}" >> $outFile
[ -z "${dplus_priority+x}" ] || echo "dplus_priority=${dplus_priority}" >> $outFile

Loading…
Cancel
Save

Powered by TurnKey Linux.