MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/driver/chipset/Amc1210ManageableReader.cpp
2024-06-07 11:12:56 +03:00

94 lines
2.7 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.

/*
* Amc1210ManageableReader.cpp
*
* Created on: 12 окт. 2020 г.
* Author: LeonidTitov
*/
#include "Amc1210ManageableReader.hh"
#include <algorithm>
#include <cstring>
float driver::detail::Amc1210ManageableReader::getSinChannel() const {
return sin_code;
}
float driver::detail::Amc1210ManageableReader::getCosChannel() const {
return cos_code;
}
driver::detail::Amc1210ManageableReader::Amc1210ManageableReader(
peripheral::ISerialPort & con,
driver::chipset::AMC1210::Packager::Frame request_data,
std::size_t data_frame_size,
driver::chipset::AMC1210::Packager::Frame request_info,
std::size_t info_frame_size,
unsigned short sin_channel_offset,
unsigned short cos_channel_offset,
uint16_t channel_mask ) :
connection(con),
data_frame_size( data_frame_size ),
info_frame_size( info_frame_size ),
request_info(request_info),
request_data(request_data),
sin_channel_offset( sin_channel_offset),
cos_channel_offset( cos_channel_offset ),
channel_mask( channel_mask ) {}
void driver::detail::Amc1210ManageableReader::process() {
if( wait_data ) {
driver::chipset::AMC1210::Packager::Frame frame;
if( connection.receive( reinterpret_cast<char *>( &frame ) ) ) {
const driver::chipset::AMC1210::Packager::Data data = driver::chipset::AMC1210::Packager::decode(frame);
sin_code = data.data[sin_channel_offset];
cos_code = data.data[cos_channel_offset];
wait_data = false;
read_data = false;
read_info = connection.transmite( &request_info, info_frame_size );
}
} else if( read_data ) {
wait_data = connection.transmite( &request_data, data_frame_size );
} else if( read_info ) {
driver::chipset::AMC1210::Packager::Frame frame;
if( connection.receive( &frame ) ) {
const driver::chipset::AMC1210::Packager::Data data = driver::chipset::AMC1210::Packager::decode(frame);
driver::chipset::AMC1210::InterruptRegister flags;
std::memcpy( &flags, &data, sizeof(driver::chipset::AMC1210::InterruptRegister) );
modulator_fault = flags.modulator_fault & channel_mask;
wait_data = connection.transmite( &request_data, data_frame_size );
read_data = ( channel_mask & flags.ack_flag ) == channel_mask;
read_info = false;
}
} else
read_info = connection.transmite( &request_info, info_frame_size );
}
const bool & driver::detail::Amc1210ManageableReader::fault() const {
return modulator_fault;
}