<commit_before>// Include the Ruby headers and goodies
#include "ruby.h"
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>

/*  3*842 The size of the memory we want to allocate case there are long error messages in the ThermalSite firmware.  382 is the current
    size of the data retrieved from BBB.
    changing to 50*842
*/
#define SHMSZ 42100

unsigned char initialized = 0;
key_t key;
char *shm, *s;
int shmid;


// Defining a space for information and references about the module to be stored internally
VALUE SharedMemoryExtension = Qnil;


// Prototype for the initialization method - Ruby calls this, not you
void Init_SharedMemoryExtension();


// Prototype for our methods 'WriteDataToSharedMemory' - methods are prefixed by 'method_' here
VALUE method_WriteDataToSharedMemory(VALUE self, VALUE rubyStringParam);
VALUE method_GetDataFromSharedMemory(VALUE self);
void method_InitializeSharedMemory(VALUE self);


// The initialization method for this module
void Init_SharedMemoryExtension() {
	SharedMemoryExtension = rb_define_module("SharedMemoryExtension");
	rb_define_method(SharedMemoryExtension, "WriteDataToSharedMemory", method_WriteDataToSharedMemory, 1);
	rb_define_method(SharedMemoryExtension, "GetDataFromSharedMemory", method_GetDataFromSharedMemory, 0);
	rb_define_method(SharedMemoryExtension, "InitializeSharedMemory", method_InitializeSharedMemory, 0);
}

VALUE method_WriteDataToSharedMemory(VALUE self, VALUE rubyStringParam) {
    /*
        return values:
        0 - no error writing to memory.
        1 - not initialized.  Run the function InitializeVariables(), first.
        2 - sent String too long.  Not all data written in.
    */
    int ct=1;
    if (!initialized) {
        /*
            It's not initialized.
        */
        INT2NUM(1);
    }
    /*
        Set the first byte to let all the processes know that the data is being updated.
    */
    while (*shm != (char)0)
        usleep(500); // Wait for a micro second until we get the buffer available for writing.
    *shm = (char)1;

    /*
     * Now put some things into the memory for the
     * other process to read.
     */
    s = (shm+1); /* +1 to skip the first character, since it's the flag that indicates memory is being written into. */
    char * sentString = StringValuePtr(rubyStringParam );
    while ( *(sentString) && ct++<SHMSZ) {
        *s++ = *(sentString++);
    }
    *s = '\0';
    
    /*
        Set the first byte to 0 to indicate that the memory is available for updating.
    */
    *shm = (char)0;
    
    if (ct < SHMSZ)
        INT2NUM(0);
    else 
        INT2NUM(2);
}<commit_msg>Did same change in board code.<commit_after>// Include the Ruby headers and goodies
#include "ruby.h"
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>

/*  3*842 The size of the memory we want to allocate case there are long error messages in the ThermalSite firmware.  382 is the current
    size of the data retrieved from BBB.
    changing to 50*842
*/
#define SHMSZ 42100

unsigned char initialized = 0;
key_t key;
char *shm, *s;
int shmid;


// Defining a space for information and references about the module to be stored internally
VALUE SharedMemoryExtension = Qnil;


// Prototype for the initialization method - Ruby calls this, not you
void Init_SharedMemoryExtension();


// Prototype for our methods 'WriteDataToSharedMemory' - methods are prefixed by 'method_' here
VALUE method_WriteDataToSharedMemory(VALUE self, VALUE rubyStringParam);
VALUE method_GetDataFromSharedMemory(VALUE self);
void method_InitializeSharedMemory(VALUE self);


// The initialization method for this module
void Init_SharedMemoryExtension() {
	SharedMemoryExtension = rb_define_module("SharedMemoryExtension");
	rb_define_method(SharedMemoryExtension, "WriteDataToSharedMemory", method_WriteDataToSharedMemory, 1);
	rb_define_method(SharedMemoryExtension, "GetDataFromSharedMemory", method_GetDataFromSharedMemory, 0);
	rb_define_method(SharedMemoryExtension, "InitializeSharedMemory", method_InitializeSharedMemory, 0);
}

VALUE method_WriteDataToSharedMemory(VALUE self, VALUE rubyStringParam) {
    /*
        return values:
        0 - no error writing to memory.
        1 - not initialized.  Run the function InitializeVariables(), first.
        2 - sent String too long.  Not all data written in.
    */
    int ct=1;
    if (!initialized) {
        /*
            It's not initialized.
        */
        INT2NUM(1);
    }
    /*
        Set the first byte to let all the processes know that the data is being updated.
    */
    while (*shm != (char)0)
        usleep(1); // Wait for a micro second until we get the buffer available for writing.
    *shm = (char)1;

    /*
     * Now put some things into the memory for the
     * other process to read.
     */
    s = (shm+1); /* +1 to skip the first character, since it's the flag that indicates memory is being written into. */
    char * sentString = StringValuePtr(rubyStringParam );
    while ( *(sentString) && ct++<SHMSZ) {
        *s++ = *(sentString++);
    }
    *s = '\0';
    
    /*
        Set the first byte to 0 to indicate that the memory is available for updating.
    */
    *shm = (char)0;
    
    if (ct < SHMSZ)
        INT2NUM(0);
    else 
        INT2NUM(2);
}
{'fraction_non_alphanumeric': 0.09053420805998126, 'fraction_numerical': 0.01499531396438613, 'mean_word_length': 3.22486144101346, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '4524420', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1526, 'n_words': 559}