startmacro

  local /MSG/
  res rmif_id 5
  message down

  say "--------------------------------------------------------------------------------"
  say "Click on MESS1 and the message should come out on the NXM side with data table"
  say "Try with and without /NRP switch"
  say "--------------------------------------------------------------------------------"

  message up

  xpipe/nmq=1000/setup/controls on

    if /NORMIF GT 0 then
      waveform _wave,,1e9
    else
      if /NRP GT 0 then
        rmif/id=rmif_id/keymsg/msgid=1/log=rln_fart.log/retry=10 9001
      else
        rmif/id=rmif_id/keymsg/msgid=1/log=rln_fart.log/retry=10 9001,,"JPHLAP:9000" _wave
      endif
    endif
    if /NRP GT 0 then
      ! Do not show pipe
    else
      xrtplot/id=3/xs=3 _wave
    endif
    xrtdisplay/id=4/xs=4 nxm_value1/"NXM_1",nxm_value2/"NXM_2"

  xpipe off
endmacro


startcontrols

  label initialentry
    xcontrol/lab=main_proc MENU item 0 ";~(red)EXIT"
    xcontrol/lab=mess_proc MSMONITOR 1 1
    xcontrol/lab=nxmsend_proc MENU item1 0 "NXM SEND;~(green)mess1,~(yellow)mess2,~(orange)mess3"
  return

procedure main_proc
label main_proc
  MESS SEND /EXIT/ 2
  MESS SEND /EXIT/ 3
  MESS SEND /EXIT/ 4
  MESS SEND /EXIT/ 5
 
  STOP

return

procedure mess_proc
label mess_proc
  message get /MSG/
  say "Got msg: UDP addr ^msg.setkey_addr, name = ^msg.name, value = ^msg.setkey_value"
  if msg.name EQS "SETKEY" then
    if msg.setkey_name EQS "RLNVAL1" then
      res nxm_value1 "RLNVAL1"
    else
      res nxm_value2 "RLNVAL2"
    endif
  else
    say "Unrecognized msg name ^msg.name"
  endif
return

procedure nxmsend_proc
label nxmsend_proc
  if ^item1 EQ 1 then
    res myData "ONE"
  elseif ^item1 EQ 2 then
    res myData "TWO"
  elseif ^item1 EQ 3 then
    res myData "THREE"
  endif
  
  info "Sending SETKEY msg data = ^mydata to RMIF id ^rmif_id"
  mess send /SETKEY/ rmif_id 0 "JPHLAP:9000" "WTF" "^mydata"

return

endcontrols


