Skip to content

Commit

Permalink
Reimplemented VantagePro logic and added test cases
Browse files Browse the repository at this point in the history
* Complete re-write from last version
* Simplified serial data buffer parsing
* Added CRC checking of serial data
* Added DMPAFT command
* Added logging hooks
  • Loading branch information
cmcginty committed Jun 25, 2010
1 parent 9d3f680 commit 9d64da4
Show file tree
Hide file tree
Showing 5 changed files with 648 additions and 140 deletions.
7 changes: 3 additions & 4 deletions weather/services/wunderground.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from __future__ import absolute_import

__doc__ = '''
'''
WUnderground.com Publisher
Abstract:
Expand Down Expand Up @@ -42,6 +39,8 @@
Date: 2006-03-27
'''

from __future__ import absolute_import

import logging
log = logging.getLogger(__name__)

Expand Down
56 changes: 56 additions & 0 deletions weather/stations/_struct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'''
Binary Data Interfaces
Abstract:
Helper classes for working with binary data structures. This simplifies data
field extraction from a binary buffer.
Author: Patrick C. McGinty (pyweather@tuxcoder.com)
Date: 2010-06-025
'''

from __future__ import absolute_import

import struct


class Struct( struct.Struct ):
'''
Implements a reusable class for working with a binary data structure. It
provides a named fields interface, similiar to C structures.
Usage: 1) subclass and extend _post_unpack method
2) instantiate directly, if no 'post unpack' processing needed
Arguments:
See `struct.Struct` class defintion.
'''
def __init__(self, fmt, order='@'):
self.fields, fmt_t = zip(*fmt)
super(Struct,self).__init__( order + ''.join(fmt_t) )


def unpack(self, buf):
'''
see unpack_from()
'''
return self.unpack_from( buf, offset=0 )


def unpack_from(self, buf, offset=0 ):
'''
unpacks data from 'buf' and returns a dication of named fields. the
fields can be post-processed by extending the _post_unpack() method.
'''
data = super(Struct,self).unpack_from( buf, offset)
items = dict(zip(self.fields,data))
return self._post_unpack(items)


def _post_unpack(self,items):
'''
perform data modification of any values, after unpacking from a buffer.
'''
return items

# vim: sts=4:ts=4:sw=4
Loading

0 comments on commit 9d64da4

Please sign in to comment.