Skip to content

Commit

Permalink
Copying IO addresses by script (#34)
Browse files Browse the repository at this point in the history
* Create draft PR for #33

* scripts modified to copy Inputs and Outputs into the structs with relative addressing

---------

Co-authored-by: MTS\Tomas_K <tomas.kovac@mts.sk>
  • Loading branch information
IX-BOT and MTS\Tomas_K authored Nov 26, 2024
1 parent 7411d30 commit 87fa00c
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 72 deletions.
15 changes: 8 additions & 7 deletions axopen.template.simple/ax/apax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ apaxVersion: 3.1.1
variables:
APAX_BUILD_ARGS: [ -d ]
PLC_NAME: "plc_line"
HWCONFIG: "TIA"
DEFAULT_NAMESPACE: "axosimple"
HWCONFIG: "HWC"
AXTARGET: 10.222.6.1
AXTARGETPLATFORMINPUT: .\bin\1500\
AX_USERNAME: "adm"
Expand Down Expand Up @@ -206,19 +207,19 @@ scripts:
fi
hwid: | # copy the generated HwIds from global constants into the type definition, matching the format as the TIA2AX tool creates
if [[ "$HWCONFIG" == "HWC" ]]; then
..\\scripts\\copy_hardware_ids.sh
..\\scripts\\copy_hardware_ids.sh $DEFAULT_NAMESPACE $PLC_NAME
fi
hwadr: | # copy the generated IoAddresses
if [[ "$HWCONFIG" == "HWC" ]]; then
..\\scripts\\copy_io_addresses.sh
..\\scripts\\copy_io_addresses.sh $DEFAULT_NAMESPACE $PLC_NAME
fi
hwfd: | # copy and install gsd, copy templates,compile, copy the HwIds, copy the IoAddresses, first download HW using password and upload certificate
if [[ "$HWCONFIG" == "HWC" ]]; then
..\\scripts\\hw_first_download.sh $PLC_NAME $AXTARGET $AX_TARGET_PWD
..\\scripts\\hw_first_download.sh $DEFAULT_NAMESPACE $PLC_NAME $AXTARGET $AX_TARGET_PWD
fi
hwu: | # copy and install gsd, copy templates, compile, copy the HwIds, copy the IoAddresses, download HW using certificate
if [[ "$HWCONFIG" == "HWC" ]]; then
..\\scripts\\hw_update.sh $PLC_NAME $AXTARGET
..\\scripts\\hw_update.sh $DEFAULT_NAMESPACE $PLC_NAME $AXTARGET
fi
swfd: | # software build and full download
if [[ "$HWCONFIG" == "HWC" ]]; then
Expand All @@ -231,13 +232,13 @@ scripts:
alf: | #clear plc except ip and name and provide all actions for install all, build and initial download hw so as sw
START=$(date +%s)
if [[ "$HWCONFIG" == "HWC" ]]; then
..\\scripts\\all_first.sh $PLC_NAME $AXTARGET $AXTARGETPLATFORMINPUT $AX_USERNAME $AX_TARGET_PWD
..\\scripts\\all_first.sh $DEFAULT_NAMESPACE $PLC_NAME $AXTARGET $AXTARGETPLATFORMINPUT $AX_USERNAME $AX_TARGET_PWD
fi
echo $(date +%D)"-"$(date +%H)":"$(date +%M)":"$(date +%S) " - Finished in :" $(expr $(date +%s) - $START) "s"
all: | #build and download hardware and software
START=$(date +%s)
if [[ "$HWCONFIG" == "HWC" ]]; then
..\\scripts\\all.sh $PLC_NAME $AXTARGET $AXTARGETPLATFORMINPUT $AX_USERNAME $AX_TARGET_PWD
..\\scripts\\all.sh $DEFAULT_NAMESPACE $PLC_NAME $AXTARGET $AXTARGETPLATFORMINPUT $AX_USERNAME $AX_TARGET_PWD
fi
echo $(date +%D)"-"$(date +%H)":"$(date +%M)":"$(date +%S) " - Finished in :" $(expr $(date +%s) - $START) "s"
publicKeys:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 16 additions & 10 deletions axopen.template.simple/scripts/all.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
if [ "$#" -ne 5 ]; then
echo "Usage: $0 <PLC_NAME> <PLC_IP_ADDRESS> <PLATFORM> <USERNAME> <PASSWORD>"
if [ "$#" -ne 6 ]; then
echo "Usage: $0 <NAMESPACE> <PLC_NAME> <PLC_IP_ADDRESS> <PLATFORM> <USERNAME> <PASSWORD>"
exit 1
fi

PLC_NAME=$1
NAMESPACE=$1
if [ -z $NAMESPACE ]; then
echo "The NAMESPACE could not be an empty string."
exit 1
fi

PLC_NAME=$2
if [ -z $PLC_NAME ]; then
echo "The PLC_NAME could not be an empty string."
exit 1
fi

PLC_IP_ADDRESS=$2
PLC_IP_ADDRESS=$3
validate_script=$( dirname ${BASH_SOURCE[0]})"\\validate_ip.sh"
if ! $validate_script "$PLC_IP_ADDRESS"; then
echo "The PLC_IP_ADDRESS '$PLC_IP_ADDRESS' is not a valid IP address."
exit 1
fi

PLATFORM=$3
PLATFORM=$4
if [ -z $PLATFORM ]; then
echo "The PLATFORM could not be an empty string."
exit 1
fi

USERNAME=$4
USERNAME=$5
if [ -z $USERNAME ]; then
echo "The USERNAME could not be an empty string."
exit 1
fi

PASSWORD=$5
PASSWORD=$6
if [ -z $PASSWORD ]; then
echo "The PASSWORD could not be an empty string."
exit 1
Expand All @@ -44,7 +50,7 @@ if ! [[ -e "$certfile" ]]; then
printf "${RED}Certification file $certfile does not exist.\r\n${NC}"
#alf #clear plc except ip and name and provide all actions for install all, build and initial download hw so as sw
alf=$( dirname ${BASH_SOURCE[0]})"\\all_first.sh"
$alf $PLC_NAME $PLC_IP_ADDRESS $PLATFORM $USERNAME $PASSWORD
$alf $NAMESPACE $PLC_NAME $PLC_IP_ADDRESS $PLATFORM $USERNAME $PASSWORD
else
check_requisites_apax_script=$( dirname ${BASH_SOURCE[0]})"\\check_requisites_apax.sh"
if ! $check_requisites_apax_script ; then
Expand All @@ -69,7 +75,7 @@ else
printf "${RED}It has to be regenerated again.\r\n${NC}"
#alf #clear plc except ip and name and provide all actions for install all, build and initial download hw so as sw
alf=$( dirname ${BASH_SOURCE[0]})"\\all_first.sh"
$alf $PLC_NAME $PLC_IP_ADDRESS $PLATFORM $USERNAME $PASSWORD
$alf $NAMESPACE $PLC_NAME $PLC_IP_ADDRESS $PLATFORM $USERNAME $PASSWORD
else

printf "${GREEN}Certification file $certfile exists and its sha1 hash is equal to the PLC's one.\r\n"
Expand All @@ -78,7 +84,7 @@ else

#hw_update # copy and install gsd, copy templates, compile, copy the HwIds, download HW using certificate
hw_update=$( dirname ${BASH_SOURCE[0]})"\\hw_update.sh"
$hw_update $PLC_NAME $PLC_IP_ADDRESS
$hw_update $NAMESPACE $PLC_NAME $PLC_IP_ADDRESS

#sw_build_and_download_full # software build and full download
sw_build_and_download_full=$( dirname ${BASH_SOURCE[0]})"\\sw_build_and_download_full.sh"
Expand Down
25 changes: 16 additions & 9 deletions axopen.template.simple/scripts/all_first.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
if [ "$#" -ne 5 ]; then
echo "Usage: $0 <PLC_NAME> <PLC_IP_ADDRESS> <PLATFORM> <USERNAME> <PASSWORD>"
if [ "$#" -ne 6 ]; then
echo "Usage: $0 <NAMESPACE> <PLC_NAME> <PLC_IP_ADDRESS> <PLATFORM> <USERNAME> <PASSWORD>"
exit 1
fi

PLC_NAME=$1
NAMESPACE=$1
if [ -z $NAMESPACE ]; then
echo "The NAMESPACE could not be an empty string."
exit 1
fi

PLC_NAME=$2
if [ -z $PLC_NAME ]; then
echo "The PLC_NAME could not be an empty string."
exit 1
fi

PLC_IP_ADDRESS=$2
PLC_IP_ADDRESS=$3
validate_script=$( dirname ${BASH_SOURCE[0]})"\\validate_ip.sh"
if ! $validate_script "$PLC_IP_ADDRESS"; then
echo "The PLC_IP_ADDRESS '$PLC_IP_ADDRESS' is not a valid IP address."
exit 1
fi

PLATFORM=$3
PLATFORM=$4
if [ -z $PLATFORM ]; then
echo "The PLATFORM could not be an empty string."
exit 1
fi

USERNAME=$4
USERNAME=$5
if [ -z $USERNAME ]; then
echo "The USERNAME could not be an empty string."
exit 1
fi

PASSWORD=$5
PASSWORD=$6
if [ -z $PASSWORD ]; then
echo "The PASSWORD could not be an empty string."
exit 1
fi


export GREEN='\033[0;32m'
export RED='\033[0;31m'
export NC='\033[0m' # No Color
Expand All @@ -59,7 +66,7 @@ apax install

#clean_plc # total reset of the PLC excluding IP and name
clean_plc=$( dirname ${BASH_SOURCE[0]})"\\clean_plc.sh"
$clean_plc
$clean_plc $PLC_IP_ADDRESS

#copy_and_install_gsd # copy and install all gsdml files from library
copy_and_install_gsd=$( dirname ${BASH_SOURCE[0]})"\\copy_and_install_gsd.sh"
Expand All @@ -75,7 +82,7 @@ $setup_secure_communication $PLC_NAME $USERNAME $PASSWORD

#hw_first_compile_and_first_download # compile, copy the HwIds, first download HW using password and upload certificate
hw_first_compile_and_first_download=$( dirname ${BASH_SOURCE[0]})"\\hw_first_compile_and_first_download.sh"
$hw_first_compile_and_first_download $PLC_NAME $PLC_IP_ADDRESS $PASSWORD
$hw_first_compile_and_first_download $NAMESPACE $PLC_NAME $PLC_IP_ADDRESS $PASSWORD

#sw_build_and_download_full # software build and full download
sw_build_and_download_full=$( dirname ${BASH_SOURCE[0]})"\\sw_build_and_download_full.sh"
Expand Down
30 changes: 23 additions & 7 deletions axopen.template.simple/scripts/copy_hardware_ids.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <NAMESPACE> <PLC_NAME>"
exit 1
fi
NAMESPACE=$1
if [ -z $NAMESPACE ]; then
echo "The NAMESPACE could not be an empty string."
exit 1
fi
PLC_NAME=$2
if [ -z $PLC_NAME ]; then
echo "The PLC_NAME could not be an empty string."
exit 1
fi
if ! [[ -d "./hwc" ]]; then
echo "Directory ".\hwc" does not exist!!!"
exit 1
Expand All @@ -16,9 +30,10 @@ output_file="$output_dir/HwIdentifiers.st"
lines_to_replace=("CONFIGURATION HardwareIDs" "VAR_GLOBAL CONSTANT" "END_VAR" "END_CONFIGURATION")
old_substrings=(": UINT := UINT" ";")
new_substrings=(":= WORD" ",")
echo "TYPE" > "$output_file"
echo " HwIdentifiers : WORD" >> "$output_file"
echo " (" >> "$output_file"
echo "NAMESPACE ${NAMESPACE}" > "$output_file"
echo " TYPE" >> "$output_file"
echo " HwIdentifiers : WORD" >> "$output_file"
echo " (" >> "$output_file"
while IFS= read -r line; do
copy_this_line=true
for line_to_replace in "${lines_to_replace[@]}"; do
Expand Down Expand Up @@ -55,9 +70,10 @@ while IFS= read -r line; do
fi
fi
done
echo "$modified_line" >> "$output_file"
echo " $modified_line" >> "$output_file"
fi
done < "$input_file"
echo " NONE := WORD#0" >> "$output_file"
echo " );" >> "$output_file"
echo "END_TYPE" >> "$output_file"
echo " NONE := WORD#0" >> "$output_file"
echo " );" >> "$output_file"
echo " END_TYPE" >> "$output_file"
echo "END_NAMESPACE" >> "$output_file"
88 changes: 74 additions & 14 deletions axopen.template.simple/scripts/copy_io_addresses.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <NAMESPACE> <PLC_NAME>"
exit 1
fi
NAMESPACE=$1
if [ -z $NAMESPACE ]; then
echo "The NAMESPACE could not be an empty string."
exit 1
fi
PLC_NAME=$2
if [ -z $PLC_NAME ]; then
echo "The PLC_NAME could not be an empty string."
exit 1
fi
if ! [[ -d "./hwc" ]]; then
echo "Directory ".\hwc" does not exist!!!"
exit 1
Expand All @@ -12,19 +26,30 @@ if ! [[ -d $output_dir ]]; then
echo "Directory $output_dir does not exist!!!"
mkdir -p $output_dir
fi
output_file="$output_dir/IoAddresses.st"
echo " " > "$output_file"
output_file_inputs="$output_dir/Inputs.st"
output_file_outputs="$output_dir/Outputs.st"
echo "NAMESPACE ${NAMESPACE}" > "$output_file_inputs"
echo "NAMESPACE ${NAMESPACE}" > "$output_file_outputs"
echo " TYPE" >> "$output_file_inputs"
echo " TYPE" >> "$output_file_outputs"
echo " {S7.extern=ReadWrite}" >> "$output_file_inputs"
echo " {S7.extern=ReadWrite}" >> "$output_file_outputs"
echo " {#ix-attr:[Container(Layout.Wrap)]}" >> "$output_file_inputs"
echo " {#ix-attr:[Container(Layout.Wrap)]}" >> "$output_file_outputs"
echo " Inputs : STRUCT" >> "$output_file_inputs"
echo " Outputs : STRUCT" >> "$output_file_outputs"

while IFS= read -r line; do
modified_line="$line"
# Check if the variable starts with a letter
# Find the position of the first non-whitespace character
first_non_white_pos=$(expr match "$modified_line" '^[[:space:]]*')
# Extract the first non-whitespace character
first_char="${modified_line:$first_non_white_pos:1}"
# Check if the string contains only whitespace
if [[ "$first_non_white_pos" -lt "${#modified_line}" ]]; then
modified_line="$line"
# Check if the variable starts with a letter
# Find the position of the first non-whitespace character
first_non_white_pos=$(expr match "$modified_line" '^[[:space:]]*')

# Extract the first non-whitespace character
first_char="${modified_line:$first_non_white_pos:1}"

# Check if the string contains only whitespace
if [[ "$first_non_white_pos" -lt "${#modified_line}" ]]; then
# Check if the first non-whitespace character is not a letter
if [[ ! "$first_char" =~ [a-zA-Z] ]]; then
# Split the string into two parts: before and after the first non-whitespace character
Expand All @@ -36,6 +61,41 @@ while IFS= read -r line; do
modified_line="${before_first_char}_${after_first_char}"
fi
fi
fi
echo "$modified_line" >> "$output_file"
fi

# Check if the modified_line contains the substring "_InputAddress"
if [[ $modified_line == *"_InputAddress"* ]]; then
# Extract the first word without "_InputAddress"
variable_name=$(echo "$line" | awk '{print $1}' | sed 's/_InputAddress//')

# Extract the number from the substring after % and before :
address_offset=$(echo "$line" | awk -F'%' '{print $2}' | awk -F':' '{print $1}' | grep -o '[0-9]\+')

# Extract the substring from : to ;, excluding : and ;
variable_type=$(echo "$line" | awk -F':' '{print $2}' | awk -F';' '{print $1}')

# Output the variables
echo " ${variable_name} AT %B${address_offset}: ${variable_type};" >> "$output_file_inputs"
fi

# Check if the modified_line contains the substring "_OutputAddress"
if [[ $modified_line == *"_OutputAddress"* ]]; then
# Extract the first word without "_OutputAddress"
variable_name=$(echo "$line" | awk '{print $1}' | sed 's/_OutputAddress//')

# Extract the number from the substring after % and before :
address_offset=$(echo "$line" | awk -F'%' '{print $2}' | awk -F':' '{print $1}' | grep -o '[0-9]\+')

# Extract the substring from : to ;, excluding : and ;
variable_type=$(echo "$line" | awk -F':' '{print $2}' | awk -F';' '{print $1}')

# Output the variables
echo " ${variable_name} AT %B${address_offset}: ${variable_type};" >> "$output_file_outputs"
fi
done < "$input_file"
echo " END_STRUCT;" >> "$output_file_inputs"
echo " END_STRUCT;" >> "$output_file_outputs"
echo " END_TYPE" >> "$output_file_inputs"
echo " END_TYPE" >> "$output_file_outputs"
echo "END_NAMESPACE" >> "$output_file_inputs"
echo "END_NAMESPACE" >> "$output_file_outputs"
18 changes: 12 additions & 6 deletions axopen.template.simple/scripts/hw_compile_and_download.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <PLC_NAME> <PLC_IP_ADDRESS>"
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <NAMESPACE> <PLC_NAME> <PLC_IP_ADDRESS>"
exit 1
fi

PLC_NAME=$1
NAMESPACE=$1
if [ -z $NAMESPACE ]; then
echo "The NAMESPACE could not be an empty string."
exit 1
fi

PLC_NAME=$2
if [ -z $PLC_NAME ]; then
echo "The PLC_NAME could not be an empty string."
exit 1
fi

PLC_IP_ADDRESS=$2
PLC_IP_ADDRESS=$3
validate_script=$( dirname ${BASH_SOURCE[0]})"\\validate_ip.sh"
if ! $validate_script "$PLC_IP_ADDRESS"; then
echo "The PLC_IP_ADDRESS '$PLC_IP_ADDRESS' is not a valid IP address."
Expand All @@ -34,7 +40,7 @@ fi

apax hwc compile -i ".\hwc" -o bin/hwc/
hwid=$( dirname ${BASH_SOURCE[0]})"\\copy_hardware_ids.sh"
$hwid
$hwid $NAMESPACE $PLC_NAME
hwadr=$( dirname ${BASH_SOURCE[0]})"\\copy_io_addresses.sh"
$hwadr
$hwadr $NAMESPACE $PLC_NAME
apax hwld -i bin/hwc/$PLC_NAME -t $PLC_IP_ADDRESS -C $certfile --nonInteractive --accept-security-disclaimer -l Information
Loading

0 comments on commit 87fa00c

Please sign in to comment.