Skip to content

Commit

Permalink
add pre_values field to support full technosoft example
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed May 17, 2024
1 parent 4cc996d commit 982f844
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/ibek/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ class EntityDefinition(BaseSettings):
description="The arguments IOC instance should supply", default=()
)
values: Sequence[Value] = Field(
description="Calculated values to use as additional arguments", default=()
description="Calculated values to use as additional arguments "
"With Jinja evaluation after all Args",
default=(),
)
pre_values: Sequence[Value] = Field(
description="Calculated values to use as additional arguments "
"With Jinja evaluation before all Args",
default=(),
)
databases: Sequence[Database] = Field(
description="Databases to instantiate", default=[]
Expand Down
6 changes: 6 additions & 0 deletions src/ibek/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def add_arg(name, typ, description, default):
# fully qualified name of the Entity class including support module
full_name = f"{support.module}.{definition.name}"

# add in the calculated values Jinja Templates as Fields in the Entity
# these are the pre_values that should be Jinja rendered before any
# Args (or post values)
for value in definition.pre_values:
add_arg(value.name, str, value.description, value.value)

# add in each of the arguments as a Field in the Entity
for arg in definition.args:
full_arg_name = f"{full_name}.{arg.name}"
Expand Down
4 changes: 2 additions & 2 deletions tests/samples/outputs/technosoft/st.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ dbLoadDatabase dbd/ioc.dbd
ioc_registerRecordDeviceDriver pdbbase

ndsCreateDevice "TechnosoftTML", "TML", "FILE=/tmp/,NAXIS=1,DEV_PATH=/tmp,HOST_ID=15,AXIS_SETUP_0=$(SUPPORT)/motorTechnosoft/tml_lib/config/star_vat_phs.t.zip,AXIS_ID_0=15,AXIS_HOMING_SW_0=LSN,AXIS_SETUP_1=$(SUPPORT)/motorTechnosoft/tml_lib/config/star_vat_phs.t.zip,AXIS_ID_1=17,AXIS_HOMING_SW_1=LSN"
dbLoadRecords("$(SUPPORT)/motorTechnosoft/db/tmlAxis.template","PREFIX=SPARC:TML, CHANNEL_ID=MOT, CHANNEL_PREFIX=ax, ASYN_PORT=, ASYN_ADDR=0, NSTEPS=200, NMICROSTEPS=256, VELO=20, VELO_MIN=0.1, VELO_MAX=50.0, ACCL=0.5, ACCL_MIN=0.01, ACCL_MAX=1.5, HAR=0.5, HVEL=10.0, JAR=1, JVEL=5, ENABLED=1, SLSP=0.8, EGU=ustep, TIMEOUT=0")
dbLoadRecords("$(SUPPORT)/motorTechnosoft/db/tmlAxis.template","PREFIX=SPARC:TML, CHANNEL_ID=MOT, CHANNEL_PREFIX=ax, ASYN_PORT=, ASYN_ADDR=0, NSTEPS=200, NMICROSTEPS=256, VELO=20, VELO_MIN=0.1, VELO_MAX=50.0, ACCL=0.5, ACCL_MIN=0.011, ACCL_MAX=1.5, HAR=0.5, HVEL=10.0, JAR=1, JVEL=5, ENABLED=1, SLSP=0.8, EGU=SPARC:TML, TIMEOUT=0")
dbLoadRecords("$(SUPPORT)/motorTechnosoft/db/tmlAxis.template","PREFIX=SPARC:TML, CHANNEL_ID=MOT, CHANNEL_PREFIX=ax0, ASYN_PORT=TML, ASYN_ADDR=0, NSTEPS=200, NMICROSTEPS=256, VELO=20, VELO_MIN=0.1, VELO_MAX=50.0, ACCL=0.5, ACCL_MIN=0.01, ACCL_MAX=1.5, HAR=0.5, HVEL=10.0, JAR=1, JVEL=5, ENABLED=1, SLSP=0.8, EGU=ustep, TIMEOUT=0")
dbLoadRecords("$(SUPPORT)/motorTechnosoft/db/tmlAxis.template","PREFIX=SPARC:TML, CHANNEL_ID=MOT, CHANNEL_PREFIX=ax1, ASYN_PORT=TML, ASYN_ADDR=0, NSTEPS=200, NMICROSTEPS=256, VELO=20, VELO_MIN=0.1, VELO_MAX=50.0, ACCL=0.5, ACCL_MIN=0.011, ACCL_MAX=1.5, HAR=0.5, HVEL=10.0, JAR=1, JVEL=5, ENABLED=1, SLSP=0.8, EGU=SPARC:TML, TIMEOUT=0")

dbLoadRecords /epics/runtime/ioc.db
iocInit
Expand Down
11 changes: 10 additions & 1 deletion tests/samples/schemas/ibek.support.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,22 @@
},
"values": {
"default": [],
"description": "Calculated values to use as additional arguments",
"description": "Calculated values to use as additional arguments With Jinja evaluation after all Args",
"items": {
"$ref": "#/$defs/Value"
},
"title": "Values",
"type": "array"
},
"pre_values": {
"default": [],
"description": "Calculated values to use as additional arguments With Jinja evaluation before all Args",
"items": {
"$ref": "#/$defs/Value"
},
"title": "Pre Values",
"type": "array"
},
"databases": {
"default": [],
"description": "Databases to instantiate",
Expand Down
8 changes: 7 additions & 1 deletion tests/samples/schemas/technosoft.ibek.ioc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
"title": "Entity Enabled",
"type": "boolean"
},
"num": {
"default": "{{ __utils__.counter(\"motorTML.axisCount\", start=0) }}",
"description": "The auto incrementing axis number",
"title": "Num",
"type": "string"
},
"controller": {
"description": "a reference to the motion controller",
"title": "Controller"
Expand Down Expand Up @@ -225,7 +231,7 @@
"type": "string"
},
"CONFIG": {
"default": "{%- set num = __utils__.counter(\"motorTML.axisCount\", start=0) -%}\n,AXIS_SETUP_{{num}}=$(SUPPORT)/motorTechnosoft/tml_lib/config/{{axconf}},AXIS_ID_{{num}}={{axid}},AXIS_HOMING_SW_{{num}}={{homing}}",
"default": ",AXIS_SETUP_{{num}}=$(SUPPORT)/motorTechnosoft/tml_lib/config/{{axconf}},AXIS_ID_{{num}}={{axid}},AXIS_HOMING_SW_{{num}}={{homing}}",
"description": "Axis configuration string to add to the controller configuration",
"title": "Config",
"type": "string"
Expand Down
10 changes: 8 additions & 2 deletions tests/samples/support/technosoft.ibek.support.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,14 @@ defs:
description: |-
Axis configuration string to add to the controller configuration
default: |-
{%- set num = __utils__.counter("motorTML.axisCount", start=0) -%}
,AXIS_SETUP_{{num}}=$(SUPPORT)/motorTechnosoft/tml_lib/config/{{axconf}},AXIS_ID_{{num}}={{axid}},AXIS_HOMING_SW_{{num}}={{homing}}
pre_values:
- name: num
description: The auto incrementing axis number
value: |-
{{ __utils__.counter("motorTML.axisCount", start=0) }}
values:
- name: axisConfiguration
description: Adds an axis configuration entry to the controller's list
Expand All @@ -207,7 +213,7 @@ defs:
pre_init:
- value: |
dbLoadRecords("$(SUPPORT)/motorTechnosoft/db/tmlAxis.template","PREFIX={{controller.P}}, CHANNEL_ID={{CHANNEL_ID}}, CHANNEL_PREFIX=ax{{num}}, ASYN_PORT={{controllerName}}, ASYN_ADDR={{ASYN_ADDR}}, NSTEPS={{NSTEPS}}, NMICROSTEPS={{NMICROSTEPS}}, VELO={{VELO}}, VELO_MIN={{VELO_MIN}}, VELO_MAX={{VELO_MAX}}, ACCL={{ACCL}}, ACCL_MIN={{ACCL_MIN}}, ACCL_MAX={{ACCL_MAX}}, HAR={{HAR}}, HVEL={{HVEL}}, JAR={{JAR}}, JVEL={{JVEL}}, ENABLED={{ENABLED}}, SLSP={{SLSP}}, EGU={{EGU}}, TIMEOUT={{TIMEOUT}}")
dbLoadRecords("$(SUPPORT)/motorTechnosoft/db/tmlAxis.template","PREFIX={{controller.P}}, CHANNEL_ID={{CHANNEL_ID}}, CHANNEL_PREFIX=ax{{num}}, ASYN_PORT={{controller.controllerName}}, ASYN_ADDR={{ASYN_ADDR}}, NSTEPS={{NSTEPS}}, NMICROSTEPS={{NMICROSTEPS}}, VELO={{VELO}}, VELO_MIN={{VELO_MIN}}, VELO_MAX={{VELO_MAX}}, ACCL={{ACCL}}, ACCL_MIN={{ACCL_MIN}}, ACCL_MAX={{ACCL_MAX}}, HAR={{HAR}}, HVEL={{HVEL}}, JAR={{JAR}}, JVEL={{JVEL}}, ENABLED={{ENABLED}}, SLSP={{SLSP}}, EGU={{EGU}}, TIMEOUT={{TIMEOUT}}")
# databases:
# # TODO as this is a simulation I have hard coded some of the DB fields,
Expand Down

0 comments on commit 982f844

Please sign in to comment.