# Path: wfcommon/units.py
# def identity(value):
# def FToC(value): 
# def CToF(value): 
# def InHgToHPa(value):
# def HPaToInHg(value):
# def HPaToMmHg(value):
# def MmHgToHPa(value):
# def InToMm(value): 
# def MmToIn(value): 
# def MpsToKt(value):
# def KtToMps(value):
# def MpsToKmh(value):
# def KmhToMps(value):
# def MphToMps(value): 
# def MpsToMph(value): 
# def MpsToBft(value):
# def BftToMps(value):
# def convert(measure, value, to_units, from_units=None):
#     def __init__(self, units):
#     def convert(self, measure, value):        
#     def convert_back(self, measure, value):        
#     def temp(self, value):
#     def press(self, value):
#     def wind(self, value):
#     def rain(self, value):
# def unit_roll(measure, unit):
# class Converter(object):


import time
import logging
import struct
import array
        import serial
from wfcommon import units
        ('SoilTemps',   '4s'), ('LeafTemps',  '4s'),  ('HumOut',      'B'),
        ('ExtraHum1',    'B'), ('ExtraHum2',   'B'),  ('ExtraHum3',   'B'), 
        ('ExtraHum4',    'B'), ('ExtraHum5',   'B'),  ('ExtraHum6',   'B'),
        ('ExtraHum7',    'B'), ('RainRate',    'H'),  ('UV',          'B'),
        ('SolarRad',     'H'), ('RainStorm',   'H'),  ('StormStartDate','H'),
        ('RainDay',      'H'), ('RainMonth',   'H'),  ('RainYear',    'H'),
        ('ETDay',        'H'), ('ETMonth',     'H'),  ('ETYear',      'H'),
        ('SoilMoist',   '4s'), ('LeafWetness','4s'),  ('AlarmIn',     'B'),
        ('AlarmRain',    'B'), ('AlarmOut' ,  '2s'),  ('AlarmExTempHum','8s'),
        ('AlarmSoilLeaf','4s'),('BatteryStatus','B'), ('BatteryVolts','H'),
        ('ForecastIcon','B'),  ('ForecastRuleNo','B'),('SunRise',     'H'),
        ('SunSet',      'H'),  ('EOL',         '2s'), ('CRC',         'H'),
      )

    def __init__(self, rain_bucket):
        super(LoopStruct,self).__init__(self.FMT,'=')
        self.rain_bucket = rain_bucket

    def _post_unpack(self,items):
        # Pressure
        items['Pressure'] = units.InHgToHPa(items['Pressure'] / 1000.0)
        # Temperature
        items['TempIn'] = units.FToC(items['TempIn'] / 10.0) if items['TempIn'] != 32767 else None
        items['TempOut'] = units.FToC(items['TempOut'] / 10.0) if items['TempOut'] != 32767 else None
        items['ExtraTemp1'] = units.FToC(items['ExtraTemp1'] - 90) if items['ExtraTemp1'] != 255 else None
        items['ExtraTemp2'] = units.FToC(items['ExtraTemp2'] - 90) if items['ExtraTemp2'] != 255 else None
        items['ExtraTemp3'] = units.FToC(items['ExtraTemp3'] - 90) if items['ExtraTemp3'] != 255 else None
        items['ExtraTemp4'] = units.FToC(items['ExtraTemp4'] - 90) if items['ExtraTemp4'] != 255 else None
        items['ExtraTemp5'] = units.FToC(items['ExtraTemp5'] - 90) if items['ExtraTemp5'] != 255 else None
        items['ExtraTemp6'] = units.FToC(items['ExtraTemp6'] - 90) if items['ExtraTemp6'] != 255 else None

# Path: wfcommon/units.py
# def identity(value):
# def FToC(value): 
# def CToF(value): 
# def InHgToHPa(value):
# def HPaToInHg(value):
# def HPaToMmHg(value):
# def MmHgToHPa(value):
# def InToMm(value): 
# def MmToIn(value): 
# def MpsToKt(value):
# def KtToMps(value):
# def MpsToKmh(value):
# def KmhToMps(value):
# def MphToMps(value): 
# def MpsToMph(value): 
# def MpsToBft(value):
# def BftToMps(value):
# def convert(measure, value, to_units, from_units=None):
#     def __init__(self, units):
#     def convert(self, measure, value):        
#     def convert_back(self, measure, value):        
#     def temp(self, value):
#     def press(self, value):
#     def wind(self, value):
#     def rain(self, value):
# def unit_roll(measure, unit):
# class Converter(object):


# Path: wfdriver/station/vantagepro2.py
import time
import logging
import struct
import array
        import serial
from wfcommon import units

        ('SoilTemps',   '4s'), ('LeafTemps',  '4s'),  ('HumOut',      'B'),
        ('ExtraHum1',    'B'), ('ExtraHum2',   'B'),  ('ExtraHum3',   'B'), 
        ('ExtraHum4',    'B'), ('ExtraHum5',   'B'),  ('ExtraHum6',   'B'),
        ('ExtraHum7',    'B'), ('RainRate',    'H'),  ('UV',          'B'),
        ('SolarRad',     'H'), ('RainStorm',   'H'),  ('StormStartDate','H'),
        ('RainDay',      'H'), ('RainMonth',   'H'),  ('RainYear',    'H'),
        ('ETDay',        'H'), ('ETMonth',     'H'),  ('ETYear',      'H'),
        ('SoilMoist',   '4s'), ('LeafWetness','4s'),  ('AlarmIn',     'B'),
        ('AlarmRain',    'B'), ('AlarmOut' ,  '2s'),  ('AlarmExTempHum','8s'),
        ('AlarmSoilLeaf','4s'),('BatteryStatus','B'), ('BatteryVolts','H'),
        ('ForecastIcon','B'),  ('ForecastRuleNo','B'),('SunRise',     'H'),
        ('SunSet',      'H'),  ('EOL',         '2s'), ('CRC',         'H'),
      )

    def __init__(self, rain_bucket):
        super(LoopStruct,self).__init__(self.FMT,'=')
        self.rain_bucket = rain_bucket

    def _post_unpack(self,items):
        # Pressure
        items['Pressure'] = units.InHgToHPa(items['Pressure'] / 1000.0)
        # Temperature
        items['TempIn'] = units.FToC(items['TempIn'] / 10.0) if items['TempIn'] != 32767 else None
        items['TempOut'] = units.FToC(items['TempOut'] / 10.0) if items['TempOut'] != 32767 else None
        items['ExtraTemp1'] = units.FToC(items['ExtraTemp1'] - 90) if items['ExtraTemp1'] != 255 else None
        items['ExtraTemp2'] = units.FToC(items['ExtraTemp2'] - 90) if items['ExtraTemp2'] != 255 else None
        items['ExtraTemp3'] = units.FToC(items['ExtraTemp3'] - 90) if items['ExtraTemp3'] != 255 else None
        items['ExtraTemp4'] = units.FToC(items['ExtraTemp4'] - 90) if items['ExtraTemp4'] != 255 else None
        items['ExtraTemp5'] = units.FToC(items['ExtraTemp5'] - 90) if items['ExtraTemp5'] != 255 else None
        items['ExtraTemp6'] = units.FToC(items['ExtraTemp6'] - 90) if items['ExtraTemp6'] != 255 else None

        items['ExtraTemp7'] = units.FToC(items['ExtraTemp7'] - 90) if items['ExtraTemp7'] != 255 else None