BIN6 protocol

Hi! I'd like to ask a simple question. I have following pulse sequence that enters my Mega 2560 digital pins:

https://postimg.org/image/sjs5ouczf/

Here is my code that reads the pulses:

const byte clockPin = 3;
const byte dataPin = 2;
int j = 0, k = 0;
int myData[24]; // the clock signal represents 6 sets times 4 pulses; see the picture

void setup() {
     pinMode(clockPin, INPUT_PULLUP);
     pinMode(dataPin, INPUT_PULLUP);
     Serial.begin(115200);
     attachInterrupt(digitalPinToInterrupt(clockPin), myISR, RISING);
}

void loop() {
     if (j >= 24) {
        j = 0;
        for (k = 23; k >= 0; k--) Serial.print(myData[k]);
        Serial.println("");
     }//if
}

void myISR() {
     myData[j] = digitalRead(dataPin);
     j++;
}

The code successfully reads the data signal and outputs a 24-bit binary code. The code format is BIN6. It is widely used by cheep Chinese digital calipers. More info about the code can be found here:

http://www.yuriystoys.com/2013/07/chinese-caliper-data-format.html

My question is how to make the code recognize the beginning of each pulse set. There is a 100 ms gap between each set of pulses. The code currently can not recognize the gap and collects data starting from random location. There is not start/end pattern similar to I2C's for instance. In addition, I am not allowed to send a request signal. The data flows automatically. Because the gap duration is quite unstable and varies, the code snippet must be tricky.

Thank you in advance!

Usually the time between two clock signals is lower than ~300µs and at least from the logic analyzer picture it seems that between two data sections there is a pause of at least 2ms. So even if the pauses are not of constant length you can just calculate the time between two clock signals. If it's greater than 2ms clear your buffer and start a new reception period.

I think I found a solution. The pulseIn function supports a timeout. The timeout should be set approximately 75% times the gap length. In this way, the pulseIn will process all pulses but the largest one, i.e. the gap itself. This is the right time for the real measurement to begin. Here is a sample code. The only modification is "do" loop in Setup function.

const byte clockPin = 3;
const byte dataPin = 2;
int j = 0, k = 0;
int myData[24];

void setup() {
int gapDuration = 0;

     pinMode(clockPin, INPUT_PULLUP);
     pinMode(dataPin, INPUT_PULLUP);
     Serial.begin(115200);
     do {
        gapDuration = pulseIn(clockPin, LOW, 75000);
     } while (gapDuration != 0);
     attachInterrupt(digitalPinToInterrupt(clockPin), myISR, RISING);
}

void loop() {

     if (j >= 24) {
        j = 0;
        for (k = 23; k >= 0; k--) Serial.print(myData[k]);
        Serial.println("");
     }//if
}

void myISR() {
     myData[j] = digitalRead(dataPin);
     j++;
}