%include "Moose:Mouse.Inc"
%include "GDMR_E:Ether.Inc"

%externalpredicatespec FS lookup(%string(31) what, %integername value)
%systemroutinespec phex2(%integer x)

%externalroutine print ether address(%bytename a)
   %integer i
      %for i = 0, 1, 5 %cycle
         print symbol('-') %unless i = 0
         phex2(a);  a == a [1]
      %repeat
%end

%begin
   %record(ether statistics fm) stats
   %record(semaphore fm) sem
   %record(mailbox fm) box
   %record(mailbox fm)%name ether box
   %record(ether request fm) req
   %record(ether request fm)%name rep
   %integer x
      %if FS lookup(ether mailbox name, x) %start
         ether box == record(x)
      %else
         printstring("No ether mailbox");  newline
         %stop
      %finish
      setup semaphore(sem)
      setup mailbox(box, sem)
      setup message(req, size of(req))
      req_code = ether statistics
      req_buffer == byteinteger(addr(stats))
      send message(req, ether box, box)
      rep == receive message(box)
      %if rep ## req %or req_status # ether success %start
         printstring("Failed: ");  write(req_status, 0);  newline
         %stop
      %finish
      printstring("Station address: ");  print ether address(stats_address(0))
      newline;  newline
      write(stats_packets in, 8);  printstring(" packets in ")
      write(stats_bytes in, 8);  printstring(" bytes in ")
      write(stats_no takers tally, 8);  printstring(" no takers");  newline
      write(stats_packets out, 8);  printstring(" packets out")
      write(stats_bytes out, 8);  printstring(" bytes out");  newline
      newline
      write(stats_babl tally, 8);  printstring(" babl")
      write(stats_miss tally, 8);  printstring(" miss")
      write(stats_merr tally, 8);  printstring(" merr")
      write(stats_buff tally, 8);  printstring(" buff");  newline
      write(stats_fram tally, 8);  printstring(" fram")
      write(stats_oflo tally, 8);  printstring(" oflo")
      write(stats_CRC  tally, 8);  printstring(" CRC ");  newline
      write(stats_more tally, 8);  printstring(" more")
      write(stats_one  tally, 8);  printstring(" one ")
      write(stats_def  tally, 8);  printstring(" def ");  newline
      write(stats_uflo tally, 8);  printstring(" uflo")
      write(stats_lcol tally, 8);  printstring(" lcol")
      write(stats_lcar tally, 8);  printstring(" lcar")
      write(stats_rtry tally, 8);  printstring(" rtry");  newline
%end %of %program
