Skip to content
Snippets Groups Projects
Commit aac3a9ee authored by Jonathan Hanks's avatar Jonathan Hanks
Browse files

Updating the simple_epics to have the ability to do r/w PVs

parent d54cfcbe
No related branches found
No related tags found
2 merge requests!439RCG 5.0 release fro deb 10,!343convert the sequencer to C++
......@@ -36,6 +36,12 @@ namespace simple_epics
class Server;
enum class PVMode
{
ReadOnly = 0,
ReadWrite = 1,
};
/*!
* @brief A description of a PV, used to describe an int PV to the server.
* @note this is given a pointer to the data. This value is only read
......@@ -47,48 +53,55 @@ namespace simple_epics
pvIntAttributes( std::string pv_name,
int* value,
std::pair< int, int > alarm_range,
std::pair< int, int > warn_range )
std::pair< int, int > warn_range,
PVMode mode = PVMode::ReadOnly )
: name_{ std::move( pv_name ) },
alarm_low_{ alarm_range.first },
alarm_high_{ alarm_range.second }, warn_low_{ warn_range.first },
warn_high_{ warn_range.second }, src_{ value }
warn_high_{ warn_range.second }, mode_{ mode }, src_{ value }
{
}
const std::string&
name( ) const
name( ) const noexcept
{
return name_;
}
int
alarm_high( ) const
alarm_high( ) const noexcept
{
return alarm_high_;
}
int
alarm_low( ) const
alarm_low( ) const noexcept
{
return alarm_low_;
}
int
warn_high( ) const
warn_high( ) const noexcept
{
return warn_high_;
}
int
warn_low( ) const
warn_low( ) const noexcept
{
return warn_low_;
}
const int*
src( ) const
src( ) const noexcept
{
return src_;
}
PVMode
mode( ) const noexcept
{
return mode_;
}
private:
std::string name_;
......@@ -97,7 +110,8 @@ namespace simple_epics
int warn_high_;
int warn_low_;
int* src_;
PVMode mode_;
int* src_{ nullptr };
};
/*!
......@@ -108,27 +122,50 @@ namespace simple_epics
class pvStringAttributes
{
public:
pvStringAttributes( std::string pv_name, const char* value )
: name_{ std::move( pv_name ) }, src_{ value }
pvStringAttributes( std::string pv_name,
const char* value,
PVMode mode = PVMode::ReadOnly,
std::size_t buffer_size = 0 )
: name_{ std::move( pv_name ) }, mode_{ mode }, src_{ value },
src_size_{ buffer_size }
{
}
const std::string&
name( ) const
name( ) const noexcept
{
return name_;
}
const char*
src( ) const
src( ) const noexcept
{
return src_;
}
char*
src( ) noexcept
{
return (char*)src_;
}
std::size_t
src_size( ) const noexcept
{
return src_size_;
}
PVMode
mode( ) const noexcept
{
return mode_;
}
private:
std::string name_;
PVMode mode_;
const char* src_;
std::size_t src_size_;
};
/*!
......@@ -142,48 +179,55 @@ namespace simple_epics
pvDoubleAttributes( std::string pv_name,
double* value,
std::pair< double, double > alarm_range,
std::pair< double, double > warn_range )
std::pair< double, double > warn_range,
PVMode mode = PVMode::ReadOnly )
: name_{ std::move( pv_name ) },
alarm_low_{ alarm_range.first },
alarm_high_{ alarm_range.second }, warn_low_{ warn_range.first },
warn_high_{ warn_range.second }, src_{ value }
warn_high_{ warn_range.second }, mode_{ mode }, src_{ value }
{
}
const std::string&
name( ) const
name( ) const noexcept
{
return name_;
}
double
alarm_high( ) const
alarm_high( ) const noexcept
{
return alarm_high_;
}
double
alarm_low( ) const
alarm_low( ) const noexcept
{
return alarm_low_;
}
double
warn_high( ) const
warn_high( ) const noexcept
{
return warn_high_;
}
double
warn_low( ) const
warn_low( ) const noexcept
{
return warn_low_;
}
const double*
src( ) const
src( ) const noexcept
{
return src_;
}
PVMode
mode( ) const noexcept
{
return mode_;
}
private:
std::string name_;
......@@ -192,7 +236,9 @@ namespace simple_epics
double warn_high_;
double warn_low_;
double* src_;
PVMode mode_;
double* src_{ nullptr };
};
/*!
......@@ -201,7 +247,7 @@ namespace simple_epics
class Server : public caServer
{
public:
Server( ) : caServer( ), pvs_{}
Server( ) : caServer( ), pvs_{ }
{
}
~Server( ) override;
......
......@@ -160,7 +160,14 @@ namespace simple_epics
caStatus
simpleIntPV::write( const casCtx& ctx, const gdd& value )
{
return S_casApp_noSupport;
if ( attr_.mode( ) != PVMode::ReadWrite )
{
return S_casApp_noSupport;
}
aitInt32 newValue;
value.get( &newValue, aitEnumInt32 );
set_value( newValue );
return S_casApp_success;
}
aitEnum
......@@ -334,7 +341,21 @@ namespace simple_epics
caStatus
simpleStringPV::write( const casCtx& ctx, const gdd& value )
{
return S_casApp_noSupport;
if ( attr_.mode( ) != PVMode::ReadWrite || attr_.src_size( ) < 1 )
{
return S_casApp_noSupport;
}
aitString newValue;
value.get( &newValue, aitEnumString );
if ( newValue.string( ) == nullptr )
{
return S_casApp_noSupport;
}
std::strncpy( attr_.src( ), newValue.string( ), attr_.src_size( ) );
attr_.src( )[ attr_.src_size( ) - 1 ] == '\0';
set_value( newValue.string( ) );
return S_casApp_success;
}
aitEnum
......@@ -505,7 +526,14 @@ namespace simple_epics
caStatus
simpleDoublePV::write( const casCtx& ctx, const gdd& value )
{
return S_casApp_noSupport;
if ( attr_.mode( ) != PVMode::ReadWrite )
{
return S_casApp_noSupport;
}
aitFloat64 newValue;
value.get( &newValue, aitEnumFloat64 );
set_value( newValue );
return S_casApp_success;
}
aitEnum
......
......@@ -60,7 +60,7 @@ namespace simple_epics
caStatus read( const casCtx& ctx, gdd& prototype ) override;
caStatus write( const casCtx& ctx, const gdd& value ) override;
void destroy( ) override{};
void destroy( ) override{ };
aitEnum bestExternalType( ) const override;
......@@ -133,7 +133,7 @@ namespace simple_epics
caStatus read( const casCtx& ctx, gdd& prototype ) override;
caStatus write( const casCtx& ctx, const gdd& value ) override;
void destroy( ) override{};
void destroy( ) override{ };
aitEnum bestExternalType( ) const override;
......@@ -199,7 +199,7 @@ namespace simple_epics
caStatus read( const casCtx& ctx, gdd& prototype ) override;
caStatus write( const casCtx& ctx, const gdd& value ) override;
void destroy( ) override{};
void destroy( ) override{ };
aitEnum bestExternalType( ) const override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment