/* * BiSSCMasterLogic.cpp * * Created on: 7 сент. 2021 г. * Author: sozonov */ #include #include "BiSSCMasterLogic.hh" driver::BiSSCMasterLogic::BiSSCMasterLogic( peripheral::ISerialPort *_serial_port, uint16_t _crc_polinom, std::pmr::memory_resource * memory_resource ) : serial_port ( _serial_port ), crc_type ( static_cast( _crc_polinom ) ), data_lenght ( 0 ), f_reading_data ( true ), crc_size ( 6 ), err_warn_size ( 2 ), fE ( false ), fW ( false ), crc_error ( false ), read_complete ( false ), write_complete ( false ), binary_sybscriber ( memory_resource ), data_lenth_to_subscriber ( 0 ) { //todo: определять длину crc полинома // crc_size = 6; } void driver::BiSSCMasterLogic::addSubscriber( std::size_t bit_address, std::size_t bit_len, communication::IBinaryDataSubscriber * subscriber ) { binary_sybscriber.addSubscriber(bit_address, bit_len, subscriber); update_size( binary_sybscriber.getBitSize() ); } void driver::BiSSCMasterLogic::process() { uint16_t *pdata_for_cpy = data_first; if( spi_tx_result ) { //уточнить, как мы понимаем, что прочитали именно ту инфу, которую запросил конкретный абонент if(serial_port->isDataReady()) { if ( serial_port->receive( pdata_for_cpy ) ){ crc_error = parce( pdata_for_cpy ); binary_sybscriber.read( pdata_for_cpy, data_lenth_to_subscriber ); } spi_tx_result = serial_port->transmite( tmp_data_to_transm, data_lenght ); } } else { spi_tx_result = serial_port->transmite( tmp_data_to_transm, data_lenght ); } } bool driver::BiSSCMasterLogic::parce( uint16_t *data ) { uint16_t crc_checksumm; uint16_t tmp_array[32] = {}; uint16_t bits_copy_counter = 0; while ( bits_copy_counter < data_lenght - err_warn_size - crc_size ) { tmp_array[bits_copy_counter / 16] |= data[bits_copy_counter / 16] & ( 0x1 << static_cast( 15 - bits_copy_counter % 16 ) ); bits_copy_counter++; } fE = data[bits_copy_counter / 16] & ( 0x1 << static_cast( 15 - bits_copy_counter % 16 ) ); bits_copy_counter++; fW = data[bits_copy_counter / 16] & ( 0x1 << static_cast( 15 - bits_copy_counter % 16 ) ); bits_copy_counter++; while ( bits_copy_counter < data_lenght ) { crc_checksumm |= data[bits_copy_counter / 16] & ( 0x1 << static_cast( 15 - bits_copy_counter % 16 ) ); bits_copy_counter++; } //todo: проверка CRC : Crc.hpp и CrcDesc.hpp вернуть из функции результат проверки crc (tasks: UFC-677, UFC-680) std::memcpy( data, tmp_array, size_of_array ); return true; } void driver::BiSSCMasterLogic::update_size( std::size_t binary_sybscriber_BitSize ) { data_lenght = binary_sybscriber_BitSize + err_warn_size + crc_size ; data_lenth_to_subscriber = ( binary_sybscriber_BitSize + ( ( binary_sybscriber_BitSize ) % CHAR_BIT ) ) / CHAR_BIT ; }