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

WIP on minor cleanups in main.cc of the sequencer.

* Added test builds of the sequencer to the cmake to facilitate building and debugging (non-functional as it does not build the dbd file, cmd file, ...
* Wrap the local EPICS variables in a new type to promote type safe read/write of data, plus give us a point to allow mocking the interface out.
* the casdf sequencer does not build right now.
parent 28a577fb
No related branches found
No related tags found
2 merge requests!439RCG 5.0 release fro deb 10,!343convert the sequencer to C++
......@@ -9,6 +9,16 @@ target_include_directories(test_sequencer_unit_tests PUBLIC
target_link_libraries(test_sequencer_unit_tests PUBLIC
catch2)
add_executable(test_casdf_seq
main.cc)
target_link_libraries(test_casdf_seq PUBLIC ini_parsing shmem epics::seq epics::ca)
target_compile_definitions(test_casdf_seq PUBLIC "-DCA_SDF=1")
add_executable(test_seq
main.cc)
target_link_libraries(test_seq PUBLIC ini_parsing shmem epics::seq epics::ca)
if (Boost_FOUND)
add_executable(standalone_edc
......
//
// Created by jonathan.hanks on 9/7/21.
//
#ifndef DAQD_TRUNK_EPICS_CHANNEL_HH
#define DAQD_TRUNK_EPICS_CHANNEL_HH
#include <cstdint>
#include <type_traits>
#include <stdexcept>
#include "dbAccess.h"
#include "fixed_size_string.hh"
namespace epics
{
using channel_name = embedded::fixed_string<256>;
inline channel_name
make_name(const char* prefix, const char* name)
{
channel_name output{};
output.printf("%s_%s", prefix, name);
return output;
}
template < dbfType T >
struct type_lookup
{
};
template <>
struct type_lookup<DBF_USHORT>
{
using type=std::uint16_t;
};
template <>
struct type_lookup<DBF_LONG>
{
using type=std::int32_t;
};
template <>
struct type_lookup<DBF_ULONG>
{
using type=std::uint32_t;
};
template <>
struct type_lookup<DBF_DOUBLE>
{
using type=double;
};
template <>
struct type_lookup<DBF_STRING>
{
using type=embedded::fixed_string<256>;
};
template<dbfType DataType>
class DBEntry {
public:
struct ValidateAddress {};
using value_type = typename type_lookup<DataType>::type;
explicit DBEntry(channel_name name)
{
dbNameToAddr(name.c_str(), &addr_);
}
DBEntry(channel_name name, ValidateAddress tag)
{
auto status = dbNameToAddr(name.c_str(), &addr_);
if ( status )
{
throw std::runtime_error("Failure with PV lookup in the EPICS "
"database. If this is the first PV "
"this usually signifies an error "
"with the .cmd passed to iocsh(), "
"or a misconfigured EPICS "
"environment");
}
}
DBEntry(channel_name name, const char* val)
{
static_assert(DataType == DBF_STRING, "Initialization by const char* must be on a string type");
dbNameToAddr(name.c_str(), &addr_);
dbPutField(&addr_, DataType, reinterpret_cast<const void*>(val), 1);
}
DBEntry(channel_name name, const value_type& val)
{
dbNameToAddr(name.c_str(), &addr_);
dbPutField(&addr_, DataType, reinterpret_cast<const void*>(&val), 1);
}
void
set(const value_type& val)
{
dbPutField(&addr_, DataType, reinterpret_cast<const void*>(&val), 1);
}
void
set(const char* val)
{
static_assert(DataType == DBF_STRING, "Setting a const char* must be done on a string type");
dbPutField(&addr_, DataType, reinterpret_cast<const void*>(val), 1);
}
void
get(value_type& val)
{
long ropts{0};
long nvals{1};
dbGetField(&addr_, DataType, &val, &ropts, &nvals, nullptr);
}
private:
dbAddr addr_{};
};
}
#endif //DAQD_TRUNK_EPICS_CHANNEL_HH
......@@ -29,6 +29,11 @@ namespace embedded
public:
typedef std::size_t size_type;
/**
* @brief the buffer object is a way to get raw access to manipulate the
* fixed_string. It looses most protections of the fixed_string class, but
* ensures that the buffer is null terminated when the buffer is destroyed.
*/
class buffer
{
friend class fixed_string;
......
This diff is collapsed.
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