//wrapper function which initializes the memory for the hitTracker structs and passes them to updateCounters
void trackAllocByHH(size_t sz, const char *file, int line){
    if(!szTracker){
        szTracker=malloc(NUMBERCOUNTERS*sizeof(hitTracker));
        freqTracker=malloc(NUMBERCOUNTERS*sizeof(hitTracker));
        memset(szTracker,0,NUMBERCOUNTERS*sizeof(hitTracker));
        memset(szTracker,0,NUMBERCOUNTERS*sizeof(hitTracker));
    }
    updateCounters(szTracker,NUMBERCOUNTERS,sz,file,line); 
    updateCounters(freqTracker,NUMBERCOUNTERS,1,file,line); 
}
//modified implementation of the algorithm "FREQUENT" which doesn't rely on differential encoding
//a pointer to an array of hitTracker structs is passed in along with the occurence which is either 1 (for count) or the size
void updateCounters(hitTracker *tracker, int elements, size_t occurrence, const char *file, int line){
    unsigned long long minimumValue;
    minimumValue=(unsigned long long)-1;    //We keep track of the minimum count in the array in order to prevent an overflow from happening
    unsigned long long subtractValue;
    for(int i=0;i<elements;++i){
        if(tracker[i].counter<minimumValue)
            minimumValue=tracker[i].counter;
        if(tracker[i].file==file&&tracker[i].line==line){
            tracker[i].counter+=occurrence;
            return;
        }
        else if(tracker[i].counter==0){
            tracker[i].file=file;
            tracker[i].line=line;
            tracker[i].counter+=occurrence;
            return;
        }
    }
    if(occurrence>minimumValue)         //occurence>minimumValue would lead to an underflow of (at least) the smallest item in the array
        subtractValue=minimumValue;
    else
        subtractValue=occurrence;
    for(int i=0;i<elements;++i){
        tracker[i].counter-=subtractValue;
    }
    if(occurrence>minimumValue)
       updateCounters(tracker,elements,occurrence-minimumValue,file,line);  //recursive call to make up for the difference of occurence and subtractValue
}
void MotorTest::show()
{
    m_cbobData->setFastRefresh();
    QObject::connect(m_cbobData, SIGNAL(refresh()), this, SLOT(updateCounters()));
    this->updateGUI();
    Page::show();
}
void MotorTest::hide()
{
    // stop all motors if the page is hidden
    // this->allStop();
    QObject::disconnect(this, SLOT(updateCounters()));
    m_cbobData->setSlowRefresh();
    Page::hide();
}
Beispiel #5
0
void RenderCounter::rendererSubtreeAttached(RenderObject* renderer)
{
    Node* node = renderer->node();
    if (node)
        node = node->parentNode();
    else
        node = renderer->generatingNode();
    if (node && !node->attached())
        return; // No need to update if the parent is not attached yet
    for (RenderObject* descendant = renderer; descendant; descendant = descendant->nextInPreOrder(renderer))
        updateCounters(descendant);
}
void PropertiesPanel::setFolder( Folder* folder ) {
    removeListeners();

    editedFolder = folder;

    mainLayout->setContentsMargins( 0, 0, 0, 0 );
    descriptionMultiLineEdit->setText( editedFolder->getDescription() );
    authorField->setText( editedFolder->getAuthor() );
    creationDateValueLabel->setText( editedFolder->getCreationDate().toString() );
    modificationDateValueLabel->setText( editedFolder->getModificationDate().toString() );

    updateCounters();

    addListeners();
}
void LayoutCounter::layoutObjectSubtreeAttached(LayoutObject* layoutObject)
{
    ASSERT(layoutObject->view());
    if (!layoutObject->view()->hasLayoutCounters())
        return;
    Node* node = layoutObject->node();
    if (node)
        node = node->parentNode();
    else
        node = layoutObject->generatingNode();
    if (node && node->needsAttach())
        return; // No need to update if the parent is not attached yet
    for (LayoutObject* descendant = layoutObject; descendant; descendant = descendant->nextInPreOrder(layoutObject))
        updateCounters(*descendant);
}
void PropertiesPanel::setVocabulary( Vocabulary* vocab ) {
    removeListeners();

    editedVocab = vocab;

    mainLayout->setContentsMargins( 8, 8, 8, 8 );
    descriptionMultiLineEdit->setText( editedVocab->getDescription() );
    authorField->setText( editedVocab->getAuthor() );
    creationDateValueLabel->setText( editedVocab->getCreationDate().toString() );
    modificationDateValueLabel->setText( editedVocab->getModificationDate().toString() );

    updateCounters();

    addListeners();
}
Beispiel #9
0
void RenderCounter::rendererSubtreeAttached(RenderElement& renderer)
{
    if (!renderer.view().hasRenderCounters())
        return;
    Element* element = renderer.element();
    if (element && !element->isPseudoElement())
        element = element->parentElement();
    else
        element = renderer.generatingElement();
    if (element && !element->renderer())
        return; // No need to update if the parent is not attached yet
    for (RenderObject* descendant = &renderer; descendant; descendant = descendant->nextInPreOrder(&renderer)) {
        if (is<RenderElement>(*descendant))
            updateCounters(downcast<RenderElement>(*descendant));
    }
}
Beispiel #10
0
void StateMachine::updateTaskToStarting(string taskId)
{
  auto it = taskMap.find(taskId);
  if (it != taskMap.end()) {
    LOG(INFO) << "Update the taskState to STARTING for " << taskId;
    TaskState& taskState = taskMap[taskId];
    updateCounters(taskState.taskType,
        taskState.currentStatus,
        Status::STARTING);
    taskState.currentStatus = Status::STARTING;
    LOG(INFO) << "After update: ";
    LOG(INFO) << taskState.toString();
  } else {
    LOG(ERROR) << "No value found in taskMap with key: " << taskId;
  }
}
Beispiel #11
0
void
MultiAggregate::reset( const Solver& solver )
{
    trace_msg( multiaggregates, 1, "Reset to level " << solver.getCurrentDecisionLevel() );
    while( !trail.empty() )
    {
        TrailElement te = trail.back();
        Literal lit = getLiteralFromTrailElement( te );
        trace_msg( multiaggregates, 2, "Lit " << lit << " is in trail" );
        if( !solver.isUndefined( lit ) ) break;
        updateCounters( te );
        trail.pop_back();        
    }
    while( solver.isUndefined( ids[ w1 ] ) ) --w1;
    while( solver.isUndefined( ids[ w2 ] ) ) w2++;
    trace_msg( multiaggregates, 3, "Restored w1=" << w1 << " and w2=" << w2 );
    trace_msg( multiaggregates, 3, "Restored current sum=" << currentSum << " and max possible sum=" << maxPossibleSum );
    assert_msg( solver.isTrue( ids[ w1 ] ), ids[ w1 ] << " (w1=" << w1 << "), is not true" );
    assert_msg( solver.isFalse( ids[ w2 ] ), ids[ w2 ] << " (w2=" << w2 << "), is not false" );
}
Beispiel #12
0
QSmartCard::ErrorType QSmartCardPrivate::handleAuthError( QSmartCardData::PinType type, const AuthError &e )
{
	updateCounters( t.d );
	if( t.retryCount( type ) < 1 ) return QSmartCard::BlockedError;
	switch( (e.SW1 << 8) + e.SW2 )
	{
	case 0x63C0: return QSmartCard::BlockedError; //pin retry count 0
	case 0x63C1: // Validate error, 1 tries left
	case 0x63C2: // Validate error, 2 tries left
	case 0x63C3: return QSmartCard::ValidateError;
	case 0x6400: // Timeout (SCM)
	case 0x6401: return QSmartCard::CancelError; // Cancel (OK, SCM)
	case 0x6402: return QSmartCard::DifferentError;
	case 0x6403: return QSmartCard::LenghtError;
	case 0x6983: return QSmartCard::BlockedError;
	case 0x6985: return QSmartCard::OldNewPinSameError;
	case 0x6A80: return QSmartCard::OldNewPinSameError;
	default: return QSmartCard::UnknownError;
	}
}
Beispiel #13
0
void CIntel::update(int frame) {
	resetCounters();

	if (enemyvector == ZeroVector)
		updateEnemyVector();

	int numUnits = ai->cbc->GetEnemyUnits(&ai->unitIDs[0], MAX_UNITS);
	
	for (int i = 0; i < numUnits; i++) {
		const int uid = ai->unitIDs[i];
		const UnitDef* ud = ai->cbc->GetUnitDef(uid);
		
		if (ud == NULL)
			continue;

		unitCategory c = UT(ud->id)->cats;

		if ((c&ATTACKER).any() && (c&MOBILE).any())
			updateCounters(c);
	}

	updateRoulette();
}
void processSnps(struct weightList *oldTableList, struct hash *newTableHash)
/* loop through oldTableHash */
/* compare to newTableHash */
/* if SNP missing from newTableHash, write to logFile*/
{
struct weightList *listPtr = NULL;
struct hashEl *helNew = NULL;
int oldWeight = 0;
int newWeight = 0;

verbose(1, "process SNPs...\n");
for (listPtr = oldTableList; listPtr != NULL; listPtr = listPtr->next)
    {
    helNew = hashLookup(newTableHash, listPtr->name);
    if (helNew == NULL) 
        {
	fprintf(logFileHandle, "%s (old weight %s) not found in new\n", listPtr->name, listPtr->weight);
	continue;
	}
    oldWeight = atoi(listPtr->weight);
    newWeight = atoi(helNew->val);
    updateCounters(listPtr->name, oldWeight, newWeight);
    }
}
Beispiel #15
0
/**
 Add/remove a position update entry to/from the average position list, updates
 the counters, adjusts the entriesCount and redetermines the cumulative
 smask, sig and fix.

 @param positionAverageList
 The position average list
 @param entry
 The entry to add/remove
 @param add
 True when the entry must be added to the list, false when it must be removed
 */
static void addOrRemoveEntryToFromCumulativeAverage(
		PositionAverageList * positionAverageList, PositionUpdateEntry * entry,
		bool add) {
	PositionUpdateEntry * cumulative =
			&positionAverageList->positionAverageCumulative;

	if (!add) {
		assert(positionAverageList->entriesCount >= positionAverageList->entriesMaxCount);
		assert(entry == getPositionAverageEntry(positionAverageList, OLDEST));

		/* do not touch present */
		/* do not touch smask */

		/* do not touch utc */

		/* do not touch sig */
		/* do not touch fix */

		/* do not touch satinfo */
	} else {
		assert(positionAverageList->entriesCount < positionAverageList->entriesMaxCount);
		assert(entry == getPositionAverageEntry(positionAverageList, INCOMING));

		/* present at the end */
		/* smask at the end */

		/* use the latest utc */
		cumulative->nmeaInfo.utc = entry->nmeaInfo.utc;

		/* sig at the end */
		/* fix at the end */

		/* use the latest satinfo */
		cumulative->nmeaInfo.satinfo = entry->nmeaInfo.satinfo;
	}

	/* PDOP, HDOP, VDOP */
	cumulative->nmeaInfo.PDOP += add ? entry->nmeaInfo.PDOP
			: -entry->nmeaInfo.PDOP;
	cumulative->nmeaInfo.HDOP += add ? entry->nmeaInfo.HDOP
			: -entry->nmeaInfo.HDOP;
	cumulative->nmeaInfo.VDOP += add ? entry->nmeaInfo.VDOP
			: -entry->nmeaInfo.VDOP;

	/* lat, lon */
	cumulative->nmeaInfo.lat += add ? entry->nmeaInfo.lat
			: -entry->nmeaInfo.lat;
	cumulative->nmeaInfo.lon += add ? entry->nmeaInfo.lon
			: -entry->nmeaInfo.lon;

	/* elv, speed */
	cumulative->nmeaInfo.elv += add ? entry->nmeaInfo.elv
			: -entry->nmeaInfo.elv;
	cumulative->nmeaInfo.speed += add ? entry->nmeaInfo.speed
			: -entry->nmeaInfo.speed;

	/* track, mtrack, magvar */
	cumulative->nmeaInfo.track += add ? entry->nmeaInfo.track : -entry->nmeaInfo.track;
	addAngleComponents(&cumulative->track, &entry->track, add);

	cumulative->nmeaInfo.mtrack += add ? entry->nmeaInfo.mtrack : -entry->nmeaInfo.mtrack;
	addAngleComponents(&cumulative->mtrack, &entry->mtrack, add);

	cumulative->nmeaInfo.magvar += add ? entry->nmeaInfo.magvar : -entry->nmeaInfo.magvar;
	addAngleComponents(&cumulative->magvar, &entry->magvar, add);

	/* adjust list count */
	positionAverageList->entriesCount += (add ? 1 : -1);

	updateCounters(positionAverageList, entry, add);
	determineCumulativePresentSmaskSigFix(positionAverageList);
}
Beispiel #16
0
void Controller::updateCountersSituation() {
	setTrackersToCounters();
	updateCounters();
}
void RenderCounter::rendererSubtreeAttached(RenderObject* renderer)
{
    for (RenderObject* descendant = renderer; descendant; descendant = descendant->nextInPreOrder(renderer))
        updateCounters(descendant);
}
Beispiel #18
0
int main(void) {
    sei();
    uint8_t resetSource = MCUSR;
    MCUSR = 0;
    wdt_reset();
    wdt_disable();

    wdt_enable(WDTO_1S);
    WDTCSR |= (1 << WDIE);  //enable watchdog interrupt
    wdt_reset();
    cli();

    clock_init();
    usart_init(1000000, 9600);
    stdout = &uart_str;
    stderr = &uart_str;
    stdin = &uart_str;

    uip_ipaddr_t ipaddr;
    struct timer periodic_timer, arp_timer;
    uint16_t timer_OW, timer_Simple, timer_Count, timer_EEProm, timer_SendData, timer_IOalarm, timer_network;
    timer_OW = 0;
    timer_Simple = 0;
    timer_Count = 0;
    timer_EEProm = 0;
    timer_SendData = 0;
    timer_IOalarm = 0;
    timer_network = 0;
    
    if(resetSource & (1<<WDRF))
    {
        printf("Mega was reset by watchdog...\r\n");
    }

    if(resetSource & (1<<BORF))
    {
        printf("Mega was reset by brownout...\r\n");
    }

    if(resetSource & (1<<EXTRF))
    {
        printf("Mega was reset by external...\r\n");
    }

    if(resetSource & (1<<PORF))
    {
        printf("Mega was reset by power on...\r\n");
    }

//else jtag (disabled)

    //sensorScan = (uint8_t*) & tempbuf;

    if (eepromReadByte(0) == 255 || eepromReadByte(11) == 255)
    {
            printf_P(PSTR("Setting default values\r\n"));
            //Set defaults
            eepromWriteByte(0, 0); //init

            myip[0] = 192;
            myip[1] = 168;
            myip[2] = 1;
            myip[3] = 67; //47 in final versions

            netmask[0] = 255;
            netmask[1] = 255;
            netmask[2] = 255;
            netmask[3] = 0;

            gwip[0] = 192;
            gwip[1] = 168;
            gwip[2] = 1;
            gwip[3] = 1;

            dnsip[0] = 8;
            dnsip[1] = 8;
            dnsip[2] = 8;
            dnsip[3] = 8;

            eepromWriteByte(29, 80);  //web port
            eepromWriteByte(10, 0);  //dhcp off

            save_ip_addresses();
            wdt_reset();

            eepromWriteStr(200, "SBNG", 4);  //default password
            eepromWriteByte(204, '\0');
            eepromWriteByte(205, '\0');
            eepromWriteByte(206, '\0');
            eepromWriteByte(207, '\0');
            eepromWriteByte(208, '\0');
            eepromWriteByte(209, '\0');

            eepromWriteByte(100, 1); //Analog port 0 = ADC
            eepromWriteByte(101, 1); //Analog port 1 = ADC
            eepromWriteByte(102, 1); //Analog port 2 = ADC
            eepromWriteByte(103, 1); //Analog port 3 = ADC
            eepromWriteByte(104, 1); //Analog port 4 = ADC
            eepromWriteByte(105, 1); //Analog port 5 = ADC
            eepromWriteByte(106, 1); //Analog port 6 = ADC
            eepromWriteByte(107, 1); //Analog port 7 = ADC

            eepromWriteByte(110, 0); //Digital port 0 = OUT
            eepromWriteByte(111, 0); //Digital port 1 = OUT
            eepromWriteByte(112, 0); //Digital port 2 = OUT
            eepromWriteByte(113, 0); //Digital port 3 = OUT

      	    wdt_reset();
            for (uint8_t alarm=1; alarm<=4; alarm++)
            {
                    uint16_t pos = 400 + ((alarm-1)*15); //400 415 430 445

                    eepromWriteByte(pos+0, 0); //enabled
                    eepromWriteByte(pos+1, 0); //sensorid
                    eepromWriteByte(pos+2, 0); //sensorid
                    eepromWriteByte(pos+3, 0); //sensorid
                    eepromWriteByte(pos+4, 0); //sensorid
                    eepromWriteByte(pos+5, 0); //sensorid
                    eepromWriteByte(pos+6, 0); //sensorid
                    eepromWriteByte(pos+7, 0); //sensorid
                    eepromWriteByte(pos+8, 0); //sensorid
                    eepromWriteByte(pos+9, '<'); //type
                    eepromWriteByte(pos+10, 0); //value
                    eepromWriteByte(pos+11, 0); //target
                    eepromWriteByte(pos+12, 0); //state
                    eepromWriteByte(pos+13, 0); //reverse
                    eepromWriteByte(pos+14, 0); //not-used
            }

            eepromWriteByte(1, EEPROM_VERSION);
    }
/*
    findSystemID(systemID);

    if (systemID[0] == 0) {
        printf_P(PSTR("No system id found, add a DS2401 or use old software"));
//        fprintf(&lcd_str, "?f?y0?x00No system id found?nAdd a DS2401 or use old software?n");
        wdt_disable();
        wdt_reset();
        while (true);
    } else {
*/    
        //MAC will be 56 51 99 36 14 00 with example system id
        mymac[1] = systemID[1];
        mymac[2] = systemID[2];
        mymac[3] = systemID[3];
        mymac[4] = systemID[4];
        mymac[5] = systemID[5];
//    }
//    fprintf(&lcd_str, "?y1?x00ID: %02X%02X%02X%02X%02X%02X%02X%02X?n", systemID[0], systemID[1], systemID[2], systemID[3], systemID[4], systemID[5], systemID[6], systemID[7]);

    loadSimpleSensorData();

    //Set digital pins based on selections...
    for (uint8_t i=8; i<=11; i++)
    {
            if (simpleSensorTypes[i] == 0)
            {
                    //output
                    SETBIT(DDRC, (i-6));
            } else {
                    //input
                    CLEARBIT(DDRC, (i-6));
            }
    }


    network_init();

    timer_set(&periodic_timer, CLOCK_SECOND / 2);
    timer_set(&arp_timer, CLOCK_SECOND * 10);

    uip_init();

    //sættes hvert for sig for uip og enc, skal rettes til en samlet setting, så vi kan bruge mymac
    struct uip_eth_addr mac = { {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5} };
//    struct uip_eth_addr mac = {mymac[0], mymac[1], mymac[2], mymac[3], mymac[4], mymac[5]};

    uip_setethaddr(mac);
    httpd_init();
    /*
    #ifdef __DHCPC_H__
            dhcpc_init(&mac, 6);
    #else
     */
    uip_ipaddr(ipaddr, myip[0], myip[1], myip[2], myip[3]);
    uip_sethostaddr(ipaddr);
    uip_ipaddr(ipaddr, gwip[0], gwip[1], gwip[2], gwip[3]);
    uip_setdraddr(ipaddr);
    uip_ipaddr(ipaddr, netmask[0], netmask[1], netmask[2], netmask[3]);
    uip_setnetmask(ipaddr);
    //#endif /*__DHCPC_H__*/

    printf("Setting ip to %u.%u.%u.%u \r\n", myip[0], myip[1], myip[2], myip[3]);

    resolv_init();
    uip_ipaddr(ipaddr, dnsip[0], dnsip[1], dnsip[2], dnsip[3]);
    resolv_conf(ipaddr);
    webclient_init();

    printf("Stokerbot NG R3 ready  -  Firmware %u.%u ...\r\n", SBNG_VERSION_MAJOR, SBNG_VERSION_MINOR);
//    fprintf(&lcd_str, "?y2?x00Firmware %u.%u ready.", SBNG_VERSION_MAJOR, SBNG_VERSION_MINOR);

//    SPILCD_init();

    wdt_reset();

    while (1) {
        //Only one event may fire per loop, listed in order of importance
        //If an event is skipped, it will be run next loop
        if (tickDiff(timer_Count) >= 1) {
            timer_Count = tick;
            wdt_reset(); //sikre at watchdog resetter os hvis timer systemet fejler, vi når her hvert 2ms
            updateCounters(); //bør ske i en interrupt istedet, for at garentere 2ms aflæsning
        } else if (tickDiffS(timer_IOalarm) >= 5) {
            printf("Timer : IO alarm \r\n");
            timer_IOalarm = tickS;
            timedAlarmCheck();
        } else if (tickDiffS(timer_OW) >= 2) {
            printf("Timer : OW \r\n");
            timer_OW = tickS;
            updateOWSensors();
        } else if (tickDiffS(timer_Simple) >= 5) {
            printf("Timer : Simple\r\n");
            timer_Simple = tickS;
            updateSimpleSensors();
        } else if (tickDiffS(timer_SendData) >= 59) {
            printf("Timer : webclient \r\n");
            timer_SendData = tickS;
            webclient_connect();
        } else if (tickDiffS(timer_EEProm) >= 60 * 30) {
            printf("Timer : eeprom \r\n");
            timer_EEProm = tickS;
            timedSaveEeprom();
        }

        //Net handling below



        if (tickDiff(timer_network) >= 1)
        {
            timer_network = tick;
            uip_len = network_read();

            if (uip_len > 0) {
                if (BUF->type == htons(UIP_ETHTYPE_IP)) {
                    uip_arp_ipin();
                    uip_input();
                    if (uip_len > 0) {
                        uip_arp_out();
                        network_send();
                    }
                } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
                    uip_arp_arpin();
                    if (uip_len > 0) {
                        network_send();
                    }
                }

            } else if (timer_expired(&periodic_timer)) {
                timer_reset(&periodic_timer);
                //FLIPBIT(PORTC,5);
    //            printf("Timers : %u %u \r\n", tick, tickS);

                for (uint8_t i = 0; i < UIP_CONNS; i++) {
                    uip_periodic(i);
                    if (uip_len > 0) {
                        uip_arp_out();
                        network_send();
                    }
                }

    #if UIP_UDP
                for (uint8_t i = 0; i < UIP_UDP_CONNS; i++) {
                    uip_udp_periodic(i);
                    if (uip_len > 0) {
                        uip_arp_out();
                        network_send();
                    }
                }
    #endif /* UIP_UDP */

                if (timer_expired(&arp_timer)) {
                    timer_reset(&arp_timer);
                    uip_arp_timer();
                }
            }
        }
    }
    return 0;
}