Ejemplo n.º 1
0
 def Total_milage_22(self, data):
     if len(data) == 4:
         self.totaltrip = (data[1] + data[2] * 256) / 10.0
         #  self.totaltrip_changed = True
         return "TOTAL TRIP {0}".format(
             self.totaltrip)  # TODO: Create NMEA for this of remove
     return ERR('ST 22 incorrect length: {}'.format(len(data))).msg
Ejemplo n.º 2
0
 def Trip_milage_21(self, data):
     if len(data) == 4:
         self.trip = (data[1] + data[2] * 256 +
                      (data[3] & 0x0F) * 4096) / 100.0
         self.trip_changed = True
         return VLW(self.trip + self.offset).msg
     return ERR('ST 21 incorrect length: {}'.format(len(data))).msg
Ejemplo n.º 3
0
 def Speed_through_water_26(self, data):
     if len(data) == 6:
         self.speedthroughwater = (data[1] + data[2] * 256) / 100
         self.averagespeedthroughwater = (data[3] + data[4] * 256) / 100
         # self.speedthroughwater_changed = True
         # self.averagespeedthroughwater_changed = True
         return VHW(self.speedthroughwater).msg
     return ERR('ST 26 incorrect length: {}'.format(len(data))).msg
Ejemplo n.º 4
0
    def Total_and_trip_25(self, data):
        if len(data) == 6:
            self.totaltrip = (data[1] + data[2] * 256 +
                              (data[0] >> 4) * 4096) / 10
            self.trip = (data[3] + data[4] * 256 +
                         (data[5] & 0x0F) * 4096) / 100
            self.trip_changed = True
            # self.totaltrip_changed = True
            return VLW(self.trip + self.offset).msg
# TODO:            self.output += "TOTAL TRIP {0}".format(self.totaltrip) # TODO: Create NMEA for this of remove
        return ERR('ST 25 incorrect length: {}'.format(len(data))).msg
Ejemplo n.º 5
0
def outputthread(outbuf, test=False):
    if test:
        outputserial = None
    else:
        outputserial = pyb.UART(6, 115200)

    if upower.vbat() < 2.0:
        outbuf.write(ERR('Low Backup Battery').msg)
    while True:
        yield 0.1
        outbuf.print(outputserial)
Ejemplo n.º 6
0
def seatalkthread(out_buff):
    stream = pyb.UART(4, 4800, bits=9)
    yield 0.5
    st = Seatalk(stream)  #, out_buff.log['daily'])
    wf = Poller(st.Poll, (4, ), 5)
    while True:
        reason = (yield wf())
        if reason[1]:
            st.update(out_buff)
            #out_buff.write(st.output)
            #st.output = []
        if reason[2]:
            out_buff.write(ERR('ST DATA TIMEOUT').msg)
Ejemplo n.º 7
0
def cthread(out_buf):
    imu = MPU9250('X', transposition=(0, 1, 2), scaling=(1, -1, 1))
    global i2c_object
    i2c_object = imu._mpu_i2c
    yield 0.03  # Allow accelerometer to settle
    compass = TCCompass(imu, timeout=1000)

    while True:
        yield
        try:
            if compass.process():
                out_buf.write(compass.output)
        except:
            out_buf.write(ERR('Compass Error').msg)
Ejemplo n.º 8
0
    def process(self, data):
        # loop while data available
        x = 0
        while len(data) > x + 1:
            newdata = data[x]
            parity = data[x + 1]
            x += 2

            # if command bit set, set status to command
            if self.paritycheck(parity):
                self.command = newdata
                self.data = []
                self.status = Status.Command

            # if on command status check for length
            elif self.status == Status.Command and self.paritycheck(
                    parity) is False:
                self.data.append(newdata)
                self.length = (newdata & 0x0F) + 1
                self.status = Status.Length

            # if on length status collect data to match length
            elif self.status == Status.Length and self.paritycheck(
                    parity) is False:
                self.data.append(newdata)
                self.length -= 1
                # if length is achieved mark as complete
                if self.length == 0:
                    self.status = Status.Complete

            # if status is complete
            if self.status == Status.Complete:
                out = ''
                try:
                    out = self.Decode[self.command](self.data)
                except:
                    out = ERR("{:2x} SEATALK SENTENCE NOT RECOGNISED".format(
                        self.command)).msg
                finally:
                    self.output.append(out)
                    self.status = Status.Empty
                    return True
        return False
Ejemplo n.º 9
0
 def Speed_through_water_20(self, data):
     if len(data) == 3:
         self.speedthroughwater = (data[1] + data[2] * 256) / 10.0
         # self.speedthroughwater_changed = True
         return VHW(self.speedthroughwater).msg
     return ERR('ST 20 incorrect length: {}'.format(len(data))).msg