Exemple #1
0
    void spanResetWires(Pin* source){
        if (source == NULL) return;
        if (source->visited()) return;
        source->visited(true);

        Wire *wire = source->wire();
        if (!wire) return;
        //cout <<"spanResetWires wire: "<< wire->info()<<endl;
        wire->voltage(false);
        list<Pin *>pins = wire->pins();
        list<Pin *>::iterator it;
        for (it = pins.begin(); it != pins.end(); it++){
            Pin *pin = (*it);
            if (pin == source) continue;
            pin->visited(true);
            Element *element = pin->element();
            if (element->type() == "switch"){
                Switch *switc = (Switch *)element;
                Pin *nextPin = switc->outPin(pin);
                spanResetWires(nextPin);
            }
            else if (element->type() == "resistor"){
                Resistor *resistor = (Resistor *)element;
                Pin *nextPin = resistor->outPin(pin);
                spanResetWires(nextPin);
                
            }
            else if (element->type() == "bridge"){
                Bridge *bridge = (Bridge *)element;
                Pin *nextPin = bridge->outPin(pin);
                spanResetWires(nextPin);
            }
        }
    }
Exemple #2
0
    //void spanResistors(Pin *source, list<Wire *>wires){
    void spanResistors(Pin *source, list<Resistor *>resistors){
        //cout <<"entering spanResistors"<<endl;
        /* 1. try to reach the end. 
         * 2. if end is reached, must go back and turn all wires on in the path
         */
        if (source == NULL) return;
        if (source->visited()) return;
        source->visited(true);
        //debug("spanResistors source pin: "<< source->fullName());

        Wire *wire = source->wire();
        if (!wire) return;
        //debug("spanResistors wire: "<< wire->name());
        list<Pin *>pins = wire->pins();
        list<Pin *>::iterator it;
        for (it = pins.begin(); it != pins.end(); it++){
            Pin *pin = (*it);
            if (pin == source) continue;
            pin->visited(true);
            //get element for source
            Element *element = pin->element();
            if (element->type() == "source"){
                //cerr << "Encountered source "<< element->info() <<" while completing circuit."<<endl;
                return;
            }
            else if (element->type() == "ground"){
                //cout <<"ground reached: "<<endl;
                //end reached.
                activateResistors(resistors);
                //upWires(wires);
            }
            else if (element->type() == "switch"){
                Switch *switc = (Switch *)element;
                if (!switc->isOn()) continue;

                Pin *nextPin = switc->outPin(pin);
                spanResistors(nextPin,resistors);
            }
            else if (element->type() == "resistor"){
                Resistor *resistor = (Resistor *)element;
                resistors.push_back(resistor);
                Pin *nextPin = resistor->outPin(pin);
                spanResistors(nextPin, resistors);
            }
            else if (element->type() == "bridge"){
                Bridge *bridge = (Bridge *)element;
                Pin *nextPin = bridge->outPin(pin);
                spanResistors(nextPin, resistors);
            }
        }
    }
Exemple #3
0
    int spanVoltage(Pin* source, bool voltage){
        if (source == NULL) return 0;
        if (source->visited()) return 0;
        source->visited(true);

        Wire *wire = source->wire();
        if (!wire) {
            return 0; //have separate audit if you want to check connectivity
            cerr << "source has no wire. source: " << source->name() <<endl;
            return 20;
        }
        /*
        if (wire->visited()){
            bool wireVoltage = wire->voltage();
            if (wireVoltage != voltage){
                cerr << "inconsistent voltage found while updating voltages on wire: " << wire->info() <<endl;
                return 21;
            }
            return 0;
        }*/
        //cout <<"spanVoltage setting wire: "<< wire->info()<< " to voltage: "<<voltage<<endl;
        wire->voltage(voltage);
        list<Pin *>pins = wire->pins();
        list<Pin *>::iterator it;
        for (it = pins.begin(); it != pins.end(); it++){
            Pin *pin = (*it);
            //cout <<"spanvoltage pin name: "<<pin->name()<<endl;
            if (pin == source) continue;
            pin->visited(true);

            Element *element = pin->element();
            if (element->type() == "source"){
                Source *source = (Source *)element;
                //warning? 

            }
            else if(element->type() == "ground"){ 
                bool gv = pin->wire()->voltage();
                if (gv){
                    cerr << "error: voltage at ground is high. " << pin->wire()->info()<<endl;
                    return 24;
                }
            }
            else if (element->type() == "switch"){
                Switch *switc = (Switch *)element;
                if (!switc->isOn()) continue;
                Pin *nextPin = switc->outPin(pin);
                int rVal = spanVoltage(nextPin, voltage);
                if (rVal != 0) return rVal;
            }
            else if (element->type() == "resistor"){
                Resistor *resistor = (Resistor *)element;
                Pin *nextPin = resistor->outPin(pin);
                bool nextVoltage = voltage;
                if (resistor->isActive()) nextVoltage = false;
                int rVal = spanVoltage(nextPin, nextVoltage);
                if (rVal != 0) return rVal;
                
            }
            else if (element->type() == "bridge"){
                Bridge *bridge = (Bridge *)element;
                Pin *nextPin = bridge->outPin(pin);
                int rVal = spanVoltage(nextPin, voltage);
                if (rVal != 0) return rVal;
            }

        }
        return 0;
    }