@@ -139,6 +139,67 @@ proc validate_identity_kins_limits {} {
139139 return $emsg
140140} ;# validate_identity_kins_limits
141141
142+ proc assert_ini_datatypes {} {
143+ # Datatype assertions, run right after parse_ini, before any comparison.
144+ # numeric: must be a real number (covers integers too: string is double)
145+ set numeric {
146+ MIN_LIMIT MAX_LIMIT MAX_VELOCITY MAX_ACCELERATION MAX_JERK
147+ FERROR MIN_FERROR BACKLASH
148+ P I D FF0 FF1 FF2 BIAS DEADBAND MAX_OUTPUT MAX_ERROR
149+ INPUT_SCALE OUTPUT_SCALE SCALE
150+ HOME HOME_OFFSET HOME_SEARCH_VEL HOME_LATCH_VEL HOME_FINAL_VEL
151+ HOME_SEQUENCE STEPGEN_MAXVEL STEPGEN_MAXACCEL
152+ }
153+ # enum: must match a fixed set (case-insensitive, mirroring LinuxCNC's
154+ # caseless maps mapJointType / convertBool)
155+ set bool {TRUE YES 1 ON FALSE NO 0 OFF}
156+ array set enum [list \
157+ TYPE {LINEAR ANGULAR} \
158+ HOME_USE_INDEX $bool \
159+ HOME_IGNORE_LIMITS $bool \
160+ HOME_IS_SHARED $bool \
161+ HOME_INDEX_NO_ENCODER_RESET $bool \
162+ VOLATILE_HOME $bool \
163+ LOCKING_INDEXER $bool \
164+ ]
165+ set emsg " "
166+ foreach g [info globals] {
167+ if {![string match JOINT_* $g ] && ![string match AXIS_* $g ]} continue
168+ foreach item [array names ::$g ] {
169+ set val [set ::${g} ($item )]
170+ # LinuxCNC reads the first occurrence (IniFile::Find defaults to num=1),
171+ # so a duplicate is not fatal. Validate the first occurrence; if there is
172+ # more than one, warn and collapse the array to it so the downstream limit
173+ # comparison uses the same value LinuxCNC would.
174+ set use [lindex $val 0]
175+ if {[llength $val ] > 1} {
176+ lappend ::wmsg " Multiple values for \[ $g \] $item : <$val > (first value is used)"
177+ set ::${g} ($item ) $use
178+ }
179+ if {[lsearch -exact $numeric $item ] >= 0} {
180+ if {![string is double -strict $use ]} {
181+ set m " \[ $g \] $item must be numeric, got: <$use >"
182+ if {[string match {*[#;]*} $use ]} {
183+ append m " \n Inline comments are not allowed: '#' and ';' start a comment"
184+ append m " \n only at the start of a line, not after a value. Move the comment"
185+ append m " \n to its own line. See the LinuxCNC manual, \" The INI File\" ->"
186+ append m " \n \" Comments\" : https://linuxcnc.org/docs/stable/html/config/ini-config.html#_comments"
187+ }
188+ lappend emsg $m
189+ }
190+ } elseif {[info exists enum($item )]} {
191+ if {[lsearch -nocase $enum($item) $use ] < 0} {
192+ lappend emsg " \[ $g \] $item must be one of {$enum($item) }, got: <$use >"
193+ }
194+ }
195+ }
196+ }
197+ if {" $emsg " != " " } {
198+ if {[info exists ::wmsg]} {warnings $::wmsg }
199+ err_exit $emsg
200+ }
201+ } ;# assert_ini_datatypes
202+
142203proc check_extrajoints {} {
143204 if ![info exists ::EMCMOT(EMCMOT)] return
144205 if {[string first motmod $::EMCMOT(EMCMOT) ] <= 0} return
@@ -158,30 +219,6 @@ proc check_extrajoints {} {
158219 }
159220} ;# check_extrajoints
160221
161- proc warn_for_multiple_ini_values {} {
162- set sections [info globals]
163- set sections_to_check {JOINT_ AXIS_}
164-
165- foreach section $sections {
166- set enforce 0
167- foreach csection $sections_to_check {
168- if {[string first $csection $section " ] >= 0} {
169- set enforce 1
170- break
171- }
172- }
173- if !$enforce continue
174- foreach name [ array names ::$section ] {
175- set gsection ::$section
176- set val [ set [set gsection] ($name )]
177- set len [ llength $val ]
178- if {$len > 1} {
179- lappend ::wmsg " Unexpected multiple values \[ $section \] $name : $val "
180- }
181- }
182- }
183- } ;# warn_for_multiple_ini_values
184-
185222# ----------------------------------------------------------------------
186223# begin
187224package require Linuxcnc ;# parse_ini
@@ -196,6 +233,8 @@ if ![file readable $inifile] {
196233}
197234parse_ini $inifile
198235
236+ assert_ini_datatypes
237+
199238check_mandatory_items
200239
201240set kins_kinematics [lindex $::KINS(KINEMATICS) end]
@@ -230,7 +269,6 @@ switch $::kins(module) {
230269}
231270check_extrajoints
232271
233- warn_for_multiple_ini_values
234272# parray ::kins
235273set emsg [validate_identity_kins_limits]
236274consistent_coords_for_trivkins $::kins(coordinates)
0 commit comments