unsigned int XMPProtocol::calculateChecksumTwo( unsigned int toggle, const CommandSequence &firstCode, const CommandSequence &secondCode) { // Start with the value 0xF: unsigned int total = 0xF; // Add the other half-bytes in the second part of the frame: total += subDeviceOne; total += toggle; total += subDeviceTwo; unsigned int codeValue = 0; CommandSequence::const_iterator i = firstCode.begin(); while (i != firstCode.end()) { // Shift codeValue over and add the bit: codeValue = codeValue << 1; codeValue += *i; ++i; } total += codeValue >> 4; total += codeValue & 0xF; codeValue = 0; i = secondCode.begin(); while (i != secondCode.end()) { codeValue = codeValue << 1; codeValue += *i; ++i; } total += codeValue >> 4; total += codeValue & 0xF; // Next, invert: total = -total; // Finally, mod 0x10: total = total % 0x10; return total; }
void PanasonicProtocol::generateChecksum( const CommandSequence &device, const CommandSequence &subdevice, const CommandSequence &command, CommandSequence &checksum) { checksum.clear(); // probably unnecessary sanity check. CommandSequence::const_iterator diter = device.begin(); CommandSequence::const_iterator siter = subdevice.begin(); CommandSequence::const_iterator citer = command.begin(); while (diter !=device.end() && siter != subdevice.end() && citer != command.end()) { checksum.push_back(*diter ^ *siter ^ *citer); ++diter; ++siter; ++citer; } }
int XMPProtocol::pushBits( const CommandSequence &bits, PIRInfraredLED &led) { unsigned int duration = 0; // We can only sent 4-bit values in XMP, so need to collect bits up into // bundles of 4: unsigned int bitsValue = 0; int count = 0; CommandSequence::const_iterator i = bits.begin(); while (i != bits.end()) { if (count < 4) { bitsValue = bitsValue << 1; bitsValue += *i; ++count; } else { led.addPair(210, 760 + (136 * bitsValue)); duration += 970 + (136 * bitsValue); count = 1; bitsValue = *i; } ++i; } if (count == 4) { led.addPair(210, 760 + (136 * bitsValue)); duration += 970 + (136 * bitsValue); } return duration; }