namespace eval pfeiffertpg {} {
}

proc stdConfig::pfeiffertpg {} {
  controller std "" 5 
  prop read pfeiffertpg::read
  prop update pfeiffertpg::update

  obj TPG rd
  prop cmd PR1
  kids TPG {
    # node prx rd -text
    # prop cmd PRX

    node sp1 rd -text
    prop cmd SP1

    node sp2 rd -text
    prop cmd SP2

    node sps rd -text
    prop cmd SPS
  }
}

proc pfeiffertpg::read {} {
  sct send "[sct cmd]\r\n"
  return update
}

proc pfeiffertpg::update {} {
  set ack x
  scan [sct result] %c ack
  if {$ack == 6} {
    sct send "\005"
    return pfeiffertpg::update2
  }
  if {$ack == 21} {
    error "NAK received on [sct cmd]"
  }
  return [pfeiffertpg::read]
}

proc pfeiffertpg::update2 {} {
  if {[sct cmd] eq "PR1"} {
    sct update [lindex [split [sct result] ,] 1]
  } else {
    sct update [sct result]
  }
  return idle
}
