From: drowe67 Date: Wed, 4 Jun 2014 11:05:20 +0000 (+0000) Subject: integrating choice of short and long varicode, short code still has some problems X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=ea1094bb7bd65a45b5a133d38f268f1c67eadb71;p=freetel-svn-tracking.git integrating choice of short and long varicode, short code still has some problems git-svn-id: https://svn.code.sf.net/p/freetel/code@1633 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/src/dlg_options.cpp b/fdmdv2/src/dlg_options.cpp index 32ae43c4..470da44c 100644 --- a/fdmdv2/src/dlg_options.cpp +++ b/fdmdv2/src/dlg_options.cpp @@ -32,6 +32,18 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c wxBoxSizer* bSizer30; bSizer30 = new wxBoxSizer(wxVERTICAL); + //------------------------------ + // Test Frames check box + //------------------------------ + + wxStaticBoxSizer* sbSizer_testFrames; + sbSizer_testFrames = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Test Frames")), wxVERTICAL); + + m_ckboxTestFrame = new wxCheckBox(this, wxID_ANY, _("Enable"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + sbSizer_testFrames->Add(m_ckboxTestFrame, 0, wxALIGN_LEFT, 0); + + bSizer30->Add(sbSizer_testFrames,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3); + //------------------------------ // Txt Msg Text Box //------------------------------ @@ -44,19 +56,21 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c sbSizer_callSign->Add(m_txtCtrlCallSign, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3); bSizer30->Add(sbSizer_callSign,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3); - + //------------------------------ - // Test Frames check box + // Txt Encoding //------------------------------ - wxStaticBoxSizer* sbSizer_testFrames; - sbSizer_testFrames = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Test Frames")), wxVERTICAL); - - m_ckboxTestFrame = new wxCheckBox(this, wxID_ANY, _("Enable"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); - sbSizer_testFrames->Add(m_ckboxTestFrame, 0, wxALIGN_LEFT, 0); + wxStaticBoxSizer* sbSizer_encoding = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Text Encoding")), wxHORIZONTAL); - bSizer30->Add(sbSizer_testFrames,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3); + m_rb_textEncoding1 = new wxRadioButton( this, wxID_ANY, wxT("Long varicode"), wxDefaultPosition, wxDefaultSize, 0); + m_rb_textEncoding1->SetValue(true); + sbSizer_encoding->Add(m_rb_textEncoding1, 0, wxALIGN_LEFT|wxALL, 1); + m_rb_textEncoding2 = new wxRadioButton( this, wxID_ANY, wxT("Short Varicode"), wxDefaultPosition, wxDefaultSize, 0); + sbSizer_encoding->Add(m_rb_textEncoding2, 0, wxALIGN_LEFT|wxALL, 1); + bSizer30->Add(sbSizer_encoding,0, wxALL|wxEXPAND, 3); + //------------------------------ // Event processing //------------------------------ @@ -155,18 +169,29 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) m_ckbox_events->SetValue(wxGetApp().m_events); m_txt_events_regexp->SetValue(wxGetApp().m_events_regexp); + + if (wxGetApp().m_textEncoding == 1) + m_rb_textEncoding1->SetValue(true); + if (wxGetApp().m_textEncoding == 2) + m_rb_textEncoding2->SetValue(true); } if(inout == EXCHANGE_DATA_OUT) { - wxGetApp().m_callSign = m_txtCtrlCallSign->GetValue(); + wxGetApp().m_callSign = m_txtCtrlCallSign->GetValue(); wxGetApp().m_testFrames = m_ckboxTestFrame->GetValue(); wxGetApp().m_events = m_ckbox_events->GetValue(); wxGetApp().m_events_regexp = m_txt_events_regexp->GetValue(); + if (m_rb_textEncoding1->GetValue()) + wxGetApp().m_textEncoding = 1; + if (m_rb_textEncoding2->GetValue()) + wxGetApp().m_textEncoding = 2; + if (storePersistent) { pConfig->Write(wxT("/Data/CallSign"), wxGetApp().m_callSign); + pConfig->Write(wxT("/Data/TextEncoding"), wxGetApp().m_textEncoding); pConfig->Write(wxT("/Events/enable"), wxGetApp().m_events); pConfig->Write(wxT("/Events/regexp"), wxGetApp().m_events_regexp); pConfig->Flush(); diff --git a/fdmdv2/src/dlg_options.h b/fdmdv2/src/dlg_options.h index cfa7eaea..897bb376 100644 --- a/fdmdv2/src/dlg_options.h +++ b/fdmdv2/src/dlg_options.h @@ -32,7 +32,7 @@ class OptionsDlg : public wxDialog public: OptionsDlg( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Options"), - const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(600,530), + const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(600,580), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~OptionsDlg(); @@ -48,6 +48,9 @@ class OptionsDlg : public wxDialog wxTextCtrl *m_txtCtrlCallSign; // TODO: this should be renamed to tx_txtmsg, and rename all related incl persis strge wxCheckBox *m_ckboxTestFrame; + wxRadioButton *m_rb_textEncoding1; + wxRadioButton *m_rb_textEncoding2; + wxCheckBox *m_ckbox_events; wxTextCtrl *m_txt_events_regexp; wxTextCtrl *m_txt_events_in; diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index 1f7bfeb2..b7c11979 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -370,6 +370,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) wxGetApp().m_SpkOutEQEnable = (float)pConfig->Read(wxT("/Filter/SpkOutEQEnable"), f); wxGetApp().m_callSign = pConfig->Read("/Data/CallSign", wxT("")); + wxGetApp().m_textEncoding = pConfig->Read("/Data/TextEncoding", 1); wxGetApp().m_events = pConfig->Read("/Events/enable", f); wxGetApp().m_events_regexp = pConfig->Read("/Events/regexp", wxT("s|onstart,mycallsign=(.*),|curl http://qso.freedv.org/cgi-bin/onstart.cgi?callsign=$1|")); @@ -450,7 +451,6 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) // data states g_txDataInFifo = fifo_create(MAX_CALLSIGN*VARICODE_MAX_BITS); g_rxDataOutFifo = fifo_create(MAX_CALLSIGN*VARICODE_MAX_BITS); - varicode_decode_init(&g_varicode_dec_states, 1); sox_biquad_start(); golay23_init(); @@ -529,6 +529,7 @@ MainFrame::~MainFrame() pConfig->Write(wxT("/Audio/snrSlow"), wxGetApp().m_snrSlow); pConfig->Write(wxT("/Data/CallSign"), wxGetApp().m_callSign); + pConfig->Write(wxT("/Data/TextEncoding"), wxGetApp().m_textEncoding); pConfig->Write(wxT("/Events/enable"), wxGetApp().m_events); pConfig->Write(wxT("/Events/regexp"), wxGetApp().m_events_regexp); @@ -898,7 +899,7 @@ void MainFrame::OnTimer(wxTimerEvent &evt) // varicode encode and write to tx data fifo short varicode[MAX_CALLSIGN*VARICODE_MAX_BITS]; - int nout = varicode_encode(varicode, callsigncr, MAX_CALLSIGN*VARICODE_MAX_BITS, strlen(callsign)+1, 1); + int nout = varicode_encode(varicode, callsigncr, MAX_CALLSIGN*VARICODE_MAX_BITS, strlen(callsign)+1, wxGetApp().m_textEncoding); fifo_write(g_txDataInFifo, varicode, nout); //printf("Callsign sending: %s nout: %d\n", callsign, nout); } @@ -1904,6 +1905,10 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) m_textLevel->SetLabel(wxT("")); m_gaugeLevel->SetValue(0); + // Init text msg decoding + + varicode_decode_init(&g_varicode_dec_states, wxGetApp().m_textEncoding); + printf("m_textEncoding = %d\n", wxGetApp().m_textEncoding); //printf("g_stats.snr: %f\n", g_stats.snr_est); // attempt to start PTT ...... diff --git a/fdmdv2/src/fdmdv2_main.h b/fdmdv2/src/fdmdv2_main.h index 0a513bff..460e8e82 100644 --- a/fdmdv2/src/fdmdv2_main.h +++ b/fdmdv2/src/fdmdv2_main.h @@ -173,6 +173,7 @@ class MainApp : public wxApp wxString m_callSign; bool m_events; + unsigned int m_textEncoding; wxString m_events_regexp; bool m_snrSlow; diff --git a/fdmdv2/src/sox_biquad.c b/fdmdv2/src/sox_biquad.c index 85abdbb0..f5a0913c 100644 --- a/fdmdv2/src/sox_biquad.c +++ b/fdmdv2/src/sox_biquad.c @@ -39,14 +39,12 @@ int lsx_biquad_flow(sox_effect_t * effp, const sox_sample_t *ibuf, void sox_biquad_start(void) { - printf("sox_biquad_start(void)\n"); int r = sox_init(); assert(r == SOX_SUCCESS); } void sox_biquad_finish(void) { - printf("sox_biquad_finish(void)\n"); sox_quit(); } diff --git a/fdmdv2/src/varicode.c b/fdmdv2/src/varicode.c index 9bfb5dca..6e0dfa4c 100644 --- a/fdmdv2/src/varicode.c +++ b/fdmdv2/src/varicode.c @@ -156,13 +156,15 @@ int varicode_encode(short varicode_out[], char ascii_in[], int max_out, int n_in void varicode_decode_init(struct VARICODE_DEC *dec_states, int code_num) { - assert((code_num ==1) || (code_num ==2)); + assert((code_num ==1) || (code_num == 2)); dec_states->state = 0; dec_states->n_zeros = 0; dec_states->v_len = 0; dec_states->packed = 0; dec_states->code_num = code_num; + dec_states->n_in = 0; + dec_states->in[0] = dec_states->in[1] = 0; } @@ -170,7 +172,7 @@ void varicode_decode_init(struct VARICODE_DEC *dec_states, int code_num) static int decode_one_bit(struct VARICODE_DEC *s, char *single_ascii, short varicode_in, int long_code) { - int found, i; + int found=0, i; unsigned short byte1, byte2; //printf("decode_one_bit : state: %d varicode_in: %d packed: 0x%x n_zeros: %d\n", @@ -228,7 +230,7 @@ static int decode_one_bit(struct VARICODE_DEC *s, char *single_ascii, short vari static int decode_two_bits(struct VARICODE_DEC *s, char *single_ascii, short varicode_in1, short varicode_in2) { - int found, i; + int found=0, i; unsigned short byte1; //printf("decode_one_bit : state: %d varicode_in: %d packed: 0x%x n_zeros: %d\n", @@ -287,7 +289,7 @@ static int decode_two_bits(struct VARICODE_DEC *s, char *single_ascii, short var int varicode_decode1(struct VARICODE_DEC *dec_states, char ascii_out[], short varicode_in[], int max_out, int n_in) { int output, n_out; - char single_ascii; + char single_ascii = 0; n_out = 0; @@ -310,22 +312,33 @@ int varicode_decode1(struct VARICODE_DEC *dec_states, char ascii_out[], short va int varicode_decode2(struct VARICODE_DEC *dec_states, char ascii_out[], short varicode_in[], int max_out, int n_in) { int output, n_out; - char single_ascii; + char single_ascii = 0; - //assert((n_in % 2) == 0); /* code always processes two bits at a time */ n_out = 0; - //printf("varicode_decode: n_in: %d\n", n_in); + //printf("varicode_decode2: n_in: %d varicode_in[0] %d dec_states->n_in: %d\n", n_in, varicode_in[0], dec_states->n_in); while(n_in && (n_out < max_out)) { - output = decode_two_bits(dec_states, &single_ascii, varicode_in[0], varicode_in[1]); - varicode_in +=2; - n_in -= 2; + + // keep two bit buffer so we can process two at a time + + dec_states->in[0] = dec_states->in[1]; + dec_states->in[1] = varicode_in[0]; + dec_states->n_in++; + varicode_in++; + n_in--; + + if (dec_states->n_in == 2) { + output = decode_two_bits(dec_states, &single_ascii, dec_states->in[0], dec_states->in[1]); + + dec_states->n_in = 0; - if (output) { - *ascii_out++ = single_ascii; - n_out++; - } + if (output) { + printf(" output: %d single_ascii: 0x%x %c\n", output, (int)single_ascii, single_ascii); + *ascii_out++ = single_ascii; + n_out++; + } + } } return n_out; @@ -388,10 +401,11 @@ void test_varicode(int code_num) { n_ascii_chars_out += varicode_decode(&dec_states, &ascii_out[n_ascii_chars_out], &varicode[half], length-n_ascii_chars_out, n_varicode_bits_out - half); - //printf("n_ascii_chars_out: %d\n", n_ascii_chars_out); - assert(n_ascii_chars_out == length); + printf(" n_ascii_chars_out: %d\n", n_ascii_chars_out); + printf(" average bits/character: %3.2f\n", (float)n_varicode_bits_out/n_ascii_chars_out); + //printf("ascii_out: %s\n", ascii_out); if (memcmp(ascii_in, ascii_out, length) == 0) @@ -401,7 +415,7 @@ void test_varicode(int code_num) { // 2. Test some ascii with a run of zeros ----------------------------------------------------- - sprintf(ascii_in, "CQ CQ CQ, this is VK5DGR"); + sprintf(ascii_in, "CQ CQ CQ this is VK5DGR"); assert(strlen(ascii_in) < length); if (code_num == 2) @@ -413,7 +427,7 @@ void test_varicode(int code_num) { n_ascii_chars_out = varicode_decode(&dec_states, ascii_out, varicode, length, n_varicode_bits_out); ascii_out[n_ascii_chars_out] = 0; - printf("ascii_out: %s\n", ascii_out); + printf(" ascii_out: %s\n", ascii_out); if (strcmp(ascii_in, ascii_out) == 0) printf(" Test 2 Pass\n"); else diff --git a/fdmdv2/src/varicode.h b/fdmdv2/src/varicode.h index dd2329a9..4834a95c 100644 --- a/fdmdv2/src/varicode.h +++ b/fdmdv2/src/varicode.h @@ -36,6 +36,8 @@ struct VARICODE_DEC { int v_len; unsigned short packed; int code_num; + int n_in; + int in[2]; }; int varicode_encode(short varicode_out[], char ascii_in[], int max_out, int n_in, int code_num); diff --git a/fdmdv2/src/varicode_table.h b/fdmdv2/src/varicode_table.h index 3bf2ac5c..08f38fd5 100644 --- a/fdmdv2/src/varicode_table.h +++ b/fdmdv2/src/varicode_table.h @@ -292,12 +292,12 @@ unsigned char const varicode_table1[256] = { // This code was used on FDMDV version 1, and is more compact that Code 1, but only covers a subset // of the ASCII cahacter set - + char const varicode_table2[] = { ' ' ,0b11000000, - ',' ,0b01000000, - '=' ,0b10000000, // (Start of message) + 13 ,0b01000000, // CR, end of message + '=' ,0b10000000, '1' ,0b11110000, '2' ,0b01110000, '3' ,0b10110000,