#ifndef DECODER_H
#define DECODER_H
#include "../image.h"
#include <QByteArray>

// receive data type
typedef enum { image_data, sensor_data, speed_measurement, none } receiving;

class Decoder : public QObject {
  Q_OBJECT
public:
  Decoder();
  ~Decoder();
  // send dummy image data
  void sendDummyData(uint32_t width, uint32_t heigth, bool rgb);

private:
  receiving rec;          // currently received data type
  QByteArray currentData; // currently received sensor data
  uint8_t sensorDataType; // currently received sensor data type
  Image img;              // currently received image
  int expectedLength;     // expected length of currently received data
  bool newCommand;        // new data avaited
  int receivedData;       // amount of currently received data

  QTime *timer; // timer for speed measurement and FPS
  int lastTime; // last time for FPS counter

  void receiveImage(const QByteArray &data);  // receive image
  void decodeCommand(const QByteArray &data); // decode incomming data type
  void receiveSpeedMeas(
      const QByteArray &data); // receive dummy data for speed measurement
  void continueReceive(
      const QByteArray &data); // continue receiving current data type
  void receiveSensorData(const QByteArray &data); // receive sensor data

signals:
  void imageData(Image *img);             // emit image data
  void sensorData(uint8_t, QByteArray &); // emit sensor data
  void registerData(uint8_t, uint16_t);   // emit register data
  void fps(double);                       // emit fps

public slots:
  void processData(const QByteArray &); // receive data
  void clearAll();                      // clear all buffers
};

#endif // DECODER_H
