1# Copyright (c) (2024), Cypress Semiconductor Corporation (an Infineon company) or 2# an affiliate of Cypress Semiconductor Corporation. 3# SPDX-License-Identifier: Apache-2.0 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# From https://wiki.tcl-lang.org/page/constants 18proc const {name value} { 19 uplevel 1 [list set $name $value] 20 uplevel 1 [list trace var $name w {error constant;} ] 21} 22 23const ARG_IDX_IN_IP 0 24 25const SUCCESS 0 26const ERROR_ARG_COUNT 1 27const ERROR_ID 2 28const ERROR_ARG_VALUE 3 29 30set channelName stdout 31 32if {[chan names ModusToolbox] eq "ModusToolbox"} { 33 set channelName ModusToolbox 34} 35 36proc parse_ip {} { 37 if {$::argc != $::ARG_IDX_IN_IP + 1} { 38 error "IP Parser requires 1 argument: 39\tstring inIPaddr - The input IP address in the format 00.00.00.00" 40 return $::ERROR_ARG_COUNT 41 } 42 43 set inIPaddr [lindex $::argv $::ARG_IDX_IN_IP] 44 45 if {![regexp {([0-999]{3}[.])} $inIPaddr]} { 46 error "Unable to parse the IP address, because it does not match the hexadecimal format 00.00.00.00" 47 return $::ERROR_ARG_VALUE 48 } 49 set inIPaddr [split $inIPaddr "."] 50 return [parse_ip_internal $inIPaddr] 51} 52 53proc parse_ip_internal {inIPaddr} { 54 set counter 0 55 foreach idx $inIPaddr { 56 puts $::channelName "param:ipField$counter=$idx" 57 incr counter 58 } 59 return $::SUCCESS 60} 61parse_ip 62