1use std::collections::HashMap;
8
9use super::params::PluginBaseParams;
10use super::runtime::PluginRuntimeHandle;
11use crate::params::ndarray_driver::NDArrayDriverParams;
12
13#[derive(Clone, Copy)]
15pub enum RegistryParamType {
16 Int32,
17 Float64,
18 Float64Array,
19 OctetString,
20}
21
22#[derive(Clone)]
24pub struct ParamInfo {
25 pub param_index: usize,
26 pub param_type: RegistryParamType,
27 pub drv_info: String,
28}
29
30impl ParamInfo {
31 pub fn int32(index: usize, drv_info: &str) -> Self {
32 Self { param_index: index, param_type: RegistryParamType::Int32, drv_info: drv_info.to_string() }
33 }
34 pub fn float64(index: usize, drv_info: &str) -> Self {
35 Self { param_index: index, param_type: RegistryParamType::Float64, drv_info: drv_info.to_string() }
36 }
37 pub fn float64_array(index: usize, drv_info: &str) -> Self {
38 Self { param_index: index, param_type: RegistryParamType::Float64Array, drv_info: drv_info.to_string() }
39 }
40 pub fn string(index: usize, drv_info: &str) -> Self {
41 Self { param_index: index, param_type: RegistryParamType::OctetString, drv_info: drv_info.to_string() }
42 }
43}
44
45pub type ParamRegistry = HashMap<String, ParamInfo>;
47
48pub fn build_plugin_base_registry(h: &PluginRuntimeHandle) -> ParamRegistry {
53 let mut map = HashMap::new();
54 let base = &h.ndarray_params;
55 let plug = &h.plugin_params;
56
57 insert_ndarray_driver_params(&mut map, base);
58 insert_plugin_base_params(&mut map, plug);
59
60 map
61}
62
63pub fn insert_ndarray_driver_params(map: &mut ParamRegistry, base: &NDArrayDriverParams) {
65 map.insert("PortName_RBV".into(), ParamInfo::string(base.port_name_self, "PORT_NAME_SELF"));
66 map.insert("ArrayCounter".into(), ParamInfo::int32(base.array_counter, "ARRAY_COUNTER"));
67 map.insert("ArrayCounter_RBV".into(), ParamInfo::int32(base.array_counter, "ARRAY_COUNTER"));
68 map.insert("ArrayCallbacks".into(), ParamInfo::int32(base.array_callbacks, "ARRAY_CALLBACKS"));
69 map.insert("ArrayCallbacks_RBV".into(), ParamInfo::int32(base.array_callbacks, "ARRAY_CALLBACKS"));
70 map.insert("ArraySizeX_RBV".into(), ParamInfo::int32(base.array_size_x, "ARRAY_SIZE_X"));
71 map.insert("ArraySizeY_RBV".into(), ParamInfo::int32(base.array_size_y, "ARRAY_SIZE_Y"));
72 map.insert("ArraySizeZ_RBV".into(), ParamInfo::int32(base.array_size_z, "ARRAY_SIZE_Z"));
73 map.insert("ArraySize_RBV".into(), ParamInfo::int32(base.array_size, "ARRAY_SIZE"));
74 map.insert("ArraySize0_RBV".into(), ParamInfo::int32(base.array_size_x, "ARRAY_SIZE_X"));
76 map.insert("ArraySize1_RBV".into(), ParamInfo::int32(base.array_size_y, "ARRAY_SIZE_Y"));
77 map.insert("ArraySize2_RBV".into(), ParamInfo::int32(base.array_size_z, "ARRAY_SIZE_Z"));
78 map.insert("NDimensions".into(), ParamInfo::int32(base.n_dimensions, "NDIMENSIONS"));
79 map.insert("NDimensions_RBV".into(), ParamInfo::int32(base.n_dimensions, "NDIMENSIONS"));
80 map.insert("DataType".into(), ParamInfo::int32(base.data_type, "DATA_TYPE"));
81 map.insert("DataType_RBV".into(), ParamInfo::int32(base.data_type, "DATA_TYPE"));
82 map.insert("ColorMode".into(), ParamInfo::int32(base.color_mode, "COLOR_MODE"));
83 map.insert("ColorMode_RBV".into(), ParamInfo::int32(base.color_mode, "COLOR_MODE"));
84 map.insert("UniqueId_RBV".into(), ParamInfo::int32(base.unique_id, "UNIQUE_ID"));
85 map.insert("BayerPattern_RBV".into(), ParamInfo::int32(base.bayer_pattern, "BAYER_PATTERN"));
86 map.insert("Codec_RBV".into(), ParamInfo::string(base.codec, "CODEC"));
87 map.insert("CompressedSize_RBV".into(), ParamInfo::int32(base.compressed_size, "COMPRESSED_SIZE"));
88 map.insert("TimeStamp_RBV".into(), ParamInfo::float64(base.timestamp_rbv, "TIMESTAMP"));
89 map.insert("EpicsTSSec_RBV".into(), ParamInfo::int32(base.epics_ts_sec, "EPICS_TS_SEC"));
90 map.insert("EpicsTSNsec_RBV".into(), ParamInfo::int32(base.epics_ts_nsec, "EPICS_TS_NSEC"));
91
92 map.insert("PoolMaxMem".into(), ParamInfo::float64(base.pool_max_memory, "POOL_MAX_MEMORY"));
94 map.insert("PoolUsedMem".into(), ParamInfo::float64(base.pool_used_memory, "POOL_USED_MEMORY"));
95 map.insert("PoolAllocBuffers".into(), ParamInfo::int32(base.pool_alloc_buffers, "POOL_ALLOC_BUFFERS"));
96 map.insert("PoolAllocBuffers_RBV".into(), ParamInfo::int32(base.pool_alloc_buffers, "POOL_ALLOC_BUFFERS"));
97 map.insert("PoolFreeBuffers".into(), ParamInfo::int32(base.pool_free_buffers, "POOL_FREE_BUFFERS"));
98 map.insert("PoolFreeBuffers_RBV".into(), ParamInfo::int32(base.pool_free_buffers, "POOL_FREE_BUFFERS"));
99 map.insert("PoolMaxBuffers_RBV".into(), ParamInfo::int32(base.pool_max_buffers, "POOL_MAX_BUFFERS"));
100 map.insert("PoolPollStats".into(), ParamInfo::int32(base.pool_poll_stats, "POOL_POLL_STATS"));
101 map.insert("NumQueuedArrays".into(), ParamInfo::int32(base.num_queued_arrays, "NUM_QUEUED_ARRAYS"));
102 map.insert("NumQueuedArrays_RBV".into(), ParamInfo::int32(base.num_queued_arrays, "NUM_QUEUED_ARRAYS"));
103}
104
105pub fn insert_plugin_base_params(map: &mut ParamRegistry, plug: &PluginBaseParams) {
107 map.insert("EnableCallbacks".into(), ParamInfo::int32(plug.enable_callbacks, "PLUGIN_ENABLE_CALLBACKS"));
108 map.insert("EnableCallbacks_RBV".into(), ParamInfo::int32(plug.enable_callbacks, "PLUGIN_ENABLE_CALLBACKS"));
109 map.insert("BlockingCallbacks".into(), ParamInfo::int32(plug.blocking_callbacks, "PLUGIN_BLOCKING_CALLBACKS"));
110 map.insert("BlockingCallbacks_RBV".into(), ParamInfo::int32(plug.blocking_callbacks, "PLUGIN_BLOCKING_CALLBACKS"));
111 map.insert("QueueSize".into(), ParamInfo::int32(plug.queue_size, "PLUGIN_QUEUE_SIZE"));
112 map.insert("QueueFree".into(), ParamInfo::int32(plug.queue_use, "PLUGIN_QUEUE_USE"));
113 map.insert("DroppedArrays".into(), ParamInfo::int32(plug.dropped_arrays, "PLUGIN_DROPPED_ARRAYS"));
114 map.insert("DroppedArrays_RBV".into(), ParamInfo::int32(plug.dropped_arrays, "PLUGIN_DROPPED_ARRAYS"));
115 map.insert("NDArrayPort".into(), ParamInfo::string(plug.nd_array_port, "PLUGIN_NDARRAY_PORT"));
116 map.insert("NDArrayPort_RBV".into(), ParamInfo::string(plug.nd_array_port, "PLUGIN_NDARRAY_PORT"));
117 map.insert("NDArrayAddress".into(), ParamInfo::int32(plug.nd_array_addr, "PLUGIN_NDARRAY_ADDR"));
118 map.insert("NDArrayAddress_RBV".into(), ParamInfo::int32(plug.nd_array_addr, "PLUGIN_NDARRAY_ADDR"));
119 map.insert("PluginType_RBV".into(), ParamInfo::string(plug.plugin_type, "PLUGIN_TYPE"));
120 map.insert("ExecutionTime_RBV".into(), ParamInfo::float64(plug.execution_time, "EXECUTION_TIME"));
121}