Browse Source

data send

Cyrille 10 years ago
parent
commit
2501b5a883
7 changed files with 80 additions and 52 deletions
  1. 7 3
      emit/emit.c
  2. 34 15
      emit/home_easy.c
  3. 9 2
      emit/home_easy.h
  4. 1 1
      emit/test/Makefile
  5. 26 29
      emit/test/test.c
  6. 2 1
      emit/utils.c
  7. 1 1
      listen/listenlib.h

+ 7 - 3
emit/emit.c

@@ -113,14 +113,18 @@ int main(int argc, char** argv)
     } else {
         printf("Sending command %c%d: %s\n", section, number, (onOff == OFF) ? "OFF" : "ON");
     }
-    
+
     command = createHomeEasyCommand(idString, section, number, onOff);
     printfByteBuffer(command);
-    
+
     printf("Code to emit:\n");
     encoded = homeEasyEncode(&command);
     printfByteBuffer(encoded);
-    
+
+    initIO();
+    sendHomeEasyCommand(idString, section, number, onOff, repeat);
+
+
     destroyByteBuffer(command);
     destroyByteBuffer(encoded);
 

+ 34 - 15
emit/home_easy.c

@@ -16,14 +16,14 @@ unsigned int timings[5][2] = {
 };
 
 unsigned char homeEasyPinOut = 0;
-unsigned char homeEasyPinIn = 1;
+unsigned char homeEasyPinIn = 2;
 
 
 /**
  * Encode bits with HomeEasy encoding (1 => 10, 0 => 01)
- * 
+ *
  * @param buffer the buffuer to encode
- * 
+ *
  * @return new buffer
  * */
 BYTE_BUFFER homeEasyEncode(BYTE_BUFFER *buffer)
@@ -38,9 +38,9 @@ BYTE_BUFFER homeEasyEncode(BYTE_BUFFER *buffer)
 
 /**
  * Decode bits with HomeEasy encoding (1 => 10, 0 => 01)
- * 
+ *
  * @param buffer the buffuer to decode
- * 
+ *
  * @return new buffer
  * */
 BYTE_BUFFER homeEasyDecode(BYTE_BUFFER *buffer)
@@ -59,9 +59,9 @@ BYTE_BUFFER homeEasyDecode(BYTE_BUFFER *buffer)
 
 /**
  * Decode a byte according to HomeEasy
- * 
+ *
  * @param byte the byte to decode
- * 
+ *
  * @return the decoded byte
  */
 unsigned char decodeByte(unsigned short int word)
@@ -132,7 +132,7 @@ BYTE_BUFFER createHomeEasyCommand(unsigned char* id, char section, unsigned char
  * @param on boolean for on/off
  * @param repeat number of repeatition
  */
-void SendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on, unsigned char repeat)
+void sendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on, unsigned char repeat)
 {
 	BYTE_BUFFER command;
 	unsigned int i;
@@ -185,6 +185,25 @@ unsigned char getHomeEasyReceptorPin()
 	return homeEasyPinIn;
 }
 
+/**
+ * Init input/output
+ *
+ * @return status
+ */
+int initIO()
+{
+    int status;
+    status = wiringPiSetup();
+    if (status != -1) {
+        printf("Setting up GPIO\n");
+        pinMode(homeEasyPinIn, INPUT);
+        pinMode(homeEasyPinOut, OUTPUT);
+    } else {
+        printf("GPIO setup failed %d\n", status);
+    }
+    return status;
+}
+
 /**
  * Send a bit to the RF transmitter
  * 
@@ -192,9 +211,9 @@ unsigned char getHomeEasyReceptorPin()
  */
 void sendHomeEasyBit(unsigned char bit)
 {
-	digitalWrite(homeEasyPinOut, 1);
+    digitalWrite(homeEasyPinOut, 1);
     delayMicroseconds(timings[bit][0]);
-   	digitalWrite(homeEasyPinOut, 0);
+    digitalWrite(homeEasyPinOut, 0);
     delayMicroseconds(timings[bit][1]);
 }
 
@@ -213,15 +232,15 @@ void sendHomeEasyByte(unsigned char byte)
 
 /**
  * Send the content of a buffer to the RF transmitter
- * 
+ *
  * @param buffer the buffer to transmit
  */
 void sendHomeEasyBytes(BYTE_BUFFER buffer)
 {
-	unsigned int i;
-	for(i=0; i<buffer.size; i++) {
-		sendHomeEasyByte(buffer.data[i]);
-	}
+    unsigned int i;
+    for(i=0; i<buffer.size; i++) {
+        sendHomeEasyByte(buffer.data[i]);
+    }
 }
 
 /**

+ 9 - 2
emit/home_easy.h

@@ -68,7 +68,7 @@ BYTE_BUFFER createHomeEasyCommand(unsigned char* id, char section, unsigned char
  * @param on boolean for on/off
  * @param repeat number of repeatition
  */
-void SendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on, unsigned char repeat);
+void sendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on, unsigned char repeat);
 
 /**
  * Configure the GPIO output pin
@@ -77,6 +77,13 @@ void SendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsi
  */
 void setHomeEasyTransmittorPin(unsigned char pinNumber);
 
+/**
+ * Init input/output
+ *
+ * @return status
+ */
+int initIO();
+
 /**
  * read the GPIO output pin
  *
@@ -140,4 +147,4 @@ unsigned int frameSize(unsigned char* data, unsigned int* high, unsigned int* lo
  */
 BYTE_BUFFER readData(unsigned long int samples, unsigned int duration);
 
- #endif
+ #endif

+ 1 - 1
emit/test/Makefile

@@ -1,7 +1,7 @@
 all : test
 
 test : test.o buffer.o home_easy.o utils.o
-	gcc -o $@ $^
+	gcc -o $@ $^ -lwiringPi
 
 test.o : test.c
 	gcc -c $< -o $@

+ 26 - 29
emit/test/test.c

@@ -10,16 +10,16 @@ void testByteBuffer()
     BYTE_BUFFER buffer;
     char bytes[] = {0xcd, 0xef, 0x12};
     TEST_START;
-    
+
     buffer = createByteBuffer();
-    
+
     pushByte(&buffer, 0xab);
     pushBytes(&buffer, bytes, 3);
     pushWord(&buffer, 0x3456);
-    
+
     printf("Should: AB CD EF 12 34 56\nGet: ");
     printfByteBuffer(buffer);
-    
+
     destroyByteBuffer(buffer);
 }
 
@@ -28,12 +28,12 @@ void testPrintBits()
     BYTE_BUFFER buffer;
     char bytes[] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
     TEST_START;
-    
+
     buffer = createByteBuffer();
     pushBytes(&buffer, bytes, 8);
 
     printfBitBuffer(buffer);
-    
+
     destroyByteBuffer(buffer);
 }
 
@@ -42,10 +42,9 @@ void testEncode()
     unsigned char srcByte = 0x28;
     unsigned short int encWord;
     TEST_START;
-    
+
     encWord = encodeByte(srcByte);
     printf("Input: %02X\nShould: 0x5995\nGet: %04X\n", srcByte, encWord);
-    
 }
 
 
@@ -54,10 +53,9 @@ void testDecode()
     unsigned short int srcWord = 0x5995;
     unsigned char decByte;
     TEST_START;
-    
+
     decByte = decodeByte(srcWord);
     printf("Input: %04X\nShould: 0x28\nGet: %02X\n", srcWord, decByte);
-    
 }
 
 void testHomeEasyEncode()
@@ -66,16 +64,16 @@ void testHomeEasyEncode()
     BYTE_BUFFER encoded;
     unsigned char bytes[] = {0x28, 0x28, 0x01};
     TEST_START;
-    
+
     source = createByteBuffer();
     pushBytes(&source, bytes, 3);
     printf("Input: ");
     printfByteBuffer(source);
     printf("Should: 59 95 59 95 55 56\nGet:    ");
-    
+
     encoded = homeEasyEncode(&source);
     printfByteBuffer(encoded);
-    
+
     destroyByteBuffer(source);
     destroyByteBuffer(encoded);
 }
@@ -86,16 +84,16 @@ void testHomeEasyDecode()
     BYTE_BUFFER decoded;
     unsigned char bytes[] = {0x59, 0x95, 0x59, 0x95, 0x55, 0x56};
     TEST_START;
-    
+
     source = createByteBuffer();
     pushBytes(&source, bytes, 6);
     printf("Input: ");
     printfByteBuffer(source);
     printf("Should: 28 28 01\nGet:    ");
-    
+
     decoded = homeEasyDecode(&source);
     printfByteBuffer(decoded);
-    
+
     destroyByteBuffer(source);
     destroyByteBuffer(decoded);
 }
@@ -107,13 +105,13 @@ void testHomeEasyCommand(char section, unsigned char num, unsigned char onOff)
     BYTE_BUFFER encoded;
     unsigned char id[] = {0x28, 0x28, 0x01, 0x80};
     TEST_START;
-    
+
     command = createHomeEasyCommand(id, section, num, onOff);
     printfByteBuffer(command);
-    
+
     encoded = homeEasyEncode(&command);
     printfByteBuffer(encoded);
-    
+
     destroyByteBuffer(command);
     destroyByteBuffer(encoded);
 }
@@ -121,21 +119,20 @@ void testHomeEasyCommand(char section, unsigned char num, unsigned char onOff)
 int main()
 {
     printf("Test\n");
-    
+
     testByteBuffer();
-    
-    //testBitBuffer();
+
     testPrintBits();
-    
+
     testEncode();
-    
+
     testDecode();
-    
+
     testHomeEasyEncode();
-    
+
     testHomeEasyDecode();
-    
-    testHomeEasyCommand('D', 4, ON);
-    
+
+    testHomeEasyCommand('D', 4, OFF);
+
     return 0;
 }

+ 2 - 1
emit/utils.c

@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/time.h>
+#include <malloc.h>
 #include "utils.h"
 
 
@@ -25,4 +26,4 @@ struct timeval* showTime(struct timeval* start)
     tv_usec = (start->tv_usec > stop->tv_usec) ? 1000000 + stop->tv_usec - start->tv_usec : stop->tv_usec - start->tv_usec;
     fprintf(stderr, "%lus %lums %luµs\n", tv_sec, tv_usec/1000, tv_sec % 1000);
     return stop;
-}
+}

+ 1 - 1
listen/listenlib.h

@@ -2,7 +2,7 @@
 #include <sys/time.h>
 
 // LED Pin - wiringPi pin 0 is BCM_GPIO 17.
-#define	LED	0
+#define	LED	2
 
 
 /**