<commit_before>#include <RCSwitch.h>

RCSwitch inputLine = RCSwitch();
RCSwitch outputLine = RCSwitch();

#define PROTOCOL_HEADER "CLS" // (C)LUSTER (L)IGHT (S)WITCH
#define PROTOCOL_VERSION '0'

// input messages
#define READ_433  '1' // <2-byte: message_num><2-byte: radio_timeout>
#define WRITE_433 '2' // <2-byte: protocol><2-byte: delay><2-byte: repetitions>
                      // <2-byte: byte-length><#-bytes: message>

// output messages
#define AWAITING_DATA    'B'
#define INCOMING_DATA    'C'
#define RADIO_TIMEOUT    'D'
#define HELLO            'E'
#define GOODBYE          'F'
#define BAD_HEADER       'G'
#define WRONG_VERSION    'H'
#define HEARTBEAT        'I'
#define UNKNOWN_OP_CODE  'Z'

#define RADIO_POLL_RATE  10 // milliseconds

void setup() {
    Serial.begin(9600);
    Serial.setTimeout(1000);
    inputLine.enableReceive(0);
    outputLine.enableTransmit(4);
    outputLine.setRepeatTransmit(1);
}

char readChar(){
    while (!Serial.available());
    return (char) Serial.read();
}

unsigned int readShort(){
    unsigned int val = 0x00;
    byte buffer[2]; 
    Serial.readBytes(buffer, 2);
    val = buffer[1];
    val <<= 8;
    val |= buffer[0];
    return val;
}

unsigned long readMessage(int byteLength){
    byte buffer[byteLength];
    Serial.readBytes(buffer, byteLength);
    unsigned long val = buffer[byteLength - 1];
    for (int i = 1; i < byteLength; i++){
        val <<= 8;
        val &= 0xFFFFFF00;
        val |= buffer[byteLength - 1 - i];
    }
    return val;
}

void writeShort(unsigned int val){
    Serial.write(val & 0xFF);
    val >>= 8;
    Serial.write(val & 0xFF);
}

void loop() { 
    
    if (Serial.available() == 0) {
        return;
    }
    
    // Get the protocol indicator signal
    char receivedHeader[4];
    receivedHeader[3] = '\0';
    Serial.readBytes(receivedHeader, 3);

    if (strcmp(receivedHeader, PROTOCOL_HEADER) != 0){
        Serial.write(BAD_HEADER);
        return;<commit_msg>prevent microcontroller from standing by forever mid-communication (capped at 1 second before reset)<commit_after>#include <RCSwitch.h>

RCSwitch inputLine = RCSwitch();
RCSwitch outputLine = RCSwitch();

#define PROTOCOL_HEADER "CLS" // (C)LUSTER (L)IGHT (S)WITCH
#define PROTOCOL_VERSION '0'

// input messages
#define READ_433  '1' // <2-byte: message_num><2-byte: radio_timeout>
#define WRITE_433 '2' // <2-byte: protocol><2-byte: delay><2-byte: repetitions>
                      // <2-byte: byte-length><#-bytes: message>

// output messages
#define AWAITING_DATA    'B'
#define INCOMING_DATA    'C'
#define RADIO_TIMEOUT    'D'
#define HELLO            'E'
#define GOODBYE          'F'
#define BAD_HEADER       'G'
#define WRONG_VERSION    'H'
#define HEARTBEAT        'I'
#define UNKNOWN_OP_CODE  'Z'

#define RADIO_POLL_RATE  10 // milliseconds

void setup() {
    Serial.begin(9600);
    Serial.setTimeout(1000);
    inputLine.enableReceive(0);
    outputLine.enableTransmit(4);
    outputLine.setRepeatTransmit(1);
}

unsigned int readShort(){
    unsigned int val = 0x00;
    byte buffer[2]; 
    Serial.readBytes(buffer, 2);
    val = buffer[1];
    val <<= 8;
    val |= buffer[0];
    return val;
}

unsigned long readMessage(int byteLength){
    byte buffer[byteLength];
    Serial.readBytes(buffer, byteLength);
    unsigned long val = buffer[byteLength - 1];
    for (int i = 1; i < byteLength; i++){
        val <<= 8;
        val &= 0xFFFFFF00;
        val |= buffer[byteLength - 1 - i];
    }
    return val;
}

char readChar(){
    return (char) readMessage(1);
}

void writeShort(unsigned int val){
    Serial.write(val & 0xFF);
    val >>= 8;
    Serial.write(val & 0xFF);
}

void loop() { 
    
    if (Serial.available() == 0) {
        return;
    }
    
    // Get the protocol indicator signal
    char receivedHeader[4];
    receivedHeader[3] = '\0';
    Serial.readBytes(receivedHeader, 3);

    if (strcmp(receivedHeader, PROTOCOL_HEADER) != 0){
        Serial.write(BAD_HEADER);
        return;
{'fraction_non_alphanumeric': 0.13728432108027006, 'fraction_numerical': 0.026506626656664166, 'mean_word_length': 2.9215686274509802, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '513053', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1377, 'n_words': 337}