Http Server
Dependencies: EthernetNetIf HTTPServer RPCInterface mbed
Fork of WeatherRx by
x10rf.cpp@0:7f9517ce9e71, 2011-08-27 (annotated)
- Committer:
- lotfi_baghli
- Date:
- Sat Aug 27 16:45:11 2011 +0000
- Revision:
- 0:7f9517ce9e71
V0.21
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lotfi_baghli | 0:7f9517ce9e71 | 1 | // Interface Lib to X10 RF transmiter |
lotfi_baghli | 0:7f9517ce9e71 | 2 | |
lotfi_baghli | 0:7f9517ce9e71 | 3 | #include "mbed.h" |
lotfi_baghli | 0:7f9517ce9e71 | 4 | |
lotfi_baghli | 0:7f9517ce9e71 | 5 | DigitalOut led_2(LED2, "led2"); |
lotfi_baghli | 0:7f9517ce9e71 | 6 | DigitalOut led_3(LED3, "led3"); |
lotfi_baghli | 0:7f9517ce9e71 | 7 | |
lotfi_baghli | 0:7f9517ce9e71 | 8 | DigitalOut RF_TX(p19); |
lotfi_baghli | 0:7f9517ce9e71 | 9 | DigitalOut RF_Alim(p18); |
lotfi_baghli | 0:7f9517ce9e71 | 10 | |
lotfi_baghli | 0:7f9517ce9e71 | 11 | void SendX10RF_bit(unsigned int databit); |
lotfi_baghli | 0:7f9517ce9e71 | 12 | void SendX10byte(unsigned int data8); |
lotfi_baghli | 0:7f9517ce9e71 | 13 | void SendX10Cmd(unsigned int data); |
lotfi_baghli | 0:7f9517ce9e71 | 14 | void SendX10RF(); |
lotfi_baghli | 0:7f9517ce9e71 | 15 | |
lotfi_baghli | 0:7f9517ce9e71 | 16 | |
lotfi_baghli | 0:7f9517ce9e71 | 17 | //----------------------------------------------------------------------------- |
lotfi_baghli | 0:7f9517ce9e71 | 18 | // http://idobartana.com/hakb/x10rf.htm |
lotfi_baghli | 0:7f9517ce9e71 | 19 | // ftp://ftp.x10.com/pub/manuals/cm17a_protocol.txt |
lotfi_baghli | 0:7f9517ce9e71 | 20 | unsigned int EncodeX10rf(char houseCode, int numberCode, int action) |
lotfi_baghli | 0:7f9517ce9e71 | 21 | {// action : 1 : On, 0 : Off, 2 : BRIGHT , 3 : DIM |
lotfi_baghli | 0:7f9517ce9e71 | 22 | unsigned int order, add; |
lotfi_baghli | 0:7f9517ce9e71 | 23 | switch (houseCode) |
lotfi_baghli | 0:7f9517ce9e71 | 24 | { |
lotfi_baghli | 0:7f9517ce9e71 | 25 | case 'A' : order= 0x6000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 26 | case 'B' : order= 0xE000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 27 | case 'C' : order= 0x2000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 28 | case 'D' : order= 0xA000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 29 | case 'E' : order= 0x1000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 30 | case 'F' : order= 0x9000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 31 | case 'G' : order= 0x5000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 32 | case 'H' : order= 0xD000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 33 | case 'I' : order= 0x7000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 34 | case 'J' : order= 0xF000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 35 | case 'K' : order= 0x3000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 36 | case 'L' : order= 0xB000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 37 | case 'M' : order= 0x0000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 38 | case 'N' : order= 0x8000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 39 | case 'O' : order= 0x4000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 40 | case 'P' : order= 0xC000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 41 | } |
lotfi_baghli | 0:7f9517ce9e71 | 42 | switch (numberCode) |
lotfi_baghli | 0:7f9517ce9e71 | 43 | { |
lotfi_baghli | 0:7f9517ce9e71 | 44 | case 1 : add= 0x0000; break; |
lotfi_baghli | 0:7f9517ce9e71 | 45 | case 2 : add= 0x0010; break; |
lotfi_baghli | 0:7f9517ce9e71 | 46 | case 3 : add= 0x0008; break; |
lotfi_baghli | 0:7f9517ce9e71 | 47 | case 4 : add= 0x0018; break; |
lotfi_baghli | 0:7f9517ce9e71 | 48 | case 5 : add= 0x0040; break; |
lotfi_baghli | 0:7f9517ce9e71 | 49 | case 6 : add= 0x0050; break; |
lotfi_baghli | 0:7f9517ce9e71 | 50 | case 7 : add= 0x0048; break; |
lotfi_baghli | 0:7f9517ce9e71 | 51 | case 8 : add= 0x0058; break; |
lotfi_baghli | 0:7f9517ce9e71 | 52 | case 9 : add= 0x0400; break; |
lotfi_baghli | 0:7f9517ce9e71 | 53 | case 10: add= 0x0410; break; |
lotfi_baghli | 0:7f9517ce9e71 | 54 | case 11: add= 0x0408; break; |
lotfi_baghli | 0:7f9517ce9e71 | 55 | case 12: add= 0x0418; break; |
lotfi_baghli | 0:7f9517ce9e71 | 56 | case 13: add= 0x0440; break; |
lotfi_baghli | 0:7f9517ce9e71 | 57 | case 14: add= 0x0450; break; |
lotfi_baghli | 0:7f9517ce9e71 | 58 | case 15: add= 0x0448; break; |
lotfi_baghli | 0:7f9517ce9e71 | 59 | case 16: add= 0x0458; break; |
lotfi_baghli | 0:7f9517ce9e71 | 60 | } |
lotfi_baghli | 0:7f9517ce9e71 | 61 | order |= add; |
lotfi_baghli | 0:7f9517ce9e71 | 62 | if (action==0) order |= 0x0020; |
lotfi_baghli | 0:7f9517ce9e71 | 63 | return order; |
lotfi_baghli | 0:7f9517ce9e71 | 64 | } |
lotfi_baghli | 0:7f9517ce9e71 | 65 | //----------------------------------------------------------------------------- |
lotfi_baghli | 0:7f9517ce9e71 | 66 | void SendX10rf(char houseCode, int numberCode, int action) |
lotfi_baghli | 0:7f9517ce9e71 | 67 | { // action : 1 : On, 0 : Off, 2 : BRIGHT , 3 : DIM |
lotfi_baghli | 0:7f9517ce9e71 | 68 | printf( "h=%c U=%d R=%d Order=%X\r\n", houseCode, numberCode, action, EncodeX10rf(houseCode, numberCode, action)); |
lotfi_baghli | 0:7f9517ce9e71 | 69 | // SendX10Cmd(0x6010); // A2 ON |
lotfi_baghli | 0:7f9517ce9e71 | 70 | // SendX10Cmd(0x6000); // A1 ON |
lotfi_baghli | 0:7f9517ce9e71 | 71 | SendX10Cmd( EncodeX10rf(houseCode, numberCode, action)); |
lotfi_baghli | 0:7f9517ce9e71 | 72 | } |
lotfi_baghli | 0:7f9517ce9e71 | 73 | //----------------------------------------------------------------------------- |
lotfi_baghli | 0:7f9517ce9e71 | 74 | void SendX10RF_bit(unsigned int databit) |
lotfi_baghli | 0:7f9517ce9e71 | 75 | { |
lotfi_baghli | 0:7f9517ce9e71 | 76 | // envoi un 1 |
lotfi_baghli | 0:7f9517ce9e71 | 77 | RF_TX=1; |
lotfi_baghli | 0:7f9517ce9e71 | 78 | wait_us(560); // 0.56 ms |
lotfi_baghli | 0:7f9517ce9e71 | 79 | RF_TX=0; |
lotfi_baghli | 0:7f9517ce9e71 | 80 | wait_us(560); // 0.56 ms |
lotfi_baghli | 0:7f9517ce9e71 | 81 | // si c'est un 0 |
lotfi_baghli | 0:7f9517ce9e71 | 82 | if (!databit) wait_us(1120); // 0.56*2 = 1.12 ms si un zero |
lotfi_baghli | 0:7f9517ce9e71 | 83 | } |
lotfi_baghli | 0:7f9517ce9e71 | 84 | //----------------------------------------------------------------------------- |
lotfi_baghli | 0:7f9517ce9e71 | 85 | void SendX10byte(unsigned int data8) |
lotfi_baghli | 0:7f9517ce9e71 | 86 | { |
lotfi_baghli | 0:7f9517ce9e71 | 87 | unsigned int j, k; |
lotfi_baghli | 0:7f9517ce9e71 | 88 | for (j=0; j<8; j++) |
lotfi_baghli | 0:7f9517ce9e71 | 89 | { |
lotfi_baghli | 0:7f9517ce9e71 | 90 | k=(data8 & 0x0080 )==0x0080; |
lotfi_baghli | 0:7f9517ce9e71 | 91 | SendX10RF_bit(k); |
lotfi_baghli | 0:7f9517ce9e71 | 92 | data8=data8 << 1; |
lotfi_baghli | 0:7f9517ce9e71 | 93 | } |
lotfi_baghli | 0:7f9517ce9e71 | 94 | } |
lotfi_baghli | 0:7f9517ce9e71 | 95 | //----------------------------------------------------------------------------- |
lotfi_baghli | 0:7f9517ce9e71 | 96 | void SendX10Cmd(unsigned int data) |
lotfi_baghli | 0:7f9517ce9e71 | 97 | { |
lotfi_baghli | 0:7f9517ce9e71 | 98 | unsigned int Cmd8; |
lotfi_baghli | 0:7f9517ce9e71 | 99 | RF_Alim=1; // Alimente le transmetteur RE8=ON |
lotfi_baghli | 0:7f9517ce9e71 | 100 | // wait_ms(20); // >20 ms |
lotfi_baghli | 0:7f9517ce9e71 | 101 | wait_ms(10); // >10 ms |
lotfi_baghli | 0:7f9517ce9e71 | 102 | wait_ms(10); // >10 ms |
lotfi_baghli | 0:7f9517ce9e71 | 103 | // en-tête |
lotfi_baghli | 0:7f9517ce9e71 | 104 | RF_TX=1; |
lotfi_baghli | 0:7f9517ce9e71 | 105 | wait_us(8960); // 8.96 ms |
lotfi_baghli | 0:7f9517ce9e71 | 106 | RF_TX=0; |
lotfi_baghli | 0:7f9517ce9e71 | 107 | wait_us(4500); // 4.5 ms |
lotfi_baghli | 0:7f9517ce9e71 | 108 | Cmd8=data>>8; // send les Hi |
lotfi_baghli | 0:7f9517ce9e71 | 109 | SendX10byte(~Cmd8); |
lotfi_baghli | 0:7f9517ce9e71 | 110 | SendX10byte(Cmd8); |
lotfi_baghli | 0:7f9517ce9e71 | 111 | Cmd8=(data) & 0xFF; // send les Low |
lotfi_baghli | 0:7f9517ce9e71 | 112 | SendX10byte(~Cmd8); |
lotfi_baghli | 0:7f9517ce9e71 | 113 | SendX10byte(Cmd8); |
lotfi_baghli | 0:7f9517ce9e71 | 114 | SendX10RF_bit(1); // 1 à la fin ?? |
lotfi_baghli | 0:7f9517ce9e71 | 115 | wait_us(1120); // 1.12 ms |
lotfi_baghli | 0:7f9517ce9e71 | 116 | RF_Alim=0; // Eteint transmetteur RE8=OFF |
lotfi_baghli | 0:7f9517ce9e71 | 117 | } |
lotfi_baghli | 0:7f9517ce9e71 | 118 | //----------------------------------------------------------------------------- |
lotfi_baghli | 0:7f9517ce9e71 | 119 | void SendX10RF() |
lotfi_baghli | 0:7f9517ce9e71 | 120 | { |
lotfi_baghli | 0:7f9517ce9e71 | 121 | // SendX10Cmd(0x6000); // A1 ON |
lotfi_baghli | 0:7f9517ce9e71 | 122 | // SendX10Cmd(0x6020); // A1 OFF |
lotfi_baghli | 0:7f9517ce9e71 | 123 | SendX10Cmd(0x6010); // A2 ON |
lotfi_baghli | 0:7f9517ce9e71 | 124 | // SendX10Cmd(0x6030); // A2 OFF |
lotfi_baghli | 0:7f9517ce9e71 | 125 | // SendX10Cmd(0x6090); // A2 DIM+ |
lotfi_baghli | 0:7f9517ce9e71 | 126 | // SendX10Cmd(0x60B0); // A2 DIM- |
lotfi_baghli | 0:7f9517ce9e71 | 127 | |
lotfi_baghli | 0:7f9517ce9e71 | 128 | //http://idobartana.com/hakb/x10rf.htm |
lotfi_baghli | 0:7f9517ce9e71 | 129 | //10101111 11011101 01010101 11011111 10101101 01010101 <-A1 OFF cmd (as seen on RF, RIGHT bit first !) |
lotfi_baghli | 0:7f9517ce9e71 | 130 | //00000100 11111011 00000110 11111001 A1 OFF (as RIGHT bit first !) |
lotfi_baghli | 0:7f9517ce9e71 | 131 | // byte 1 byte 2 byte 3 byte 4 |
lotfi_baghli | 0:7f9517ce9e71 | 132 | //bit function |
lotfi_baghli | 0:7f9517ce9e71 | 133 | //0 always 0 |
lotfi_baghli | 0:7f9517ce9e71 | 134 | //1 always 0 |
lotfi_baghli | 0:7f9517ce9e71 | 135 | //2 always 0 |
lotfi_baghli | 0:7f9517ce9e71 | 136 | //3 bit B1 of unit number |
lotfi_baghli | 0:7f9517ce9e71 | 137 | //4 bit B0 of unit number |
lotfi_baghli | 0:7f9517ce9e71 | 138 | //5 1 for OFF command. DIM B2 ON/OFF B0 B1 <--(unit number -1= 0bB2B1B0 ) |
lotfi_baghli | 0:7f9517ce9e71 | 139 | //6 bit B2 of unit number ------------------>| |
lotfi_baghli | 0:7f9517ce9e71 | 140 | //7 1 for DIM (if bit 5=1) or BRIGHT (if bit 5=0) command |
lotfi_baghli | 0:7f9517ce9e71 | 141 | |
lotfi_baghli | 0:7f9517ce9e71 | 142 | // à l'envers aussi mais bytes inversées |
lotfi_baghli | 0:7f9517ce9e71 | 143 | //A- 00001 ON |
lotfi_baghli | 0:7f9517ce9e71 | 144 | //00032: 11111001 00000110 11111111 00000000 0x6000 |
lotfi_baghli | 0:7f9517ce9e71 | 145 | //A- 00001 OFF |
lotfi_baghli | 0:7f9517ce9e71 | 146 | //00032: 11111001 00000110 11111011 00000100 0x6020 |
lotfi_baghli | 0:7f9517ce9e71 | 147 | //A- 00002 ON |
lotfi_baghli | 0:7f9517ce9e71 | 148 | //00032: 11111001 00000110 11110111 00001000 0x6080 |
lotfi_baghli | 0:7f9517ce9e71 | 149 | //A- 00002 OFF |
lotfi_baghli | 0:7f9517ce9e71 | 150 | //00032: 11111001 00000110 11110011 00001100 0x60C0 |
lotfi_baghli | 0:7f9517ce9e71 | 151 | //A- 00002 DIM+ |
lotfi_baghli | 0:7f9517ce9e71 | 152 | //00032: 11111001 00000110 11110111 00001000 0x6090 |
lotfi_baghli | 0:7f9517ce9e71 | 153 | //http://camelspit.org/modified-x10-rf-transmitter/ |
lotfi_baghli | 0:7f9517ce9e71 | 154 | } |
lotfi_baghli | 0:7f9517ce9e71 | 155 | //--------------------------------------------------------------------- |