Exemple #1
0
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;
}
Exemple #2
0
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;
}
Exemple #3
0
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;
}
Exemple #4
0
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;
}
int AirtechProtocol::generateCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // In the Airtech protocol, we have seven bits of device data, and five
  // bits of command data.  They are simply sent together in MSB format.
  duration += pushBits(preData, led);
  duration += pushBits(pkb.firstCode, led);

  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);
}
Exemple #7
0
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;
}
Exemple #8
0
void TorMorse::setupSOSCode()
{
  // We'll do the standard SOS, followed by a standard 7-dot word space.

  // S: Three dots, plus char space:
  sosCodeBits.push_back(true);
  sosCodeBits.push_back(false);
  sosCodeBits.push_back(true);
  sosCodeBits.push_back(false);
  sosCodeBits.push_back(true);
  pushBits(sosCodeBits, false, 4);

  // O: Three dashes, plus char space:
  pushBits(sosCodeBits, true, 3);
  sosCodeBits.push_back(false);
  pushBits(sosCodeBits, true, 3);
  sosCodeBits.push_back(false);
  pushBits(sosCodeBits, true, 3);
  pushBits(sosCodeBits, false, 4);

  // S: Three dots, plus word space:
  sosCodeBits.push_back(true);
  sosCodeBits.push_back(false);
  sosCodeBits.push_back(true);
  sosCodeBits.push_back(false);
  sosCodeBits.push_back(true);
  pushBits(sosCodeBits, false, 8);
}
Exemple #9
0
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;
}
Exemple #10
0
void TorMorse::setupECode()
{
  // We'll do an "E" (single dot), followed by 7-dot word space:
  eCodeBits.push_back(true);
  pushBits(eCodeBits, false, 8);
}
Exemple #11
0
void TorMorse::fourUnitGap()
{
  pushBits(morseCodeBits, false, 4);
}
Exemple #12
0
void TorMorse::threeUnitGap()
{
  pushBits(morseCodeBits, false, 3);
}
Exemple #13
0
void TorMorse::dash()
{
  pushBits(morseCodeBits, true, 3);
  morseCodeBits.push_back(false);
}
Exemple #14
0
void CanalSatProtocol::startSendingCommand(
  unsigned int threadableID,
  PIRKeyName command)
{
  try
  {
    if (threadableID != id) return;

    clearRepeatFlag();

    KeycodeCollection::const_iterator i = keycodes.find(command);

    // Sanity check, make sure command exists first:
    if (i == keycodes.end())
    {
      QMutexLocker cifLocker(&commandIFMutex);
      commandInFlight = false;
      return;  // should send an error message here!!!
    }

    // Create object to communicate with device driver:
    PIRInfraredLED led(carrierFrequency, dutyCycle);

    int repeatCount = 0;
    int commandDuration = 0;
    while (repeatCount < MAX_REPEAT_COUNT)
    {
      // Construct the CanalSat command string.

      commandDuration += pushBits((*i).second, repeatCount, led);

      // Clear out the buffer, if necessary:
      if (buffer)
      {
        led.addSingle(buffer);
        commandDuration += buffer;

        buffer = 0;
        bufferContainsSpace = false;
        bufferContainsPulse = false;
      }

      // Send the command:
      led.sendCommandToDevice();

      // Sleep for the prescribed amount of time:
      sleepUntilRepeat(commandDuration);

      // Have we been told to stop?
      if (checkRepeatFlag())
      {
        break;
      }

      ++repeatCount;
    }

    QMutexLocker cifLocker(&commandIFMutex);
    commandInFlight = false;
  }
  catch (PIRException e)
  {
    emit commandFailed(e.getError().c_str());
  }
  catch (...)
  {
    emit commandFailed("Generic Error Message");
  }
}