101 lines
3.0 KiB
C++
101 lines
3.0 KiB
C++
/*
|
|
* BiSSCMasterLogic.cpp
|
|
*
|
|
* Created on: 7 ñåíò. 2021 ã.
|
|
* Author: sozonov
|
|
*/
|
|
#include <cstring>
|
|
|
|
#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<CrcType>( _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<uint16_t>( 15 - bits_copy_counter % 16 ) );
|
|
bits_copy_counter++;
|
|
}
|
|
|
|
fE = data[bits_copy_counter / 16] & ( 0x1 << static_cast<uint16_t>( 15 - bits_copy_counter % 16 ) );
|
|
bits_copy_counter++;
|
|
|
|
fW = data[bits_copy_counter / 16] & ( 0x1 << static_cast<uint16_t>( 15 - bits_copy_counter % 16 ) );
|
|
bits_copy_counter++;
|
|
|
|
while ( bits_copy_counter < data_lenght ) {
|
|
|
|
crc_checksumm |= data[bits_copy_counter / 16] & ( 0x1 << static_cast<uint16_t>( 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 ;
|
|
}
|
|
|
|
|