48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
|
|
/*
|
|||
|
|
* PlatformValues.cpp
|
|||
|
|
*
|
|||
|
|
* Created on: 29 <EFBFBD><EFBFBD><EFBFBD>. 2021 <EFBFBD>.
|
|||
|
|
* Author: titov
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#include "PlatformValues.hh"
|
|||
|
|
|
|||
|
|
#include <cmath>
|
|||
|
|
#include <cstring>
|
|||
|
|
|
|||
|
|
using namespace systemic;
|
|||
|
|
|
|||
|
|
SignalImpl::SignalImpl( std::pair<const char *, std::size_t> (* platform_info)( std::size_t info_id ),
|
|||
|
|
std::size_t info_id,
|
|||
|
|
std::size_t offset ) : platform_info(platform_info), id(info_id), offset(offset) {}
|
|||
|
|
|
|||
|
|
SignalImpl::operator float() const {
|
|||
|
|
|
|||
|
|
std::pair<const char *, std::size_t> data = platform_info( id );
|
|||
|
|
|
|||
|
|
if( data.second < sizeof(float) + offset )
|
|||
|
|
return NAN;
|
|||
|
|
|
|||
|
|
std::memcpy( reinterpret_cast<void *>( &value ), data.first + offset, sizeof(float) );
|
|||
|
|
|
|||
|
|
return value;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
StatusImpl::StatusImpl( std::pair<const char *, std::size_t> (* platform_info)( std::size_t info_id ),
|
|||
|
|
std::size_t info_id,
|
|||
|
|
std::size_t offset ) : platform_info(platform_info), id(info_id), offset(offset) {}
|
|||
|
|
|
|||
|
|
StatusImpl::operator bool() const {
|
|||
|
|
|
|||
|
|
std::pair<const char *, std::size_t> data = platform_info( id );
|
|||
|
|
|
|||
|
|
if( data.second < sizeof(bool) + offset )
|
|||
|
|
return NAN;
|
|||
|
|
|
|||
|
|
std::memcpy( reinterpret_cast<void *>( &value ), data.first + offset, sizeof(float) );
|
|||
|
|
|
|||
|
|
return value;
|
|||
|
|
|
|||
|
|
}
|