Ejemplo n.º 1
0
// Blocks until a valid message is received or timeout expires
// Return true if there is a message available
bool RF22::waitAvailableTimeout(unsigned long timeout)
{
    unsigned long endtime = getTimestamp() + timeout;
	unsigned long currenttime = getTimestamp();
    while (currenttime < endtime) {
		currenttime = getTimestamp();
		if (available()) {
			return true;
		}
	}
		
    return false;
}
bool isSorted(const VoumeSequence &seq) {
    if (seq.size() <= 1) {
        return true;
    }
    auto prev = getTimestamp(seq.front());
    auto it = seq.begin() + 1;
    for (; it < seq.end(); ++it) {
        auto t = getTimestamp(*it);
        if (prev >= t) return false;
        prev = t;
    }
    return true;
}
Ejemplo n.º 3
0
void _pco_acq_thread_dimax_live(void *argin) {
	DEF_FNID;

	Camera* m_cam = (Camera *) argin;
	SyncCtrlObj* m_sync = m_cam->_getSyncCtrlObj();
	//BufferCtrlObj* m_buffer = m_sync->_getBufferCtrlObj();
	BufferCtrlObj* m_buffer = m_cam->_getBufferCtrlObj();

	char _msg[LEN_MSG + 1];
    __sprintfSExt(_msg, LEN_MSG, "%s> [ENTRY]", fnId);
	m_cam->_traceMsg(_msg);

	struct stcPcoData *m_pcoData = m_cam->_getPcoData();

	TIME_USEC tStart;
	msElapsedTimeSet(tStart);
	int error;
	long msXfer;
	int requestStop = stopNone;

	m_cam->_sprintComment(true, fnId, "[ENTRY]");

	HANDLE m_handle = m_cam->getHandle();

	m_sync->setAcqFrames(0);

	// dimax recording time -> live NO record
	m_pcoData->msAcqRec  = 0;
	m_pcoData->msAcqRecTimestamp = getTimestamp();


	pcoAcqStatus status = (pcoAcqStatus) m_buffer->_xferImag();
	m_sync->setExposing(status);
	//m_sync->stopAcq();
	const char *msg = m_cam->_pco_SetRecordingState(0, error);
	if(error) {
		printf("=== %s [%d]> ERROR %s\n", fnId, __LINE__, msg);
		//throw LIMA_HW_EXC(Error, "_pco_SetRecordingState");
	}

	// dimax xfer time
	m_pcoData->msAcqXfer = msXfer = msElapsedTime(tStart);
	m_pcoData->msAcqXferTimestamp = getTimestamp();
	__sprintfSExt(_msg, LEN_MSG, "%s> [EXIT] xfer[%ld] (ms) status[%s]\n", 
			fnId, msXfer, sPcoAcqStatus[status]);
	m_cam->_traceMsg(_msg);

	m_sync->setStarted(false); // to test

	_endthread();
}
Ejemplo n.º 4
0
epicsUInt32
evgMrm::sendTimestamp() {
    /*Start the timer*/
    m_timerEvent->signal();

    /*If the time since last update is more than 1.5 secs(i.e. if wdTimer expires) 
    then we need to resync the time after 5 good pulses*/
    if(m_wdTimer->getPilotCount()) {
        m_wdTimer->decrPilotCount();
        if(m_wdTimer->getPilotCount() == 0) {
            syncTimestamp();
            printf("Starting timestamping\n");
            ((epicsTime)getTimestamp()).show(1);
        }
        return 0;
    }

    m_alarmTimestamp = TS_ALARM_NONE;

    incrTimestamp();
    scanIoRequest(ioScanTimestamp);

    if(m_syncTimestamp) {
        syncTimestamp();
        m_syncTimestamp = false;
    }

    struct epicsTimeStamp ts;
    epicsTime ntpTime, storedTime;
    if(epicsTimeOK == generalTimeGetExceptPriority(&ts, 0, 50)) {
        ntpTime = ts;
        storedTime = (epicsTime)getTimestamp();

        double errorTime = ntpTime - storedTime;

        /*If there is an error between storedTime and ntpTime then we just print
            the relevant information but we send out storedTime*/
        if(fabs(errorTime) > evgAllowedTsGitter) {
            m_alarmTimestamp = TS_ALARM_MINOR;
            printf("NTP time:\n");
            ntpTime.show(1);
            printf("EVG time:\n");
            storedTime.show(1);
            printf("----Timestamping Error of %f Secs----\n", errorTime);
        } 
    }

    return getTimestamp().secPastEpoch + 1 + POSIX_TIME_AT_EPICS_EPOCH;
}
OpTime ReplicationCoordinatorExternalStateImpl::onTransitionToPrimary(OperationContext* opCtx,
                                                                      bool isV1ElectionProtocol) {
    invariant(opCtx->lockState()->isW());

    // Clear the appliedThrough marker so on startup we'll use the top of the oplog. This must be
    // done before we add anything to our oplog.
    // We record this update at the 'lastAppliedOpTime'. If there are any outstanding
    // checkpoints being taken, they should only reflect this write if they see all writes up
    // to our 'lastAppliedOpTime'.
    invariant(
        _replicationProcess->getConsistencyMarkers()->getOplogTruncateAfterPoint(opCtx).isNull());
    auto lastAppliedOpTime = repl::ReplicationCoordinator::get(opCtx)->getMyLastAppliedOpTime();
    _replicationProcess->getConsistencyMarkers()->clearAppliedThrough(
        opCtx, lastAppliedOpTime.getTimestamp());

    if (isV1ElectionProtocol) {
        writeConflictRetry(opCtx, "logging transition to primary to oplog", "local.oplog.rs", [&] {
            WriteUnitOfWork wuow(opCtx);
            opCtx->getClient()->getServiceContext()->getOpObserver()->onOpMessage(
                opCtx,
                BSON("msg"
                     << "new primary"));
            wuow.commit();
        });
    }
    const auto opTimeToReturn = fassertStatusOK(28665, loadLastOpTime(opCtx));

    _shardingOnTransitionToPrimaryHook(opCtx);
    _dropAllTempCollections(opCtx);

    serverGlobalParams.validateFeaturesAsMaster.store(true);

    return opTimeToReturn;
}
Ejemplo n.º 6
0
static void *timeWaitFunction(void *arg) {
	Connection *conn = (Connection *) arg;
	Segment rcvsgm;
	int rcvd;
	struct timespec start;

	start = getTimestamp();

	while (getElapsedNow(start) < RUSP_TIMEWTTM) {

		rcvd = receiveSegment(conn, &rcvsgm);

		if (rcvd == -1)
			break;

		if (rcvd == 0)
			continue;

		if ((matchWindow(&(conn->rcvwnd), rcvsgm.hdr.seqn) == 0) && (rcvsgm.hdr.ctrl & RUSP_FIN))
			sendSACK(conn, RUSP_NXTSEQN(rcvsgm.hdr.seqn, 1));
	}

	setConnectionState(conn, RUSP_CLOSED);

	destroyConnection(conn);

	return NULL;
}
Ejemplo n.º 7
0
status_t GraphicBufferSource::submitBuffer_l(const BufferItem &item, int cbi) {
    ALOGV("submitBuffer_l cbi=%d", cbi);

    int64_t timeUs = getTimestamp(item);
    if (timeUs < 0ll) {
        return UNKNOWN_ERROR;
    }

    CodecBuffer& codecBuffer(mCodecBuffers.editItemAt(cbi));
    codecBuffer.mGraphicBuffer = mBufferSlot[item.mBuf];
    codecBuffer.mBuf = item.mBuf;
    codecBuffer.mFrameNumber = item.mFrameNumber;

    OMX_BUFFERHEADERTYPE* header = codecBuffer.mHeader;
    sp<GraphicBuffer> buffer = codecBuffer.mGraphicBuffer;
    status_t err = mNodeInstance->emptyGraphicBuffer(
            header, buffer, OMX_BUFFERFLAG_ENDOFFRAME, timeUs,
            item.mFence->isValid() ? item.mFence->dup() : -1);
    if (err != OK) {
        ALOGW("WARNING: emptyNativeWindowBuffer failed: 0x%x", err);
        codecBuffer.mGraphicBuffer = NULL;
        return err;
    }

    ALOGV("emptyNativeWindowBuffer succeeded, h=%p p=%p buf=%p bufhandle=%p",
            header, header->pBuffer, buffer->getNativeBuffer(), buffer->handle);
    return OK;
}
Ejemplo n.º 8
0
AREXPORT void ArMapId::log(const char *prefix) const
{
  time_t idTime = getTimestamp();

  char timeBuf[500];

  struct tm *idTm = NULL;
  
  if (idTime != -1) {
    idTm = localtime(&idTime);
  }
  if (idTm != NULL) {
    strftime(timeBuf, sizeof(timeBuf), "%c", idTm);
  }
  else {
    snprintf(timeBuf, sizeof(timeBuf), "NULL");
  }

  ArLog::log(ArLog::Normal,
             "%s%smap %s %s%s checksum = \"%s\" size = %i  time = %s",
             ((prefix != NULL) ? prefix : ""),
             ((prefix != NULL) ? " " : ""),
             getFileName(),
             (!ArUtil::isStrEmpty(getSourceName()) ? "source " : ""),
             (!ArUtil::isStrEmpty(getSourceName()) ? getSourceName() : ""),
             getDisplayChecksum(),
             getSize(),
             timeBuf);
  
}
status_t GraphicBufferSource::submitBuffer_l(
        const BufferQueue::BufferItem &item, int cbi) {

    int64_t timeUs = getTimestamp(item);
    if (timeUs < 0ll) {
        return UNKNOWN_ERROR;
    }

    CodecBuffer& codecBuffer(mCodecBuffers.editItemAt(cbi));
    codecBuffer.mGraphicBuffer = mBufferSlot[item.mBuf];
    codecBuffer.mBuf = item.mBuf;
    codecBuffer.mFrameNumber = item.mFrameNumber;

    OMX_BUFFERHEADERTYPE* header = codecBuffer.mHeader;
    CHECK(header->nAllocLen >= 4 + sizeof(buffer_handle_t));
    OMX_U8* data = header->pBuffer;
    const OMX_U32 type = kMetadataBufferTypeGrallocSource;
    buffer_handle_t handle = codecBuffer.mGraphicBuffer->handle;
    memcpy(data, &type, 4);
    memcpy(data + 4, &handle, sizeof(buffer_handle_t));

    status_t err = mNodeInstance->emptyDirectBuffer(header, 0,
            4 + sizeof(buffer_handle_t), OMX_BUFFERFLAG_ENDOFFRAME,
            timeUs);
    if (err != OK) {
        ALOGW("WARNING: emptyDirectBuffer failed: 0x%x", err);
        codecBuffer.mGraphicBuffer = NULL;
        return err;
    }

    return OK;
}
Ejemplo n.º 10
0
void HDF5Recording::writeData(int writeChannel, int realChannel, const float* buffer, int size)
{
	if (size > bufferSize) //Shouldn't happen, and if it happens it'll be slow, but better this than crashing. Will be reset on flie close and reset.
	{
		std::cerr << "Write buffer overrun, resizing to" << size << std::endl;
		bufferSize = size;
		scaledBuffer.malloc(size);
		intBuffer.malloc(size);
	}
	double multFactor = 1 / (float(0x7fff) * getChannel(realChannel)->bitVolts);
	int index = processorMap[getChannel(realChannel)->recordIndex];
	FloatVectorOperations::copyWithMultiply(scaledBuffer.getData(), buffer, multFactor, size);
	AudioDataConverters::convertFloatToInt16LE(scaledBuffer.getData(), intBuffer.getData(), size);
	fileArray[index]->writeRowData(intBuffer.getData(), size, recordedChanToKWDChan[writeChannel]);

	int sampleOffset = channelLeftOverSamples[writeChannel];
	int blockStart = sampleOffset;
	int64 currentTS = getTimestamp(writeChannel);

	if (sampleOffset > 0)
	{
		currentTS += TIMESTAMP_EACH_NSAMPLES - sampleOffset;
		blockStart += TIMESTAMP_EACH_NSAMPLES - sampleOffset;
	}
	
	for (int i = 0; i < size; i += TIMESTAMP_EACH_NSAMPLES)
	{
		if ((blockStart + i) < (sampleOffset + size))
		{
			channelTimestampArray[writeChannel]->add(currentTS);
			currentTS += TIMESTAMP_EACH_NSAMPLES;
		}
	}
	channelLeftOverSamples.set(writeChannel, (size + sampleOffset) % TIMESTAMP_EACH_NSAMPLES);
}
Ejemplo n.º 11
0
void Stopwatch::setTo(long ms, bool notify)
{
    snaped = ms;
    time = getTimestamp() - ms;
    if(notify)
        sendTimeSync();
}
Ejemplo n.º 12
0
void llPairDelete(queue *sl, queue *bl){

	int vol1 = sl->item[sl->head].vol, vol2 = bl->item[bl->head].vol;
	int pvol = 0;
	int id1 = sl->item[sl->head].id, id2 = bl->item[bl->head].id;
	order ord;
	if (vol1 < vol2) {
		currentPriceX10 = ( sl->item[sl->head].price1 + bl->item[bl->head].price1)/2;
		vol2 = vol2 - vol1;
		pvol = vol1;
		queueDel(sl,&ord);
		bl->item[bl->head].vol = vol2;
		
		pthread_cond_broadcast(sl->notFull);
	} else if (vol1 > vol2) {
		currentPriceX10 = ( sl->item[sl->head].price1 + bl->item[bl->head].price1)/2;
		vol1 = vol1 - vol2;
		pvol = vol2;
		queueDel(bl,&ord);
		sl->item[sl->head].vol = vol1;
		pthread_cond_broadcast(bl->notFull);
	} else {
		currentPriceX10 = ( sl->item[sl->head].price1 + bl->item[bl->head].price1)/2;
		queueDel(sl,&ord);
		queueDel(bl,&ord);
		pvol = vol1;
		pthread_cond_broadcast(sl->notFull);
		pthread_cond_broadcast(bl->notFull);
	}
	
	fprintf(log_file,"%08ld	%08ld	%5.1f	%05d	%08d	%08d\n", ord.timestamp, getTimestamp(), (float)currentPriceX10/10, pvol, id1, id2);

}
Ejemplo n.º 13
0
void n900accelerometer::poll()
{
    // Note that this is a rather inefficient way to generate this data.
    // Ideally the kernel would scale the hardware's values to m/s^2 for us
    // and give us a timestamp along with that data.

    FILE *fd = fopen(filename, "r");
    if (!fd) return;
    int x, y, z;
    int rs = fscanf(fd, "%i %i %i", &x, &y, &z);
    fclose(fd);
    if (rs != 3) return;

    // Convert from milli-Gs to meters per second per second
    // Using 1 G = 9.80665 m/s^2
    qreal ax = x * 0.00980665;
    qreal ay = y * -0.00980665;
    qreal az = z * -0.00980665;

    m_reading.setTimestamp(getTimestamp());
    if (portraitOrientation) {
        m_reading.setX(ay);
        m_reading.setY(-ax);
    } else {
        m_reading.setX(ax);
        m_reading.setY(ay);
    }
    m_reading.setZ(az);

    newReadingAvailable();
}
Ejemplo n.º 14
0
Status OplogReader::_compareRequiredOpTimeWithQueryResponse(const OpTime& requiredOpTime) {
    auto containsMinValid = more();
    if (!containsMinValid) {
        return Status(
            ErrorCodes::NoMatchingDocument,
            "remote oplog does not contain entry with optime matching our required optime");
    }
    auto doc = nextSafe();
    const auto opTime = fassertStatusOK(40351, OpTime::parseFromOplogEntry(doc));
    if (requiredOpTime != opTime) {
        return Status(ErrorCodes::BadValue,
                      str::stream() << "remote oplog contain entry with matching timestamp "
                                    << opTime.getTimestamp().toString()
                                    << " but optime "
                                    << opTime.toString()
                                    << " does not "
                                       "match our required optime");
    }
    if (requiredOpTime.getTerm() != opTime.getTerm()) {
        return Status(ErrorCodes::BadValue,
                      str::stream() << "remote oplog contain entry with term " << opTime.getTerm()
                                    << " that does not "
                                       "match the term in our required optime");
    }
    return Status::OK();
}
Ejemplo n.º 15
0
void trace(const char *file, int line, const char *function,
	traceLevelE level, const char *format, ...)
{
	va_list argp;

	if (level & gTraceLevel || level == TRACE_PRINTF) {
		char *time = getTimestamp(level);

		if (level & TRACE_ERROR)
			printf("%sERROR!!! %s:%d %s()\n", time, file, line, function);

		printf("%s", time);
		va_start(argp, format);
#if !defined(BCMDRIVER)
		vprintf(format, argp);
#else
		{
			char buffer[128] = {0};
			vsprintf(buffer, format, argp);
			printf(buffer);
		}
#endif /* !BCMDRIVER */
		va_end(argp);
	}
}
Ejemplo n.º 16
0
void MapBlock::serializeDiskExtra(std::ostream &os, u8 version)
{
	// Versions up from 9 have block objects. (DEPRECATED)
	if(version >= 9)
	{
		// count=0
		writeU16(os, 0);
	}
	
	// Versions up from 15 have static objects.
	if(version >= 15)
	{
		m_static_objects.serialize(os);
	}

	// Timestamp
	if(version >= 17)
	{
		writeU32(os, getTimestamp());
	}

	// Scan and write node definition id mapping
	if(version >= 21){
		NameIdMapping nimap;
		getBlockNodeIdMapping(&nimap, this, m_gamedef->ndef());
		nimap.serialize(os);
	}
}
int GyroSensor::enable(int32_t, int en) {
    int flags = en ? 1 : 0;
    if (flags != mEnabled) {
        int fd;
        strcpy(&input_sysfs_path[input_sysfs_path_len], "enable");
        fd = open(input_sysfs_path, O_RDWR);
        if (fd >= 0) {
            char buf[2];
            int err;
            buf[1] = 0;
            if (flags) {
                buf[0] = '1';
                mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
            } else {
                buf[0] = '0';
            }
            err = write(fd, buf, sizeof(buf));
            close(fd);
            mEnabled = flags;
            setInitialState();
            return 0;
        }
        return -1;
    }
    return 0;
}
int RotationVectorSensor::readEvents(sensors_event_t* data, int count)
{
    int size, numEventReceived = 0;
    char buf[512];
    struct rotation_vector_data *p_data;
    int unit_size = sizeof(struct rotation_vector_data);
    int64_t current_timestamp;
    int64_t step;

    if (count < 1)
        return -EINVAL;

    D("RotationVectorSensor::%s, count is %d", __FUNCTION__, count);

    if (mHandle == NULL)
        return 0;

    if ((unit_size * count) <= 512)
        size = unit_size * count;
    else
        size = (512 / unit_size) * unit_size;

    size = read(data_fd, buf, size);
    count = size / unit_size;

    D("RotationVectorSensor::readEvents read size is %d", size);

    current_timestamp = getTimestamp();

    step = (current_timestamp - last_timestamp) / count;

    char *p = buf;

    p_data = (struct rotation_vector_data *)buf;
    while (size > 0) {

        mPendingEvent.data[0] = (float)p_data->x/65536;
        mPendingEvent.data[1] = (float)p_data->y/65536;
        mPendingEvent.data[2] = (float)p_data->z/65536;
        mPendingEvent.data[3] = (float)p_data->w/65536;

        mPendingEvent.timestamp = last_timestamp + step * (numEventReceived + 1);

        if (mEnabled == 1) {
            *data++ = mPendingEvent;
            numEventReceived++;
        }

        size = size - unit_size;
        p = p + unit_size;
        p_data = (struct rotation_vector_data *)p;
    }

    D("RotationVectorSensor::%s, numEventReceived is %d", __FUNCTION__,
      numEventReceived);

    last_timestamp = current_timestamp;

    return numEventReceived;
}
Ejemplo n.º 19
0
void ChatDialog::sendMsg()
{
    // Generates the datagram.
    QByteArray msg =
        ProtocolParser::generateDatagram(CMD_MESSAGE,
                                         mName,
                                         mChannel->localAddress(),
                                         mChannel->localPort(),
                                         mTxtSend->toPlainText());
    // Writes to peer.
    if (mChannel->writeDatagram(msg, mPeerAddr, mPeerPort) == -1)
    {
        mTxtRecv->append(tr("** ERROR! **\nSend msg to %1@%2:%3 failed!")
                         .arg(mPeerName)
                         .arg(mPeerAddr.toString())
                         .arg(mPeerPort));
    }

    // Displays in recv area.
    mTxtRecv->append(FMT_CLI_MSG_SELF
                     .arg(getTimestamp())
                     .arg(mTxtSend->toPlainText()));
    // Clears the send area for next msg to be sent.
    mTxtSend->clear();
}
int RotationVectorSensor::setDelay(int32_t handle, int64_t ns)
{
    int data_rate = 0,delay_ms, ret;

    if (mHandle == NULL)
        return -1;

    if (mEnabled == 0)
        return 0;

    D("psh_start_streaming(), data_rate is %d", data_rate);

    delay_ms = ns / 1000000;
    data_rate = 1000 / delay_ms;

    if (data_rate == 0)
        return -1;

    if (data_rate > MAX_DATA_RATE)
        data_rate = MAX_DATA_RATE;

    last_timestamp = getTimestamp();

    ret = psh_start_streaming(mHandle, data_rate, 0);
    if (ret != 0) {
        E("psh_start_streaming failed, ret is %d", ret);
        return -1;
    }

    return 0;
}
Ejemplo n.º 21
0
int GyroSensor::enable(int32_t, int en) {
	int flags = en ? 1 : 0;
	char propBuf[PROPERTY_VALUE_MAX];
	property_get("sensors.gyro.loopback", propBuf, "0");
	if (strcmp(propBuf, "1") == 0) {
		mEnabled = flags;
		ALOGE("sensors.gyro.loopback is set");
		return 0;
	}
	if (flags != mEnabled) {
		int fd;
		strlcpy(&input_sysfs_path[input_sysfs_path_len],
				SYSFS_ENABLE, SYSFS_MAXLEN);
		fd = open(input_sysfs_path, O_RDWR);
		if (fd >= 0) {
			char buf[2];
			int err;
			buf[1] = 0;
			if (flags) {
				buf[0] = '1';
				mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
			} else {
				buf[0] = '0';
			}
			err = write(fd, buf, sizeof(buf));
			close(fd);
			mEnabled = flags;
			setInitialState();
			return 0;
		}
		return -1;
	}
	return 0;
}
Ejemplo n.º 22
0
int MagneticSensor::setDelay(int32_t handle, int64_t ns)
{
    int fd, ms, data_rate = 0, ret;

    D("%s setDelay ns = %lld\n", __func__, ns);

    if (mHandle == NULL)
        return -1;

    if (mEnabled == 0)
        return 0;

    if (ns < COMPASS_MIN_DELAY)
        ns = COMPASS_MIN_DELAY;

    ms = ns / 1000 / 1000;

    if (ms != 0)
        data_rate = 1000/ms;
    D("psh_start_streaming(), data_rate is %d", data_rate);

    if (data_rate == 0)
        return -1;

    last_timestamp = getTimestamp();

    ret = psh_start_streaming(mHandle, data_rate, 0);

    if (ret != 0) {
        E("psh_start_streaming failed, ret is %d", ret);
        return -1;
    }

    return 0;
}
Ejemplo n.º 23
0
void EventsManager::init() {
	if (!GfxMan.ready())
		throw Common::Exception("The GraphicsManager needs to be initialized first");

	RequestMan.init();
	NotificationMan.init();
	TimerMan.init();

	_fullQueue = false;
	_queueSize = 0;

	_ready = true;

	initJoysticks();

	SDL_RegisterEvents(1);

	std::srand(getTimestamp());

	// Forcing enableTextInput to be disabled requires _textInputCounter = 1 to not underrun the counter.
	_textInputCounter = 1;
	enableTextInput(false);

	_repeatCounter = 0;
}
Ejemplo n.º 24
0
int PressureSensor::setDelay(int32_t handle, int64_t delay_ns)
{
    int fd, ms, data_rate, ret;
    char buf[10] = { 0 };

    LOGD("PressureSensor: %s delay_ns=%lld", __FUNCTION__, delay_ns);

    if (mHandle == NULL)
        return -1;

    if (mEnabled == 0)
        return 0;

    if (delay_ns < BARO_MIN_DELAY)
        delay_ns = BARO_MIN_DELAY;

    ms = delay_ns / 1000000;
    data_rate = 1000 / ms;

    last_timestamp = getTimestamp();

    ret = psh_start_streaming(mHandle, data_rate, 0);
    if (ret != 0) {
        E("psh_start_streaming failed, ret is %d", ret);
        return -1;
    }

    mEnabled = 1;

    return 0;
}
Ejemplo n.º 25
0
OpTime OplogEntry::getOpTime() const {
    long long term = OpTime::kUninitializedTerm;
    if (getTerm()) {
        term = getTerm().get();
    }
    return OpTime(getTimestamp(), term);
}
Ejemplo n.º 26
0
int MagnetoSensor::enable(int32_t, int en) {
    int flags = en ? 1 : 0;
    getAttributeFilePath(input_sysfs_path, SYSFS_PATH_MAG, "mode");
    LOGD("XXXXXXXXX Enabling magnetometer %s %d", input_sysfs_path, flags);
    if (flags != mEnabled) {
        int fd;
        fd = open(input_sysfs_path, O_RDWR);
        if (fd >= 0) {
            char buf[2];
            int err;
            buf[1] = 0;
            if (flags) {
                buf[0] = '0';
                mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
            } else {
                buf[0] = '3';
            }
            err = write(fd, buf, sizeof(buf));
            close(fd);
            mEnabled = flags;
            if (flags) {
                setInitialState();
            }
            return 0;
        }
        return -1;
    }
    return 0;
}
Ejemplo n.º 27
0
Status SyncSourceResolver::_compareRequiredOpTimeWithQueryResponse(
    const Fetcher::QueryResponse& queryResponse) {
    if (queryResponse.documents.empty()) {
        return Status(
            ErrorCodes::NoMatchingDocument,
            "remote oplog does not contain entry with optime matching our required optime");
    }
    const OplogEntry oplogEntry(queryResponse.documents.front());
    const auto opTime = oplogEntry.getOpTime();
    if (_requiredOpTime != opTime) {
        return Status(ErrorCodes::BadValue,
                      str::stream() << "remote oplog contain entry with matching timestamp "
                                    << opTime.getTimestamp().toString()
                                    << " but optime "
                                    << opTime.toString()
                                    << " does not "
                                       "match our required optime");
    }
    if (_requiredOpTime.getTerm() != opTime.getTerm()) {
        return Status(ErrorCodes::BadValue,
                      str::stream() << "remote oplog contain entry with term " << opTime.getTerm()
                                    << " that does not "
                                       "match the term in our required optime");
    }
    return Status::OK();
}
Ejemplo n.º 28
0
int PedometerSensor::enable(int32_t handle, int en)
{
    int fd;
    int flags = en ? 1 : 0;
	
	ALOGD("Pdr enable: handle:%d, en:%d \r\n",handle, en);
       strcpy(&input_sysfs_path[input_sysfs_path_len], "pdractive");
	ALOGD("path:%s \r\n",input_sysfs_path);
	fd = open(input_sysfs_path, O_RDWR);
	if(fd<0)
	{
	  	ALOGD("no Pdr enable control attr\r\n" );
	  	return -1;
	}
	
	mEnabled = flags;
	char buf[2];
	buf[1] = 0;
	if (flags) 
	{
 		buf[0] = '1';
     	mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
	}
	else 
 	{
      	buf[0] = '0';
	}
    write(fd, buf, sizeof(buf));
  	close(fd);
	
    ALOGD("Pdr enable(%d) done", mEnabled );    
    return 0;

}
Ejemplo n.º 29
0
bool FFMPEGMovie::_readVideoFrame()
{
    int avReadStatus = 0;

    AVPacket packet;
    av_init_packet( &packet );

    // keep reading frames until we decode a valid video frame
    while( (avReadStatus = av_read_frame( _avFormatContext, &packet )) >= 0 )
    {
        auto picture = _videoStream->decode( packet );
        if( picture )
        {
            _queue.enqueue( picture );
            _streamPosition = _videoStream->getPositionInSec( picture->getTimestamp( ));

            // free the packet that was allocated by av_read_frame
            av_free_packet( &packet );
            break;
        }
        // free the packet that was allocated by av_read_frame
        av_free_packet( &packet );
    }

    // False if file read error or EOF reached
    _isAtEOF = (avReadStatus < 0);
    return !_isAtEOF;
}
int CompassSensor::masterEnable(int en)
{
    VFUNC_LOG;
    LOGV_IF(SYSFS_VERBOSE, "HAL:sysfs:echo %d > %s (%lld)",
            en, compassSysFs.chip_enable, getTimestamp());
    return write_sysfs_int(compassSysFs.chip_enable, en);
}