#!/usr/bin/ruby
#
# Indices into the parsed values array 'v'
# 
RPM = 2
VOLT = 5
PWR = 6
PSI = 12
SCALE = 13

# Array of label/index pairs for output
# 
vals = [
   ["RPM", RPM],
   ["Volts", VOLT],
   ["Power", PWR],
   ["CompPSI", PSI],
   ["Scale", SCALE]
]

Signal.trap("INT") { STDOUT.flush(); puts("\nDone"); exit }

# Execute continuously or just once
# 
n = 0
while(1) do
   next unless (line = gets())

   # Examine every tenth line
   # 
   n += 1
   next unless (n >= 10) 

   n = 0
   # This parses the line using ',' as a separator.
   # Array 'v' contains the string values.
   # 
   v = line.split(',')

   # Write the labels and values
   # 
   vals.each do |i|
      STDOUT.write("#{i[0]}=#{v[i[1]].lstrip}  ")
   end
   STDOUT.write("\n")
   STDOUT.flush()

   #break  # Just once for now

end
