Example #1
0
    def connect(self):
        """ Issue connect command and set up a reader"""
        if self.connected:
            return
        if not self.dump:
            self.port.write(CONNECT)

        raw = self.port.read(0x20)
        if len(raw) == 0:
            _log.fatal("Did you plug your watches? Check the clip!")
            raise NotConnected()
        else:
            self.connected = True

        if self._debug:
            self.backup = open(os.path.join(tempfile.gettempdir(), "schwinn810.bin"), mode="wb")
            self.backup.write(raw)

        (ee, e1, e2, e3, bcd1, bcd2, bcd3, serial, v1, v2, sign1) = struct.unpack("sBBBBBB6s6s7s2xI", raw)
        if sign1:  # 0x0130ff00
            raw = self.port.read(4)
            if self._debug:
                self.backup.write(raw)
            (sign2,) = struct.unpack("I", raw)
            if sign1 != sign2:
                print("0x{:X} != 0x{:X}".format(sign1, sign2))
                # port.close()
                # print("We are reading something wrong. Are you trying to communicate with another device?", file=sys.stderr)
                # exit(-1)
            self.reader = SchwinnReader(self.port, self.backup)
        else:  # Cresta/Mio
            self.reader = CrestaReader(self.port, self.backup)
            _log.warn("File a bug if you are not using Cresta or Mio watch!")
        id = "{0:s} {1:s} {2:s} {3:02d} {4:02d} {5:02d} {6:02d} {7:02d} {8:02d}".format(
            serial.decode("ascii"),
            v1.decode("ascii"),
            ee.decode("ascii"),
            e1,
            e2,
            e3,
            unpack_bcd(bcd1),
            unpack_bcd(bcd2),
            unpack_bcd(bcd3),
        )
        _log.info("Found %s" % id)
Example #2
0
    def connect(self):
        """ Issue connect command and set up a reader"""
        if self.connected:
            return
        if not self.dump:
            self.port.write(CONNECT)

        raw = self.port.read(0x20)
        if len(raw)==0:
            _log.fatal("Did you plug your watches? Check the clip!")
            raise NotConnected()
        else:
            self.connected = True

        if self._debug:
            self.backup = open(os.path.join(tempfile.gettempdir(), "schwinn810.bin"), mode="wb")
            self.backup.write(raw)

        (ee, e1, e2, e3, bcd1, bcd2, bcd3, serial, v1, v2, sign1) = struct.unpack("sBBBBBB6s6s7s2xI", raw)
        if sign1:               # 0x0130ff00
            raw = self.port.read(4)
            if self._debug:
                self.backup.write(raw)
            (sign2,) = struct.unpack("I", raw)
            if sign1 != sign2:
                print("0x{:X} != 0x{:X}".format(sign1, sign2))
                # port.close()
                # print("We are reading something wrong. Are you trying to communicate with another device?", file=sys.stderr)
                # exit(-1)
            self.reader = SchwinnReader(self.port, self.backup)
        else:   # Cresta/Mio
            self.reader = CrestaReader(self.port, self.backup)
            _log.warn("File a bug if you are not using Cresta or Mio watch!")
        id = "{0:s} {1:s} {2:s} {3:02d} {4:02d} {5:02d} {6:02d} {7:02d} {8:02d}" \
            .format(serial.decode('ascii'), v1.decode('ascii'), ee.decode('ascii'), \
                        e1, e2, e3, unpack_bcd(bcd1), unpack_bcd(bcd2), unpack_bcd(bcd3))
        _log.info("Found %s" % id)
Example #3
0
    def connect(self):
        """ Issue connect command and set up a reader"""
        if self.connected:
            return
        if not self.dump:
            self.port.write(SOLEUS_DISCONNECT)
            self.port.write(CONNECT)

        raw = self.port.read(0x20)
        if len(raw) == 0:
            _log.fatal("Did you plug your watches? Check the clip!")
            raise NotConnected()
        else:
            self.connected = True

        if self._debug:
            self.backup = open(os.path.join(tempfile.gettempdir(),
                                            "schwinn810.bin"),
                               mode="wb")
            self.backup.write(raw)

        (ee, e1, e2, e3, bcd1, bcd2, bcd3, serial, v1, v2,
         sign1) = struct.unpack("sBBBBBB6s6s7s2xI", raw)
        _log.debug("read header")
        _log.debug(
            "{:s} 0x{:x} 0x{:x} 0x{:x} 0x{:x} 0x{:x} 0x{:x} {:s} {:s} {:s} 0x{:x}"
            .format(ee, e1, e2, e3, bcd1, bcd2, bcd3, serial, v1, v2, sign1))

        if sign1:  # 0x0130ff00
            raw = self.port.read(4)
            if self._debug:
                self.backup.write(raw)
            (sign2, ) = struct.unpack("I", raw)
            if sign1 != sign2:
                print("0x{:X} != 0x{:X}".format(sign1, sign2))
                # port.close()
                # print("We are reading something wrong. Are you trying to communicate with another device?", file=sys.stderr)
                # exit(-1)
            if sign1 == 0x243601:  #kb: think maybe we need something else to identify soleus.  This might be specific to my watch.  Perhaps the M11165 string?
                self.detected_watch_type = 'soleus'
            else:
                self.detected_watch_type = 'schwinn'

        else:  # Cresta/Mio
            self.detected_watch_type = 'cresta'

        if self.watch_type:
            if self.watch_type != self.detected_watch_type:
                _log.warn("Detected watch type " + self.detected_watch_type +
                          " but using watch type " + self.watch_type)
                print("Detected watch type " + self.detected_watch_type +
                      " but using watch type " + self.watch_type)
        else:
            self.watch_type = self.detected_watch_type

        if self.watch_type == 'soleus':
            self.reader = SoleusReader(self.port, self.backup)
        elif self.watch_type == 'schwinn':
            self.reader = SchwinnReader(self.port, self.backup)
        elif self.watch_type == 'cresta':
            self.reader = CrestaReader(self.port, self.backup)
            _log.warn("File a bug if you are not using Cresta or Mio watch!")
            id = "{0:s} {1:s} {2:s} {3:02d} {4:02d} {5:02d} {6:02d} {7:02d} {8:02d}" \
            .format(serial.decode('ascii'), v1.decode('ascii'), ee.decode('ascii'), \
                        e1, e2, e3, unpack_bcd(bcd1), unpack_bcd(bcd2), unpack_bcd(bcd3))
            _log.info("Found %s" % id)
        else:
            raise UnknownWatchType("don't know what to do for watch type " +
                                   self.watch_type)
Example #4
0
    def connect(self):
        """ Issue connect command and set up a reader"""
        if self.connected:
            return
        if not self.dump:
            self.port.write(SOLEUS_DISCONNECT)
            self.port.write(CONNECT)

        raw = self.port.read(0x20)
        if len(raw)==0:
            _log.fatal("Did you plug your watches? Check the clip!")
            raise NotConnected()
        else:
            self.connected = True

        if self._debug:
            self.backup = open(os.path.join(tempfile.gettempdir(), "schwinn810.bin"), mode="wb")
            self.backup.write(raw)

        (ee, e1, e2, e3, bcd1, bcd2, bcd3, serial, v1, v2, sign1) = struct.unpack("sBBBBBB6s6s7s2xI", raw)
        _log.debug("read header")
        _log.debug("{:s} 0x{:x} 0x{:x} 0x{:x} 0x{:x} 0x{:x} 0x{:x} {:s} {:s} {:s} 0x{:x}".format(ee, e1, e2, e3, bcd1, bcd2, bcd3, serial, v1, v2, sign1))

        if sign1:               # 0x0130ff00
            raw = self.port.read(4)
            if self._debug:
                self.backup.write(raw)
            (sign2,) = struct.unpack("I", raw)
            if sign1 != sign2:
                print("0x{:X} != 0x{:X}".format(sign1, sign2))
                # port.close()
                # print("We are reading something wrong. Are you trying to communicate with another device?", file=sys.stderr)
                # exit(-1)
            if sign1 == 0x243601:  #kb: think maybe we need something else to identify soleus.  This might be specific to my watch.  Perhaps the M11165 string?
              self.detected_watch_type = 'soleus'
            else:
              self.detected_watch_type = 'schwinn'
            
        else:   # Cresta/Mio
          self.detected_watch_type = 'cresta'


        if self.watch_type:
          if self.watch_type != self.detected_watch_type:
            _log.warn("Detected watch type " + self.detected_watch_type + " but using watch type " + self.watch_type)
            print("Detected watch type " + self.detected_watch_type + " but using watch type " + self.watch_type)
        else:
          self.watch_type = self.detected_watch_type

        if self.watch_type == 'soleus':
          self.reader = SoleusReader(self.port, self.backup)
        elif self.watch_type == 'schwinn':
          self.reader = SchwinnReader(self.port, self.backup)
        elif self.watch_type == 'cresta':
          self.reader = CrestaReader(self.port, self.backup)
          _log.warn("File a bug if you are not using Cresta or Mio watch!")
          id = "{0:s} {1:s} {2:s} {3:02d} {4:02d} {5:02d} {6:02d} {7:02d} {8:02d}" \
          .format(serial.decode('ascii'), v1.decode('ascii'), ee.decode('ascii'), \
                      e1, e2, e3, unpack_bcd(bcd1), unpack_bcd(bcd2), unpack_bcd(bcd3))
          _log.info("Found %s" % id)
        else:
          raise UnknownWatchType("don't know what to do for watch type " + self.watch_type)