Template Function ska::pst::common::unpack_bytes

Function Documentation

template<typename T>
auto ska::pst::common::unpack_bytes(const char *data, size_t data_length, uint32_t nbit) -> std::vector<T>

unpack bytes of data where nbit <= 8

This will take data of N bytes long and return the unpacked data of N * 8 / nbit long.

The DSPSR GenericVoltageDigitizer packs the data where the least significant bits (LSBs) has the earlier value. An example is for NBIT=2 with a total of 4 values packed into 1 byte, would be pack as [val4][val3][val2][val1] and the unpacker will return 4 int values in the order of [val1, val2, val3, val4].

For NBIT=1, this unpacker will map bits with values 0 to being output value of -1, and bits with values of 1 to being output value of 0. This is different to the expected -1 and 1 respectively. This makes performing statistical calculations on it easier. To map the values of -1 and 0 to being -1 and 1 one needs to do (2 * val + 1).

Template Parameters

T – the output type, should be int8_t or int16_t

Parameters
  • data – the pointer to the input bytes to unpack

  • data_length – the length of data to unpack

  • nbit – the number of bits per value

Returns

std::vector<T> the unpacked data.