#ifndef __RigState_h__
#define __RigState_h__

#define UBITX_VFOA_UPDATE  0x01
#define UBITX_VFOB_UPDATE  0x02
#define UBITX_RIT_UPDATE   0x04
#define UBITX_XIT_UPDATE   0x08
#define UBITX_FLAGS_UPDATE 0x10

#define UBITX_VFOB_FLAG   0x01
#define UBITX_SPLIT_FLAG  0x02
#define UBITX_RIT_FLAG    0x04
#define UBITX_XIT_FLAG    0x08
#define UBITX_CW_FLAG     0x10
#define UBITX_USB_FLAG    0x20
#define UBITX_TX_FLAG     0x40

struct UBitxRigState {
  uint8_t header = 0;
  uint32_t vfo[2];
  uint16_t rit;
  uint16_t xit;
  uint8_t flags = 0;
};

/*
class UBitxRig {
  public:
  inline int freqA() const { return state.vfo[0]; }
  inline int freqB() const { return state.vfo[1]; }
  inline int freqRIT() const { return state.rit; }
  inline int freqXIT() const { return state.xit; }

  inline char vfo() const { return (state.flags & UBITX_VFOB_FLAG) == UBITX_VFOB_FLAG; }
  inline char isSplit() const { return (state.flags & UBITX_SPLIT_FLAG) == UBITX_SPLIT_FLAG; }
  inline char isRIT() const { return (state.flags & UBITX_RIT_FLAG) == UBITX_RIT_FLAG; }
  inline char isXIT() const { return (state.flags & UBITX_XIT_FLAG) == UBITX_XIT_FLAG; }
  inline char isCW() const { return (state.flags & UBITX_CW_FLAG) == UBITX_CW_FLAG; }
  inline char isLSB() const { return (state.flags & UBITX_USB_FLAG) != UBITX_USB_FLAG; }
  inline char isUSB() const { return (state.flags & UBITX_USB_FLAG) == UBITX_USB_FLAG; }

  char* packDelta() {
    buflen = 0;

    // first byte: what fields have changed
    buf[buflen++] = uint8_t(state.dirty);

    // next (if req'd): VFO A frequency
    if (state.dirty & UBITX_VFOA_UPDATE) {
      packInt(state.vfo[0];
    }

    // next (if req'd): VFO B frequency
    if (state.dirty & UBITX_VFOB_UPDATE) {
      packInt(state.vfo[0];
    }

  
  private:
  inline void packByte(uint8_t b) { buf[buflen++] = uint8_t(state.dirty);

  inline void packInt(int i) {
    int tmp = i;
    for (int j = 0; j < 32; j+=8) {
      tmp = tmp >> j;
      buf[buflen++] = uint8_t(tmp & 0x000000FF);
    }
  }
  
  UBitxRigState state;
  uint8_t buf[sizeof(uint8_t) + sizeof(UBitxRigState)];
  int buflen = 0;
};
*/

#endif
