void MovieHash::randomDoubleFeature(std::string input1, std::string input2){
    int i;
    int z=0;
    int j=0;
    bool firstPick=false;
    bool found1=false;
    bool found2=false;
    HashElem *tmp=new HashElem;
    for(int x=0; x<5;x++){
        if(hashTable[x]!=NULL){
            tmp=hashTable[x];
            while(tmp!=NULL){
                if(tmp->title==input1){
                    bool SoE=true;
                    addTime(z,tmp->startTime,tmp->endTime,SoE);
                    tmp=tmp->next;
                    z=z+2;
                    if(z==8){
                        z=0;
                    }
                    found1=true;
                }
                else if(tmp->title==input2){
                    bool SoE=false;
                    addTime(j,tmp->startTime,tmp->endTime,SoE);
                    tmp=tmp->next;
                    j=j+2;
                    if(j==8){
                        j=0;
                    }
                    found2=true;
                }
                else{
                    tmp=tmp->next;
                }
            }
        }
    }
        for(int a=0;a<5;a=a+2){
            bool compare=timeCompare(movieOne[a],movieOne[a+1],movieTwo[a],movieTwo[a+1]);
            if(compare==true){
                if(firstPick==false){
                    if(movieTwo[a]<movieOne[a]){
                        cout<<input1<<" from "<<movieTwo[a]<<"-"<<movieTwo[a+1]<<", and "<<input2<<" from "<<movieOne[a]<<"-"<<movieOne[a+1]<<endl;
                        firstPick=true;
                    }
                    else{
                        cout<<input1<<" from "<<movieOne[a]<<"-"<<movieOne[a+1]<<", and "<<input2<<" from "<<movieTwo[a]<<"-"<<movieTwo[a+1]<<endl;
                        firstPick=true;
                    }
                }
        }
      }
}
示例#2
0
/* pack and send various messages */
void issueSync(PtpClock *ptpClock)
{
  TimeInternal internalTime;
  TimeRepresentation originTimestamp;
  
  ++ptpClock->last_sync_event_sequence_number;
  ptpClock->grandmaster_sequence_number = ptpClock->last_sync_event_sequence_number;

  /* try to predict outgoing time stamp */
  getTime(&internalTime, ptpClock);
  fromInternalTime(&internalTime, &originTimestamp, ptpClock->halfEpoch);
  msgPackSync(ptpClock->msgObuf, FALSE, TRUE, &originTimestamp, ptpClock);
  
  if(!netSendEvent(ptpClock->msgObuf, SYNC_PACKET_LENGTH,
                   ptpClock->delayedTiming ? &internalTime : NULL,
                   ptpClock))
    toState(PTP_FAULTY, ptpClock);
  else
  {
    DBGV("sent sync message\n");
    if(ptpClock->delayedTiming)
    {
      if (internalTime.seconds || internalTime.nanoseconds) {
        /* compensate with configurable latency, then tell client real time stamp */
        addTime(&internalTime, &internalTime, &ptpClock->runTimeOpts.outboundLatency);
        issueFollowup(&internalTime, ptpClock);
      } else {
        NOTIFY("WARNING: sync message without hardware time stamp, skipped followup\n");
      }
    }
  }
}
示例#3
0
文件: time_test.c 项目: mhcrnl/Code
int main()
{
    Time t;
    initTime(&t);
    addTime(&t, 14, 30, 2);
    printTime(&t);
    addTime(&t, 19, 32, 36);
    printTime(&t);
    setTime(&t, 2, 7, 12);
    printTime(&t);
    addTime(&t, 15, 5, 45);
    printTime(&t);
    setTime(&t, 15, 30, 21);
    printTime(&t);
    return 0;
}
示例#4
0
void issueDelayReq(PtpClock *ptpClock)
{
  TimeInternal internalTime;
  TimeRepresentation originTimestamp;
  
  ptpClock->sentDelayReq = TRUE;
  ptpClock->sentDelayReqSequenceId = ++ptpClock->last_sync_event_sequence_number;

  /* try to predict outgoing time stamp */
  getTime(&internalTime, ptpClock);
  fromInternalTime(&internalTime, &originTimestamp, ptpClock->halfEpoch);
  msgPackDelayReq(ptpClock->msgObuf, FALSE, FALSE, &originTimestamp, ptpClock);
  
  if(!netSendEvent(ptpClock->msgObuf, DELAY_REQ_PACKET_LENGTH,
                   ptpClock->delayedTiming ? &internalTime : NULL,
                   ptpClock))
    toState(PTP_FAULTY, ptpClock);
  else
  {
    DBGV("sent delay request message\n");
    if(ptpClock->delayedTiming)
    {
      if (internalTime.seconds || internalTime.nanoseconds) {
        /* compensate with configurable latency, then store for later use */
        addTime(&internalTime, &internalTime, &ptpClock->runTimeOpts.outboundLatency);
        ptpClock->delay_req_send_time = internalTime;
      } else {
        NOTIFY("WARNING: delay request message without hardware time stamp, will skip response\n");
        ptpClock->sentDelayReq = FALSE;
      }
    }
  }
}
示例#5
0
文件: issue.c 项目: freudshow/learnc
U8 calcTimeNode(U8* buf, U16 bufSize, U8* startTime, U8 timeCnt, time_node_ptr pTimeNodes)
{
	U16 i = 0;
	U8	delim = ';';
	em_time_state state = tm_state_init;
	time_node_str timeInterval = { 0,0 };
	time_node_str startTimeStr = { 0,0 };
	U8 hour = 0;
	U8 lu8Time[10] = { 0 };

	if (timeCnt > MAX_TIME_NODE)
		return ERROR;
	//24个小时不能被下列数整除
	if (timeCnt == 7 || timeCnt == 11 || timeCnt == 13 || timeCnt == 14 || timeCnt == 17 || timeCnt == 19 || timeCnt == 21 || timeCnt == 23)
		return ERROR;
	if (timeLegal(startTime, strlen(startTime), &state) == ERROR)
		return ERROR;
	timeStrToBin(startTime, strlen(startTime), &startTimeStr);
	hour = 24 / timeCnt;
	for (i = 0; i < timeCnt ; i++) {
		timeInterval.u8hour = i*hour;
		addTime(&startTimeStr, &timeInterval, &(pTimeNodes[i]));
		printf("pTimeNodes[%d], hour: %d, minute: %d\n", i, pTimeNodes[i].u8hour, pTimeNodes[i].u8minute);
		sprintf(lu8Time, "%02d%c%02d;", pTimeNodes[i].u8hour, TIME_DELIM, pTimeNodes[i].u8minute);
		strcat(buf, lu8Time);
	}
	return NO_ERR;
}
示例#6
0
void EventLoop::installTimerEvent(uint64_t timerId, double interval, event_callback_fn cb_func, int type, void *arg) {
  struct event *timer = NULL;
  // add a persist timer
  if (0 == type) {
    timer = ::event_new(base_, -1, EV_PERSIST, cb_func, arg);
  }
  // add a one-shot timer
  else if (1 == type) {
    timer = ::event_new(base_, -1, 0, cb_func, arg);
  }
  assert(timer);

  struct timeval tv;
  int64_t microSeconds = static_cast<int64_t>(interval * Timestamp::kMicroSecondsPerSecond);
  tv.tv_sec  = static_cast<time_t>(interval);
  tv.tv_usec = static_cast<suseconds_t>(microSeconds % Timestamp::kMicroSecondsPerSecond);
  if (0 != ::event_add(timer, &tv)) {
    LOG(FATAL) << "EventLoop::installTimerEvent failed";
  }

  std::map<uint64_t, struct event*>::iterator timer_it = timer_.find(timerId);
  assert(timer_it == timer_.end());

  timer_[timerId] = timer;

  if (1 == type) {
    Timestamp time(addTime(Timestamp::now(), interval));
    oneShotTimerDeadLine_[timerId] = time.microSecondsSinceEpoch();
  }
}
示例#7
0
/*Pack and send on event multicast ip adress a PDelayReq message*/
static void issuePDelayReq(PtpClock *ptpClock)
{
    Timestamp originTimestamp;
    TimeInternal internalTime;
    getTime(&internalTime);
    fromInternalTime(&internalTime, &originTimestamp);

    msgPackPDelayReq(ptpClock, ptpClock->msgObuf, &originTimestamp);

    if (!netSendPeerEvent(&ptpClock->netPath, ptpClock->msgObuf, PDELAY_REQ_LENGTH, &internalTime))
    {
        ERROR("issuePDelayReq: can't sent\n");
        toState(ptpClock, PTP_FAULTY);
    }
    else
    {
        DBGV("issuePDelayReq\n");
        ptpClock->sentPDelayReqSequenceId++;

        /* Delay req TX timestamp is valid */

        if (internalTime.seconds != 0)
        {
            addTime(&internalTime, &internalTime, &ptpClock->outboundLatency);
            ptpClock->pdelay_t1 = internalTime;
        }
    }
}
示例#8
0
文件: main.c 项目: JohnXinhua/UVa
int main() {
	int ch;
	int n, i, h, m, s;
	scanf("%d", &n);
	Time *t = (Time*) malloc(sizeof(Time)*n);
	while ((ch = getchar()) != EOF) {
		switch(ch) {
			case 'i':
				scanf("%d", &i);
				initTime(&t[i]);
				break;
			case 's':
				scanf("%d%d%d%d", &i, &h, &m, &s);
				setTime(&t[i], h, m, s);
				break;
			case 'a':
				scanf("%d%d%d%d", &i, &h, &m, &s);
				addTime(&t[i], h, m, s);
				break;
			case 'p':
				scanf("%d", &i);
				printTime(&t[i]);
				printTime24(&t[i]);
				break;
			default:
				break;
		}
	}
	free(t);
	return 0;
}
示例#9
0
文件: rt_tmon.c 项目: Strongc/proview
static void
subbCheck (
  sTimer	*tp
)
{
  sub_sBuffer	*bp = (sub_sBuffer *)tp->data;

  if (gdbroot->db->log.b.tmon)
    errh_Info("subbCheck: %u", tp->clock);

#if 0
  if (EXCL_ON) {
    /* Exclusive mode is on, requeue the
       buffer for later transmission */

    addTime(nowTime(&tp->time), msToTime(NULL, bp->dt)); 
    insertTimer(tp);
  }
#endif

  if (subsm_SendBuffer(bp)) {
    setTimer(tp, msToClock(NULL, bp->dt));
    insertTimer(tp);
  } else {
    freeTimer(tp);
  }
}
示例#10
0
//searches for the first available slot from input date and time onwards
std::string LogicClass::freeSlotSearch(int date, int time) {
	std::ostringstream freeSlot;

	if (sizeOfArray == 0) {
		freeSlot << date << "|" << time;
		return freeSlot.str();					
	} else {
		int freeDate = date;
		int freeTime = time;
		
		sortDateAndTime();
		
		//if date and time is in between ith array element,
		//move to next element, updating the possible free time to date and time right after
		//ith array element
		for (int i = 0; i < sizeOfArray; i++) {
			//below condition checks if date and time is in between the duration of ith array element
			if ((infoArray[i].startDate < freeDate) || 
				((infoArray[i].startDate == freeDate) && (infoArray[i].startTime <= freeTime))) {
					if ((infoArray[i].endDate > freeDate) ||
						((infoArray[i].endDate == freeDate) && (infoArray[i].endTime >= freeTime))) {
							freeDate = infoArray[i].endDate;
							freeTime = addTime(infoArray[i].endTime, 1);
					} 
			}
		}

		freeSlot << freeDate << "|" << freeTime;
		return freeSlot.str();
	}
}
示例#11
0
/*Pack and send on event multicast ip adress a Sync message*/
static void issueSync(PtpClock *ptpClock)
{
    Timestamp originTimestamp;
    TimeInternal internalTime;

    /* try to predict outgoing time stamp */
    getTime(&internalTime);
    fromInternalTime(&internalTime, &originTimestamp);

    msgPackSync(ptpClock, ptpClock->msgObuf, &originTimestamp);

    if (!netSendEvent(&ptpClock->netPath, ptpClock->msgObuf, SYNC_LENGTH, &internalTime))
    {
        ERROR("issueSync: can't sent\n");
        toState(ptpClock, PTP_FAULTY);
    }
    else
    {
        DBGV("issueSync\n");
        ptpClock->sentSyncSequenceId++;

        /* sync TX timestamp is valid */

        if ((internalTime.seconds != 0) && (ptpClock->defaultDS.twoStepFlag))
        {
            // waitingForLoopback = false;
            addTime(&internalTime, &internalTime, &ptpClock->outboundLatency);
            issueFollowup(ptpClock, &internalTime);
        }
        else
        {
            // waitingForLoopback = ptpClock->twoStepFlag;
        }
    }
}
示例#12
0
文件: timer.cpp 项目: JianboZhu/cobra
void Timer::restart(Timestamp now) {
  if (repeat_) {
    expiration_ = addTime(now, interval_);
  } else {
    expiration_ = Timestamp::invalid();
  }
}
示例#13
0
/**********************************************************
 *  Function: controller
 *********************************************************/
void *controller(void *arg)
{    
	
	char request[10];
	char answer[10];
	MIXER_STATE = 0;
	TIME_LAST_CHANGE_MIXER = time(NULL);
	
    // Endless loop
	memset(request,'\0',10);
	memset(answer,'\0',10);
    
	struct timespec timeInit, timeEnd, timeDiff, timePeriod;
	timePeriod.tv_sec = (time_t) TIME_SEC_CYCLE_SECONDS;
	timePeriod.tv_nsec = (long) TIME_SEC_CYCLE_NANOSECONDS;
	
	while(1) {
//    	- Lectura de la pendiente actual
    	if(read_slope(request, answer) == 2) {
    		printf("Error in read slope");
    	}
    	
    	
//    	- Lectura de la velocidad actual
    	if(read_speed(request, answer) == -1.0) {
    		//Error
    		printf("Error in read speed");
    	}
    	
    	
//    	- Activar el acelerador
    	if(gas_turn(request, answer) != 0 ) {
			//Error
			printf("Error in break. Current value = ");
		}
    	
    	
//    	- Activar el freno
    	if(break_turn(request, answer) != 0 ) {
			//Error
			printf("Error in break. Current value = ");
		}
    	
    	
//    	- Activar el Mezclador
    	if(mixer_turn(request, answer) != 0 ) {
			//Error
			printf("Error in break. Current value = ");
		}
    	
		sec_cycle = (sec_cycle + 1) % TOTAL_SEC_CYCLES;
    	clock_gettime(CLOCK_REALTIME, &timeEnd);
    	
    	diffTime(timeEnd, timeInit, &timeDiff);
    	diffTime(timePeriod, timeDiff, &timeDiff);
    	nanosleep(&timeDiff, NULL);
		addTime(timeInit, timePeriod, &timeInit);		
    }
    //return (0);
}
示例#14
0
/*****************************************************************************
 * Function: main()
 *****************************************************************************/
int main()
{
    struct timespec start,end,diff,cycle;
    unsigned char buf[SEND_SIZE];
    int fd_file = -1;
    int fd_serie = -1;
    int ret = 0;
    
	// Uncomment to test on the Arduino
    //fd_serie = initSerialMod_WIN_115200 ();

	// Uncomment to test on the PC
	iniciarAudio_Windows ();

	/* Open music file */
	printf("open file %s begin\n",FILE_NAME);
	fd_file = open (FILE_NAME, O_RDONLY, 0644);
	if (fd_file < 0) {
		printf("open: error opening file\n");
		return -1;
	}

    // loading cycle time
    cycle.tv_sec=PERIOD_TASK_SEC;
    cycle.tv_nsec=PERIOD_TASK_NSEC;
    
    clock_gettime(CLOCK_REALTIME,&start);
	while (1) {
	
		// read from music file
		ret=read(fd_file,buf,SEND_SIZE);
		if (ret < 0) {
			printf("read: error reading file\n");
			return NULL;
		}
		
		// write to serial port  		
		// Uncomment to test on the Arduino
		//ret = writeSerialMod_256 (buf);

		// Uncomment to test on the PC
		ret = reproducir_1bit_4000 (buf);
		if (ret < 0) {
			printf("write: error writting serial\n");
			return NULL;
		}
		
		// get end time, calculate lapso and sleep
	    clock_gettime(CLOCK_REALTIME,&end);
	    diffTime(end,start,&diff);
	    if (0 >= compTime(cycle,diff)) {
			printf("ERROR: lasted long than the cycle\n");
			return NULL;
	    }
	    diffTime(cycle,diff,&diff);
		nanosleep(&diff,NULL);   
	    addTime(start,cycle,&start);
	}
}
示例#15
0
void handleDelayReq(MsgHeader *header, Octet *msgIbuf, ssize_t length, TimeInternal *time, Boolean badTime, Boolean isFromSelf, PtpClock *ptpClock)
{
  if(length < DELAY_REQ_PACKET_LENGTH)
  {
    ERROR("short delay request message\n");
    toState(PTP_FAULTY, ptpClock);
    return;
  }
  
  switch(ptpClock->port_state)
  {
  case PTP_MASTER:
    if(isFromSelf)
    {
      DBG("handleDelayReq: ignore from self\n");
      return;
    }
    
    if( header->sourceCommunicationTechnology == ptpClock->clock_communication_technology
      || header->sourceCommunicationTechnology == PTP_DEFAULT
      || ptpClock->clock_communication_technology == PTP_DEFAULT )
    {
      if( badTime )
        NOTIFY("avoid inaccurate DelayResp because of bad time stamp\n");
      else
        issueDelayResp(time, &ptpClock->msgTmpHeader, ptpClock);
    }
    
    break;
    
  case PTP_SLAVE:
    if(isFromSelf)
    {
      DBG("handleDelayReq: self\n");
      
      ptpClock->delay_req_send_time.seconds = time->seconds;
      ptpClock->delay_req_send_time.nanoseconds = time->nanoseconds;
      
      addTime(&ptpClock->delay_req_send_time, &ptpClock->delay_req_send_time, &ptpClock->runTimeOpts.outboundLatency);
      
      if(ptpClock->delay_req_receive_time.seconds)
      {
        updateDelay(&ptpClock->delay_req_send_time, &ptpClock->delay_req_receive_time,
          &ptpClock->owd_filt, ptpClock);
        
        ptpClock->delay_req_send_time.seconds = 0;
        ptpClock->delay_req_send_time.nanoseconds = 0;
        ptpClock->delay_req_receive_time.seconds = 0;
        ptpClock->delay_req_receive_time.nanoseconds = 0;
      }
    }
    break;
    
  default:
    DBGV("handleDelayReq: disreguard\n");
    return;
  }
}
示例#16
0
void 
handlePDelayRespFollowUp(MsgHeader *header, Octet *msgIbuf, ssize_t length, 
			 Boolean isFromSelf, RunTimeOpts *rtOpts, 
			 PtpClock *ptpClock){

	if (ptpClock->delayMechanism == P2P) {
		TimeInternal responseOriginTimestamp;
		TimeInternal correctionField;
	
		DBGV("PdelayRespfollowup message received : \n");
	
		if(length < PDELAY_RESP_FOLLOW_UP_LENGTH) {
			ERROR("short PDelayRespfollowup message\n");
			toState(PTP_FAULTY, rtOpts, ptpClock);
			return;
		}	
	
		switch(ptpClock->portState) {
		case PTP_INITIALIZING:
		case PTP_FAULTY:
		case PTP_DISABLED:
		case PTP_UNCALIBRATED:
			DBGV("HandlePdelayResp : disregard\n");
			return;
		
		case PTP_SLAVE:
		case PTP_MASTER:
			if ((header->sequenceId == 
			    ptpClock->sentPDelayReqSequenceId-1) && (header->sequenceId == ptpClock->recvPDelayRespSequenceId)) {
				msgUnpackPDelayRespFollowUp(
					ptpClock->msgIbuf,
					&ptpClock->msgTmp.prespfollow);
				toInternalTime(
					&responseOriginTimestamp,
					&ptpClock->msgTmp.prespfollow.responseOriginTimestamp);
				ptpClock->pdelay_resp_send_time.seconds = 
					responseOriginTimestamp.seconds;
				ptpClock->pdelay_resp_send_time.nanoseconds = 
					responseOriginTimestamp.nanoseconds;
				integer64_to_internalTime(
					ptpClock->msgTmpHeader.correctionfield,
					&correctionField);
				addTime(&correctionField,&correctionField,
					&ptpClock->lastPdelayRespCorrectionField);
				updatePeerDelay (&ptpClock->owd_filt,
						 rtOpts, ptpClock,
						 &correctionField,TRUE);
				break;
			}
		default:
			DBGV("Disregard PdelayRespFollowUp message  \n");
		}
	} else { /* (End to End mode..) */
		ERROR("Peer Delay messages are disregarded in End to End "
		      "mode \n");
	}
}
示例#17
0
int main(void)
{
	Time *time = (Time *)malloc(sizeof(Time));
	initTime(time);
	setTime(time, 15, 56, 17);
	addTime(time, 1, 8, 56);
	printTime(time);
	return 0;
}
示例#18
0
void addTimeAndBusyWait(struct timespec* time, long nanoseconds)
{
    addTime(time, nanoseconds);
    struct timespec actualTime;
    do
    {
        get_monotonic_boottime(&actualTime);
    } while (timespec_compare(time, &actualTime) > 0);
}
示例#19
0
void 
handlePDelayReq(MsgHeader *header, Octet *msgIbuf, ssize_t length, 
		TimeInternal *time, Boolean isFromSelf, 
		RunTimeOpts *rtOpts, PtpClock *ptpClock)
{
	if (ptpClock->delayMechanism == P2P) {
		DBGV("PdelayReq message received : \n");

		if(length < PDELAY_REQ_LENGTH) {
			ERROR("short PDelayReq message\n");
			toState(PTP_FAULTY, rtOpts, ptpClock);
			return;
		}

		switch (ptpClock->portState ) {
		case PTP_INITIALIZING:
		case PTP_FAULTY:
		case PTP_DISABLED:
		case PTP_UNCALIBRATED:
		case PTP_LISTENING:
			DBGV("HandlePdelayReq : disregard\n");
			return;

		case PTP_SLAVE:
		case PTP_MASTER:
		case PTP_PASSIVE:
			if (isFromSelf) {
				/*
				 * Get sending timestamp from IP stack
				 * with SO_TIMESTAMP
				 */
				ptpClock->pdelay_req_send_time.seconds = 
					time->seconds;
				ptpClock->pdelay_req_send_time.nanoseconds = 
					time->nanoseconds;
			
				/*Add latency*/
				addTime(&ptpClock->pdelay_req_send_time,
					&ptpClock->pdelay_req_send_time,
					&rtOpts->outboundLatency);
				break;
			} else {
				msgUnpackHeader(ptpClock->msgIbuf,
						&ptpClock->PdelayReqHeader);
				issuePDelayResp(time, header, rtOpts, 
						ptpClock);	
				break;
			}
		default:
			DBG("do unrecognized state3\n");
			break;
		}
	} else /* (End to End mode..) */
		ERROR("Peer Delay messages are disregarded in End to End "
		      "mode \n");
}
示例#20
0
int main(void)
{   Time youTime,tempTime;
    int choi;
    printf("Hello....\npress enter");
    getchar();
    printf("ustanovit vremia ili obnulit'>?(1/2)\n");
    scanf("%d",&choi);
    if(choi==1)
        enterTime(&youTime);
    if(choi==2){
        youTime.hour=0;
        youTime.minut=0;
        youTime.sec=0;
    }
    if(choi!=1&&choi!=2){
        fprintf(stderr,"invalid value");
    exit(1);
    }
    tempTime=youTime;
    while(choi!=4){

        printf("1.adding time\n2.show time \n3.diff time\n4.exit\n");
        scanf("%d",&choi);
        system("clear");
        switch (choi) {
        case 1:
           addTime(&tempTime);
           showTime(tempTime);
            break;
        case 2:
            printf("first time\n");
            showTime(youTime);
            printf("real time\n");
            showTime(tempTime);
            break;
        case 3:
            printf(" diff time %d sec\n",chekTime(youTime,tempTime));

            break;
        case 4:
            printf("end.\n");
            break;

        default:
            fprintf(stderr,"inalid value\n");
            exit(1);
            break;
        }


    }



    return 0;
}
示例#21
0
    void TimeMap::addFromDATESKeyword( const DeckKeyword& DATESKeyword ) {
        if (DATESKeyword.name() != "DATES")
            throw std::invalid_argument("Method requires DATES keyword input.");

        for (size_t recordIndex = 0; recordIndex < DATESKeyword.size(); recordIndex++) {
            const auto& record = DATESKeyword.getRecord( recordIndex );
            boost::posix_time::ptime nextTime = TimeMap::timeFromEclipse( record );
            addTime( nextTime );
        }
    }
示例#22
0
文件: rt_tmon.c 项目: Strongc/proview
static void
waitTime (
  pwr_tTime		*t
)
{
  pwr_tStatus		sts;
  pwr_tTime		now;
  pwr_tTime		then = *t;
  char tims[24];
  short len;
  struct dsc$descriptor_s tims_desc = {
    sizeof(tims)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S,};

#if 0
  subTime(&then, nowTime(&now));
#endif

  if ((int)then.tv_sec > 0 || ((int)then.tv_sec == 0 && then.tv_nsec > 0)) {
#if defined OS_VMS || defined OS_ELN
    int			tv_nsec;
    int			vmstime[2];
    int			multiplier = -10000000;	      /* Used to convert 1 s to 100 ns, delta time.  */
    static pwr_tTime	tick = {0, 10000000};

    addTime(&then, &tick);
    tv_nsec = -then.tv_nsec/100;   /* Convert to 100 ns.  */
    sts = lib$emul(&then.tv_sec, &multiplier, &tv_nsec, vmstime);

#if defined OS_VMS
    tims_desc.dsc$a_pointer = tims;
    sys$asctim( &len, &tims_desc, vmstime, 0);
    tims[len] = '\0';
    printf("  %s\n", tims);
#if 0
    sts = sys$clref(timerFlag);
    sts = sys$setimr(timerFlag, vmstime, 0, 0, 0);
    sts = sys$waitfr(timerFlag);
#endif
#elif defined OS_ELN
    eln$time_string(tims, vmstime);
    tims[23] = '\0';
    printf("  %s\n", tims);
#if 0
    ker$wait_any(&sts, NULL, vmstime);
#endif
#endif

#elif defined OS_LYNX
    pwr_tTime rmt;

    nanosleep(&then, &rmt);
#endif
  }
}
示例#23
0
文件: arith.c 项目: wowczarek/ptpd
void timeDelta(TimeInternal *before, TimeInternal *meas, TimeInternal *after, TimeInternal *delta)
{

	TimeInternal tmpDelta;

	div2Time(before);
	div2Time(after);
	addTime(&tmpDelta, before, after);
	subTime(delta, &tmpDelta, meas);

}
示例#24
0
void Logger::writeLine(const wchar_t* line)
{
	if(!m_Opened)
		return;
	//int result = fwrite(line,wcslen(line),1,m_fp);
	//fwrite("\n",1,1,m_fp);
	wchar_t* timedLine = addTime(line);

	m_TextFile.WriteString(NULL, timedLine);
	m_TextFile.WriteString(NULL,L"\n");
}
示例#25
0
void KTimeEdit::keyPressEvent(QKeyEvent *qke)
{
    switch(qke->key())
    {
        case Key_Down:
            addTime(QTime(0, 1, 0));
            break;
        case Key_Up:
            subTime(QTime(0, 1, 0));
            break;
        case Key_Prior:
            subTime(QTime(1, 0, 0));
            break;
        case Key_Next:
            addTime(QTime(1, 0, 0));
            break;
        default:
            QComboBox::keyPressEvent(qke);
            break;
    } // switch
}
示例#26
0
文件: Timer.cpp 项目: 1suming/msmuduo
void Timer::restart(Timestamp now)
{
	if (repeat_)
	{
		expiration_ = addTime(now, interval_);//addTime在Timestamp中定义为全局函数

	}
	else
	{
		expiration_ = Timestamp::invalid(); //Timestamp 为0
	}
}
示例#27
0
mtime LTimerManager::GetActualTime() {
    mtime ret = actionTime_;
    timeval actual;
    if (gettimeofday(&actual, 0) < 0) {
        ret.valid = false;
        return ret;
    } else
        ret.valid = true;
    timeval res;
    timersub(&actual, &actionval_, &res);
    addTime(ret, res);
    return ret;
}
示例#28
0
void RunTimes::stop(Category c)
{
  Element e = category_stack.top();
  category_stack.pop();
  if (e.first != c)
    {
      std::cerr << e.first;
      std::cerr << c;
      BEEV::FatalError("Don't match");
    }
  addTime(c, getCurrentTime() - e.second);
  addCount(c);
}
示例#29
0
Vector2f PxController::controlStep(Vector2f &pos, double dt) {
    if(boost_count_ < BOOSTTIME) {
        input_ = -drift_ + start_point_ + flight_time_*VNORM*v_*BOOSTPARAM;
        boost_count_++;
    }else if (boost_count_ == BOOSTTIME){
        setStartPoint(pos);
        input_ = -drift_ + start_point_ + flight_time_*VNORM*v_;
        boost_count_++;
    }else{
        input_ = -drift_ + start_point_ + flight_time_*VNORM*v_;
    }
    //input_ = pos - drift_ + v_;
    addTime(dt);
    checkBoundLock();
    return input_;
}
void safeToProcess(const Event* const thisEvent, Time* safeTimestamp) {
    Time tempTime;
        if (thisEvent->offsetTime.secs < 0 || (thisEvent->offsetTime.secs == 0
                        && thisEvent->offsetTime.nsecs < 0)) {
                tempTime.secs = (uint32) (-thisEvent->offsetTime.secs);
                tempTime.nsecs = (uint32) (-thisEvent->offsetTime.nsecs);
                addTime(thisEvent->tag.timestamp, tempTime, safeTimestamp);
        } else {
                int16 out;
                tempTime.secs = (uint32) (thisEvent->offsetTime.secs);
                tempTime.nsecs = (uint32) (thisEvent->offsetTime.nsecs);
                out = subTime(thisEvent->tag.timestamp, tempTime, safeTimestamp);
                if (out == -1) {
                        safeTimestamp->secs = 0;
                        safeTimestamp->nsecs = 0;
                }
        }
}