<commit_before>/****************************************************************************
CAN Read Demo for the SparkFun CAN Bus Shield. 

Written by <NAME>. 
Original tutorial available here: http://www.instructables.com/id/CAN-Bus-Sniffing-and-Broadcasting-with-Arduino
Used with permission 2016. License CC By SA. 

Distributed as-is; no warranty is given.
*************************************************************************/

#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>

//********************************Setup Loop*********************************//

void setup() {
  Serial.begin(9600); // For debug use
  Serial.println("CAN Read - Testing receival of CAN Bus message");  
  delay(1000);
  
  if(Canbus.init(9))  //Initialise MCP2515 CAN controller at the specified speed
    Serial.println("CAN Init ok");
  else
    Serial.println("Can't init CAN");
    
  delay(1000);
}

//********************************Main Loop*********************************//

void loop(){

  tCAN message;
if (mcp2515_check_message()) 
  {
    if (mcp2515_get_message(&message)) 
  {
        //if(message.id == 0x620 and message.data[2] == 0xFF)  //uncomment when you want to filter
             //{
               
               Serial.print("ID: ");
               Serial.print(message.id,HEX);
               Serial.print(", ");
               Serial.print("Data: ");
               Serial.print(message.header.length,DEC);
               for(int i=0;i<message.header.length;i++) 
                { 
                  Serial.print(message.data[i],HEX);
                  Serial.print(" ");
                }
               Serial.println("");
             //}
           }}

}<commit_msg>Add filtering by message ID<commit_after>/****************************************************************************
CAN Read Demo for the SparkFun CAN Bus Shield. 

Written by <NAME>. 
Original tutorial available here: http://www.instructables.com/id/CAN-Bus-Sniffing-and-Broadcasting-with-Arduino
Used with permission 2016. License CC By SA. 

Distributed as-is; no warranty is given.
*************************************************************************/

#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>

byte incomingByte;
char message[255] = {};
int index = 0;
int messageId;

//********************************Setup Loop*********************************//

void setup() {
  Serial.begin(9600); // For debug use
  Serial.println("CAN Read - Testing receival of CAN Bus message");  
  delay(1000);
  
  if(Canbus.init(9))  //Initialise MCP2515 CAN controller at the specified speed
    Serial.println("CAN Init ok");
  else
    Serial.println("Can't init CAN");
    
  delay(1000);
}

//********************************Main Loop*********************************//

void loop(){
//  printBuffer();
  initFilter();
  tCAN message;
if (mcp2515_check_message()) 
  {
    if (mcp2515_get_message(&message)) 
    {
        if(message.id == messageId || messageId == NULL)
        {
               
               Serial.print("ID: ");
               Serial.print(message.id,HEX);
               Serial.print(", ");
               Serial.print("Data [");
               Serial.print(message.header.length,DEC);
               Serial.print(" bytes]: ");
               for(int i=0;i<message.header.length;i++) 
                { 
                  Serial.print(message.data[i],HEX);
                  Serial.print(" ");
                }
               Serial.println("");
        }
     }
  }
}

void initFilter() {
if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if ((int)incomingByte == 10) {
        // ignore space
    } else if ((char)incomingByte == '!') {
        memset(message, 0, sizeof(message));
        index = 0;
        messageId = NULL;
        Serial.println("=============================");
        Serial.println("=== Filter disabled =========");
        Serial.println("=============================");
    } else if ((char)incomingByte == '*') {
        message[index] = '\0';
        sscanf(message, "%x", &messageId);

        memset(message, 0, sizeof(message));
        index = 0;
        Serial.println("=== Filter enabled ==============");
        Serial.print("=== Filter on message ID: ");
        Serial.print(messageId, HEX);
        Serial.println(" ===");
        Serial.println("===============================");
    } else {
        message[index] = (char)incomingByte;
        index++;
    }    
  }  
}

void printBuffer() {
  int i;
  for(i = 0; i < sizeof(message); i++) {
    Serial.print(message[i]);
    }
    Serial.println();
}
{'fraction_non_alphanumeric': 0.2709704820556381, 'fraction_numerical': 0.02017413463580378, 'mean_word_length': 2.634259259259259, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7646971', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1276, 'n_words': 291}