Here is a copy of the tclproc we use for an example for you.
There is startup/shutdown stuff that may be helpful.
######################################################################
# Name: rad_shake
# Purpose:
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (”start”, “run” or “time”)
# MSGID message handle
# ARGS user-supplied arguments:
#
#
# Returns: tps disposition list:
#
#
proc rad_shake {args} {
keylget args MODE mode
global HciSite HciConnName HciProcessesDir
set module “$HciSite/$HciConnName/rad_shake: ”
set ctrfile radidxctr
if {[file exists $ctrfile.ctr] == 1} {
#echo “$module Using counterfile $ctrfile…”
#echo [pwd]
#echo $HciProcessesDir
} else {
echo “$module Initializing counterfile ‘$ctrfile’…”
CtrInitCounter $ctrfile file 1 99999 1
}
set dispList {}
switch -exact — $mode {
start {
# Perform special init functions
# N.B.: there may or may not be a MSGID key in args
}
run {
keylget args MSGID mh
set msg [msgget -cvtnull _ $mh]
switch -exact — $msg {
“START-UP XXXX” {
append msg “V0000 ”
set response [msgcreate Y$msg]
lappend dispList “KILL $mh” “OVER $response”
}
“SHUTDOWN XXXX” {
append msg ” ”
set response [msgcreate Y$msg]
lappend dispList “KILL $mh” “OVER $response”
}
default {
set dstring [clock format [clock seconds] -format %y%m%d%H%M%S]00
set response [msgcreate “Y[string range $msg 0 12] “]
if {[crange $msg 13 13] == “R” && [msglength $mh] == 166} {
msgset $mh [strsub $msg 56 73 [rad_dr_n2a [crange $msg 56 61]][rad_dr_n2a [crange $msg 62 67]][rad_dr_n2a [crange $msg 68 73]]]
}
msginsert $mh “[crange [expr 100000 + [CtrNextValue $ctrfile]] 1 end] [crange $dstring 0 5] [crange $dstring 6 13]”
#kill test patients with MRN beginning with 8-88-8 per WR 61688
if {[crange $msg 14 14] == “D” || [crange $msg 14 19] == “8-88-8″} {
lappend dispList “KILL $mh” “OVER $response”
} else {
lappend dispList “CONTINUE $mh” “OVER $response”
}
}
}
}
time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
}
shutdown {
# Doing some clean-up work
}
default {
error “$module Unknown mode ‘$mode'”
}
}
return $dispList
}