Browse Source

complete analyze of the command

Cyrille 10 years ago
parent
commit
e358526cdb
5 changed files with 55 additions and 9 deletions
  1. 3 5
      .gitignore
  2. 6 1
      analyze.c
  3. 34 2
      home_easy.c
  4. 11 0
      home_easy.h
  5. 1 1
      listen.c

+ 3 - 5
.gitignore

@@ -1,6 +1,4 @@
 **.o
-listen/listen
-listen/*.txt
-emit/*.o
-emit/emit
-emit/test/test
+emit
+listen
+test/test

+ 6 - 1
analyze.c

@@ -26,6 +26,9 @@ void analyse(BYTE_BUFFER buffer, FILE* output, unsigned char all)
     unsigned char bitNumber = 0;
     unsigned char startData = 0;
     unsigned char* data = buffer.data;
+    unsigned char extractedSection;
+    unsigned char extractedNumber;
+    unsigned char extractedOnOff;
     BYTE_BUFFER readFrame;
     unsigned long int readDWord;
     readFrame = createByteBuffer();
@@ -39,7 +42,9 @@ void analyse(BYTE_BUFFER buffer, FILE* output, unsigned char all)
                 currentByte = 0;
                 if (readFrame.size == 8) {
                     readDWord = homeEasyDecode(&readFrame);
-                    fprintf(output, "Decoded command: %08X\nID found: %08X\n", readDWord, getHomeEasyId(readDWord));
+                    getHomeEasyInfo(readDWord, 0, &extractedOnOff, &extractedSection, &extractedNumber);
+                    fprintf(output, "\nDecoded command: %08X\nID found: %08X\n", readDWord, getHomeEasyId(readDWord));
+                    fprintf(output, "Button %c%d - %s pressed", extractedSection, extractedNumber, (extractedOnOff ? "OFF" : "ON"));
                 } else {
                     fprintf(output, "Nothing to decode with %d byte(s)\n", readFrame.size);
                 }

+ 34 - 2
home_easy.c

@@ -22,8 +22,6 @@
 #include "utils.h"
 
 unsigned int timings[5][2] = {
-    //{310, 310},  // bit 0
-    //{310, 1340}, // bit 1
     {275, 275},  //  bit 0
     {275, 1300}, //  bit 1
     {275, 9900},  //  start of data
@@ -195,6 +193,40 @@ unsigned long int getHomeEasyId(unsigned long int frame)
     return frame >> 6;
 }
 
+/**
+ * Get all information about the homeEasy frame
+ *
+ * @param frame the frame to read
+ * @param id the identifier to extract
+ * @param onOff boolean to extract; if true : off
+ * @param section letter section to extract
+ * @param number number to extract
+ */
+void getHomeEasyInfo(unsigned long int frame, unsigned long int* id, unsigned char* onOff, unsigned char* section, unsigned char* number)
+{
+    unsigned char data = (unsigned char)(frame & 0x0000007f);
+    if (id) {
+        *id = getHomeEasyId(frame);
+    }
+    if (onOff) {
+        *onOff = ((data & 0x10) == 0);
+    }
+    if (section) {
+        if ((data & 0x20) == 0x20) {
+            *section = 'G';
+        } else {
+            *section = ((data & 0x0f) >> 2) + 'A';
+        }
+    }
+    if (number) {
+        if ((data & 0x20) != 0x20) {
+            *number = 1 + (data & 0x03);
+        } else {
+            *number=0;
+        }
+    }
+}
+
 /**
  * Configure the GPIO output pin
  *

+ 11 - 0
home_easy.h

@@ -103,6 +103,17 @@ int initIO();
  */
 unsigned long int getHomeEasyId(unsigned long int frame);
 
+/**
+ * Get all information about the homeEasy frame
+ *
+ * @param frame the frame to read
+ * @param id the identifier to extract
+ * @param onOff boolean to extract; if true : on
+ * @param section letter section to extract
+ * @param number number to extract
+ */
+void getHomeEasyInfo(unsigned long int frame, unsigned long int* id, unsigned char* onOff, unsigned char* section, unsigned char* number);
+
 /**
  * read the GPIO output pin
  *

+ 1 - 1
listen.c

@@ -35,7 +35,7 @@ int main (int argc, char** argv)
     struct timeval* start;
     int option;
     unsigned int duration = 80;
-    unsigned long int samples = 10000;
+    unsigned long int samples = 50000;
     unsigned char verbose = 0;
     unsigned char all = 0;
     FILE* output=0;