]> Pileus Git - ~andy/csm213a-hw/blobdiff - vis/device.py
Start work on interfaces
[~andy/csm213a-hw] / vis / device.py
index 852b87391e6ca9f975a8ee1032162009bd980687..cf2d16d409c983de12b79e388fdac5ca1e17ddb2 100644 (file)
@@ -79,6 +79,12 @@ class Frame:
                    TYP_U8:  'B', TYP_U16: 'H', TYP_U32: 'I',
                    TYP_F32: 'f', TYP_F64: 'd'}
 
+       sampleNum= {SNS_ACC:   0,
+                   SNS_MAG:   0,
+                   SNS_LGT:   0,
+                   SNS_TCH:   0,
+                   SNS_A2D:   0}
+
        # Parser data
        index    = 0   # read index
        count    = 0   # number of items in frame
@@ -153,8 +159,14 @@ class Frame:
                fmt = Frame.fmtMap[self.bits_typ] * self.count
                sns = Frame.snsMap[self.bits_sns]
                self.values = unpack('<'+fmt, self.binary)
-               print('convert: %3s = \'%3s\'%%[%s] -> [%s]' %
-                       (sns, fmt, hexDump(self.binary), fltDump(self.values)))
+
+               # Print debug output
+               self.sampleNum[self.bits_sns] += 1
+               #if self.sampleNum[self.bits_sns] == 1000:
+               if self.sampleNum[self.bits_sns] == 1000:
+                       print('convert: %3s = \'%3s\'%%[%s] -> [%s]' %
+                               (sns, fmt, hexDump(self.binary), fltDump(self.values)))
+                       self.sampleNum[self.bits_sns] = 0
 
                # Create state
                state = State()
@@ -215,32 +227,15 @@ class Device:
                self._write_binary('B', bits)
 
        def process(self):
-               items = []
-               count = 0
-               limit = 1000
-
                if not self.running():
-                       return items
-
-               while self.serial.readable():
-                       try:
-                               byte  = self.serial.read()
-                       except Exception as ex:
-                               # Not sure why this is excepting
-                               # if it says it's readable
-                               break
-                       if len(byte) == 0:
-                               break
+                       return []
 
+               items = []
+               while self.serial.inWaiting():
+                       byte  = self.serial.read()
                        state = self.frame.parse(byte)
                        if state:
                                items.append(state)
-                       if count > limit:
-                               print('[ERROR] Exceeded Read Limit')
-                               break
-
-                       count += 1
-
                return items