MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/driver/ResolverSerialPortAdapter.hpp
2024-06-07 11:12:56 +03:00

52 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* ResolverSerialPortAdapter.hpp
*
* Created on: 30 янв. 2020 г.
* Author: user
*/
#ifndef UMLIBRARY_DRIVER_RESOLVERSERIALPORTADAPTER_HPP_
#define UMLIBRARY_DRIVER_RESOLVERSERIALPORTADAPTER_HPP_
#include "SpiPortReader.hpp"
#include "IResolver.hh"
#include <cmath>
namespace driver {
template<typename Packager>
class ResolverSerialPortAdapter : public IResolver {
public:
float getSinChannel() const override { return sin_channel; }
float getCosChannel() const override { return cos_channel; }
void process() {
typename Packager::Data data_time_regs = Packager::decode( reader.get() );
sin_channel = data_time_regs.data[sin_channel_offset];
cos_channel = data_time_regs.data[cos_channel_offset];
}
ResolverSerialPortAdapter( peripheral::ISerialPort & port, std::size_t frame_size, typename Packager::Frame request_frame,
unsigned short sin_channel_offset, unsigned short cos_channel_offset ) :
reader(port, frame_size, request_frame), sin_channel(NAN), cos_channel(NAN),
sin_channel_offset(sin_channel_offset), cos_channel_offset(cos_channel_offset) {}
virtual ~ResolverSerialPortAdapter() = default;
private:
float sin_channel;
float cos_channel;
const unsigned short sin_channel_offset;
const unsigned short cos_channel_offset;
driver::SpiPortReader<typename Packager::Frame> reader;
};
}
#endif /* UMLIBRARY_DRIVER_RESOLVERSERIALPORTADAPTER_HPP_ */