diff --git a/build/generic_scfe b/build/generic_scfe index bfcafb0..df9ac86 100755 Binary files a/build/generic_scfe and b/build/generic_scfe differ diff --git a/build/submodule/mepicsca/m_epics_ca_test b/build/submodule/mepicsca/m_epics_ca_test index 52252cb..31e03b7 100755 Binary files a/build/submodule/mepicsca/m_epics_ca_test and b/build/submodule/mepicsca/m_epics_ca_test differ diff --git a/src/device/generic.cpp b/src/device/generic.cpp index ccdd5be..49dbc4e 100644 --- a/src/device/generic.cpp +++ b/src/device/generic.cpp @@ -1,8 +1,127 @@ #include "generic.h" - +#include "generic_conf.h" #include "tmfe.h" +#include + +struct channelInfo { + bool isInput; + bool isOutput; + std::string type; + std::string input; + std::string output; +}; generic::generic(std::string equipmentName, const char *equipmentFilename) - : TMFeEquipment(equipmentName.c_str(), equipmentFilename) {} + : TMFeEquipment(equipmentName.c_str(), equipmentFilename) { -void generic::HandlePeriodic() {} \ No newline at end of file + this->equipmentName = equipmentName; + fEqConfPeriodMilliSec = 100; + fEqConfLogHistory = 60; + fEqConfReadOnlyWhenRunning = false; + fEqConfWriteEventsToOdb = true; +} + +void generic::HandlePeriodic() { + std::vector channel_names; + std::vector is_input_channels; + std::vector is_output_channels; + std::vector channel_types; + std::vector inputs; + std::vector outputs; + + { + std::string varname = + DEVICE_DIR_NAME + std::string("/") + CHANNEL_NAMES_VARNAME; + fOdbEqSettings->RSA(varname.c_str(), &channel_names, true); + } + + { + std::string varname = + DEVICE_DIR_NAME + std::string("/") + IS_INPUT_CHANNELS_VARNAME; + fOdbEqSettings->RBA(varname.c_str(), &is_input_channels, true); + } + + { + std::string varname = + DEVICE_DIR_NAME + std::string("/") + IS_OUTPUT_CHANNELS_VARNAME; + fOdbEqSettings->RBA(varname.c_str(), &is_output_channels, true); + } + + { + std::string varname = + DEVICE_DIR_NAME + std::string("/") + CHANNEL_TYPES_VARNAME; + fOdbEqSettings->RSA(varname.c_str(), &channel_types, true); + } + + { + std::string varname = INPUT_VARNAME; + fOdbEqVariables->RSA(varname.c_str(), &inputs, true); + } + + { + std::string varname = OUTPUT_VARNAME; + fOdbEqVariables->RSA(varname.c_str(), &outputs, true); + } + + std::map cache; + + int size = (int)this->channel_names.size(); + size = 1; + + // for (int i = 0; i < size; i++) { + // std::string name = this->channel_names.at(i); + // bool isInput = this->is_input_channels.at(i); + // bool isOutput = this->is_output_channels.at(i); + // std::string type = this->channels_type.at(i); + // std::string input = this->inputs.at(i); + // std::string output = this->outputs.at(i); + // cache.insert({name, {isInput, isOutput, type, input, output}}); + // } + + // this->channel_names = channel_names; + // this->is_input_channels = is_input_channels; + // this->is_output_channels = is_output_channels; + // this->channels_type = channel_types; + // this->inputs = inputs; + // this->outputs = outputs; + + /** + * Create epics channels + */ + + for (int i = 0; i < 1; i++) { + this->epics_channels.resize(channel_names.size()); + + // std::string type = channels_type.at(i); + std::string type = "string"; + std::string channel_name = channel_names.at(i); + if (type == "string") { + printf("create string channel called %s\n", channel_name.c_str()); + this->epics_channels.at(i) = + std::make_unique>( + std::string_view(channel_name.c_str())); + } + } + + /** + * If channels is output / input => read and write data if value change + */ + + for (int i = 0; i < 1; i++) { + if (this->is_input_channels.at(i)) { + std::string value; + std::get>>( + this->epics_channels.at(i)) + ->get(&value); + printf("value readed %s\n", value.c_str()); + } + + if (is_input_channels.at(i)) { + std::string value = outputs.at(i); + std::get>>( + this->epics_channels.at(i)) + ->put(&value); + printf("value %s written\n", value.c_str()); + } + } +} \ No newline at end of file diff --git a/src/device/generic.h b/src/device/generic.h index 545f62f..a4bb1b0 100644 --- a/src/device/generic.h +++ b/src/device/generic.h @@ -1,7 +1,9 @@ #ifndef GENERIC_H #define GENERIC_H +#include "m_epics_ca.h" #include "tmfe.h" +#include class generic : public TMFeEquipment { public: @@ -9,10 +11,18 @@ class generic : public TMFeEquipment { void HandlePeriodic(); private: - // std::vector channel_names; - // std::vector is_input_channels; - // std::vector is_output_channels; - // std::vector channels_type; + std::string equipmentName; + std::vector channel_names; // store the epics channel name + std::vector is_input_channels; // does this channel is an input ? + std::vector is_output_channels; // does this channel is a output ? + std::vector channels_type; // what type is this chanel ? + + std::vector>, + std::unique_ptr>>> + epics_channels; + + std::vector inputs; + std::vector outputs; }; #endif \ No newline at end of file