Skip to content

Commit 4aaac85

Browse files
authored
Pocsag improvements (#20)
* Update analog_audio_app.cpp (#353) * Adding phase field (extracted from @jamesshao8 repo)
1 parent 3e15baa commit 4aaac85

File tree

9 files changed

+51
-11
lines changed

9 files changed

+51
-11
lines changed

firmware/application/apps/pocsag_app.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
6969
&field_vga,
7070
&field_frequency,
7171
&options_bitrate,
72+
&options_phase,
7273
&check_log,
7374
&check_ignore,
7475
&sym_ignore,
@@ -99,10 +100,13 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
99100
};
100101

101102
options_bitrate.on_change = [this](size_t, OptionsField::value_t v) {
102-
on_bitrate_changed(v);
103+
on_config_changed(v, options_phase.selected_index_value());
103104
};
104105
options_bitrate.set_selected_index(1); // 1200bps
105106

107+
options_phase.on_change = [this](size_t, OptionsField::value_t v) {
108+
on_config_changed(options_bitrate.selected_index_value(),v);
109+
};
106110
check_ignore.set_value(ignore);
107111
check_ignore.on_select = [this](Checkbox&, bool v) {
108112
ignore = v;
@@ -197,8 +201,8 @@ void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) {
197201
logger->log_raw_data(message->packet, target_frequency());
198202
}
199203

200-
void POCSAGAppView::on_bitrate_changed(const uint32_t new_bitrate) {
201-
baseband::set_pocsag(pocsag_bitrates[new_bitrate]);
204+
void POCSAGAppView::on_config_changed(const uint32_t new_bitrate, bool new_phase) {
205+
baseband::set_pocsag(pocsag_bitrates[new_bitrate], new_phase);
202206
}
203207

204208
void POCSAGAppView::set_target_frequency(const uint32_t new_value) {

firmware/application/apps/pocsag_app.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ class POCSAGAppView : public View {
9393
{ "2400bps", 2 }
9494
}
9595
};
96+
OptionsField options_phase {
97+
{ 6 * 8, 21 },
98+
1,
99+
{
100+
{ "P", 0 },
101+
{ "N", 1 },
102+
}
103+
};
96104
Checkbox check_log {
97105
{ 22 * 8, 21 },
98106
3,
@@ -124,7 +132,7 @@ class POCSAGAppView : public View {
124132

125133
void on_packet(const POCSAGPacketMessage * message);
126134

127-
void on_bitrate_changed(const uint32_t new_bitrate);
135+
void on_config_changed(const uint32_t new_bitrate, const bool phase);
128136

129137
uint32_t target_frequency() const;
130138
void set_target_frequency(const uint32_t new_value);

firmware/application/apps/ui_pocsag_tx.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ bool POCSAGTXView::start_tx() {
7171
return false;
7272
}
7373
}
74+
MessageType phase = (MessageType)options_phase.selected_index_value();
7475

7576
pocsag_encode(type, BCH_code, options_function.selected_index_value(), message, address, codewords);
7677

@@ -79,14 +80,21 @@ bool POCSAGTXView::start_tx() {
7980
progressbar.set_max(total_frames);
8081

8182
transmitter_model.set_sampling_rate(2280000);
83+
transmitter_model.set_rf_amp(true);
84+
transmitter_model.set_lna(40);
85+
transmitter_model.set_vga(40);
8286
transmitter_model.set_baseband_bandwidth(1750000);
8387
transmitter_model.enable();
8488

8589
uint8_t * data_ptr = shared_memory.bb_data.data;
8690

8791
bi = 0;
8892
for (i = 0; i < codewords.size(); i++) {
93+
if (phase == 0)
94+
codeword = ~(codewords[i]);
95+
else
8996
codeword = codewords[i];
97+
9098
data_ptr[bi++] = (codeword >> 24) & 0xFF;
9199
data_ptr[bi++] = (codeword >> 16) & 0xFF;
92100
data_ptr[bi++] = (codeword >> 8) & 0xFF;
@@ -126,6 +134,7 @@ POCSAGTXView::POCSAGTXView(
126134
&field_address,
127135
&options_type,
128136
&options_function,
137+
&options_phase,
129138
&text_message,
130139
&button_message,
131140
&progressbar,

firmware/application/apps/ui_pocsag_tx.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class POCSAGTXView : public View {
7171
{ { 3 * 8, 6 * 8 }, "Address:", Color::light_grey() },
7272
{ { 6 * 8, 8 * 8 }, "Type:", Color::light_grey() },
7373
{ { 2 * 8, 10 * 8 }, "Function:", Color::light_grey() },
74+
{ { 5 * 8, 12 * 8 }, "Phase:", Color::light_grey() },
7475
{ { 0 * 8, 14 * 8 }, "Message:", Color::light_grey() }
7576
};
7677

@@ -110,6 +111,15 @@ class POCSAGTXView : public View {
110111
{ "D", 3 }
111112
}
112113
};
114+
115+
OptionsField options_phase {
116+
{ 11 * 8, 12 * 8 },
117+
1,
118+
{
119+
{ "P", 0 },
120+
{ "N", 1 },
121+
}
122+
};
113123

114124
Text text_message {
115125
{ 0 * 8, 16 * 8, 16 * 8, 16 },

firmware/application/baseband_api.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,10 @@ void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit,
224224
send_message(&message);
225225
}
226226

227-
void set_pocsag(const pocsag::BitRate bitrate) {
227+
void set_pocsag(const pocsag::BitRate bitrate, bool phase) {
228228
const POCSAGConfigureMessage message {
229-
bitrate
229+
bitrate,
230+
phase
230231
};
231232
send_message(&message);
232233
}

firmware/application/baseband_api.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void set_ook_data(const uint32_t stream_length, const uint32_t samples_per_bit,
7777
const uint32_t pause_symbols);
7878
void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint32_t shift,
7979
const uint32_t progress_notice);
80-
void set_pocsag(const pocsag::BitRate bitrate);
80+
void set_pocsag(const pocsag::BitRate bitrate, bool phase);
8181
void set_adsb();
8282
void set_jammer(const bool run, const jammer::JammerType type, const uint32_t speed);
8383
void set_rds_data(const uint16_t message_length);

firmware/baseband/proc_pocsag.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
4747
const int32_t audio_sample = __SSAT(sample_int, 16);
4848

4949
slicer_sr <<= 1;
50-
slicer_sr |= (audio_sample < 0); // Do we need hysteresis ?
51-
50+
if (phase == 0)
51+
slicer_sr |= (audio_sample < 0); // Do we need hysteresis ?
52+
else
53+
slicer_sr |= !(audio_sample < 0);
54+
5255
// Detect transitions to adjust clock
5356
if ((slicer_sr ^ (slicer_sr >> 1)) & 1) {
5457
if (sphase < (0x8000u - sphase_delta_half))
@@ -162,6 +165,7 @@ void POCSAGProcessor::configure(const POCSAGConfigureMessage& message) {
162165
//audio_output.configure(false);
163166

164167
bitrate = message.bitrate;
168+
phase = message.phase;
165169
sphase_delta = 0x10000u * bitrate / POCSAG_AUDIO_RATE;
166170
sphase_delta_half = sphase_delta / 2; // Just for speed
167171
sphase_delta_eighth = sphase_delta / 8;

firmware/baseband/proc_pocsag.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class POCSAGProcessor : public BasebandProcessor {
9595
bool configured = false;
9696
rx_states rx_state { WAITING };
9797
pocsag::BitRate bitrate { pocsag::BitRate::FSK1200 };
98+
bool phase;
9899
uint32_t codeword_count { 0 };
99100
pocsag::POCSAGPacket packet { };
100101

firmware/common/message.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,13 +989,16 @@ class FSKConfigureMessage : public Message {
989989
class POCSAGConfigureMessage : public Message {
990990
public:
991991
constexpr POCSAGConfigureMessage(
992-
const pocsag::BitRate bitrate
992+
const pocsag::BitRate bitrate,
993+
const bool phase
993994
) : Message { ID::POCSAGConfigure },
994-
bitrate(bitrate)
995+
bitrate(bitrate),
996+
phase(phase)
995997
{
996998
}
997999

9981000
const pocsag::BitRate bitrate;
1001+
const bool phase;
9991002
};
10001003

10011004
class ADSBConfigureMessage : public Message {

0 commit comments

Comments
 (0)