Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of WH23xxConfigurator class #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 75 additions & 10 deletions bin/user/wh23xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
WH2301 (no RCC)
WH4000
Tycon TP2700

WH2310
Based on the protocol specified in "TP2700 EEPROM data structure" V1.0 with
serial number FOS-ENG-022-A for model WH2300, and "TP2700 PC Protocol".

Expand Down Expand Up @@ -219,14 +219,20 @@
from weewx.wxformulas import calculate_rain

DRIVER_NAME = 'WH23xx'
DRIVER_VERSION = '0.6'
DRIVER_VERSION = '0.7'

CORE_PARAMETERS = ['eeprom', 'id', 'interval', 'latitude', 'longitude',
'mode', 'model', 'timezone', 'version']


def loader(config_dict, _):
return WH23xxDriver(**config_dict[DRIVER_NAME])

def confeditor_loader():
return WH23xxConfigurationEditor()

def configurator_loader(config_dict):
return WH23xxConfigurator()

def logmsg(level, msg):
syslog.syslog(level, 'wh23xx: %s' % msg)
Expand All @@ -240,6 +246,11 @@ def loginf(msg):
def logerr(msg):
logmsg(syslog.LOG_ERR, msg)

def print_info(x, display_keys=None):
keys = x.keys() if not display_keys else list(set(x.keys()) & set(display_keys))
keys.sort()
for k in keys:
print "%s: %s" % (k, x[k])

#' '.join(["%0.2X" % ord(c) for c in buf]))
def _fmt(buf):
Expand Down Expand Up @@ -290,6 +301,67 @@ def default_stanza(self):
driver = user.wh23xx
"""

class WH23xxConfigurator(weewx.drivers.AbstractConfigurator):
def add_options(self, parser):
super(WH23xxConfigurator, self).add_options(parser)
parser.add_option('--version', dest='version', action='store_true',
help='display driver version')
parser.add_option('--info', dest='info', action='store_true',
help='show basic info')
parser.add_option('--info-all', dest='info_all', action='store_true',
help='show all info')
parser.add_option('--current', dest='current', action='store_true',
help='show current data')
parser.add_option('--sync-time', dest='sync_time', action='store_true',
help="sync station's clock with PC's clock")
parser.add_option('--eeprom-time', dest='eeprom_time', action='store_true',
help='show date of the first record in eeprom')
parser.add_option('--eeprom-dump-raw', dest='dump', action='store_true',
help='dump raw data from eeprom')
parser.add_option('--clear-history', dest='clear_history', action='store_true',
help='delete all historical data in eeprom')

def do_options(self, options, parser, config_dict, prompt):
self.driver = WH23xxDriver(**config_dict[DRIVER_NAME])
with WH23xxStation() as s:
if options.debug:
syslog.setlogmask(syslog.LOG_UPTO(syslog.LOG_DEBUG))
elif options.version:
print "driver version %s" % DRIVER_VERSION
elif options.info:
print_info(s.get_station_info(), CORE_PARAMETERS)
elif options.info_all:
print_info(s.get_station_info())
elif options.current:
raw = s.get_current()
if options.debug:
print _fmt(raw)
print WH23xxStation.decode_weather_data(raw)
elif options.sync_time:
s.sync_time()
elif options.clear_history:
s.clear_history()
elif options.eeprom_time:
raw = s._read_eeprom(0x02c8, 8)
print _fmt(raw[0:8])
print "%04d.%02d.%02d %02d:%02d %ss" % (
2000 + raw[0], raw[1], raw[2], raw[3], raw[4],
raw[5] + raw[6] * 256)
elif options.dump:
size = 0x20
for i in range(0x0000, 0xffff, size):
for n in range(0, 3):
try:
raw = s._read_eeprom(i, 0x20)
print "%04x" % i, _fmt(raw[:size])
break
except Exception, e:
print "failed read %d of 3 for 0x%04x: %s" % (n+1, i, e)
print "waiting 3 seconds before retry"
time.sleep(3)
else:
raise Exception("retries failed")


class WH23xxDriver(weewx.drivers.AbstractDevice):
def __init__(self, **stn_dict):
Expand Down Expand Up @@ -836,14 +908,6 @@ def decode_station_info(raw):
"",
"",
]
CORE_PARAMETERS = ['eeprom', 'id', 'interval', 'latitude', 'longitude',
'mode', 'model', 'timezone', 'version']

def print_info(x, display_keys=None):
keys = x.keys() if not display_keys else list(set(x.keys()) & set(display_keys))
keys.sort()
for k in keys:
print "%s: %s" % (k, x[k])

import optparse

Expand Down Expand Up @@ -924,3 +988,4 @@ def print_info(x, display_keys=None):
time.sleep(3)
else:
raise Exception("retries failed")