void testSuite() { hashtable table = init_hashtable(7); printf(":: Table elems: %d\n", table->p); printf(":: Inserting elements in hashtable\n"); put(&table, "toto", "hey"); put(&table, "lablab", "monk"); put(&table, "blabla", "plop"); put(&table, "toto", "ho!"); put(&table, "tops", "hahah"); put(&table, "pots", "huhuh"); displayHashTable(table); printf(":: Seeking for hello: %s\n", get(table, "hello")); printf(":: Seeking for toto: %s\n", get(table, "toto")); printf(":: Removing elem tops, toto and lablab\n"); rmove(&table, "tops"); rmove(&table, "toto"); rmove(&table, "lablab"); displayHashTable(table); printf(":: Changing hash function and adding two elems\n"); hashtable table2 = init_hashtable(7); set_hfunc(&table2, &idx_hashfunction); put(&table2, "toto", "hey"); put(&table2, "blabla", "plop"); put(&table2, "lablab", "monk"); displayHashTable(table2); printf(":: Fonction for first hashtable: %p\n", get_hfunc(table)); printf(":: Fonction for second hashtable: %p\n", get_hfunc(table2)); printf(":: Stats for first table\n"); put(&table, "lablab", "monk"); put(&table, "toto", "ho!"); put(&table, "tops", "hahah"); displayStats(get_stats(table)); printf(":: Stats for second table\n"); displayStats(get_stats(table2)); printf(":: Rehash table with 11 buckets\n"); set_hfunc(&table, &idx_hashfunction); rehash_table(&table, 11); displayHashTable(table); }
void Ocean::initCells(void) { addEmptyCells(); addObstacles(); addPredators(); addPrey(); displayStats(-1); displayBorder(); Ocean1 = this; }
int main() { Creature test(10, 10, 100, 5, 0, "Joe"); cout << "Displaying original stats..." << endl; displayStats(test); cin.get(); cout << "Changing the stats..." << endl; changeStats(test); cin.get(); cout << "Displaying stats after the changes..." << endl; displayStats(test); cin.get(); cout << "Setting the stats..." << endl; setStats(test); cin.get(); cout << "Displaying stats after setting..." << endl; displayStats(test); cin.get(); cout << "Using an item..." << endl; useAnItem(test); cin.get(); cout << "Displaying stats after using the item..." << endl; displayStats(test); cin.get(); return 0; }
void Ocean::run(void) { unsigned numIterations = DefaultNumIterations; // instead of cin if (numIterations > 1000) numIterations = DefaultNumIterations; for (unsigned iteration = 0; iteration < numIterations; iteration++) { if (numPredators > 0 && numPrey > 0) { for (unsigned row = 0; row < numRows; row++) for (unsigned col = 0; col < numCols; col++) cells[row][col]->process(); displayStats(iteration); displayCells(); displayBorder(); } } }
/* Main */ int main(int argc, char *argv[]) { char *filename; double secondsPerFrame = 0.1; if (argc < 2) { printf("Usage: disp_stats <filename>\n"); printf(" <filename> should be a .txt file (output by sim_stats_nr)\n"); return -1; } filename = argv[1]; printf("Press 'q' to close window\n"); displayStats(filename); } // end main
void updateClock(RunTimeOpts *rtOpts, PtpClock *ptpClock) { Integer32 adj=0; TimeInternal timeTmpA; // AKB: Added values for adjusting calc based on time to get time TimeInternal timeTmpB; TimeInternal timeTmpC; TimeInternal timeTmpD; TimeInternal timeTmpE; TimeInternal timeTmpF; Integer64 delta_time_calc; DBGV("updateClock:\n"); if(ptpClock->offset_from_master.seconds) { /* if offset from master seconds is non-zero, then this is a "big jump: * in time. Check Run Time options to see if we will reset the clock or * set frequency adjustment to max to adjust the time */ if(!rtOpts->noAdjust) { if(!rtOpts->noResetClock) { if (!isNonZeroTime(&ptpClock->t1_sync_delta_time)) { // Delta time is zero, so this is the first sync to capture and we'll do the major // adjustment on the next sync instead of this one // // Store t1 and t2 times as current delta, next time we'll subtract // copyTime(&ptpClock->t1_sync_delta_time, &ptpClock->t1_sync_tx_time ); copyTime(&ptpClock->t2_sync_delta_time, &ptpClock->t2_sync_rx_time ); NOTIFY("updateClock: Storing current T1 and T2 values for later calc\n"); DBG("updateClock: Storing T1: %10ds %11dns\n", ptpClock->t1_sync_delta_time.seconds, ptpClock->t1_sync_delta_time.nanoseconds ); DBG("updateClock: Storing T2: %10ds %11dns\n", ptpClock->t2_sync_delta_time.seconds, ptpClock->t2_sync_delta_time.nanoseconds ); return; } // If we are here then t1 and t2 sync delta were set to previous t1 and t2 // values. Now we calculate the deltas DBG("updateClock: Current T1: %10ds %11dns\n", ptpClock->t1_sync_tx_time.seconds, ptpClock->t1_sync_tx_time.nanoseconds ); DBG("updateClock: Current T2: %10ds %11dns\n", ptpClock->t2_sync_rx_time.seconds, ptpClock->t2_sync_rx_time.nanoseconds ); subTime(&ptpClock->t1_sync_delta_time, &ptpClock->t1_sync_tx_time, &ptpClock->t1_sync_delta_time ); subTime(&ptpClock->t2_sync_delta_time, &ptpClock->t2_sync_rx_time, &ptpClock->t2_sync_delta_time ); DBG("updateClock: Delta T1: %10ds %11dns\n", ptpClock->t1_sync_delta_time.seconds, ptpClock->t1_sync_delta_time.nanoseconds ); DBG("updateClock: Delta T2: %10ds %11dns\n", ptpClock->t2_sync_delta_time.seconds, ptpClock->t2_sync_delta_time.nanoseconds ); // Now we get the difference between the two time bases and store in the T2 time delta // as we will use the T1 time as the divisor (so master clock drives the time) subTime(&ptpClock->t2_sync_delta_time, &ptpClock->t2_sync_delta_time, &ptpClock->t1_sync_delta_time ); DBG("updateClock: Delta T2 - Delta T1: %10ds %11dns\n", ptpClock->t2_sync_delta_time.seconds, ptpClock->t2_sync_delta_time.nanoseconds ); delta_time_calc = getNanoseconds(&ptpClock->t2_sync_delta_time) * 1000000000; delta_time_calc /= getNanoseconds(&ptpClock->t1_sync_delta_time); DBG("updateClock: Calculated Parts/billion: %d\n", (int)delta_time_calc ); /* clamp the accumulator to ADJ_FREQ_MAX for sanity */ if( delta_time_calc > ADJ_FREQ_MAX) adj = ADJ_FREQ_MAX; else if(delta_time_calc < -ADJ_FREQ_MAX) adj = -ADJ_FREQ_MAX; else adj = (UInteger32)delta_time_calc; NOTIFY("updateClock: Initial clock adjust: %d, base: %d\n", adj, ptpClock->baseAdjustValue ); NOTIFY("updateClock: Offset from Master %ds.%9.9d seconds\n", ptpClock->offset_from_master.seconds, ptpClock->offset_from_master.nanoseconds ); DBG( "updateClock: offset_from_master seconds != 0\n"); DBGV(" master-to-slave delay: %10ds %11dns\n", ptpClock->master_to_slave_delay.seconds, ptpClock->master_to_slave_delay.nanoseconds ); DBGV(" slave-to-master delay: %10ds %11dns\n", ptpClock->slave_to_master_delay.seconds, ptpClock->slave_to_master_delay.nanoseconds ); DBGV(" one-way delay: %10ds %11dns\n", ptpClock->one_way_delay.seconds, ptpClock->one_way_delay.nanoseconds ); DBG( " offset from master: %10ds %11dns\n", ptpClock->offset_from_master.seconds, ptpClock->offset_from_master.nanoseconds ); DBG( " observed drift: %10d\n", ptpClock->observed_drift ); getTime(&timeTmpA, ptpClock->current_utc_offset); // Get current time #1 getTime(&timeTmpB, ptpClock->current_utc_offset); // Get current time #2 subTime(&timeTmpC, // Calculate time #3, time elapsed between calls &timeTmpB, &timeTmpA ); getTime(&timeTmpD, ptpClock->current_utc_offset); // Get current time #4 subTime(&timeTmpE, // Subtract calculated offset from master &timeTmpD, &ptpClock->offset_from_master ); addTime(&timeTmpF, // Add calculated time to get timer value &timeTmpE, &timeTmpC ); setTime(&timeTmpF, ptpClock->current_utc_offset); // Set new PTP time DBGV(" get Time A : %10ds %11dns\n", timeTmpA.seconds, timeTmpA.nanoseconds ); DBGV(" get Time B : %10ds %11dns\n", timeTmpB.seconds, timeTmpB.nanoseconds ); DBGV(" calc Time C (B-A) : %10ds %11dns\n", timeTmpC.seconds, timeTmpC.nanoseconds ); DBGV(" get Time D : %10ds %11dns\n", timeTmpD.seconds, timeTmpD.nanoseconds ); DBGV(" offset from master : %10ds %11dns\n", ptpClock->offset_from_master.seconds, ptpClock->offset_from_master.nanoseconds ); DBGV(" calc Time E (D+offset): %10ds %11dns\n", timeTmpE.seconds, timeTmpE.nanoseconds ); DBGV(" calc Time F (E+C) : %10ds %11dns\n", timeTmpF.seconds, timeTmpF.nanoseconds ); DBGV("updateClock: set time to Time F\n"); // Initialize clock variables based on run time options (rtOpts) initClockVars(rtOpts, ptpClock); // Adjust clock based on calculation from Delta T1, T2 times adjFreq(ptpClock->baseAdjustValue - adj); // Set initial observed drift to this calculated value ptpClock->observed_drift = adj; DBG( "updateClock: after initClock:\n"); DBGV(" master-to-slave delay: %10ds %11dns\n", ptpClock->master_to_slave_delay.seconds, ptpClock->master_to_slave_delay.nanoseconds ); DBGV(" slave-to-master delay: %10ds %11dns\n", ptpClock->slave_to_master_delay.seconds, ptpClock->slave_to_master_delay.nanoseconds ); DBG( " one-way delay: %10ds %11dns\n", ptpClock->one_way_delay.seconds, ptpClock->one_way_delay.nanoseconds ); DBG( " offset from master: %10ds %11dns\n", ptpClock->offset_from_master.seconds, ptpClock->offset_from_master.nanoseconds ); DBG( " observed drift: %10d\n", ptpClock->observed_drift ); } else { /* Run time options indicate we can't reset the clock, so we slow * it down or speed it up based on ADJ_FREQ_MAX adjustment rather * than actually setting the time. */ adj = ptpClock->offset_from_master.nanoseconds > 0 ? ADJ_FREQ_MAX : -ADJ_FREQ_MAX; adjFreq(ptpClock->baseAdjustValue - adj); } } } else { /* Offset from master is less than one second. Use the the PI controller * to adjust the time */ DBGV("updateClock: using PI controller to update clock\n"); /* no negative or zero attenuation */ if(rtOpts->ap < 1) rtOpts->ap = 1; if(rtOpts->ai < 1) rtOpts->ai = 1; DBGV(" previous observed drift: %10d\n", ptpClock->observed_drift ); DBGV(" run time opts P: %10d\n", rtOpts->ap ); DBGV(" run time opts I: %10d\n", rtOpts->ai ); DBGV(" current observed drift: %d\n", ptpClock->observed_drift ); DBGV(" current offset %dns\n", rtOpts->ai ); /* the accumulator for the I component */ ptpClock->observed_drift += ptpClock->offset_from_master.nanoseconds/rtOpts->ai; DBGV(" new observed drift (I): %d\n", ptpClock->observed_drift ); /* clamp the accumulator to ADJ_FREQ_MAX for sanity */ if( ptpClock->observed_drift > ADJ_FREQ_MAX) ptpClock->observed_drift = ADJ_FREQ_MAX; else if(ptpClock->observed_drift < -ADJ_FREQ_MAX) ptpClock->observed_drift = -ADJ_FREQ_MAX; DBGV(" clamped drift: %d\n", ptpClock->observed_drift ); adj = ptpClock->offset_from_master.nanoseconds/rtOpts->ap + ptpClock->observed_drift; DBGV(" calculated adjust: %d\n", adj ); DBGV(" base adjust: %d\n", ptpClock->baseAdjustValue ); /* apply controller output as a clock tick rate adjustment */ if(!rtOpts->noAdjust) { DBGV(" calling adjFreq with: %d\n", (ptpClock->baseAdjustValue-adj) ); adjFreq(ptpClock->baseAdjustValue - adj); if (rtOpts->rememberAdjustValue == TRUE) { if ( ptpClock->offset_from_master.nanoseconds <= 100 && ptpClock->offset_from_master.nanoseconds >= -100 ) { ptpClock->lastAdjustValue = -adj; // Store value if it gave a good clock // result. } } } } /* Display statistics (save to a file if -f specified) if run time option enabled */ if(rtOpts->displayStats) displayStats(rtOpts, ptpClock); DBGV(" offset from master: %10ds %11dns\n", ptpClock->offset_from_master.seconds, ptpClock->offset_from_master.nanoseconds ); DBGV(" master-to-slave delay: %10ds %11dns\n", ptpClock->master_to_slave_delay.seconds, ptpClock->master_to_slave_delay.nanoseconds ); DBGV(" slave-to-master delay: %10ds %11dns\n", ptpClock->slave_to_master_delay.seconds, ptpClock->slave_to_master_delay.nanoseconds ); DBGV(" one-way delay: %10ds %11dns\n", ptpClock->one_way_delay.seconds, ptpClock->one_way_delay.nanoseconds ); DBGV( " current observed drift: %10d\n", ptpClock->observed_drift ); DBGV(" clock adjust value: %10d\n", (ptpClock->baseAdjustValue - adj) ); }
// This function does boundary checking on the ball, also determines where // it hits the paddle, and changes the behavior of the ball depending. void checkBallCollisions(int paddlePos) { // first check for any brick collisions char detected = drawBricks(&ball); // if no bricks hit, continue with normal collision detection if(detected == 'n') { // right wall if(ball.x >= SCREEN_WIDTH - BALL_RADIUS) { ball.x = SCREEN_WIDTH - (BALL_RADIUS + 1); xdir = -xdir; playTone(500, 50); return; } // left wall if(ball.x <= BALL_RADIUS) { ball.x = BALL_RADIUS + 1; xdir = -xdir; playTone(500, 50); return; } // ceiling if(ball.y >= SCREEN_HEIGHT - BALL_RADIUS) { ydir = -1.0; playTone(500, 50); return; } // middle of paddle if(ball.y <= 19 && (ball.x <= paddlePos + (PADDLE_WIDTH / 2) + (BALL_RADIUS + 1) && ball.x >= paddlePos + (PADDLE_WIDTH / 2) - (BALL_RADIUS + 1))) { paddleHits++; // increase ball speed slightly with every 6 paddle hits if((paddleHits % 18 == 0) && (paddleHits <= 36)) speed += 1.0; ball.y = 20; ydir = 1.0; playTone(500,50); return; } // right side of paddle else if(ball.y <= 19 && ((ball.x <= paddlePos + PADDLE_WIDTH) && (ball.x > paddlePos + (PADDLE_WIDTH / 2) + (BALL_RADIUS + 1)))) { paddleHits++; // increase ball speed slightly with every 6 paddle hits if((paddleHits % 18 == 0) && (paddleHits <= 36)) speed += 1.0; ball.y = 20; ydir = 1.0; xdir += 1.0; playTone(500, 50); return; } // left side of paddle else if(ball.y <= 19 && ((ball.x >= paddlePos) && (ball.x < paddlePos + (PADDLE_WIDTH / 2) - (BALL_RADIUS + 1)))) { paddleHits++; // increase ball speed slightly with every 6 paddle hits if((paddleHits % 18 == 0) && (paddleHits <= 36)) speed += 1.0; ball.y = 20; ydir = 1.0; xdir -= 1.0; playTone(500, 50); return; } // ball hits floor, lives lost, score deducted if(ball.y <= 10 && ((ball.x < paddlePos) || (ball.x > paddlePos + PADDLE_WIDTH))) { playTone(50,500); tft.fillCircle(ball.y, ball.x, BALL_RADIUS, ST7735_BLACK); drawPaddle(); initializeBall(getDifficulty()); decreaseLives(); displayStats(); delay(20); } } // brick collision detected, adjust ball accordingly else { // corner of brick hit if(detected == 'c') { xdir = -xdir; ydir = -ydir; playTone(200,50); return; } else { // left/right side of brick hit if(detected == 'x') { xdir = -xdir; playTone(200,50); return; } // top/bottom of brick hit else if(detected == 'y') { ydir = -ydir; playTone(200,50); return; } } } }
/* perform actions required when leaving 'port_state' and entering 'state' */ void toState(UInteger8 state, PtpClock *ptpClock) { ptpClock->message_activity = TRUE; /* leaving state tasks */ switch(ptpClock->port_state) { case PTP_MASTER: timerStop(SYNC_INTERVAL_TIMER, ptpClock->itimer); timerStart(SYNC_RECEIPT_TIMER, PTP_SYNC_RECEIPT_TIMEOUT(ptpClock->sync_interval), ptpClock->itimer); break; case PTP_SLAVE: initClock(ptpClock); break; default: break; } timeToState(state, ptpClock); /* entering state tasks */ switch(state) { case PTP_INITIALIZING: DBG("state PTP_INITIALIZING\n"); timerStop(SYNC_RECEIPT_TIMER, ptpClock->itimer); ptpClock->port_state = PTP_INITIALIZING; break; case PTP_FAULTY: DBG("state PTP_FAULTY\n"); timerStop(SYNC_RECEIPT_TIMER, ptpClock->itimer); ptpClock->port_state = PTP_FAULTY; break; case PTP_DISABLED: DBG("state change to PTP_DISABLED\n"); timerStop(SYNC_RECEIPT_TIMER, ptpClock->itimer); ptpClock->port_state = PTP_DISABLED; break; case PTP_LISTENING: DBG("state PTP_LISTENING\n"); timerStart(SYNC_RECEIPT_TIMER, PTP_SYNC_RECEIPT_TIMEOUT(ptpClock->sync_interval), ptpClock->itimer); ptpClock->port_state = PTP_LISTENING; break; case PTP_MASTER: DBG("state PTP_MASTER\n"); if(ptpClock->port_state != PTP_PRE_MASTER) timerStart(SYNC_INTERVAL_TIMER, PTP_SYNC_INTERVAL_TIMEOUT(ptpClock->sync_interval), ptpClock->itimer); timerStop(SYNC_RECEIPT_TIMER, ptpClock->itimer); ptpClock->port_state = PTP_MASTER; break; case PTP_PASSIVE: DBG("state PTP_PASSIVE\n"); ptpClock->port_state = PTP_PASSIVE; break; case PTP_UNCALIBRATED: DBG("state PTP_UNCALIBRATED\n"); ptpClock->port_state = PTP_UNCALIBRATED; break; case PTP_SLAVE: DBG("state PTP_PTP_SLAVE\n"); initClock(ptpClock); /* R is chosen to allow a few syncs before we first get a one-way delay estimate */ /* this is to allow the offset filter to fill for an accurate initial clock reset */ ptpClock->Q = 0; ptpClock->R = getRand(&ptpClock->random_seed)%4 + 4; DBG("Q = %d, R = %d\n", ptpClock->Q, ptpClock->R); ptpClock->waitingForFollow = FALSE; 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; timerStart(SYNC_RECEIPT_TIMER, PTP_SYNC_RECEIPT_TIMEOUT(ptpClock->sync_interval), ptpClock->itimer); ptpClock->port_state = PTP_SLAVE; break; default: DBG("to unrecognized state\n"); break; } if(ptpClock->runTimeOpts.displayStats) displayStats(ptpClock); }
void MTArrayT<MT>::dump(int level) const { // display on stderr the table. displayStats(std::cerr); if (level > 0) display(std::cerr, level-1); }
/* perform actions required when leaving 'port_state' and entering 'state' */ void toState(UInteger8 state, RunTimeOpts *rtOpts, PtpClock *ptpClock) { ptpClock->message_activity = TRUE; /* leaving state tasks */ switch (ptpClock->portState) { case PTP_MASTER: timerStop(SYNC_INTERVAL_TIMER, ptpClock->itimer); timerStop(ANNOUNCE_INTERVAL_TIMER, ptpClock->itimer); timerStop(PDELAYREQ_INTERVAL_TIMER, ptpClock->itimer); break; case PTP_SLAVE: timerStop(ANNOUNCE_RECEIPT_TIMER, ptpClock->itimer); if (ptpClock->delayMechanism == E2E) timerStop(DELAYREQ_INTERVAL_TIMER, ptpClock->itimer); else if (ptpClock->delayMechanism == P2P) timerStop(PDELAYREQ_INTERVAL_TIMER, ptpClock->itimer); initClock(rtOpts, ptpClock); break; case PTP_PASSIVE: timerStop(PDELAYREQ_INTERVAL_TIMER, ptpClock->itimer); timerStop(ANNOUNCE_RECEIPT_TIMER, ptpClock->itimer); break; case PTP_LISTENING: timerStop(ANNOUNCE_RECEIPT_TIMER, ptpClock->itimer); break; default: break; } /* entering state tasks */ /* * No need of PRE_MASTER state because of only ordinary clock * implementation. */ switch (state) { case PTP_INITIALIZING: DBG("state PTP_INITIALIZING\n"); ptpClock->portState = PTP_INITIALIZING; break; case PTP_FAULTY: DBG("state PTP_FAULTY\n"); ptpClock->portState = PTP_FAULTY; break; case PTP_DISABLED: DBG("state PTP_DISABLED\n"); ptpClock->portState = PTP_DISABLED; break; case PTP_LISTENING: /* in Listening mode, make sure we don't send anything. Instead we just expect/wait for announces (started below) */ timerStop(SYNC_INTERVAL_TIMER, ptpClock->itimer); timerStop(ANNOUNCE_INTERVAL_TIMER, ptpClock->itimer); timerStop(PDELAYREQ_INTERVAL_TIMER, ptpClock->itimer); timerStop(DELAYREQ_INTERVAL_TIMER, ptpClock->itimer); /* * Count how many _unique_ timeouts happen to us. * If we were already in Listen mode, then do not count this as a seperate reset, but stil do a new IGMP refresh */ if (ptpClock->portState != PTP_LISTENING) { ptpClock->reset_count++; } /* Revert to the original DelayReq interval, and ignore the one for the last master */ ptpClock->logMinDelayReqInterval = rtOpts->initial_delayreq; /* force a IGMP refresh per reset */ if (rtOpts->do_IGMP_refresh) { netRefreshIGMP(&ptpClock->netPath, rtOpts, ptpClock); } DBG("state PTP_LISTENING\n"); INFO(" now in state PTP_LISTENING\n"); timerStart(ANNOUNCE_RECEIPT_TIMER, (ptpClock->announceReceiptTimeout) * (pow(2,ptpClock->logAnnounceInterval)), ptpClock->itimer); ptpClock->portState = PTP_LISTENING; break; case PTP_MASTER: DBG("state PTP_MASTER\n"); INFO(" now in state PTP_MASTER\n"); timerStart(SYNC_INTERVAL_TIMER, pow(2,ptpClock->logSyncInterval), ptpClock->itimer); DBG("SYNC INTERVAL TIMER : %f \n", pow(2,ptpClock->logSyncInterval)); timerStart(ANNOUNCE_INTERVAL_TIMER, pow(2,ptpClock->logAnnounceInterval), ptpClock->itimer); timerStart(PDELAYREQ_INTERVAL_TIMER, pow(2,ptpClock->logMinPdelayReqInterval), ptpClock->itimer); ptpClock->portState = PTP_MASTER; break; case PTP_PASSIVE: DBG("state PTP_PASSIVE\n"); INFO(" now in state PTP_PASSIVE\n"); timerStart(PDELAYREQ_INTERVAL_TIMER, pow(2,ptpClock->logMinPdelayReqInterval), ptpClock->itimer); timerStart(ANNOUNCE_RECEIPT_TIMER, (ptpClock->announceReceiptTimeout) * (pow(2,ptpClock->logAnnounceInterval)), ptpClock->itimer); ptpClock->portState = PTP_PASSIVE; p1(ptpClock, rtOpts); break; case PTP_UNCALIBRATED: DBG("state PTP_UNCALIBRATED\n"); ptpClock->portState = PTP_UNCALIBRATED; break; case PTP_SLAVE: DBG("state PTP_SLAVE\n"); INFO(" now in state PTP_SLAVE\n"); initClock(rtOpts, ptpClock); ptpClock->waitingForFollow = FALSE; ptpClock->waitingForDelayResp = FALSE; // FIXME: clear these vars inside initclock clearTime(&ptpClock->pdelay_req_send_time); clearTime(&ptpClock->pdelay_req_receive_time); clearTime(&ptpClock->pdelay_resp_send_time); clearTime(&ptpClock->pdelay_resp_receive_time); timerStart(OPERATOR_MESSAGES_TIMER, OPERATOR_MESSAGES_INTERVAL, ptpClock->itimer); timerStart(ANNOUNCE_RECEIPT_TIMER, (ptpClock->announceReceiptTimeout) * (pow(2,ptpClock->logAnnounceInterval)), ptpClock->itimer); /* * Previously, this state transition would start the delayreq timer immediately. * However, if this was faster than the first received sync, then the servo would drop the delayResp * Now, we only start the timer after we receive the first sync (in handle_sync()) */ ptpClock->waiting_for_first_sync = TRUE; ptpClock->waiting_for_first_delayresp = TRUE; ptpClock->portState = PTP_SLAVE; break; default: DBG("to unrecognized state\n"); break; } if (rtOpts->displayStats) displayStats(rtOpts, ptpClock); }