int ProtonProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // The Proton protocol contains an 8 bit address and an 8 bit command, // in LSB order. Between these two is a gap made up of a 500 usec pulse // and a 4000 usec space. // - "preData" should contain the address. // - "firstCode" should contain the command. duration += pushReverseBits(preData, led); led.addPair(500, 4000); duration += 4500; duration += pushReverseBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int KathreinProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // Kathrein protocol has four bits of address and eight bits of command. // As in NEC protocol, the address and command are complemented. // - "preData" should contain the 4-bit address // - "firstCode" should contain the 8-bit command duration += pushReverseBits(preData, led); duration += pushInvertedReverseBits(preData, led); duration += pushReverseBits(pkb.firstCode, led); duration += pushInvertedReverseBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int DenonProtocol::generateRepeatCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // The address should be 5 bits long, and the control data 8 bits. // For the repeat, the control data is inverted. // Both are sent in LSB order. duration += pushReverseBits(pkb.firstCode, led); duration += pushInvertedReverseBits(pkb.secondCode, led); // Next, two One bits are sent (the inverse of the normal command): led.addPair(onePulse, oneSpace); duration += onePulse + oneSpace; led.addPair(onePulse, oneSpace); duration += onePulse + oneSpace; // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int DaewooProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // The address data: duration += pushReverseBits(preData, led); // The Daewoo mid-train marker: led.addPair(midPulse, midSpace); duration += (midPulse + midSpace); // The command data: duration += pushReverseBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int RECS80Protocol::generateCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // Next, a toggle bit: if (keypressCount % 2) { led.addPair(zeroPulse, zeroSpace); duration += (zeroPulse + zeroSpace); } else { led.addPair(onePulse, oneSpace); duration += (onePulse + oneSpace); } // Next, the device code and command code. The device code is three // bits long; the command code is six bits long. Both are sent in MSB order. duration += pushBits(preData, led); duration += pushBits(pkb.firstCode, led); // Finally, add the trailing pulse: led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int AiwaProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // From the information I've got, the "address" portion of the Aiwa protocol // might be split into 8-bit device and 5-bit subdevice subsections, but // for now, I'm just lumping both into a single 13-bit address value. // The command is an 8-bit value. // As with NEC, the address is sent LSB first, then inverted LSB first, // then the command is sent LSB first, then inverted LSB first. duration += pushReverseBits(preData, led); duration += pushInvertedReverseBits(preData, led); duration += pushReverseBits(pkb.firstCode, led); duration += pushInvertedReverseBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int XMPProtocol::generateRepeatCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // an XMP repeat frame is identical to the start frame, except that // the "toggle" value is now 8. duration += pushHalfByte(subDeviceOne, led); duration += pushHalfByte(calculateChecksumOne(), led); duration += pushHalfByte(subDeviceTwo, led); duration += pushHalfByte(0xF, led); duration += pushFullByte(oemCode, led); duration += pushFullByte(deviceCode, led); led.addPair(210, 13800); duration += 14010; duration += pushHalfByte(subDeviceOne, led); duration += pushHalfByte( calculateChecksumTwo(0x8, pkb.firstCode, pkb.secondCode), led); duration += pushHalfByte(0x8, led); duration += pushHalfByte(subDeviceTwo, led); duration += pushBits(pkb.firstCode, led); duration += pushBits(pkb.secondCode, led); // Finally add the "trail": led.addSingle(210); duration += 210; return duration; }
int PaceProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // Next, the toggle bit: if (keypressCount % 2) { led.addPair(onePulse, oneSpace); duration += (onePulse + oneSpace); } else { led.addPair(zeroPulse, zeroSpace); duration += (zeroPulse + zeroSpace); } // Next, three bits of pre-data: duration += pushBits(preData, led); // Next, six bits of data: duration += pushBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int XMPProtocol::generateFinalCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // an XMP final frame is basically a pair of repeat frames, but the // gap between them is only 13800 usec, and the "toggle" value of the // second frame is 9. duration += pushHalfByte(subDeviceOne, led); duration += pushHalfByte(calculateChecksumOne(), led); duration += pushHalfByte(subDeviceTwo, led); duration += pushHalfByte(0xF, led); duration += pushFullByte(oemCode, led); duration += pushFullByte(deviceCode, led); led.addPair(210, 13800); duration += 14010; duration += pushHalfByte(subDeviceOne, led); duration += pushHalfByte( calculateChecksumTwo(0x8, pkb.firstCode, pkb.secondCode), led); duration += pushHalfByte(0x8, led); duration += pushHalfByte(subDeviceTwo, led); duration += pushBits(pkb.firstCode, led); duration += pushBits(pkb.secondCode, led); led.addPair(210, 13800); duration += 14010; duration += pushHalfByte(subDeviceOne, led); duration += pushHalfByte(calculateChecksumOne(), led); duration += pushHalfByte(subDeviceTwo, led); duration += pushHalfByte(0xF, led); duration += pushFullByte(oemCode, led); duration += pushFullByte(deviceCode, led); led.addPair(210, 13800); duration += 14010; duration += pushHalfByte(subDeviceOne, led); duration += pushHalfByte( calculateChecksumTwo(0x9, pkb.firstCode, pkb.secondCode), led); duration += pushHalfByte(0x9, led); duration += pushHalfByte(subDeviceTwo, led); duration += pushBits(pkb.firstCode, led); duration += pushBits(pkb.secondCode, led); // Finally add the "trail": led.addSingle(210); duration += 210; return duration; }
void SamsungACProtocol::generateTimerCommand( PIRInfraredLED &led) { // First, the "header" pulse: led.addPair(headerPulse, headerSpace); // Next, the "address" information (12 bits): pushReverseBits(preData, led); // The checksum (4 bits): CommandSequence checksum; calculateTimerChecksum(checksum); pushReverseBits(checksum, led); // Push an 0xF to indicate this is a timer command. pushBits(timerHeader, led); // if this is an off timer, push the time, otherwise 0: if (timerCommandType == 0x4) { pushReverseBits(timerMinutes, led); pushReverseBits(timerHours, led); } else { pushBits(emptyTimer, led); } // if this is an on timer, push the time, otherwise 0: if (timerCommandType == 0x2) { pushReverseBits(timerMinutes, led); pushReverseBits(timerHours, led); } else { pushBits(emptyTimer, led); } // This is a hack to add in 4 bits of 0: pushBits(fourBitZero, led); // Push the timer command type: pushReverseBits(timerOption, led); // Finish off the command: pushBits(timerFooter, led); // Add the "trail": led.addSingle(trailerPulse); }
int XMPProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // XMP frames have the following structure: // 1) The first 4 bits of the "sub-device" code // 2) A four-bit checksum value // 3) The second 4 bits of the "sub-device" code // 4) The four-bit value 0xF // 5) An eight-bit OEM code (normally 0x44) // 6) An eight-bit device code // 7) a 210 usec pulse, 13800 usec space divider // 8) The first 4 bits of the "sub-device" code (again) // 9) Another four-bit checksum value // 10) The four-bit toggle value // 11) The second 4 bits of the "sub-device" code (again) // 12) A pair of 8-bit command codes (often one of them will be 0) // All of this is sent in MSB order. // The checksums are constructed by adding up all the half-bytes in // their side of the frame to 15, taking the complement, and modding the // result with 16. duration += pushHalfByte(subDeviceOne, led); duration += pushHalfByte(calculateChecksumOne(), led); duration += pushHalfByte(subDeviceTwo, led); duration += pushHalfByte(0xF, led); duration += pushFullByte(oemCode, led); duration += pushFullByte(deviceCode, led); led.addPair(210, 13800); duration += 14010; duration += pushHalfByte(subDeviceOne, led); duration += pushHalfByte( calculateChecksumTwo(0x0, pkb.firstCode, pkb.secondCode), led); duration += pushHalfByte(0x0, led); duration += pushHalfByte(subDeviceTwo, led); duration += pushBits(pkb.firstCode, led); duration += pushBits(pkb.secondCode, led); // Finally add the "trail": led.addSingle(210); duration += 210; return duration; }
int GIProtocol::generateRepeatCommand( PIRInfraredLED &led) { int duration = 0; // Add the repeat pulse: led.addPair(repeatPulse, repeatSpace); duration += (repeatPulse + repeatSpace); // Add the trailer: led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int MitsubishiProtocol::generateCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // For this protocol, the device code and command code are both 8 bits, // and sent in LSB order: duration += pushReverseBits(preData, led); duration += pushReverseBits(pkb.firstCode, led); // Finally add the "trail" bit: led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int NECXProtocol::generateRepeatCommand( PIRInfraredLED &led) { int duration = 0; // Start with the header: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // Add a "1": led.addPair(onePulse, oneSpace); duration += (onePulse + oneSpace); // Add the trailer: led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int KathreinProtocol::generateRepeatCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // The Kathrein repeat block contains the 8-bit command and nothing else: duration += pushReverseBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
void SamsungACProtocol::generateCommand( PIRInfraredLED &led) { // First, the "header" pulse: led.addPair(headerPulse, headerSpace); // Next, the "address" information (12 bits): pushReverseBits(preData, led); // Now, the fun part. We'll need to construct a massive command, containing // all the state information for the air conditioner. // First, calculate and push the checksum (4 bits): CommandSequence checksum; calculateChecksum(checksum); pushReverseBits(checksum, led); // Next, push the swing mode (8 bits): pushReverseBits(swing, led); // Next, the turbo mode (8 bits): pushReverseBits(turbo, led); // Next, the temperature (8 bits): pushReverseBits(temperature, led); // Next, the fan (4 bits): pushReverseBits(fan, led); // Next, the mode (4 bits): pushReverseBits(mode, led); // Next, "air clean" (4 bits): pushReverseBits(airclean, led); // Next, power (4 bits): pushReverseBits(power, led); // Finally add the "trail": led.addSingle(trailerPulse); }
int NECProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // Now, check the encoding format: if (isExtendedNEC) { // In extended NEC, the address has been extended to 16 bits, and is only // sent once. The command portion stays the same. // - "preData" should contain 16-bit value // - "bits" should contain 8-bit value duration += pushReverseBits(preData, led); duration += pushReverseBits(pkb.firstCode, led); duration += pushInvertedReverseBits(pkb.firstCode, led); } else { // Standard NEC is made up of an eight-bit "address" and an eight-bit // "command". First the address bits are sent (in reverse order), then // the address bits are inverted and sent again (in reverse order). // Next, we do the same to the command bits. // - "preData" should contain 8-bit value // - "bits" should contain 8-bit value duration += pushReverseBits(preData, led); duration += pushInvertedReverseBits(preData, led); duration += pushReverseBits(pkb.firstCode, led); duration += pushInvertedReverseBits(pkb.firstCode, led); } // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int PanasonicProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the header pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // Similar to the "Kaseikyo" protocol, this protocol is 48 bits long. // In this case, the first 16 bits are a fixed value (defining the // manufacturer?). Next comes eight bits for the "device", eight more // bits for the "subdevice", and then eight bits for the "command". // Finally, the last eight bits are a checksum generated by x-oring the // device, subdevice, and command bytes. // The 16 manufacturer code bits: duration += pushReverseBits(preData, led); // The eight device bits: duration += pushReverseBits(pkb.firstCode, led); // The eight subdevice bits: duration += pushReverseBits(pkb.secondCode, led); // The eight command bits: duration += pushReverseBits(pkb.thirdCode, led); // Finally, the checksum: CommandSequence checksum; generateChecksum(pkb.firstCode, pkb.secondCode, pkb.thirdCode, checksum); duration += pushReverseBits(checksum, led); // Add the trailer pulse: led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int RCAProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // Now, set up the address and command bits: duration += pushBits(preData, led); duration += pushBits(pkb.firstCode, led); duration += pushInvertedBits(preData, led); duration += pushInvertedBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int BoseProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // The Bose protocol uses 1/2 of the NEC protocol; it has the command // portion, but no device address portion. So, we only need to reverse // the command, then invert and reverse the command: duration += pushReverseBits(pkb.firstCode, led); duration += pushInvertedReverseBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int DenonProtocol::generateCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // The address should be 5 bits long, and the control data 8 bits. // Both are sent in LSB order. duration += pushReverseBits(pkb.firstCode, led); duration += pushReverseBits(pkb.secondCode, led); // Next, two Zero bits are sent: led.addPair(zeroPulse, zeroSpace); duration += zeroPulse + zeroSpace; led.addPair(zeroPulse, zeroSpace); duration += zeroPulse + zeroSpace; // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int NECXProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // In NECX, the address is 16 bits, and is only sent once. The command // portion is 8 bits, and an inverted copy is sent. // - "preData" should contain 16-bit value // - "bits" should contain 8-bit value duration += pushReverseBits(preData, led); duration += pushReverseBits(pkb.firstCode, led); duration += pushInvertedReverseBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int GIProtocol::generateStandardCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // First, the "header" pulse: led.addPair(headerPulse, headerSpace); duration += (headerPulse + headerSpace); // The GI protocol consists of a 4-bit device code and an 8-bit command. // These are sent in reverse order. Finally, a checksum is added at the // end. I am lacking enough information to calculate the checksum right // now, so I'm going to dump all 16 bits into the "firstCode" in MSB // order, and reverse them here: duration += pushReverseBits(pkb.firstCode, led); // Finally add the "trail": led.addSingle(trailerPulse); duration += trailerPulse; return duration; }
int CanalSatProtocol::pushBit( bool bitValue, PIRInfraredLED &led) { unsigned int duration = 0; if (bitValue) { // This is a "1", so first pulse, then space: if (bufferContainsPulse) { // Merge our pulse with preceding pulse, and add it to device: led.addSingle(buffer + biphaseUnit); duration += (buffer + biphaseUnit); buffer = 0; bufferContainsPulse = false; } else { // Flush out the buffer: if (bufferContainsSpace) { led.addSingle(buffer); duration += buffer; buffer = 0; bufferContainsSpace = false; } // Push our pulse into the device: led.addSingle(biphaseUnit); duration += biphaseUnit; } // Finally, push our space into the buffer: buffer = biphaseUnit; bufferContainsSpace = true; } else { // This is a "0", so first space, then pulse. if (bufferContainsSpace) { // Merge our space with the preceding space, and add it to device: led.addSingle(buffer + biphaseUnit); duration += (buffer + biphaseUnit); buffer = 0; bufferContainsSpace = false; } else { // Flush out the buffer: if (bufferContainsPulse) { led.addSingle(buffer); duration += buffer; buffer = 0; bufferContainsPulse = false; } // Add a space: led.addSingle(biphaseUnit); duration += biphaseUnit; } // Finally, push a pulse into the buffer: buffer = biphaseUnit; bufferContainsPulse = true; } return duration; }
int IRobotProtocol::generateCommand( const PIRKeyBits &pkb, PIRInfraredLED &led) { int duration = 0; // The protocol seems to involve 8 command bits, a 16000 usec pause, and // the same 8 bits repeated again. So, we need to tack a 16000 usec // space on at the end of the first 8 bits, and just drop the last space // definition at the end of the second 8 bits: // The first 7 bits: int index = 0; CommandSequence::const_iterator i = pkb.firstCode.begin(); while ((index < 7) && (i != pkb.firstCode.end())) { if (*i) { led.addPair(onePulse, oneSpace); duration += onePulse + oneSpace; } else { led.addPair(zeroPulse, zeroSpace); duration += zeroPulse + zeroSpace; } ++index; ++i; } // Eighth bit with extra space at the end: if (i != pkb.firstCode.end()) { if (*i) { led.addPair(onePulse, oneSpace + 16000); duration += onePulse + oneSpace + 16000; } else { led.addPair(zeroPulse, zeroSpace + 16000); duration += zeroPulse + zeroSpace + 16000; } } // The following seven bits: index = 0; i = pkb.firstCode.begin(); while ((index < 7) && (i != pkb.firstCode.end())) { if (*i) { led.addPair(onePulse, oneSpace); duration += onePulse + oneSpace; } else { led.addPair(zeroPulse, zeroSpace); duration += zeroPulse + zeroSpace; } ++index; ++i; } // The last half-bit: if (i != pkb.firstCode.end()) { if (*i) { led.addSingle(onePulse); duration += onePulse; } else { led.addSingle(zeroPulse); duration += zeroPulse; } } return duration; }