96 lines
3.6 KiB
C++
96 lines
3.6 KiB
C++
/*
|
|
* BinaryEncoderInitializer.cpp
|
|
*
|
|
* Created on: 23 èþí. 2023 ã.
|
|
* Author: titov
|
|
*/
|
|
|
|
#include "BinaryEncoder.hh"
|
|
|
|
#include "../../driver/BinaryEncoder.hpp"
|
|
|
|
enum EncoderType {
|
|
Binary,
|
|
Grey
|
|
};
|
|
|
|
driver::detail::BinaryEncoderInterface * instance_encoder( std::pmr::memory_resource & mr,
|
|
communication::format::bits::bitsize angle_size,
|
|
communication::format::bits::bitsize turn_size,
|
|
bool inversion, EncoderType encoder_type );
|
|
|
|
bool application::board::BinaryEncoder::input( Environment & env ) {
|
|
|
|
return grab( data_master, env.rholder.getShared<communication::ISubscriberRegistrator>( links.data_master ) );
|
|
|
|
}
|
|
|
|
void application::board::BinaryEncoder::build( Environment & env ) {
|
|
|
|
Local<communication::ISubscriberRegistrator> local_data_master( data_master, *env.rholder.getShared<communication::ISubscriberRegistrator>( links.data_master ) );
|
|
|
|
EncoderType encoder_type = static_cast<EncoderType>(config.encoder_type);
|
|
|
|
driver::detail::BinaryEncoderInterface * encoder = instance_encoder( env.static_object_ma,
|
|
config.agnle_bitsize, config.turn_bitsize,
|
|
config.inversion, encoder_type );
|
|
|
|
local_data_master->addSubscriber( config.frame_bitoffset, config.frame_bitsize, encoder );
|
|
|
|
env.rholder.share<driver::IEncoder>( *encoder, links.encoder );
|
|
|
|
}
|
|
|
|
application::board::BinaryEncoder::BinaryEncoder(
|
|
const Links & links, const Setting & config ) : links(links), config(config) {}
|
|
|
|
driver::detail::BinaryEncoderInterface * instance_encoder( std::pmr::memory_resource & allocator,
|
|
communication::format::bits::bitsize angle_size,
|
|
communication::format::bits::bitsize turn_size,
|
|
bool inversion, EncoderType encoder_type ) {
|
|
|
|
driver::detail::BinaryEncoderInterface * interface = nullptr;
|
|
|
|
switch(encoder_type) {
|
|
case Binary: {
|
|
|
|
if( angle_size + turn_size <= 16 ) {
|
|
|
|
typedef driver::detail::BinaryEncoder<uint16_t> DBE16;
|
|
typedef driver::detail::BinaryEncoderInverted<uint16_t> IBE16;
|
|
|
|
if( not inversion )
|
|
interface = memories::instance_object<DBE16>( allocator, angle_size, turn_size );
|
|
else
|
|
interface = memories::instance_object<IBE16>( allocator, angle_size, turn_size );
|
|
|
|
} else if( angle_size + turn_size <= 32 ) {
|
|
|
|
typedef driver::detail::BinaryEncoder<uint32_t> DBE32;
|
|
typedef driver::detail::BinaryEncoderInverted<uint32_t> IBE32;
|
|
|
|
if( not inversion )
|
|
interface = memories::instance_object<DBE32>( allocator, angle_size, turn_size );
|
|
else
|
|
interface = memories::instance_object<IBE32>( allocator, angle_size, turn_size );
|
|
|
|
} else if( angle_size + turn_size <= 64 ) {
|
|
|
|
typedef driver::detail::BinaryEncoder<uint64_t> DBE64;
|
|
typedef driver::detail::BinaryEncoderInverted<uint64_t> IBE64;
|
|
|
|
if( not inversion )
|
|
interface = memories::instance_object<DBE64>( allocator, angle_size, turn_size );
|
|
else
|
|
interface = memories::instance_object<IBE64>( allocator, angle_size, turn_size );
|
|
|
|
}
|
|
|
|
} break;
|
|
case Grey: {} break;
|
|
}
|
|
|
|
return interface;
|
|
|
|
}
|