123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include <stdio.h>
- #include <wiringPi.h>
- #include <unistd.h>
- #include <sys/time.h>
- #include <malloc.h>
- #include "home_easy.h"
- #include "analyze.h"
- void analyse(BYTE_BUFFER buffer, FILE* output, unsigned char all)
- {
- unsigned long int cursor=0;
- int detectMarker = 1;
- int currentMarker = 0;
- unsigned int lowLengthFrame;
- unsigned int highLengthFrame;
- unsigned int totalLengthFrame;
- unsigned char currentByte = 0;
- unsigned char bitNumber = 0;
- unsigned char startData = 0;
- unsigned char* data = buffer.data;
- BYTE_BUFFER readFrame;
- unsigned long int readDWord;
- readFrame = createByteBuffer();
- while (cursor<buffer.size) {
- totalLengthFrame = frameSize(&data[cursor], &highLengthFrame, &lowLengthFrame);
- if (currentMarker>0) {
-
- if ((lowLengthFrame > 20) && (lowLengthFrame<50)) {
- detectMarker++;
- bitNumber = 0;
- currentByte = 0;
- if (readFrame.size == 8) {
- readDWord = homeEasyDecode(&readFrame);
- fprintf(output, "Decoded command: %08X\nID found: %08X\n", readDWord, getHomeEasyId(readDWord));
- } else {
- fprintf(output, "Nothing to decode with %d byte(s)\n", readFrame.size);
- }
- readFrame.size = 0;
- fprintf(output, "\n%02d: ", detectMarker);
- } else {
- currentMarker = detectMarker;
- }
-
- if (currentMarker == detectMarker) {
-
- currentByte = currentByte << 1;
- if ((lowLengthFrame<2) || (highLengthFrame>5)) {
- fprintf(output, "There might be an error from here\n");
- if (!all) return;
- }
- currentByte += (lowLengthFrame < 5 ? 0 : 1);
-
- if (bitNumber == 7) {
- bitNumber = 0;
- fprintf(output, "%02X ", currentByte);
- pushByte(&readFrame, currentByte);
- currentByte = 0;
- } else {
- bitNumber++;
- }
- }
-
- } else {
- if ((lowLengthFrame > 20) && (lowLengthFrame<50) && (startData)) {
- currentMarker = 1;
- currentByte = 0;
- bitNumber = 0;
- fprintf(output, "DataStart at %lu\n", cursor);
- fprintf(output, "\n%02d: ", detectMarker);
- }
- if (lowLengthFrame > 100) {
- startData = 1;
- }
- }
- cursor += totalLengthFrame;
- }
- destroyByteBuffer(readFrame);
- }
|