Ejemplo n.º 1
0
bool Track::getClosestBefore(TimePosition target, TimePosition &resultPosition, Message **resultMessage)
{
    if (numberOfEvents() == 0)
        return false;
    else if (getDuration() == 0L)
        return false;

    EventVecIter iter;
    EventVecIter cursor = events_.begin();
    TimePosition smallest = getDuration();
    for (iter = events_.begin(); iter < events_.end(); ++iter)
    {
        TimePosition pos = (*iter).get<0>();
        if (pos <= target)
        {
            TimePosition distance = (TimePosition) std::abs(((double) target) - ((double) pos));
            if (distance < smallest)
            {
                cursor = iter;
                smallest = distance;
            }
        }
    }
    (* resultMessage) = &((*cursor).get<1>());
    (resultPosition) = (*cursor).get<0>();
    return true;
}
Ejemplo n.º 2
0
Message *Track::getClosest(TimePosition target)
{
    TimePosition duration = getDuration();
    if (numberOfEvents() == 0)
    {
        return 0;
    }
    else if (duration == 0L)
    {
        return getFirst();
    }
    EventVecIter iter;
    EventVecIter ret;
    ret = events_.begin();
    TimePosition smallest = getDuration();
    
    for (iter = events_.begin(); iter < events_.end(); ++iter)
    {
        TimePosition pos = (*iter).get<0>();
        TimePosition distance = (TimePosition) std::abs(((double) target) - ((double) pos));
        if (distance < smallest)
        {
            //std::cout << "smallest:" << smallest << " target=" << target << " pos=" << pos << " abs:" << distance << std::endl;
            ret = iter;
            smallest = distance;
        }
    }
    return &(*ret).get<1>();
}
Ejemplo n.º 3
0
bool emberAfEventsClusterPublishEventLogCallback(uint16_t totalNumberOfEvents,
                                                    uint8_t commandIndex,
                                                    uint8_t totalCommands,
                                                    uint8_t logPayloadControl,
                                                    uint8_t* logPayload)
{
  emberAfEventsClusterPrint("RX: PublishEventLog 0x%2x, 0x%x, 0x%x, 0x%x",
                            totalNumberOfEvents,
                            commandIndex,
                            totalCommands,
                            logPayloadControl);

  #if defined(EMBER_AF_PRINT_ENABLE) && defined(EMBER_AF_PRINT_EVENTS_CLUSTER)
  uint16_t logPayloadLen = (emberAfCurrentCommand()->bufLen
                          - (emberAfCurrentCommand()->payloadStartIndex
                             + sizeof(totalNumberOfEvents)
                             + sizeof(commandIndex)
                             + sizeof(totalCommands)
                             + sizeof(logPayloadControl)));
  uint16_t logPayloadIndex = 0;
  uint8_t i;
  if (NULL != logPayload) {
    for (i = 0; i < numberOfEvents(logPayloadControl); i++) {
      uint8_t logId;
      uint16_t eventId;
      uint32_t eventTime;
      uint8_t *eventData;
      uint8_t eventDataLen;
      logId = emberAfGetInt8u(logPayload, logPayloadIndex, logPayloadLen);
      logPayloadIndex++;
      eventId = emberAfGetInt16u(logPayload, logPayloadIndex, logPayloadLen);
      logPayloadIndex += 2;
      eventTime = emberAfGetInt32u(logPayload, logPayloadIndex, logPayloadLen);
      logPayloadIndex += 4;
      eventData = logPayload + logPayloadIndex;
      eventDataLen = emberAfGetInt8u(logPayload, logPayloadIndex, logPayloadLen);
      logPayloadIndex += (1 + eventDataLen);
      emberAfEventsClusterPrint(" [");
      emberAfEventsClusterPrint("0x%x, 0x%2x, 0x%4x, 0x%x", logId, eventId, eventTime, eventDataLen);
      if (eventDataLen > 0) {
        emberAfEventsClusterPrint(", ");
        emberAfEventsClusterPrintString(eventData);
      }
      emberAfEventsClusterPrint("]");
    }
  }
  emberAfEventsClusterPrintln("");
#endif // defined(EMBER_AF_PRINT_ENABLE) && defined(EMBER_AF_PRINT_EVENTS_CLUSTER)

  emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
  return true;
}
	pcoBase::~pcoBase()
	{
		for (unsigned int i =0; i < numberOfEvents(); i++)
			eventHandler::unregisterCallBack(i);
	}