From 04ab4b77c00959f43950af053a845761c8554d61 Mon Sep 17 00:00:00 2001 From: Scott Petersen Date: Wed, 15 May 2013 10:25:17 -0700 Subject: [PATCH] Initial message format. --- pyad2usb/ad2usb.py | 168 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 7 deletions(-) diff --git a/pyad2usb/ad2usb.py b/pyad2usb/ad2usb.py index 743e2fe..15b0bb8 100644 --- a/pyad2usb/ad2usb.py +++ b/pyad2usb/ad2usb.py @@ -103,6 +103,8 @@ class AD2USB(object): on_read = event.Event('Called when a line has been read from the device') on_write = event.Event('Called when data has been written to the device') + on_message = event.Event('Called when a message has been received from the device.') + def __init__(self, device): self._device = device @@ -123,22 +125,174 @@ class AD2USB(object): self._device.on_read += self._on_read self._device.on_write += self._on_write - def _on_open(self, sender, args): - print '_on_open: {0}'.format(args) + def _handle_message(self, data): + if data[0] == '!': + return None + + msg = Message() + msg.ignore_packet = True + + print msg.ignore_packet + def _on_open(self, sender, args): self.on_open(args) def _on_close(self, sender, args): - print '_on_close: {0}'.format(args) - self.on_close(args) def _on_read(self, sender, args): - print '_on_read: {0}'.format(args) + msg = self._handle_message(args) + if msg: + self.on_message(msg) self.on_read(args) def _on_write(self, sender, args): - print '_on_write: {0}'.format(args) - self.on_write(args) + +class Message(object): + def __init__(self): + self._ignore_packet = False + self._ready = False + self._armed_away = False + self._armed_home = False + self._backlight = False + self._programming_mode = False + self._beeps = -1 + self._bypass = False + self._ac = False + self._chime_mode = False + self._alarm_event_occurred = False + self._alarm_bell = False + self._numeric = "" + self._text = "" + self._cursor = -1 + self._raw_text = "" + + @property + def ignore_packet(self): + return self._ignore_packet + + @ignore_packet.setter + def ignore_packet(self, value): + self._ignore_packet = value + + @property + def ready(self): + return self._ready + + @ready.setter + def ready(self, value): + self._ready = value + + @property + def armed_away(self): + return self._armed_away + + @armed_away.setter + def armed_away(self, value): + self._armed_away = value + + @property + def armed_home(self): + return self._armed_home + + @armed_home.setter + def armed_home(self, value): + self._armed_home = value + + @property + def backlight(self): + return self._backlight + + @backlight.setter + def backlight(self, value): + self._backlight = value + + @property + def programming_mode(self): + return self._programming_mode + + @programming_mode.setter + def programming_mode(self, value): + self._programming_mode = value + + @property + def beeps(self): + return self._beeps + + @beeps.setter + def beeps(self, value): + self._beeps = value + + @property + def bypass(self): + return self._bypass + + @bypass.setter + def bypass(self, value): + self._bypass = value + + @property + def ac(self): + return self._ac + + @ac.setter + def ac(self, value): + self._ac = value + + @property + def chime_mode(self): + return self._chime_mode + + @chime_mode.setter + def chime_mode(self, value): + self._chime_mode = value + + @property + def alarm_event_occurred(self): + return self._alarm_event_occurred + + @alarm_event_occurred.setter + def alarm_event_occurred(self, value): + self._alarm_event_occurred = value + + @property + def alarm_bell(self): + return self._alarm_bell + + @alarm_bell.setter + def alarm_bell(self, value): + self._alarm_bell = value + + @property + def numeric(self): + return self._numeric + + @numeric.setter + def numeric(self, value): + self._numeric = value + + @property + def text(self): + return self._text + + @text.setter + def text(self, value): + self._text = value + + @property + def cursor(self): + return self._cursor + + @cursor.setter + def cursor(self, value): + self._cursor = value + + @property + def raw_text(self): + return self._raw_text + + @raw_text.setter + def raw_text(self, value): + self._raw_text = value