Newer
Older
weather-servlet / src / main / scala / uk / org / floop / msc / wview / LoopPacket.scala
package uk.org.floop.msc.wview

object VALUE_TYPE extends Enumeration {
  val FLOAT, USHORT, TIME_T, SHORT, UCHAR = Value
  def sizeof(t: Value): Int = t match {
    case VALUE_TYPE.FLOAT => 4
    case VALUE_TYPE.USHORT => 2
    case VALUE_TYPE.TIME_T => 4
    case VALUE_TYPE.SHORT => 2
    case VALUE_TYPE.UCHAR => 1
  }
}

object LoopPacket {
  val fields = List(
      (VALUE_TYPE.FLOAT, "barometer"),       // inches
      (VALUE_TYPE.FLOAT, "stationPressure"), // inches
      (VALUE_TYPE.FLOAT, "altimeter"),       // inches
      (VALUE_TYPE.FLOAT, "inTemp"),          // degrees F
      (VALUE_TYPE.FLOAT, "outTemp"),         // degrees F
      (VALUE_TYPE.USHORT, "inHumidity"),     // percent
      (VALUE_TYPE.USHORT, "outHumidity"),    // percent
      (VALUE_TYPE.USHORT, "windSpeed"),      // mph
      (VALUE_TYPE.USHORT, "windDir"),        // degrees
      (VALUE_TYPE.USHORT, "windGust"),       // mph
      (VALUE_TYPE.USHORT, "windGustDir"),    // degrees
      (VALUE_TYPE.FLOAT,  "rainRate"),       // in/hr
      (VALUE_TYPE.FLOAT,  "sampleRain"),     // inches
      (VALUE_TYPE.FLOAT,  "sampleET"),       // ET
      (VALUE_TYPE.USHORT, "radiation"),      // watts/m^3
      (VALUE_TYPE.USHORT, "padding1"),       // ! 2 bytes of padding
      (VALUE_TYPE.FLOAT, "UV"),             // UV index * 10
      (VALUE_TYPE.FLOAT,  "dewpoint"),       // degrees F
      (VALUE_TYPE.FLOAT,  "windchill"),      // degrees F
      (VALUE_TYPE.FLOAT,  "heatindex"),      // degrees F
    
        // computed values - station should not alter these
      (VALUE_TYPE.FLOAT,  "stormRain"),         // inches
      (VALUE_TYPE.TIME_T, "stormStart"),        // time_t
      (VALUE_TYPE.FLOAT,  "dayRain"),           // inches
      (VALUE_TYPE.FLOAT,  "monthRain"),         // inches
      (VALUE_TYPE.FLOAT,  "yearRain"),          // inches
      (VALUE_TYPE.FLOAT,  "dayET"),             // inches
      (VALUE_TYPE.FLOAT,  "monthET"),           // inches
      (VALUE_TYPE.FLOAT,  "yearET"),            // inches
      (VALUE_TYPE.FLOAT,  "intervalAvgWCHILL"), // degrees F
      (VALUE_TYPE.USHORT,  "intervalAvgWSPEED"), // mph
      (VALUE_TYPE.USHORT, "yearRainMonth"),     // 1-12 Rain Start Month
    
        // --- The following may or may not be supported for a given station ---
    
        // Vantage Pro
      (VALUE_TYPE.USHORT, "rxCheckPercent"),        // 0 - 100
      (VALUE_TYPE.USHORT, "tenMinuteAvgWindSpeed"), // mph
      (VALUE_TYPE.USHORT, "forecastIcon"),          // VP only
      (VALUE_TYPE.USHORT, "forecastRule"),          // VP only
      (VALUE_TYPE.USHORT, "txBatteryStatus"),       // VP only
      (VALUE_TYPE.USHORT, "consBatteryVoltage"),    // VP only
      (VALUE_TYPE.FLOAT,  "extraTemp1"),            // degrees F + 90
      (VALUE_TYPE.FLOAT,  "extraTemp2"),            // degrees F + 90
      (VALUE_TYPE.FLOAT,  "extraTemp3"),            // degrees F + 90
      (VALUE_TYPE.FLOAT,  "soilTemp1"),             // degrees F + 90
      (VALUE_TYPE.FLOAT,  "soilTemp2"),             // degrees F + 90
      (VALUE_TYPE.FLOAT,  "soilTemp3"),             // degrees F + 90
      (VALUE_TYPE.FLOAT,  "soilTemp4"),             // degrees F + 90
      (VALUE_TYPE.FLOAT,  "leafTemp1"),             // degrees F + 90
      (VALUE_TYPE.FLOAT,  "leafTemp2"),             // degrees F + 90
      (VALUE_TYPE.UCHAR,  "extraHumid1"),           // percent
      (VALUE_TYPE.UCHAR,  "extraHumid2"),           // percent
      (VALUE_TYPE.UCHAR,  "soilMoist1"),
      (VALUE_TYPE.UCHAR,  "soilMoist2"),
      (VALUE_TYPE.UCHAR,  "leafWet1"),
      (VALUE_TYPE.UCHAR,  "leafWet2"),
      (VALUE_TYPE.USHORT, "padding2"),      // !two bytes of padding 
    
        // Vaisala WXT-510
      (VALUE_TYPE.FLOAT,  "wxt510Hail"),             // inches
      (VALUE_TYPE.FLOAT,  "wxt510Hailrate"),         // in/hr
      (VALUE_TYPE.FLOAT,  "wxt510HeatingTemp"),      // degrees F
      (VALUE_TYPE.FLOAT,  "wxt510HeatingVoltage"),   // volts
      (VALUE_TYPE.FLOAT,  "wxt510SupplyVoltage"),    // volts
      (VALUE_TYPE.FLOAT,  "wxt510ReferenceVoltage"),  // volts
      (VALUE_TYPE.FLOAT,  "wxt510RainDuration"),      // sec
      (VALUE_TYPE.FLOAT,  "wxt510RainPeakRate"),     // volts
      (VALUE_TYPE.FLOAT,  "wxt510HailDuration"),     // sec
      (VALUE_TYPE.FLOAT,  "wxt510HailPeakRate"),     // volts
      (VALUE_TYPE.FLOAT,  "wxt510Rain"),             // inches

      // WMR918/968
      (VALUE_TYPE.FLOAT,  "wmr918Pool"),             // degrees F
      (VALUE_TYPE.UCHAR,  "wmr918Humid3"),           // percent
      (VALUE_TYPE.UCHAR,  "wmr918Tendency"),         // WMR's Forecast
      (VALUE_TYPE.UCHAR,  "wmr918WindBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "wmr918RainBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "wmr918OutTempBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "wmr918InTempBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "wmr918poolTempBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "wmr918extra1BatteryStatus"),
      (VALUE_TYPE.UCHAR,  "wmr918extra2BatteryStatus"),
      (VALUE_TYPE.UCHAR,  "wmr918extra3BatteryStatus"),
      (VALUE_TYPE.USHORT, "padding3"),       // ! 2 bytes of padding

      // Generic extra sensor and status support:
      (VALUE_TYPE.FLOAT,  "extraTemp0"),
      (VALUE_TYPE.FLOAT,  "extraTemp1"),
      (VALUE_TYPE.FLOAT,  "extraTemp2"),
      (VALUE_TYPE.FLOAT,  "extraTemp3"),
      (VALUE_TYPE.FLOAT,  "extraTemp4"),
      (VALUE_TYPE.FLOAT,  "extraTemp5"),
      (VALUE_TYPE.FLOAT,  "extraTemp6"),
      (VALUE_TYPE.FLOAT,  "extraTemp7"),
      (VALUE_TYPE.FLOAT,  "extraTemp8"),
      (VALUE_TYPE.FLOAT,  "extraTemp9"),
      (VALUE_TYPE.FLOAT,  "extraTempA"),
      (VALUE_TYPE.FLOAT,  "extraTempB"),
      (VALUE_TYPE.FLOAT,  "extraTempC"),
      (VALUE_TYPE.FLOAT,  "extraTempD"),
      (VALUE_TYPE.FLOAT,  "extraTempE"),
      (VALUE_TYPE.FLOAT,  "extraTempF"),
      (VALUE_TYPE.USHORT, "extraHumidity0"),
      (VALUE_TYPE.USHORT, "extraHumidity1"),
      (VALUE_TYPE.USHORT, "extraHumidity2"),
      (VALUE_TYPE.USHORT, "extraHumidity3"),
      (VALUE_TYPE.USHORT, "extraHumidity4"),
      (VALUE_TYPE.USHORT, "extraHumidity5"),
      (VALUE_TYPE.USHORT, "extraHumidity6"),
      (VALUE_TYPE.USHORT, "extraHumidity7"),
      (VALUE_TYPE.USHORT, "extraHumidity8"),
      (VALUE_TYPE.USHORT, "extraHumidity9"),
      (VALUE_TYPE.USHORT, "extraHumidityA"),
      (VALUE_TYPE.USHORT, "extraHumidityB"),
      (VALUE_TYPE.USHORT, "extraHumidityC"),
      (VALUE_TYPE.USHORT, "extraHumidityD"),
      (VALUE_TYPE.USHORT, "extraHumidityE"),
      (VALUE_TYPE.USHORT, "extraHumidityF"),
      (VALUE_TYPE.UCHAR,  "windBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "rainBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "outTempBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "consoleBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "uvBatteryStatus"),
      (VALUE_TYPE.UCHAR,  "solarBatteryStatus"),
      (VALUE_TYPE.USHORT, "padding4"),       // ! 2 bytes of padding
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus0"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus1"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus2"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus3"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus4"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus5"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus6"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus7"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus8"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatus9"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatusA"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatusB"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatusC"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatusD"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatusE"),
      (VALUE_TYPE.UCHAR,  "extraTempBatteryStatusF")      
  )
  
  val START_FRAME = Array(0x88, 0xf3, 0xa2, 0xc6, 0xda, 0xda, 0x01, 0x00).map(_.toByte)
  
  val SIZE = LoopPacket.fields.map(pair => VALUE_TYPE.sizeof(pair._1)).foldLeft(0)(_ + _)

}