Skip to content

Commit

Permalink
Improve yaml processing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelldls committed Jul 4, 2024
1 parent dfb0bf1 commit 3342844
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ARG DEVELOPER=${REGISTRY}/epics-base${IMAGE_EXT}-developer:${BASE}
##### build stage ##############################################################
FROM ${DEVELOPER} AS developer

# Add missing dependancies
RUN curl -o /usr/bin/yq -L https://github.com/mikefarah/yq/releases/download/v4.44.2/yq_linux_amd64 && chmod +x /usr/bin/yq

# The devcontainer mounts the project root to /epics/generic-source
# Using the same location here makes devcontainer/runtime differences transparent.
ENV SOURCE_FOLDER=/epics/generic-source
Expand Down Expand Up @@ -68,6 +71,7 @@ FROM ${RUNTIME} AS runtime

# get runtime assets from the preparation stage
COPY --from=runtime_prep /assets /
COPY --from=runtime_prep /usr/bin/yq /usr/bin/yq

# install runtime system dependencies, collected from install.sh scripts
RUN ibek support apt-install-runtime-packages --skip-non-native
Expand Down
50 changes: 27 additions & 23 deletions ioc/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,34 @@ elif [ -f ${ibek_src} ]; then
db_src=${RUNTIME_DIR}/ioc.subst
final_ioc_startup=${RUNTIME_DIR}/st.cmd

# Find address (ID) and CLASS of the first camera in the IOC instance yaml.
# NOTE this does not support mixed types of cameras in the same IOC
# ONE camera per IOC instance is recommended
# Multiple cameras of the same type are supported
# Mixed cameras will work but may not expose all their GenICam config parameters
instance_class=$(grep -m1 -oP "(?<=CLASS:\s).*" ${ibek_src}) || true # https://regex101.com/r/358gq3/1
instance_id=$(grep -m1 -oP "(?<=ID:\s).*" ${ibek_src}) || true # https://regex101.com/r/358gq3/1
if [[ -n $instance_id ]]; then
if [[ $instance_class == "AutoADGenICam" ]]; then
# Auto generate GenICam database from camera parameters XML
arv-tool-0.8 -a ${instance_id} genicam > /tmp/genicam.xml
python /epics/support/ADGenICam/scripts/makeDb.py /tmp/genicam.xml /epics/support/ADGenICam/db/AutoADGenICam.template
instance_type="INIT"
COUNT=0
while [ $instance_type != "null" ] # Iterate thoough config entity array
do
instance_type=$(yq .entities[${COUNT}].type ${ibek_src})
if [ $instance_type = "ADAravis.aravisCamera" ]
then
instance_class=$(yq .entities[${COUNT}].CLASS ${ibek_src})
instance_id=$(yq .entities[${COUNT}].ID ${ibek_src})

if [[ $instance_class == "AutoADGenICam" ]]; then
# Auto generate GenICam database from camera parameters XML
arv-tool-0.8 -a ${instance_id} genicam > /tmp/${instance_id}-genicam.xml
python /epics/support/ADGenICam/scripts/makeDb.py /tmp/${instance_id}-genicam.xml /epics/support/ADGenICam/db/AutoADGenICam.template # "${READ_ID}-AutoADGenICam.template" when ibek fixed
fi
# Generate pvi device from the GenICam DB
pvi convert device --template /epics/support/ADGenICam/db/$instance_class.template /epics/pvi-defs/ /epics/support/ADGenICam/include/ADGenICam.h
mv /epics/pvi-defs/ADGenICam.pvi.device.yaml /epics/pvi-defs/$instance_class.pvi.device.yaml
# change the title of the pvi device to match the camera ID
sed -i "s/arvFeature/Aravis $instance_id/g" /epics/pvi-defs/ADAravis.pvi.device.yaml
sed -i "s/label: ADGenICam/label: GenICam $instance_id/g" /epics/pvi-defs/$instance_class.pvi.device.yaml
# remove ADDriver from GenICam device
sed -i "s/ADDriver//" /epics/pvi-defs/$instance_class.pvi.device.yaml
# TODO: pvi changes should allow us to remove the last 3 sed lines above
# a) you will be able to specify no parent, b) you will be able to specify the label
fi
# Generate pvi device from the GenICam DB
pvi convert device --template /epics/support/ADGenICam/db/$instance_class.template /epics/pvi-defs/ /epics/support/ADGenICam/include/ADGenICam.h
mv /epics/pvi-defs/ADGenICam.pvi.device.yaml /epics/pvi-defs/$instance_class.pvi.device.yaml
# change the title of the pvi device to match the camera ID
sed -i "s/arvFeature/Aravis $instance_id/g" /epics/pvi-defs/ADAravis.pvi.device.yaml
sed -i "s/label: ADGenICam/label: GenICam $instance_id/g" /epics/pvi-defs/$instance_class.pvi.device.yaml
# remove ADDriver from GenICam device
sed -i "s/ADDriver//" /epics/pvi-defs/$instance_class.pvi.device.yaml
fi
# TODO: pvi changes should allow us to remove the last 3 sed lines above
# a) you will be able to specify no paretn, b) you will be able to specify the label
COUNT=$((COUNT+1))
done

# get the ibek support yaml files this ioc's support modules
defs=/epics/ibek-defs/*.ibek.support.yaml
Expand Down

0 comments on commit 3342844

Please sign in to comment.