Skip to content

Commit

Permalink
Send the program type indicated in the SIG
Browse files Browse the repository at this point in the history
  • Loading branch information
argilo committed Aug 1, 2023
1 parent 92e56c0 commit c13100c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ This block assembles HDC audio frames and PSD PDUs into the audio transport, pro

The "Data bytes" setting controls how many bytes of each layer 2 PDU are set aside for Advanced Application Services (AAS) data.

The Layer 2 encoder gets program type information from the SIS & SIG encoder via the "aas" message port, so this port should be connected even when "Data bytes" is set to zero.

### Layer 1 FM encoder

This block implements Layer 1 FM (as defined in https://www.nrscstandards.org/standards-and-guidelines/documents/standards/nrsc-5-d/reference-docs/1011s.pdf). It takes PIDS and Layer 2 PDUs as input, and produces OFDM symbols as output. Only the Hybrid and Extended Hybrid modes have been implemented and tested so far. The All Digital modes are currently under development.
Expand Down
34 changes: 31 additions & 3 deletions lib/l2_encoder_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ l2_encoder_impl::l2_encoder_impl(const int num_progs,

this->num_progs = num_progs;
this->first_prog = first_prog;
memset(program_type, 0, sizeof(program_type));
this->size = size;
this->data_bytes = data_bytes;
payload_bytes = (size - 22) / 8;
Expand Down Expand Up @@ -125,8 +126,8 @@ int l2_encoder_impl::general_work(int noutput_items,
const unsigned char** psd = (const unsigned char**)&input_items[num_progs];
unsigned char* out = (unsigned char*)output_items[0];

int hdc_off[8] = { 0 };
int psd_off[8] = { 0 };
int hdc_off[MAX_PROGRAMS] = { 0 };
int psd_off[MAX_PROGRAMS] = { 0 };

for (int out_off = 0; out_off < noutput_items * size; out_off += size) {
memset(out_buf, 0, payload_bytes);
Expand Down Expand Up @@ -218,7 +219,7 @@ int l2_encoder_impl::general_work(int noutput_items,
write_hef(out_program + 14 + len_locators(nop),
program_number,
/*access*/ 0,
/*program_type*/ 0);
program_type[program_number]);

memcpy(out_program + (14 + len_locators(nop) + 3),
psd[p] + psd_off[p],
Expand Down Expand Up @@ -454,12 +455,39 @@ void l2_encoder_impl::handle_aas_pdu(pmt::pmt_t msg)
std::vector<unsigned char> pdu_bytes = pmt::u8vector_elements(pmt::cdr(msg));
int port = (pdu_bytes[2] << 8) | pdu_bytes[1];

if ((pdu_bytes[0] == AAS_PACKET_FORMAT) && (port == SIG_PORT)) {
decode_sig(pdu_bytes);
}

std::vector<unsigned char> pdu_encoded = hdlc_encode(pdu_bytes);

for (auto c : pdu_encoded) {
aas_queues[port].push(c);
}
}

void l2_encoder_impl::decode_sig(std::vector<unsigned char>& pdu_bytes)
{
int offset = 5;
while (offset < pdu_bytes.size()) {
unsigned char type = pdu_bytes[offset++];
switch (type & 0xf0) {
case 0x40:
offset += 3;
break;
case 0x60:
unsigned char length = pdu_bytes[offset++];
if (type == 0x66) {
unsigned char port = pdu_bytes[offset + 1];
unsigned char type = pdu_bytes[offset + 2];
if (port < MAX_PROGRAMS) {
program_type[port] = type;
}
}
offset += length - 1;
}
}
}

} /* namespace nrsc5 */
} /* namespace gr */
10 changes: 8 additions & 2 deletions lib/l2_encoder_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ constexpr unsigned char CRC8_TABLE[] = {

constexpr unsigned char BBM[] = { 0x7d, 0x3a, 0xe2, 0x42 };

constexpr int MAX_PROGRAMS = 8;
constexpr uint8_t AAS_PACKET_FORMAT = 0x21;
constexpr uint16_t SIG_PORT = 0x20;

class l2_encoder_impl : public l2_encoder
{
private:
int num_progs;
int first_prog;
int program_type[MAX_PROGRAMS];
int size;
int data_bytes;
int payload_bytes;
Expand All @@ -66,9 +71,9 @@ class l2_encoder_impl : public l2_encoder
int pdu_seq_no;
int pdu_seq_len;
int codec_mode;
int start_seq_no[8];
int start_seq_no[MAX_PROGRAMS];
int target_seq_no;
int partial_bytes[8];
int partial_bytes[MAX_PROGRAMS];
int ccc_width;
unsigned char ccc_count;
std::vector<unsigned char> ccc;
Expand Down Expand Up @@ -101,6 +106,7 @@ class l2_encoder_impl : public l2_encoder
int adts_length(const unsigned char* header);
int len_locators(int nop);
void handle_aas_pdu(pmt::pmt_t msg);
void decode_sig(std::vector<unsigned char>& pdu_bytes);

public:
l2_encoder_impl(const int num_progs,
Expand Down

0 comments on commit c13100c

Please sign in to comment.