COSA
An Object-Oriented Platform for Arduino Programming
HammingCodec_8_4.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_HAMMINGCODEC_8_4_HH
22 #define COSA_HAMMINGCODEC_8_4_HH
23 
24 #include <VWI.h>
25 
38 class HammingCodec_8_4 : public VWI::Codec {
39 public:
45  VWI::Codec(8, 0x5a55, 8)
46  {
47  }
48 
54  virtual const uint8_t* preamble()
55  {
56  return (s_preamble);
57  }
58 
65  virtual uint8_t encode4(uint8_t nibble)
66  {
67  return (pgm_read_byte(&s_symbols[nibble & 0xf]));
68  };
69 
76  virtual uint8_t decode4(uint8_t symbol)
77  {
78  uint8_t code = pgm_read_byte(&s_codes[symbol >> 1]);
79  return ((symbol & 0x01) ? (code & 0x0f) : (code >> 4));
80  }
81 
82 private:
84  static const uint8_t s_symbols[] PROGMEM;
85 
87  static const uint8_t s_codes[] PROGMEM;
88 
90  static const uint8_t s_preamble[] PROGMEM;
91 };
92 
93 #endif
Definition: VWI.hh:64
virtual uint8_t encode4(uint8_t nibble)
Codec(uint8_t bits_per_symbol, uint16_t start_symbol, uint8_t preamble_max=VWI::Transmitter::PREAMBLE_MAX)
Definition: VWI.cpp:59
virtual const uint8_t * preamble()
virtual uint8_t decode4(uint8_t symbol)