Browse Source

emit - version 1.0

Cyrille 10 years ago
parent
commit
943beaba4c
9 changed files with 281 additions and 667 deletions
  1. 3 0
      emit/Makefile
  2. 11 44
      emit/emit.c
  3. 0 384
      emit/emitlib.c
  4. 0 201
      emit/emitlib.h
  5. 47 30
      emit/home_easy.c
  6. 16 8
      emit/home_easy.h
  7. 7 0
      hcc/Makefile
  8. BIN
      hcc/radioEmission
  9. 197 0
      hcc/radioEmission.cpp

+ 3 - 0
emit/Makefile

@@ -11,3 +11,6 @@ emit.o : emit.c
 
 clean:
 	rm -f emit *.o
+
+install: emit
+	cp -f emit /usr/local/bin/.

+ 11 - 44
emit/emit.c

@@ -9,9 +9,6 @@
 #include <unistd.h>
 #include <errno.h>
 
-#define DEFAULT_FREQ 20000
-
-
 
 /**
  * Usage of this program
@@ -24,7 +21,6 @@ void usage(char** argv)
     fprintf(stderr, "\t-x:\n\t\tOff (default On)\n");
     fprintf(stderr, "\t-r number:\n\t\tnumber of repeatitions\n");
     fprintf(stderr, "\t-d id:\n\t\thexadecimal id from your command (13 letters <=> 52 bits)\n");
-    fprintf(stderr, "\t-f frequency: configuration frequency for the SPI (default %dHz)\n", DEFAULT_FREQ);
     fprintf(stderr, "\t-v: verbose bits\n");
 }
 
@@ -44,12 +40,11 @@ int main(int argc, char** argv)
     BYTE_BUFFER command;
     BYTE_BUFFER encoded;
     int i;
-    char optstring[] = "xvb:d:f:r:";
+    char optstring[] = "xvb:d:r:";
     int option;
     unsigned char number = 1;
     unsigned char section = 'A';
     char *idString=0;
-    unsigned long int frequency = DEFAULT_FREQ;
     unsigned char onOff = ON;
     unsigned int verbose = 0;
     unsigned repeat = 5;
@@ -80,10 +75,6 @@ int main(int argc, char** argv)
                     }
                 }
                 break;
-            case 'f':
-                // SPI frequency
-                sscanf(optarg, "%lu", &frequency);
-                break;
             case 'x':
                 // OFF ?
                 onOff = OFF;
@@ -106,53 +97,29 @@ int main(int argc, char** argv)
     }
 
     // Show informations
-    printf("Frequency config on SPI: %luHz\n", frequency);
-
     if (section == 'G') {
         printf("Sending command G: %s\n", (onOff == OFF) ? "OFF" : "ON");
     } else {
         printf("Sending command %c%d: %s\n", section, number, (onOff == OFF) ? "OFF" : "ON");
     }
 
-    command = createHomeEasyCommand(idString, section, number, onOff);
-    printfByteBuffer(command);
+    // Display mor information
+    if (verbose) {
+        command = createHomeEasyCommand(idString, section, number, onOff);
+        printfByteBuffer(command);
 
-    printf("Code to emit:\n");
-    encoded = homeEasyEncode(&command);
-    printfByteBuffer(encoded);
+        printf("Code to emit:\n");
+        encoded = homeEasyEncode(&command);
+        printfByteBuffer(encoded);
+    }
 
+    // Send the data
     initIO();
     sendHomeEasyCommand(idString, section, number, onOff, repeat);
 
+    // release the memory
     destroyByteBuffer(command);
     destroyByteBuffer(encoded);
 
-    // Preparing the buffer
-    /*buffer = createBitBuffer();
-
-    // Building the data
-    for (i=0; i<repeat; i++) {
-        pushCode(&buffer, idString, section, number, onOff, global, frequency);
-    }
-    printf("\n");
-
-    // Want to see the bits ?
-    if (verbose) {
-        printfBitBuffer(buffer);
-    }
-
-#ifdef __arm__
-    // preparing the output
-    if (wiringPiSPISetup(0, frequency) < 0) {
-        printf("SPI Setup Failed: %s\n", strerror(errno));
-        return -1;
-    }
-    // Send data
-    wiringPiSPIDataRW(0, (unsigned char*)buffer.data, buffer.byteSize);
-#endif
-
-    // release memory
-    destroyBitBuffer(buffer);*/
-    
     return 0;
 }

+ 0 - 384
emit/emitlib.c

@@ -1,384 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <string.h>
-#include "emitlib.h"
-
-
-/*unsigned int timings[4][2] = {
-    {250, 250},  //  bit 0
-    {250, 1200}, //  bit 1
-    {250, 2600}, //  start of frame
-    {250, 9900}  //  end of data
-};*/
-
-unsigned int timings[4][2] = {
-    {310, 310},  //  bit 0
-    {310, 1340}, //  bit 1
-    {275, 2675}, //  start of frame
-    {275, 9900}  //  end of data
-};
-
-
-unsigned char numbering[4] = {0x05, 0x06, 0x09, 0x0A};
-
-/**
- * Create a new buffer
- *
- * @return the created buffer
- */
-BIT_BUFFER createBitBuffer()
-{
-    BIT_BUFFER buffer;
-    buffer.byteSize = 1;
-    buffer.bitSize = 0;
-    buffer.data = (char*) malloc(1);
-    buffer.data[0] = 0;
-    return buffer;
-}
-
-/**
- * Release the memory
- *
- * @param buffer the buffer to destroy
- */
-void destroyBitBuffer(BIT_BUFFER buffer)
-{
-    free(buffer.data);
-}
-
-/**
- * Create a new byte buffer
- *
- * @return the created buffer
- */
-BYTE_BUFFER createByteBuffer()
-{
-    BYTE_BUFFER buffer;
-    buffer.size = 0;
-    buffer.data = (char*) malloc(1);
-    return buffer;
-}
-
-/**
- * Release the memory
- *
- * @param buffer the buffer to destroy
- */
-void destroyByteBuffer(BYTE_BUFFER buffer)
-{
-    free(buffer.data);
-}
-
-/**
- * Print all the bits from a buffer
- *
- * @param buffer the buffer holding the data
- */
-/*void printfBitBuffer(BIT_BUFFER buffer)
-{
-    printf("bytes: %lu\nbits: %d\n", buffer.byteSize, buffer.bitSize);
-    unsigned char byte;
-    unsigned char bit;
-    unsigned int x;
-    int i;
-    for(x=0; x<(buffer.bitSize ? buffer.byteSize : buffer.byteSize-1) ; x++) {
-        byte = buffer.data[x];
-        for(i=0x80; i>0; i>>=1) {
-            if ((bit==0) && (byte & i)) {
-                fprintf(stdout, "\n");
-            }
-            bit = ((byte & i) == i);
-            fprintf(stdout, "%d", bit);
-        }
-    }
-}*/
-void printfBitBuffer(BYTE_BUFFER buffer)
-{
-    printf("bytes: %lu\nbits: %lu\n", buffer.size, buffer.size*8);
-    unsigned int x;
-    for(x=0; x<buffer.size ; x++) {
-        printfBit(buffer.data[x]);
-        printf("\n");
-    }
-}
-
-/**
- * Print a byte in binary
- * 
- * @param byte the byte to print
- */
-void printfBit(unsigned char byte)
-{
-    int i;
-    for(i=0x80; i>0; i>>=1) {
-        fprintf(stdout, "%d", ((byte & i) == i));
-    }
-}
-
-
-/**
- * Print all the bytes from a buffer
- *
- * @param buffer the buffer holding the data
- */
-void printfByteBuffer(BYTE_BUFFER buffer)
-{
-    unsigned int i;
-    for(i=0; i<buffer.size; i++) {
-        fprintf(stdout, "%02X ", (unsigned char)buffer.data[i]);
-    }
-    fprintf(stdout, "\n");
-}
-
-/**
- * Push a bit in a buffer
- *
- * @param buffer the buffer holding the data
- * @param bit the bit to push
- */
-/*void bitPushBit(BIT_BUFFER* buffer, unsigned char bit)
-{
-    buffer->data[buffer->byteSize-1] |= bit << (7-buffer->bitSize);
-    buffer->bitSize++;
-    if (buffer->bitSize == 8) {
-        buffer->bitSize = 0;
-        buffer->byteSize++;
-        buffer->data = (char*)realloc(buffer->data, buffer->byteSize);
-        buffer->data[buffer->byteSize-1] = 0;
-    }
-}*/
-
-/**
- * Push a byte in a buffer
- *
- * @param buffer the buffer holding the data
- * @param byte the byte to push
- */
-void pushByte(BYTE_BUFFER* buffer, unsigned char byte)
-{
-    buffer->size++;
-    buffer->data = (char*)realloc(buffer->data, buffer->size);
-    buffer->data[buffer->size-1] = byte;
-}
-
-/**
- * Push a word in a buffer
- *
- * @param buffer the buffer holding the data
- * @param word the word to push
- */
-void pushWord(BYTE_BUFFER* buffer, unsigned short int word)
-{
-    unsigned char* data = (unsigned char*)&word;
-    pushByte(buffer, data[1]);
-    pushByte(buffer, data[0]);
-}
-/**
- * Push some bytes in a buffer
- *
- * @param buffer the buffer holding the data
- * @param bytes the bytes to push
- * @param len the number of bytes to push
- */
-void pushBytes(BYTE_BUFFER* buffer, unsigned char *byte, unsigned int len)
-{
-    buffer->data = (char*)realloc(buffer->data, buffer->size+len);
-    memcpy(&buffer->data[buffer->size], byte, len);
-    buffer->size += len;
-}
-
-/**
- * Encode bits with HomeEasy encoding (1 => 10, 0 => 01)
- * 
- * @param buffer the buffuer to encode
- * 
- * @return new buffer
- * */
-BYTE_BUFFER homeEasyEncode(BYTE_BUFFER *buffer)
-{
-    BYTE_BUFFER result = createByteBuffer();
-    unsigned int i;
-    for(i=0; i<buffer->size; i++) {
-        pushWord(&result, encodeByte(buffer->data[i]));
-    }
-    return result;
-}
-
-/**
- * Decode bits with HomeEasy encoding (1 => 10, 0 => 01)
- * 
- * @param buffer the buffuer to decode
- * 
- * @return new buffer
- * */
-BYTE_BUFFER homeEasyDecode(BYTE_BUFFER *buffer)
-{
-    BYTE_BUFFER result = createByteBuffer();
-    unsigned short int word;
-    unsigned char *byte = (unsigned char*)&word;
-    unsigned int i;
-    for(i=0; i<(buffer->size+1)/2; i++) {
-        byte[1] = buffer->data[2*i];
-        byte[0] = (2*i+1 < buffer->size ? buffer->data[2*i+1]:0);
-        pushByte(&result, decodeByte(word));
-    }
-    return result;
-}
-
-/**
- * Decode a byte according to HomeEasy
- * 
- * @param byte the byte to decode
- * 
- * @return the decoded byte
- */
-unsigned char decodeByte(unsigned short int word)
-{
-    unsigned char decodedChar=0;
-    int j;
-    int shift = 7;
-    for(j=0x8000;j>0; j>>=2) {
-      decodedChar |= (((word & j) == j) ? 0x01 : 0x00) << shift;
-      shift -=1;
-    }
-    return decodedChar;
-}
-
-/**
- * Encode a byte according to HomeEasy
- * 
- * @param byte the byte to encode
- * 
- * @return the encoded byte
- */
-unsigned short int encodeByte(unsigned char byte)
-{
-    unsigned short int encodedChar=0;
-    int j;
-    int shift = 14;
-    for(j=0x80;j>0; j>>=1) {
-      encodedChar |= (((byte & j) == j) ? 0x02 : 0x01) << shift;
-      shift -=2;
-    }
-    return encodedChar;
-}
-
-/**
- * Gives the bit at a specific position
- * 
- * @param buffer the buffer to evaluate
- * @param n the bit position
- * 
- * @return the bit value
- */
-unsigned int bitAt(BYTE_BUFFER buffer, unsigned long int n)
-{
-    unsigned char byte = buffer.data[n / 8];
-    return (byte & (0x80 >> (n % 8)) != 0);
-}
-
-/**
- * Append a complete command according to Chacon protocole
- *
- * @param id command id (refer to your remote)
- * @param section button section ('A' | 'B'  | 'C'  | 'D'  | 'G')
- * @param nb button number(1, 2, 3, 4)
- * @param on boolean for on/off
- */
-BYTE_BUFFER createHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on)
-{
-    unsigned char last = id[3] & 0xc0;
-    BYTE_BUFFER command;
-    char formatedSection = (section<='Z' ? section : section + 'A' - 'a');
-    // adding global
-    last |= (formatedSection == 'G' ? 0x20 : 0);
-    // adding on/off
-    last |= (on ? 0x10 : 0);
-    // adding section
-    last |= ((formatedSection == 'G' ? 0 : formatedSection - 'A') << 2) & 0x0c;
-    // adding num
-    last |= (formatedSection == 'G' ? 0 : nb-1) & 0x03;;
-    //Preparing output buffer
-    command = createByteBuffer();
-    pushBytes(&command, id, 3);
-    pushByte(&command, last);
-    return command;
-}
-
-/**
- * Append a bit that will be emitted for a specific time
- *
- * @param buffer the buffer holding the data
- * @param bit the bit to push
- * @param usec time in µs
- * @param clock frequency
- */
-/*void appendBit(BIT_BUFFER* buffer, unsigned char bit, unsigned int usec, unsigned int freq)
-{
-    unsigned int i;
-    for(i=0; i<(usec * freq) / 1e6; i++) {
-        bitPushBit(buffer, bit);
-    }
-}*/
-
-/**
- * Append data according to Chacon protocole
- *
- * @param buffer the buffer holding the data
- * @param type data type (BIT0 | BIT1 | START_OF_FRAME | END_OF_DATA)
- * @param clock frequency
- */
-/*void appendData(BIT_BUFFER* buffer, unsigned int type, unsigned int freq)
-{
-    appendBit(buffer, 1, timings[type][0], freq);
-    appendBit(buffer, 0, timings[type][1], freq);
-}*/
-
-/**
- * Append a byte according to Chacon protocole
- *
- * @param buffer the buffer holding the data
- * @param byte the byte to append
- * @param clock frequency
- */
-/*void appendByte(BIT_BUFFER* buffer, unsigned char byte, unsigned int freq)
-{
-    int i;
-    for(i=0x80; i>0; i>>=1) {
-        appendData(buffer, ((byte & i) == i), freq);
-    }
-    printf("%02X ", byte);
-}*/
-
-
-/**
- * Append a complete command according to Chacon protocole
- *
- * @param buffer the buffer holding the data
- * @param id command id (refer to your remote)
- * @param section button section (0:A, 1:B, 2:C, 3:D)
- * @param nb button number(1, 2, 3, 4)
- * @param on boolean for on/off
- * @param global if true G button is selected (nb will be ignore)
- * @param clock frequency
- */
-/*void pushCode(BIT_BUFFER* buffer, unsigned char* id, unsigned char section, unsigned char nb, unsigned char on, unsigned char global, unsigned int freq)
-{
-    unsigned char byte6 = (id[6] & 0xf0) + numbering[on + (global ? 2 : 0)];
-    unsigned char byte7 = (numbering[section] << 4) + numbering[nb];
-    unsigned int i;
-    if (global) {
-        byte7 = 0x55;
-    }
-    appendData(buffer, START_OF_DATA, freq);
-    appendData(buffer, START_OF_FRAME, freq);
-    printf("SOF ");
-    for(i=0; i<6; i++) {
-            appendByte(buffer, id[i], freq);
-    }
-    appendByte(buffer, byte6, freq);
-    appendByte(buffer, byte7, freq);
-    appendData(buffer, START_OF_FRAME, freq);
-    printf("EOD ");
-}*/

+ 0 - 201
emit/emitlib.h

@@ -1,201 +0,0 @@
-#include <stdio.h>
-
-
-typedef struct {
-    char* data;
-    unsigned long int byteSize;
-    unsigned int bitSize;
-} BIT_BUFFER;
-
-typedef struct {
-    char* data;
-    unsigned long int size;
-} BYTE_BUFFER;
-
-#define BIT0 0
-#define BIT1 1
-#define START_OF_FRAME  2
-#define START_OF_DATA 3
-
-#define ON 1
-#define OFF 0
-
-/**
- * Create a new bit buffer
- *
- * @return the created buffer
- */
-BIT_BUFFER createBitBuffer();
-
-/**
- * Create a new byte buffer
- *
- * @return the created buffer
- */
-BYTE_BUFFER createByteBuffer();
-
-/**
- * Release the memory
- *
- * @param buffer the buffer to destroy
- */
-void destroyBitBuffer(BIT_BUFFER buffer);
-
-/**
- * Release the memory
- *
- * @param buffer the buffer to destroy
- */
-void destroyByteBuffer(BYTE_BUFFER buffer);
-
-/**
- * Print all the bits from a buffer
- *
- * @param buffer the buffer holding the data
- */
-//void printfBitBuffer(BIT_BUFFER buffer);
-void printfBitBuffer(BYTE_BUFFER buffer);
-
-/**
- * Print a byte in binary
- * 
- * @param byte the byte to print
- */
-void printfBit(unsigned char byte);
-
-/**
- * Print all the bytes from a buffer
- *
- * @param buffer the buffer holding the data
- */
-void printfByteBuffer(BYTE_BUFFER buffer);
-
-/**
- * Push a bit in a buffer
- *
- * @param buffer the buffer holding the data
- * @param bit the bit to push
- */
-//void bitPushBit(BIT_BUFFER* buffer, unsigned char bit);
-
-/**
- * Push a byte in a buffer
- *
- * @param buffer the buffer holding the data
- * @param byt the byte to push
- */
-void pushByte(BYTE_BUFFER* buffer, unsigned char byte);
-
-/**
- * Push a word in a buffer
- *
- * @param buffer the buffer holding the data
- * @param word the word to push
- */
-void pushWord(BYTE_BUFFER* buffer, unsigned short int word);
-
-/**
- * Push some bytes in a buffer
- *
- * @param buffer the buffer holding the data
- * @param bytes the bytes to push
- * @param len the number of bytes to push
- */
-void pushBytes(BYTE_BUFFER* buffer, unsigned char *byte, unsigned int len);
-
-/**
- * Encode bits with HomeEasy encoding (1 => 10, 0 => 01)
- * 
- * @param buffer the buffuer to encode
- * 
- * @return new buffer
- * */
-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);
-
-/**
- * Encode a byte according to HomeEasy
- * 
- * @param byte the byte to encode
- * 
- * @return the encoded byte
- */
-unsigned short int encodeByte(unsigned char byte);
-
-/**
- * Decode a byte according to HomeEasy
- * 
- * @param byte the byte to decode
- * 
- * @return the decoded byte
- */
-unsigned char decodeByte(unsigned short int word);
-
-/**
- * Gives the bit at a specific position
- * 
- * @param buffer the buffer to evaluate
- * @param n the bit position
- * 
- * @return the bit value
- */
-unsigned int bitAt(BYTE_BUFFER buffer, unsigned long int n);
-
-/**
- * Append a complete command according to Chacon protocole
- *
- * @param id command id (refer to your remote)
- * @param section button section ('A' | 'B'  | 'C'  | 'D'  | 'G')
- * @param nb button number(1, 2, 3, 4)
- * @param on boolean for on/off
- */
-BYTE_BUFFER createHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on);
-
-/**
- * Append a bit that will be emitted for a specific time
- *
- * @param buffer the buffer holding the data
- * @param bit the bit to push
- * @param usec time in µs
- * @param clock frequency
- */
-//void appendBit(BIT_BUFFER* buffer, unsigned char bit, unsigned int usec, unsigned int freq);
-
-/**
- * Append data according to Chacon protocole
- *
- * @param buffer the buffer holding the data
- * @param type data type (BIT0 | BIT1 | START_OF_FRAME | END_OF_DATA)
- * @param clock frequency
- */
-//void appendData(BIT_BUFFER* buffer, unsigned int type, unsigned int freq);
-
-/**
- * Append a byte according to Chacon protocole
- *
- * @param buffer the buffer holding the data
- * @param byte the byte to append
- * @param clock frequency
- */
-//void appendByte(BIT_BUFFER* buffer, unsigned char byte, unsigned int freq);
-
-/**
- * Append a complete command according to Chacon protocole
- *
- * @param buffer the buffer holding the data
- * @param id command id (refer to your remote)
- * @param section button section (0:A, 1:B, 2:C, 3:D)
- * @param nb button number(1, 2, 3, 4)
- * @param on boolean for on/off
- * @param global if true G button is selected (nb will be ignore)
- * @param clock frequency
- */
-//void pushCode(BIT_BUFFER* buffer, unsigned char* id, unsigned char section, unsigned char nb, unsigned char on, unsigned char global, unsigned int freq);

+ 47 - 30
emit/home_easy.c

@@ -8,13 +8,13 @@
 #include "utils.h"
 
 unsigned int timings[5][2] = {
-    {310, 310},  // bit 0
-    {310, 1340}, // bit 1
-    //{275, 275},  //  bit 0
-    //{275, 1300}, //  bit 1
+    //{310, 310},  // bit 0
+    //{310, 1340}, // bit 1
+    {275, 275},  //  bit 0
+    {275, 1300}, //  bit 1
     {275, 9900},  //  start of data
     {275, 2675}, //  start of frame
-    {275, 2675},  //  end of data
+    {275, 10000},  //  end of data
 };
 
 unsigned char homeEasyPinOut = 0;
@@ -80,9 +80,9 @@ unsigned char decodeByte(unsigned short int word)
 
 /**
  * Encode a byte according to HomeEasy
- * 
+ *
  * @param byte the byte to encode
- * 
+ *
  * @return the encoded byte
  */
 unsigned short int encodeByte(unsigned char byte)
@@ -125,6 +125,29 @@ BYTE_BUFFER createHomeEasyCommand(unsigned char* id, char section, unsigned char
     return command;
 }
 
+/**
+ * Send n times a data frame
+ *
+ * @param frame the data to send
+ * @param repeat number of repeatition
+ */
+void sendFrame(BYTE_BUFFER frame, unsigned int repeat)
+{
+    unsigned int i;
+    // switch to real time
+    scheduler_realtime();
+    // send header
+    sendHomeEasyBit(START_OF_DATA);
+    sendHomeEasyBit(START_OF_FRAME);
+    // repeat the command
+    for(i=0; i<repeat; i++) {
+        sendHomeEasyBytes(frame);
+        sendHomeEasyBit(END_OF_FRAME);
+    }
+    // Exit real time mode
+    scheduler_standard();
+}
+
 /**
  * Send a complete command according to Chacon protocole
  *
@@ -136,22 +159,17 @@ BYTE_BUFFER createHomeEasyCommand(unsigned char* id, char section, unsigned char
  */
 void sendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on, unsigned char repeat)
 {
-	BYTE_BUFFER command;
-	unsigned int i;
+    BYTE_BUFFER command;
+    BYTE_BUFFER encoded;
     // build the command
-	command = createHomeEasyCommand(id, section, nb, on);
-    // switch to real time
-    scheduler_realtime();
-    // send header
-	sendHomeEasyBit(START_OF_DATA);
-	sendHomeEasyBit(START_OF_FRAME);
-    // repeat the command
-	for(i=0; i<repeat; i++) {
-		sendHomeEasyBytes(command);
-		sendHomeEasyBit(END_OF_FRAME);
-	}
-    // Exit real time mode
-    scheduler_standard();
+    command = createHomeEasyCommand(id, section, nb, on);
+    // encode the command
+    encoded = homeEasyEncode(&command);
+    // send data
+    sendFrame(encoded, repeat);
+    // release the memory
+    destroyByteBuffer(command);
+    destroyByteBuffer(encoded);
 }
 
 /**
@@ -161,7 +179,7 @@ void sendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsi
  */
 void setHomeEasyTransmittorPin(unsigned char pinNumber)
 {
-	homeEasyPinOut = pinNumber;
+    homeEasyPinOut = pinNumber;
 }
 
 /**
@@ -171,7 +189,7 @@ void setHomeEasyTransmittorPin(unsigned char pinNumber)
  */
 unsigned char getHomeEasyTransmittorPin()
 {
-	return homeEasyPinOut;
+    return homeEasyPinOut;
 }
 
 /**
@@ -181,7 +199,7 @@ unsigned char getHomeEasyTransmittorPin()
  */
 void setHomeEasyReceptorPin(unsigned char pinNumber)
 {
-	homeEasyPinIn = pinNumber;
+    homeEasyPinIn = pinNumber;
 }
 
 /**
@@ -191,7 +209,7 @@ void setHomeEasyReceptorPin(unsigned char pinNumber)
  */
 unsigned char getHomeEasyReceptorPin()
 {
-	return homeEasyPinIn;
+    return homeEasyPinIn;
 }
 
 /**
@@ -204,7 +222,6 @@ int initIO()
     int status;
     status = wiringPiSetup();
     if (status != -1) {
-        printf("Setting up GPIO\n");
         pinMode(homeEasyPinIn, INPUT);
         pinMode(homeEasyPinOut, OUTPUT);
     } else {
@@ -215,7 +232,7 @@ int initIO()
 
 /**
  * Send a bit to the RF transmitter
- * 
+ *
  * @param bit the bit to transmit (0 | 1 | TRIGGER0 | TRIGGER1 | END_OF_FRAME)
  */
 void sendHomeEasyBit(unsigned char bit)
@@ -229,7 +246,7 @@ void sendHomeEasyBit(unsigned char bit)
 
 /**
  * Send a byte to the RF transmitter
- * 
+ *
  * @param byte the byte to transmit
  */
 void sendHomeEasyByte(unsigned char byte)
@@ -288,7 +305,7 @@ BYTE_BUFFER readData(unsigned long int samples, unsigned int duration)
     struct timeval* start;
     BYTE_BUFFER result;
     unsigned long int i;
-    
+
     result = createByteBuffer();
     result.size = samples;
     result.data = (char*) realloc(result.data, samples);

+ 16 - 8
emit/home_easy.h

@@ -15,36 +15,36 @@
 
 /**
  * Encode bits with HomeEasy encoding (1 => 10, 0 => 01)
- * 
+ *
  * @param buffer the buffuer to encode
- * 
+ *
  * @return new buffer
  * */
 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);
 
 /**
  * Encode a byte according to HomeEasy
- * 
+ *
  * @param byte the byte to encode
- * 
+ *
  * @return the encoded byte
  */
 unsigned short int encodeByte(unsigned char byte);
 
 /**
  * Decode a byte according to HomeEasy
- * 
+ *
  * @param byte the byte to decode
- * 
+ *
  * @return the decoded byte
  */
 unsigned char decodeByte(unsigned short int word);
@@ -70,6 +70,14 @@ BYTE_BUFFER createHomeEasyCommand(unsigned char* id, char section, unsigned char
  */
 void sendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on, unsigned char repeat);
 
+/**
+ * Send n times a data frame
+ *
+ * @param frame the data to send
+ * @param repeat number of repeatition
+ */
+void sendFrame(BYTE_BUFFER frame, unsigned int repeat);
+
 /**
  * Configure the GPIO output pin
  *

+ 7 - 0
hcc/Makefile

@@ -0,0 +1,7 @@
+all: radioEmission
+
+radioEmission: radioEmission.o
+	gcc -o $@ $^ -lwiringPi
+
+%.o: %.cpp
+	gcc -c -o $@ $<

BIN
hcc/radioEmission


+ 197 - 0
hcc/radioEmission.cpp

@@ -0,0 +1,197 @@
+#include <wiringPi.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <time.h>
+#include <stdlib.h>
+#include <sched.h>
+#include <string.h>
+
+/*
+Par Idleman (idleman@idleman.fr - http://blog.idleman.fr)
+Licence : CC by sa
+Toutes question sur le blog ou par mail, possibilité de m'envoyer des bières via le blog
+*/
+
+
+int pin;
+bool bit2[26]={};              // 26 bit Identifiant emetteur
+bool bit2Interruptor[4]={};
+int interruptor;
+int sender;
+char onoff;
+
+
+void scheduler_realtime()
+{
+    struct sched_param p;
+    p.__sched_priority = sched_get_priority_max(SCHED_RR);
+    if (sched_setscheduler( 0, SCHED_RR, &p ) == -1 ) {
+        perror("Failed to switch to realtime scheduler.");
+    }
+}
+
+void scheduler_standard()
+{
+    struct sched_param p;
+    p.__sched_priority = 0;
+    if( sched_setscheduler( 0, SCHED_OTHER, &p ) == -1 ) {
+        perror("Failed to switch to normal scheduler.");
+    }
+}
+
+
+
+//Envois d'une pulsation (passage de l'etat haut a l'etat bas)
+//1 = 310µs haut puis 1340µs bas
+//0 = 310µs haut puis 310µs bas
+void sendBit(bool b) {
+   if (b) {
+       digitalWrite(pin, HIGH);
+       delayMicroseconds(310);   //275 orinally, but tweaked.
+       digitalWrite(pin, LOW);
+       delayMicroseconds(1340);  //1225 orinally, but tweaked.
+   } else {
+       digitalWrite(pin, HIGH);
+       delayMicroseconds(310);   //275 orinally, but tweaked.
+       digitalWrite(pin, LOW);
+       delayMicroseconds(310);   //275 orinally, but tweaked.
+   }
+}
+
+//Calcul le nombre 2^chiffre indiqué, fonction utilisé par itob pour la conversion decimal/binaire
+unsigned long power2(int power)
+{
+    unsigned long integer=1;
+    for (int i=0; i<power; i++){
+        integer*=2;
+    }
+    return integer;
+}
+
+//Convertis un nombre en binaire, nécessite le nombre, et le nombre de bits souhaité en sortie (ici 26)
+// Stocke le résultat dans le tableau global "bit2"
+void itob(unsigned long integer, int length)
+{
+    for (int i=0; i<length; i++){
+        if ((integer / power2(length-1-i))==1) {
+            integer-=power2(length-1-i);
+            bit2[i]=1;
+        } else {
+            bit2[i]=0;
+        }
+    }
+}
+
+void itobInterruptor(unsigned long integer, int length)
+{
+    for (int i=0; i<length; i++) {
+        if ((integer / power2(length-1-i))==1) {
+            integer-=power2(length-1-i);
+            bit2Interruptor[i]=1;
+        } else {
+            bit2Interruptor[i]=0;
+        }
+    }
+}
+
+
+
+
+//Envoie d'une paire de pulsation radio qui definissent 1 bit réel : 0 =01 et 1 =10
+//c'est le codage de manchester qui necessite ce petit bouzin, ceci permet entre autres de dissocier les données des parasites
+void sendPair(bool b) {
+    if(b) {
+        sendBit(true);
+        sendBit(false);
+    } else {
+        sendBit(false);
+        sendBit(true);
+    }
+}
+
+
+//Fonction d'envois du signal
+//recoit en parametre un booleen définissant l'arret ou la marche du matos (true = on, false = off)
+void transmit(int blnOn)
+{
+    int i;
+
+    // Sequence de verrou anoncant le départ du signal au recepeteur
+    digitalWrite(pin, HIGH);
+    delayMicroseconds(275);     // un bit de bruit avant de commencer pour remettre les delais du recepteur a 0
+    digitalWrite(pin, LOW);
+    delayMicroseconds(9900);     // premier verrou de 9900µs
+
+    digitalWrite(pin, HIGH);   // high again
+    delayMicroseconds(275);      // attente de 275µs entre les deux verrous
+    digitalWrite(pin, LOW);    // second verrou de 2675µs
+    delayMicroseconds(2675);
+
+    digitalWrite(pin, HIGH);  // On reviens en état haut pour bien couper les verrous des données
+
+    // Envoie du code emetteur (272946 = 1000010101000110010  en binaire)
+    for(i=0; i<26;i++) {
+        sendPair(bit2[i]);
+    }
+
+    // Envoie du bit définissant si c'est une commande de groupe ou non (26em bit)
+    sendPair(false);
+
+    // Envoie du bit définissant si c'est allumé ou eteint 27em bit)
+    sendPair(blnOn);
+
+    // Envoie des 4 derniers bits, qui représentent le code interrupteur, ici 0 (encode sur 4 bit donc 0000)
+    // nb: sur  les télécommandes officielle chacon, les interrupteurs sont logiquement nommés de 0 à x
+    // interrupteur 1 = 0 (donc 0000) , interrupteur 2 = 1 (1000) , interrupteur 3 = 2 (0100) etc...
+    for(i=0; i<4;i++) {
+        if(bit2Interruptor[i]==0){
+	    sendPair(false);
+        } else {
+	    sendPair(true);
+        }
+    }
+
+    digitalWrite(pin, HIGH);   // coupure données, verrou
+    delayMicroseconds(275);      // attendre 275µs
+    digitalWrite(pin, LOW);    // verrou 2 de 2675µs pour signaler la fermeture du signal
+    delayMicroseconds(2675);
+}
+
+
+
+
+int main (int argc, char** argv)
+{
+    pin = atoi(argv[1]);
+    sender = atoi(argv[2]);
+    interruptor = atoi(argv[3]);
+    onoff = (strcmp(argv[4], "on")==0);
+
+    //Si on ne trouve pas la librairie wiringPI, on arrête l'execution
+    if (wiringPiSetup() == -1) {
+        printf("Librairie Wiring PI introuvable, veuillez lier cette librairie...\n");
+        return -1;
+    }
+
+    pinMode(pin, OUTPUT);
+    printf("Pin GPIO configure en sortie\n");
+
+    itob(sender,26);            // convertion du code de l'emetteur (ici 8217034) en code binaire
+    itobInterruptor(interruptor,4);
+
+    scheduler_realtime();
+    if(onoff){
+        printf("envoi du signal ON\n");
+	for(int i=0;i<5;i++){
+             transmit(true);            // envoyer ON
+	}
+    } else {
+        printf("envoi du signal OFF\n");
+	for(int i=0;i<5;i++){
+             transmit(false);           // envoyer OFF
+	}
+    }
+
+    scheduler_standard();
+}
+