SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
leansdr::s2_deframer Struct Reference

#include <dvbs2.h>

+ Inheritance diagram for leansdr::s2_deframer:
+ Collaboration diagram for leansdr::s2_deframer:

Public Member Functions

 s2_deframer (scheduler *sch, pipebuf< bbframe > &_in, pipebuf< tspacket > &_out, pipebuf< int > *_state_out=NULL, pipebuf< unsigned long > *_locktime_out=NULL)
 
void run ()
 
- Public Member Functions inherited from leansdr::runnable
 runnable (scheduler *_sch, const char *name)
 
- Public Member Functions inherited from leansdr::runnable_common
 runnable_common (const char *_name)
 
virtual ~runnable_common ()
 
virtual void shutdown ()
 

Private Member Functions

void run_bbframe (bbframe *pin)
 
void info_unlocked ()
 
void info_good_packet ()
 
void info_is_locked (bool newstate)
 

Private Attributes

crc8_engine crc8
 
int missing
 
uint8_t leftover [188]
 
bool locked
 
pipereader< bbframein
 
pipewriter< tspacketout
 
int current_state
 
pipewriter< int > * state_out
 
bool report_state
 
unsigned long locktime
 
pipewriter< unsigned long > * locktime_out
 

Static Private Attributes

static const int MAX_TS_PER_BBFRAME = fec_info::KBCH_MAX / 8 / 188 + 1
 

Additional Inherited Members

- Public Attributes inherited from leansdr::runnable_common
const char * name
 
- Protected Attributes inherited from leansdr::runnable
schedulersch
 

Detailed Description

Definition at line 2514 of file dvbs2.h.

Constructor & Destructor Documentation

◆ s2_deframer()

leansdr::s2_deframer::s2_deframer ( scheduler sch,
pipebuf< bbframe > &  _in,
pipebuf< tspacket > &  _out,
pipebuf< int > *  _state_out = NULL,
pipebuf< unsigned long > *  _locktime_out = NULL 
)
inline

Definition at line 2516 of file dvbs2.h.

2519  : runnable(sch, "S2 deframer"),
2520  missing(-1),
2521  in(_in), out(_out, MAX_TS_PER_BBFRAME),
2522  current_state(false),
2523  state_out(opt_writer(_state_out, 2)),
2524  report_state(true),
2525  locktime(0),
2526  locktime_out(opt_writer(_locktime_out, MAX_TS_PER_BBFRAME))
2527  {
2528  }
unsigned long locktime
Definition: dvbs2.h:2659
static const int MAX_TS_PER_BBFRAME
Definition: dvbs2.h:2652
runnable(scheduler *_sch, const char *name)
Definition: framework.h:193
pipewriter< tspacket > out
Definition: dvbs2.h:2655
pipereader< bbframe > in
Definition: dvbs2.h:2654
pipewriter< int > * state_out
Definition: dvbs2.h:2657
pipewriter< T > * opt_writer(pipebuf< T > *buf, unsigned long min_write=1)
Definition: framework.h:329
scheduler * sch
Definition: framework.h:199
pipewriter< unsigned long > * locktime_out
Definition: dvbs2.h:2660

Member Function Documentation

◆ info_good_packet()

void leansdr::s2_deframer::info_good_packet ( )
inlineprivate

Definition at line 2632 of file dvbs2.h.

References leansdr::opt_write().

2633  {
2634  info_is_locked(true);
2635  ++locktime;
2637  }
unsigned long locktime
Definition: dvbs2.h:2659
void info_is_locked(bool newstate)
Definition: dvbs2.h:2638
void opt_write(pipewriter< T > *p, T val)
Definition: framework.h:341
pipewriter< unsigned long > * locktime_out
Definition: dvbs2.h:2660
+ Here is the call graph for this function:

◆ info_is_locked()

void leansdr::s2_deframer::info_is_locked ( bool  newstate)
inlineprivate

Definition at line 2638 of file dvbs2.h.

References leansdr::opt_write().

2639  {
2640  if (newstate != current_state)
2641  {
2642  opt_write(state_out, newstate ? 1 : 0);
2643  current_state = newstate;
2644  }
2645  }
void opt_write(pipewriter< T > *p, T val)
Definition: framework.h:341
pipewriter< int > * state_out
Definition: dvbs2.h:2657
+ Here is the call graph for this function:

◆ info_unlocked()

void leansdr::s2_deframer::info_unlocked ( )
inlineprivate

Definition at line 2627 of file dvbs2.h.

2628  {
2629  info_is_locked(false);
2630  locktime = 0;
2631  }
unsigned long locktime
Definition: dvbs2.h:2659
void info_is_locked(bool newstate)
Definition: dvbs2.h:2638

◆ run()

void leansdr::s2_deframer::run ( )
inlinevirtual

Reimplemented from leansdr::runnable_common.

Definition at line 2529 of file dvbs2.h.

References leansdr::opt_writable(), leansdr::opt_write(), leansdr::pipereader< T >::rd(), leansdr::pipereader< T >::read(), leansdr::pipereader< T >::readable(), and leansdr::pipewriter< T >::writable().

2530  {
2531  while (in.readable() >= 1 && out.writable() >= MAX_TS_PER_BBFRAME &&
2532  opt_writable(state_out, 2) &&
2534  {
2535  if (report_state)
2536  {
2537  // Report unlocked state on first invocation.
2538  opt_write(state_out, 0);
2539  report_state = false;
2540  }
2541  run_bbframe(in.rd());
2542  in.read(1);
2543  }
2544  }
void run_bbframe(bbframe *pin)
Definition: dvbs2.h:2547
static const int MAX_TS_PER_BBFRAME
Definition: dvbs2.h:2652
pipewriter< tspacket > out
Definition: dvbs2.h:2655
pipereader< bbframe > in
Definition: dvbs2.h:2654
void opt_write(pipewriter< T > *p, T val)
Definition: framework.h:341
bool opt_writable(pipewriter< T > *p, int n=1)
Definition: framework.h:335
pipewriter< int > * state_out
Definition: dvbs2.h:2657
pipewriter< unsigned long > * locktime_out
Definition: dvbs2.h:2660
+ Here is the call graph for this function:

◆ run_bbframe()

void leansdr::s2_deframer::run_bbframe ( bbframe pin)
inlineprivate

Definition at line 2547 of file dvbs2.h.

References leansdr::bbframe::bytes, leansdr::tspacket::data, leansdr::pipewriter< T >::wr(), and leansdr::pipewriter< T >::written().

2548  {
2549  uint8_t *bbh = pin->bytes;
2550  uint16_t upl = (bbh[2] << 8) | bbh[3];
2551  uint16_t dfl = (bbh[4] << 8) | bbh[5];
2552  uint8_t sync = bbh[6];
2553  uint16_t syncd = (bbh[7] << 8) | bbh[8];
2554  uint8_t crcexp = crc8.compute(bbh, 9);
2555  uint8_t crc = bbh[9];
2556  uint8_t *data = bbh + 10;
2557  int ro_code = bbh[0] & 3;
2558  if (sch->debug2)
2559  {
2560  static float ro_values[] = {0.35, 0.25, 0.20, 0};
2561  fprintf(stderr, "BBH: crc %02x/%02x %s ma=%02x%02x ro=%.2f"
2562  " upl=%d dfl=%d sync=%02x syncd=%d\n",
2563  crc, crcexp, (crc == crcexp) ? "OK" : "KO",
2564  bbh[0], bbh[1], ro_values[ro_code], upl, dfl, sync, syncd);
2565  }
2566  if (crc != crcexp || upl != 188 * 8 || sync != 0x47 || dfl > fec_info::KBCH_MAX ||
2567  syncd > dfl || (dfl & 7) || (syncd & 7))
2568  {
2569  // Note: Maybe accept syncd=65535
2570  fprintf(stderr, "Bad bbframe\n");
2571  missing = -1;
2572  info_unlocked();
2573  return;
2574  }
2575  // TBD Handle packets as payload+finalCRC and do crc8 before pout
2576  int pos; // Start of useful data in this bbframe
2577  if (missing < 0)
2578  {
2579  // Skip unusable data at beginning of bbframe
2580  pos = syncd / 8;
2581  fprintf(stderr, "Start TS at %d\n", pos);
2582  missing = 0;
2583  }
2584  else
2585  {
2586  // Sanity check
2587  if (syncd / 8 != missing)
2588  {
2589  fprintf(stderr, "Lost a bbframe ?\n");
2590  missing = -1;
2591  info_unlocked();
2592  return;
2593  }
2594  pos = 0;
2595  }
2596  if (missing)
2597  {
2598  // Complete and output the partial TS packet in leftover[].
2599  tspacket *pout = out.wr();
2600  memcpy(pout->data, leftover, 188 - missing);
2601  memcpy(pout->data + (188 - missing), data + pos, missing);
2602  out.written(1);
2603  info_good_packet();
2604  ++pout;
2605  // Skip to beginning of next TS packet
2606  pos += missing;
2607  missing = 0;
2608  }
2609  while (pos + 188 <= dfl / 8)
2610  {
2611  tspacket *pout = out.wr();
2612  memcpy(pout->data, data + pos, 188);
2613  pout->data[0] = sync; // Replace CRC
2614  out.written(1);
2615  info_good_packet();
2616  pos += 188;
2617  }
2618  int remain = dfl / 8 - pos;
2619  if (remain)
2620  {
2621  memcpy(leftover, data + pos, remain);
2622  leftover[0] = sync; // Replace CRC
2623  missing = 188 - remain;
2624  }
2625  }
pipewriter< tspacket > out
Definition: dvbs2.h:2655
void info_unlocked()
Definition: dvbs2.h:2627
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned short uint16_t
Definition: rtptypes_win.h:44
crc8_engine crc8
Definition: dvbs2.h:2647
uint8_t leftover[188]
Definition: dvbs2.h:2651
scheduler * sch
Definition: framework.h:199
void info_good_packet()
Definition: dvbs2.h:2632
uint8_t compute(const uint8_t *buf, int len)
Definition: crc.h:43
+ Here is the call graph for this function:

Member Data Documentation

◆ crc8

crc8_engine leansdr::s2_deframer::crc8
private

Definition at line 2647 of file dvbs2.h.

◆ current_state

int leansdr::s2_deframer::current_state
private

Definition at line 2656 of file dvbs2.h.

◆ in

pipereader<bbframe> leansdr::s2_deframer::in
private

Definition at line 2654 of file dvbs2.h.

◆ leftover

uint8_t leansdr::s2_deframer::leftover[188]
private

Definition at line 2651 of file dvbs2.h.

◆ locked

bool leansdr::s2_deframer::locked
private

Definition at line 2653 of file dvbs2.h.

◆ locktime

unsigned long leansdr::s2_deframer::locktime
private

Definition at line 2659 of file dvbs2.h.

◆ locktime_out

pipewriter<unsigned long>* leansdr::s2_deframer::locktime_out
private

Definition at line 2660 of file dvbs2.h.

◆ MAX_TS_PER_BBFRAME

const int leansdr::s2_deframer::MAX_TS_PER_BBFRAME = fec_info::KBCH_MAX / 8 / 188 + 1
staticprivate

Definition at line 2652 of file dvbs2.h.

◆ missing

int leansdr::s2_deframer::missing
private

Definition at line 2648 of file dvbs2.h.

◆ out

pipewriter<tspacket> leansdr::s2_deframer::out
private

Definition at line 2655 of file dvbs2.h.

◆ report_state

bool leansdr::s2_deframer::report_state
private

Definition at line 2658 of file dvbs2.h.

◆ state_out

pipewriter<int>* leansdr::s2_deframer::state_out
private

Definition at line 2657 of file dvbs2.h.


The documentation for this struct was generated from the following file: