Beispiel #1
0
    def _j1939xmit_tp(self, pf, ps, sa, message, prio=6, edp=0, dp=0):
        pgn2 = (edp << 1) | dp
        pgn1 = pf
        if pgn1 < 240:
            pgn0 = 0
        else:
            pgn0 = ps

        msgs = [
            b'%c' % (x + 1) + message[x * 7:(x * 7) + 7]
            for x in range((len(message) + 6) // 7)
        ]
        if len(msgs) > 255:
            raise Exception(
                "J1939xmit_tp: attempt to send message that's too large")

        cm_msg = struct.pack('<BHBBBBB', CM_RTS, len(message), len(msgs), 0xff,
                             pgn2, pgn1, pgn0)

        arbid = emitArbid(prio, edp, dp, PF_TP_CM, ps, sa)
        # print("TXe: %x : %s" % (arbid, hexlify(cm_msg).decode()))
        self.CANxmit(arbid, cm_msg, extflag=1)
        time.sleep(.01)  # hack: should watch for CM_CTS
        for msg in msgs:
            #self.J1939xmit(PF_TP_DT, ps, sa, msg, prio=prio)
            arbid = emitArbid(prio, edp, dp, PF_TP_DT, ps, sa)
            print("TXe: %x : %s" % (arbid, hexlify(msg).decode()))
            self.CANxmit(arbid, msg, extflag=1)
Beispiel #2
0
    def J1939xmit(self, pf, ps, sa, data, prio=6, edp=0, dp=0):
        if len(data) <= 8:
            arbid = emitArbid(prio, edp, dp, pf, ps, sa)
            # print("TX: %x : %s" % (arbid, hexlify(data).decode()))
            self.CANxmit(arbid, data, extflag=1)
            return

        self._j1939xmit_tp(pf, ps, sa, data, prio, edp, dp)
Beispiel #3
0
 def _reprArbid(self, arbtup):
     #return "pri/edp/dp: %d/%d/%d, PG: %.2x %.2x  sa: %.2x" % arbid
     arbid = emitArbid(*arbtup)
     if arbid <= 0x7FF:
         return " %8x                 " % arbid
     else:
         prio, edp, dp, pf, ps, sa = arbtup
         return " %08x   (%d/%d/%d   %.2x%.2x %.2x)" % (arbid, prio, edp,
                                                        dp, pf, ps, sa)