+
+
+ def addFilter(self,standardid, verbose= True):
+ """ This method will configure filters on the board. Filters are positive filters meaning that they will only
+ store messages that match the ids provided in the list of standardid. Since there are 2 buffers and due to the configuration
+ of how the filtering works (see MCP2515 documentation), at least 3 filters must be set to guarentee you do not get any
+ unwanted messages. However even with only 1 filter set you should get all messages from that ID but the other buffer will store
+ any additional messages.
+ @type standardid: list of integers
+ @param standardid: List of standard ids that need to be set. There can be at most 6 filters set.
+ @type verbose: Boolean
+ @param verbose: If true it will print out messages and diagnostics to terminal.
+
+ @rtype: None
+ @return: This method does not return anything
+ @todo: rename setFilters
+ """
+
+ ### ON-CHIP FILTERING
+ if(standardid != None):
+ self.client.MCPreqstatConfiguration();
+ self.client.poke8(0x60,0x26); # set RXB0 CTRL register to ONLY accept STANDARD messages with filter match (RXM1=0, RMX0=1, BUKT=1)
+ self.client.poke8(0x20,0xFF); #set buffer 0 mask 1 (SID 10:3) to FF
+ self.client.poke8(0x21,0xE0); #set buffer 0 mask 2 bits 7:5 (SID 2:0) to 1s
+ if(len(standardid)>2):
+ self.client.poke8(0x70,0x20); # set RXB1 CTRL register to ONLY accept STANDARD messages with filter match (RXM1=0, RMX0=1)
+ self.client.poke8(0x24,0xFF); #set buffer 1 mask 1 (SID 10:3) to FF
+ self.client.poke8(0x25,0xE0); #set buffer 1 mask 2 bits 7:5 (SID 2:0) to 1s
+
+ for filter,ID in enumerate(standardid):
+
+ if (filter==0):
+ RXFSIDH = 0x00;
+ RXFSIDL = 0x01;
+ elif (filter==1):
+ RXFSIDH = 0x04;
+ RXFSIDL = 0x05;
+ elif (filter==2):
+ RXFSIDH = 0x08;
+ RXFSIDL = 0x09;
+ elif (filter==3):
+ RXFSIDH = 0x10;
+ RXFSIDL = 0x11;
+ elif (filter==4):
+ RXFSIDH = 0x14;
+ RXFSIDL = 0x15;
+ else:
+ RXFSIDH = 0x18;
+ RXFSIDL = 0x19;
+
+ #### split SID into different regs
+ SIDlow = (ID & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
+ SIDhigh = (ID >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
+
+ #write SID to regs
+ self.client.poke8(RXFSIDH,SIDhigh);
+ self.client.poke8(RXFSIDL, SIDlow);
+
+ if (verbose == True):
+ print "Filtering for SID %d (0x%02xh) with filter #%d"%(ID, ID, filter);
+
+ self.client.MCPreqstatNormal();
+
+ def filterForPacket(self, standardid, DB0, DB1, verbose= True):
+ """
+ This method will configure filters on the board to listen for a specific packet originating
+ from standardid with data bytes 0 and 1. It will configure all six filters, so you will not receive any other packets.
+
+ @type standardid: integer
+ @param standardid: standardID to listen for
+ @type DB0: integer
+ @param standardid: DB0 contents to filter for
+ @type DB1: integer
+ @param standardid: DB1 contents to filter for
+ @type verbose: Boolean
+ @param verbose: If true it will print out messages and diagnostics to terminal.
+
+ @rtype: None
+ @return: This method does not return anything
+ """
+
+ ### ON-CHIP FILTERING
+
+ self.client.MCPreqstatConfiguration();
+
+ # SID filtering: set CTRL registers to only accept standard messages
+ self.client.poke8(0x60,0x06); # set RXB0 CTRL register to ONLY accept STANDARD messages with filter match (RXM1=0, RXM=1, BUKT=1)
+ self.client.poke8(0x70,0x00); # set RXB1 CTRL register to ONLY accept STANDARD messages with filter match (RXM1=0, RXM0=1)
+
+ # Mask buffer 0 to match SID, DB0, DB1
+ self.client.poke8(0x20,0xFF); #set buffer 0 mask 1 (SID 10:3) to FF
+ self.client.poke8(0x21,0xE0); #set buffer 0 mask 2 bits 7:5 (SID 2:0) to 1s
+ self.client.poke8(0x22,0xFF); #set buffer 0 mask 3 (DB0) to FF
+ self.client.poke8(0x23,0xFF); #set buffer 0 mask 4 (DB0) to FF
+
+ # Mask buffer 1 to match SID, DB0, DB1
+ self.client.poke8(0x24,0xFF); #set buffer 1 mask 1 (SID 10:3) to FF
+ self.client.poke8(0x25,0xE0); #set buffer 1 mask 2 bits 7:5 (SID 2:0) to 1s
+ self.client.poke8(0x26,0xFF); #set buffer 1 mask 3 (DB0) to FF
+ self.client.poke8(0x27,0xFF); #set buffer 1 mask 4 (DB1) to FF
+
+ # Split SID into high and low bytes
+ SIDlow = (standardid & 0x07) << 5; # get SID bits 2:0, rotate them to bits 7:5
+ SIDhigh = (standardid >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
+
+
+ for filter in range(0,5):
+ if (filter==0):
+ RXFSIDH = 0x00;
+ RXFSIDL = 0x01;
+ RXFDB0 = 0x02;
+ RXFDB1 = 0x03;
+ elif (filter==1):
+ RXFSIDH = 0x04;
+ RXFSIDL = 0x05;
+ RXFDB0 = 0x06;
+ RXFDB1 = 0x07;
+ elif (filter==2):
+ RXFSIDH = 0x08;
+ RXFSIDL = 0x09;
+ RXFDB0 = 0x0A;
+ RXFDB1 = 0x0B;
+ elif (filter==3):
+ RXFSIDH = 0x10;
+ RXFSIDL = 0x11;
+ RXFDB0 = 0x12;
+ RXFDB1 = 0x13;
+ elif (filter==4):
+ RXFSIDH = 0x14;
+ RXFSIDL = 0x15;
+ RXFDB0 = 0x16;
+ RXFDB1 = 0x17;
+ else:
+ RXFSIDH = 0x18;
+ RXFSIDL = 0x19;
+ RXFDB0 = 0x1A;
+ RXFDB1 = 0x1B;
+
+ self.client.poke8(RXFSIDH, SIDhigh);
+ self.client.poke8(RXFSIDL, SIDlow);
+ self.client.poke8(RXFDB0, DB0);
+ self.client.poke8(RXFDB1, DB1);
+
+ if (verbose == True):
+ print "Filtering for SID %d DB0 %d DB1 %d with filter #%d"%(standardid, DB0, DB1, filter);
+
+ self.client.MCPreqstatNormal();
+
+ def multiPacketTest(self):
+
+ self.reset();
+ self.client.MCPsetrate(500);
+ self.client.MCPreqstatNormal();
+
+ packet0 = [0x00, 0x00, 0x00,0x00, # pad out EID regs
+ 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
+ # lower nibble is DLC
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
+
+ packet1 = [0x00, 0x20, 0x00,0x00, # pad out EID regs
+ 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
+ # lower nibble is DLC
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
+ packet2 = [0x00, 0x40, 0x00,0x00, # pad out EID regs
+ 0x08, # bit 6 must be set to 0 for data frame (1 for RTR)
+ # lower nibble is DLC
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
+
+ comm.multiPacketSpit(packet0=packet0, packet1=packet1, packet2=packet2)
+
+ comm.multiPacketSpit(packet0rts=True, packet1rts=True, packet2rts=True)
+ comm.multiPacketSpit(packet2rts=True)
+ comm.multiPacketSpit(packet1rts=True)
+ comm.multiPacketSpit(packet0rts=True)
+
+
+
+ def multiPacketSpit(self, packet0 = None, packet1 = None, packet2 = None, packet0rts = False, packet1rts = False, packet2rts = False):
+ """
+ This method writes packets to the chip's TX buffers and/or sends the contents of the buffers onto the bus.
+
+ @type packet0: list of integer
+ @param packet0: A list of 13 integers of the format [SIDhigh SIDlow 0 0 DLC DB0-7] to be loaded into TXBF0
+
+ @type packet1: list of integer
+ @param packet1: A list of 13 integers of the format [SIDhigh SIDlow 0 0 DLC DB0-7] to be loaded into TXBF1
+
+ @type packet2: list of integer
+ @param packet2: A list of 13 integers of the format [SIDhigh SIDlow 0 0 DLC DB0-7] to be loaded into TXBF2
+
+ @type packet0rts: Boolean
+ @param packet0rts: If true the message in TX buffer 0 will be sent
+
+ @type packet2rts: Boolean
+ @param packet0rts: If true the message in TX buffer 1 will be sent
+
+ @type packet2rts: Boolean
+ @param packet0rts: If true the message in TX buffer 2 will be sent
+
+ """
+
+ if(packet0 != None):
+ self.client.writetxbuffer(packet0,0)
+ # print("trying to write TX buffer 0");
+ # for db in packet0:
+ # print" %d" %db
+ if (packet1 != None):
+ self.client.writetxbuffer(packet1,1)
+ # print("trying to write TX buffer 1");
+ # for db in packet0:
+ # print" %d" %db
+ if (packet2 != None):
+ self.client.writetxbuffer(packet2,2)
+ # print("trying to write TX buffer 2");
+ # for db in packet0:
+ # print" %d" %db
+
+ # if(packet0rts):
+ # print("trying to send TX buffer 0")
+ #if(packet1rts):
+ # print("trying to send TX buffer 1")
+ #if(packet2rts):
+ # print("trying to send TX buffer 2")
+
+ self.client.MCPrts(TXB0=packet0rts, TXB1=packet1rts, TXB2=packet2rts)
+