//
// Created by kirillius on 09.04.2022.
//

#ifndef COOLER_CONTROLLER_COMMESSAGE_H
#define COOLER_CONTROLLER_COMMESSAGE_H

#include <avr/io.h>

enum MessageType {
    SAVE,
    PING,
    REBOOT,
    READ,
    WRITE,
    ERROR
};

enum ErrorCodes{
    ERR_UNSUPPORTED_OPERATION,
    ERR_UNKNOWN_DATA_TYPE,
    ERR_UNKNOWN_ACTION_TYPE,
    ERR_INVALID_CHECKSUM
};

enum DataType{
    NONE,
    TEMP,
    LEVEL,
    START_TEMP,
    STOP_TEMP,
    MAX_TEMP,
    MIN_LEVEL,
    MAX_LEVEL
};

struct Message {
public:
    MessageType action;
    DataType dataType;
    uint8_t value;
    uint8_t checksum;

    void validate() {
        checksum = calcChecksum();
    }

    bool isValid() {
        return checksum == calcChecksum();
    }

private:
    uint8_t calcChecksum() {
        return 18 + value + action * 23 + 42 * value+5*dataType;
    }
};

#endif //COOLER_CONTROLLER_COMMESSAGE_H
