Skip to content

Commit

Permalink
Merge pull request #221 from epics-containers/motor-demo2
Browse files Browse the repository at this point in the history
Technosoft motor support
  • Loading branch information
gilesknap authored May 16, 2024
2 parents 5477c59 + b7e37a8 commit a3bb5db
Show file tree
Hide file tree
Showing 18 changed files with 747 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/ibek/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def NATIVE(self):
@property
def STATIC_BUILD(self):
"""True if the target architecture is not the default architecture."""
return os.getenv("STATIC_BUILD", self._EPICS_TARGET_ARCH != self._DEFAULT_ARCH)
return os.getenv("STATIC_BUILD", self.EPICS_TARGET_ARCH != self._DEFAULT_ARCH)

@property
def IBEK_DEFS(self):
Expand Down
8 changes: 7 additions & 1 deletion src/ibek/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

from enum import Enum
from typing import Dict, List
from typing import Any, Dict, List, Sequence

from pydantic import (
Field,
Expand Down Expand Up @@ -72,6 +72,8 @@ def add_ibek_attributes(self):
# Jinja expansion of any of the Entity's string args/values
value = UTILS.render(entity_dict, value)
setattr(self, arg, str(value))
# update the entity_dict with the rendered value
entity_dict[arg] = value

if model_field.annotation == object:
# if the field is an object but the type is str then look up
Expand Down Expand Up @@ -104,3 +106,7 @@ class IOC(BaseSettings):
ioc_name: str = Field(description="Name of IOC instance")
description: str = Field(description="Description of what the IOC does")
entities: List[Entity]
shared: Sequence[Any] = Field(
description="A place to create any anchors required for repeating YAML",
default=(),
)
21 changes: 12 additions & 9 deletions src/ibek/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def set_var(self, key: str, value: Any):

def get_var(self, key: str) -> Any:
"""get the value a global variable for our jinja context"""
# Intentionally raises a KeyError if the key doesn't exist
return self.variables[key]
return self.variables.get(key, "")

def counter(
self, name: str, start: int = 0, stop: int = 65535, inc: int = 1
Expand Down Expand Up @@ -110,13 +109,17 @@ def render(self, context: Any, template_text: Any) -> str:
# be passed a non string which will always render to itself
return template_text

jinja_template = Template(template_text)
return jinja_template.render(
context,
__utils__=self,
ioc_yaml_file_name=self.file_name,
ioc_name=self.ioc_name,
)
try:
jinja_template = Template(template_text)
return jinja_template.render(
context,
__utils__=self,
ioc_yaml_file_name=self.file_name,
ioc_name=self.ioc_name,
)
except Exception:
print(f"ERROR RENDERING TEMPLATE:\n{template_text}")
raise

def render_map(self, context: Any, map: Mapping[str, str | None]) -> dict[str, str]:
"""
Expand Down
14 changes: 13 additions & 1 deletion tests/generate_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,16 @@ mv `pwd`/epics/{runtime,opi}/* `pwd`/outputs/gauges

echo making ioc based on quadem support yaml
EPICS_ROOT=`pwd`/epics ibek runtime generate iocs/quadem.ibek.ioc.yaml support/ADCore.ibek.support.yaml support/quadem.ibek.support.yaml
mv `pwd`/epics/{runtime,opi}/* `pwd`/outputs/quadem
mv `pwd`/epics/{runtime,opi}/* `pwd`/outputs/quadem


############################################################################

# technosoft motor example

echo making an ioc schema using technosoft support yaml
ibek ioc generate-schema --no-ibek-defs support/technosoft.ibek.support.yaml --output schemas/technosoft.ibek.ioc.schema.json

echo making techosoft ioc
EPICS_ROOT=`pwd`/epics ibek runtime generate iocs/technosoft.ibek.ioc.yaml support/technosoft.ibek.support.yaml
mv `pwd`/epics/{runtime,opi}/* `pwd`/outputs/technosoft
44 changes: 44 additions & 0 deletions tests/samples/iocs/technosoft.ibek.ioc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# yaml-language-server: $schema=../schemas/technosoft.ibek.ioc.schema.json

ioc_name: yag
description: YAG motors

shared:
- &motor
type: motorTML.motorAxis
controller: TML
NSTEPS: 200
NMICROSTEPS: 256
VELO: 20
VELO_MAX: 50
VELO_MIN: 0.1
ACCL: 0.5
ACCL_MAX: 1.5
ACCL_MIN: 0.01
HAR: 0.5
HVEL: 10
JAR: 1
JVEL: 5
EGU: "ustep"
SLSP: 0.8
ENABLED: 1
TIMEOUT: 0

entities:
- type: motorTML.CreateController
controllerName: TML
P: "SPARC:TML"
TTY: /tmp # /var/tmp/ttyV0
numAxes: 1
hostid: 15

- <<: *motor
axid: 15

- <<: *motor
axid: 17
# example of overriding a value from the shared dictionary merge
ACCL_MIN: 0.011
# (UNREALISTIC) example of using Jinja expression in an arg value
EGU: |-
{{controller.P}}
28 changes: 28 additions & 0 deletions tests/samples/outputs/technosoft/index.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<display version="2.0.0">
<name>yag</name>
<x>0</x>
<y use_class="true">0</y>
<width>10</width>
<height>35</height>
<grid_step_x>4</grid_step_x>
<grid_step_y>4</grid_step_y>
<widget type="label" version="2.0.0">
<name>Title</name>
<class>TITLE</class>
<text>yag</text>
<x use_class="true">0</x>
<y use_class="true">0</y>
<width>10</width>
<height>25</height>
<font use_class="true">
<font name="Header 1" family="Liberation Sans" style="BOLD" size="22.0">
</font>
</font>
<foreground_color use_class="true">
<color name="Text" red="0" green="0" blue="0">
</color>
</foreground_color>
<transparent use_class="true">true</transparent>
<horizontal_alignment>1</horizontal_alignment>
</widget>
</display>
3 changes: 3 additions & 0 deletions tests/samples/outputs/technosoft/ioc.subst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#############################################################################
# DB substitution file generated by http://github.com/epics-containers/ibek #
#############################################################################
6 changes: 6 additions & 0 deletions tests/samples/outputs/technosoft/reference.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ndsCreateDevice "TechnosoftTML", "", "FILE=/tmp/,NAXIS=4,DEV_PATH=/dev/ttyS0,HOST_ID=1,
AXIS_SETUP_0=$(SUPPORT)/motorTechnosoft/tml_lib/config/config.txt,AXIS_ID_0=1,AXIS_HOMING_SW_0=LSN,
AXIS_SETUP_1=$(SUPPORT)/motorTechnosoft/tml_lib/config/config.txt,AXIS_ID_1=2,AXIS_HOMING_SW_1=LSN,
AXIS_SETUP_2=$(SUPPORT)/motorTechnosoft/tml_lib/config/config.txt,AXIS_ID_2=3,AXIS_HOMING_SW_2=LSN,
AXIS_SETUP_3=$(SUPPORT)/motorTechnosoft/tml_lib/config/config.txt,AXIS_ID_3=4,AXIS_HOMING_SW_3=LSN"

21 changes: 21 additions & 0 deletions tests/samples/outputs/technosoft/st.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EPICS IOC Startup Script generated by https://github.com/epics-containers/ibek

cd "/epics/ioc"
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 /epics/runtime/ioc.db
iocInit



dbpf("SPARC:TML:MOT:MSGRS","START")
dbl

dbpf("SPARC:TML:MOT:MSGRS","START")
dbl

7 changes: 7 additions & 0 deletions tests/samples/schemas/gauges.ibek.ioc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@
},
"title": "Entities",
"type": "array"
},
"shared": {
"default": [],
"description": "A place to create any anchors required for repeating YAML",
"items": {},
"title": "Shared",
"type": "array"
}
},
"required": [
Expand Down
7 changes: 7 additions & 0 deletions tests/samples/schemas/motorSim.ibek.ioc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@
},
"title": "Entities",
"type": "array"
},
"shared": {
"default": [],
"description": "A place to create any anchors required for repeating YAML",
"items": {},
"title": "Shared",
"type": "array"
}
},
"required": [
Expand Down
7 changes: 7 additions & 0 deletions tests/samples/schemas/quadem.ibek.ioc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3169,6 +3169,13 @@
},
"title": "Entities",
"type": "array"
},
"shared": {
"default": [],
"description": "A place to create any anchors required for repeating YAML",
"items": {},
"title": "Shared",
"type": "array"
}
},
"required": [
Expand Down
7 changes: 7 additions & 0 deletions tests/samples/schemas/single.ibek.ioc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@
},
"title": "Entities",
"type": "array"
},
"shared": {
"default": [],
"description": "A place to create any anchors required for repeating YAML",
"items": {},
"title": "Shared",
"type": "array"
}
},
"required": [
Expand Down
Loading

0 comments on commit a3bb5db

Please sign in to comment.