#ifndef GENERIC_PLATFORM_SCALE_H
#define GENERIC_PLATFORM_SCALE_H
#include <shared_mutex>

#include "platform_scale.h"
#include "platform_scale_properties.h"
#include "serial_port/serial_port.h"

namespace zsy
{
    class GenericPlatformScaleProcessor : public SerialPort::Processor
    {
    public:
        std::atomic<uint64_t> steady;

        std::atomic<double> weight;

        GenericPlatformScaleProcessor();

        uint32_t process(const std::vector<uint8_t> &buffer) override;

        static std::string data(const std::vector<uint8_t> &buffer, uint8_t count = 12);

        ~GenericPlatformScaleProcessor() override = default;
    };

    class GenericPlatformScale : public PlatformScale
    {
        // 0-->不可用，1-->已启动，2-->正在读取，3-->已关闭，4-->错误
        uint8_t status;
        std::shared_mutex status_mtx;
        PlatformScaleProperties config;
        SerialPort *serialPort;

    public:
        explicit GenericPlatformScale(const PlatformScaleProperties &config);

        [[nodiscard]] double reading() override;

        ~GenericPlatformScale() override;
    };
} // zsy

#endif //GENERIC_PLATFORM_SCALE_H
