<commit_before>/*******************************************************************************
RTC内のメモリの読み書きドライバ(整数値)

下記のウェブサイトの情報に基づいて作成しました。

http://jiwashin.blogspot.jp/2016/07/esp30.html
https://lowreal.net/2016/01/10/1
*******************************************************************************/

#define kOffset         65
int WAKE_COUNT;

struct RtcStorage{
    char iot[4];
    int count;
    int data;
};

void printRtcInt(char *iot,int count, int data,int size){
    Serial.print("Ident = "); Serial.print(iot);
    Serial.print(", Count = "); Serial.print(count);
    Serial.print(", Value = "); Serial.print(data);
    Serial.print(", Size  = "); Serial.println(size);
}

int readRtcInt(){
    struct RtcStorage mem_init={"IoT",0,0};
    struct RtcStorage mem_read={"...",0,0};
    bool ok;

    ok = system_rtc_mem_read(kOffset, &mem_read, sizeof(mem_read));
    Serial.println("Read from RTC Memory");
    printRtcInt(mem_read.iot, mem_read.count, mem_read.data, sizeof(mem_read));
    if(!ok || strncmp(mem_init.iot,mem_read.iot,3) ){
        Serial.println("Initializing...");
        printRtcInt(mem_init.iot, mem_init.count, mem_init.data, sizeof(mem_init));
        system_rtc_mem_write(kOffset, &mem_init, sizeof(mem_init));
        mem_read.count=0;
        if (!ok) Serial.println("readRtcInt : write fail");
    }
    WAKE_COUNT=mem_read.count+1;
    return mem_read.data;
}

bool writeRtcInt(int in) {
    struct RtcStorage mem={"IoT",WAKE_COUNT,in};
    bool ok;

    Serial.println("Write to RTC Memory");
    printRtcInt(mem.iot, mem.count, mem.data, sizeof(mem));
    ok = system_rtc_mem_write(kOffset, &mem, sizeof(mem));
    if(!ok) Serial.println("Error : writeRtcInt : system_rtc_mem_write fail");
    return ok;
}
<commit_msg>起動カウントの不具合修正<commit_after>/*******************************************************************************
RTC内のメモリの読み書きドライバ(整数値)

下記のウェブサイトの情報に基づいて作成しました。

http://jiwashin.blogspot.jp/2016/07/esp30.html
https://lowreal.net/2016/01/10/1
*******************************************************************************/

#define kOffset         65
int WAKE_COUNT;

struct RtcStorage{
    char iot[4];
    int count;
    int data;
};

void printRtcInt(char *iot,int count, int data,int size){
    Serial.print("Ident = "); Serial.print(iot);
    Serial.print(", Count = "); Serial.print(count);
    Serial.print(", Value = "); Serial.print(data);
    Serial.print(", Size  = "); Serial.println(size);
}

int readRtcInt(){
    struct RtcStorage mem_init={"IoT",0,0};
    struct RtcStorage mem_read={"...",0,0};
    bool ok;

    ok = system_rtc_mem_read(kOffset, &mem_read, sizeof(mem_read));
    Serial.println("Read from RTC Memory");
    printRtcInt(mem_read.iot, mem_read.count, mem_read.data, sizeof(mem_read));
    if(!ok || strncmp(mem_init.iot,mem_read.iot,3) ){
        Serial.println("Initializing...");
        printRtcInt(mem_init.iot, mem_init.count, mem_init.data, sizeof(mem_init));
        ok=system_rtc_mem_write(kOffset, &mem_init, sizeof(mem_init));
        mem_read.count=1;
        if (!ok) Serial.println("readRtcInt : write fail");
    }else{
        mem_read.count++;
        ok = system_rtc_mem_write(kOffset, &mem_read, 4 + sizeof(int) );
        if (!ok) Serial.println("readRtcInt : write fail");
    }
    WAKE_COUNT=mem_read.count;
    return mem_read.data;
}

bool writeRtcInt(int in) {
    struct RtcStorage mem={"IoT",WAKE_COUNT,in};
    bool ok;

    Serial.println("Write to RTC Memory");
    printRtcInt(mem.iot, mem.count, mem.data, sizeof(mem));
    ok = system_rtc_mem_write(kOffset, &mem, sizeof(mem));
    if(!ok) Serial.println("Error : writeRtcInt : system_rtc_mem_write fail");
    return ok;
}

{'fraction_non_alphanumeric': 0.2281081081081081, 'fraction_numerical': 0.014594594594594595, 'mean_word_length': 4.234794908062235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7131121', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1300, 'n_words': 220}