Search in sources :

Example 1 with Terminal

use of com.cas.circuit.vo.Terminal in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompCPU method elecCompStart.

/**
 * 开元器件指示灯<br>
 * 产生信号电<br>
 */
protected void elecCompStart() {
    LOG.info("开始启动{}{}", elecComp.getName(), elecComp.getProxy().getTagName());
    // System.err.println(this.getClass().getCanonicalName() + ".elecCompStart(start...)");
    getElecComp().getLightIOList().forEach(l -> l.openLight());
    // 信号电压起源
    R r = null;
    Terminal ipHigher = null;
    Terminal ipLower = null;
    // CBX - CB104 CB105 CB106 CB107
    if (cb_evn_names != null) {
        for (int i = 0; i < cb_evn_names.size(); i++) {
            r = R.getR(cb_evn_names.get(i));
            if (r == null) {
                ipLower = cbx_jacks.get(i).getStitch(1);
                ipHigher = cbx_jacks.get(i).getStitch(2);
                if (ipHigher == null || ipLower == null) {
                    // System.err.println(getClass() + cbx_jacks.get(i).getId() + "中找不到1 或 2号针脚");
                    continue;
                }
                r = R.createSignal(cb_evn_names.get(i), ipHigher, ipLower, CB_SIGNAL_VOLT);
            }
            r.shareVoltage();
        }
    }
    // JF - JD1A JD1B
    if (jf_evn_names != null) {
        for (int i = 0; i < jf_evn_names.size(); i++) {
            r = R.getR(jf_evn_names.get(i));
            if (r == null) {
                ipHigher = jf_jacks.get(i).getStitch(3);
                ipLower = jf_jacks.get(i).getStitch(13);
                if (ipHigher == null || ipLower == null) {
                    // System.err.println(getClass() + jf_jacks.get(i).getId() + "中找不到3 或 13号针脚");
                    continue;
                }
                r = R.createSignal(jf_evn_names.get(i), ipHigher, ipLower, JF_SIGNAL_VOLT);
            }
            r.shareVoltage();
        }
    }
    // COP - COP10B COP10B
    if (cop_jacks != null) {
        for (int i = 0; i < cop_evn_names.size(); i++) {
            r = R.getR(cop_evn_names.get(i));
            if (r == null) {
                ipHigher = cop_jacks.get(i).getStitch(1);
                ipLower = cop_jacks.get(i).getStitch(3);
                if (ipHigher == null || ipLower == null) {
                    LOG.warn("{}.{}中找不到1 或 3号针脚", getClass(), cop_jacks.get(i).getId());
                    continue;
                }
                r = R.createSignal(cop_evn_names.get(i), ipHigher, ipLower, COP_SIGNAL_VOLT);
            }
            r.shareVoltage();
        }
    }
    // jfr* - jfr1 jfr2
    if (jfr_jacks != null) {
        String env = null;
        for (int i = 0; i < jfr_evn_names.size(); i++) {
            for (int j = 0; j < jfrEnvEnds.length; j++) {
                // env = jfr_evn_names.get(i) + jfrEnvEnds[j][0] + "_" + jfrEnvEnds[j][1];
                env = MessageFormat.format("{0}{1}_{2}", jfr_evn_names.get(i), jfrEnvEnds[j][0], jfrEnvEnds[j][1]);
                r = R.getR(env);
                if (r == null) {
                    ipHigher = jfr_jacks.get(i).getStitch(jfrEnvEnds[j][0]);
                    ipLower = jfr_jacks.get(i).getStitch(jfrEnvEnds[j][1]);
                    if (ipHigher == null || ipLower == null) {
                        // System.err.println(getClass() + jfr_jacks.get(i).getId() + "中找不到" + jfrEnvEnds[j][0] + " 或 " + jfrEnvEnds[j][1] + "号针脚");
                        continue;
                    }
                    r = R.createSignal(env, ipHigher, ipLower, COP_SIGNAL_VOLT);
                }
                r.shareVoltage();
            }
        }
    }
    // System.err.println(this.getClass().getCanonicalName() + ".elecCompStart(end...)");
    LOG.info("{}{}启动完成!", elecComp.getName(), elecComp.getProxy().getTagName());
}
Also used : R(com.cas.circuit.util.R) Terminal(com.cas.circuit.vo.Terminal)

Example 2 with Terminal

use of com.cas.circuit.vo.Terminal in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompCPU method getStitch.

/**
 * @param jackNm 信号发生的插孔名称
 * @param index 具体的针脚号
 */
public Terminal getStitch(String jackName, int index) {
    Jack jack = getJackMap().get(jackName);
    if (jack == null) {
        String errMsg = MessageFormat.format("没有找到名称为: {0}的插孔", jackName);
        LOG.warn(errMsg);
        throw new RuntimeException(errMsg);
    }
    Terminal stitch = jack.getStitch(index);
    if (stitch == null) {
        String errMsg = MessageFormat.format("插孔{0}中没有找到第{1}跟针脚", jackName, index);
        LOG.warn(errMsg);
        throw new RuntimeException(errMsg);
    }
    return stitch;
}
Also used : Jack(com.cas.circuit.vo.Jack) Terminal(com.cas.circuit.vo.Terminal)

Example 3 with Terminal

use of com.cas.circuit.vo.Terminal in project TeachingInSimulation by ScOrPiOzzy.

the class Inverter method onReceivedLocal.

@Override
protected void onReceivedLocal(Terminal terminal) {
    super.onReceivedLocal(terminal);
    if (_r == terminal || _s == terminal || _t == terminal) {
        // 分别测量uvw三者之间的电压情况
        MesureResult resultUV = R.matchRequiredVolt(Voltage.IS_AC, _r, _s, 380, 10);
        MesureResult resultVW = R.matchRequiredVolt(Voltage.IS_AC, _s, _t, 380, 10);
        MesureResult resultWU = R.matchRequiredVolt(Voltage.IS_AC, _t, _r, 380, 10);
        // 判断三者之间是否存在电势差
        boolean tmp = Util.notEmpty(resultUV) && Util.notEmpty(resultWU) && Util.notEmpty(resultVW);
        List<R> controlVoltPower = R.get3Phase(controlVoltEnv);
        if (tmp && !workable) {
            workable = true;
        // if (controlVoltPower == null) {
        // controlVoltPower = R.create3Phase(controlVoltEnv, _u, _v, _w, new Terminal(), 380);
        // }
        // R.set3PhaseFrequency(controlVoltEnv, frequency);
        // R.reversePhase(controlVoltEnv, dir == Dir.CW);
        // 
        // for (R r : controlVoltPower) {
        // r.shareVoltage();
        // }
        } else if (!tmp && workable) {
            if (controlVoltPower != null) {
                for (R r : controlVoltPower) {
                    r.shutPowerDown();
                }
            }
            workable = false;
        }
    } else if (!workable) {
        return;
    } else if (_rda == terminal || _rdb == terminal) {
        // 处理PLC侧发来的数据
        MesureResult result = R.matchRequiredVolt(Voltage.IS_DC, _rda, _rdb, 5, 1);
        if (result != null) {
            Map<String, String> data = R.getR(result.getEvn()).getVoltage().getData();
            assist.decode(data);
        }
        if (voltNeedChange) {
            List<R> controlVoltPower = R.get3Phase(controlVoltEnv);
            if (controlVoltPower != null) {
                // 断电
                for (R r : controlVoltPower) {
                    r.shutPowerDown();
                }
            }
            if (dir != null) {
                controlVoltPower = R.create3Phase(controlVoltEnv, _u, _v, _w, new Terminal(), 380);
                // 通电
                // System.err.println("Inverter.onReceivedLocal()" + frequency);
                R.set3PhaseFrequency(controlVoltEnv, frequency);
                R.reversePhase(controlVoltEnv, dir == Dir.CW);
                for (R r : controlVoltPower) {
                    r.shareVoltage();
                }
            }
        }
    } else {
    }
}
Also used : MesureResult(com.cas.circuit.util.MesureResult) R(com.cas.circuit.util.R) Terminal(com.cas.circuit.vo.Terminal)

Example 4 with Terminal

use of com.cas.circuit.vo.Terminal in project TeachingInSimulation by ScOrPiOzzy.

the class R method collectIsopotentialTerminal.

public static void collectIsopotentialTerminal(Terminal ref, IP isopotential, R r) {
    // }
    if (!isopotential.hasTerminal(ref)) {
        isopotential.addTerminal(ref);
    }
    // 遍历所有和ref关联的导线
    List<Terminal> wireAnotherTerms = new ArrayList<Terminal>();
    for (Wire wire : ref.getWires()) {
        if (!wire.isBothBinded()) {
            // toRemove.add(linker);
            continue;
        }
        if (isopotential.getPassedWires().contains(wire) || wire.isBrokenBreak()) {
            continue;
        }
        isopotential.getPassedWires().add(wire);
        Terminal anotherTerm = wire.getAnother(ref);
        if (anotherTerm != null) {
            // System.out.println(str + "R.collectIsopotentialTerminal ()" + wire);
            wireAnotherTerms.add(anotherTerm);
            collectIsopotentialTerminal(anotherTerm, isopotential, r);
        }
    }
    // FIXME 删除只接了一个连接头的导线????
    // wires.removeAll(toRemove);
    // 获取线缆中与ref关联的连接头
    Terminal contacted = ref.getContacted();
    if (contacted != null && !isopotential.getPassedContacted().contains(contacted)) {
        isopotential.getPassedContacted().add(contacted);
        collectIsopotentialTerminal(contacted, isopotential, r);
    }
    // 遍历和ref有电阻关系的电阻
    Map<Terminal, ResisRelation> resisRelationMap = ref.getResisRelationMap();
    Iterator<Entry<Terminal, ResisRelation>> iter = resisRelationMap.entrySet().iterator();
    Terminal key_Terminal = null;
    ResisRelation resisRelation = null;
    while (iter.hasNext()) {
        Map.Entry<Terminal, ResisRelation> entry = iter.next();
        key_Terminal = entry.getKey();
        resisRelation = entry.getValue();
        if (!isopotential.getPassedResis().contains(key_Terminal)) {
            isopotential.getPassedResis().add(key_Terminal);
            if (resisRelation.getValue() == 0 || wireAnotherTerms.contains(key_Terminal)) {
                // 阻值为零,则以ref对应的连接头递归处理   或  此电阻被短接了
                collectIsopotentialTerminal(key_Terminal, isopotential, r);
            } else {
                isopotential.getResisRelationList().add(resisRelation);
                if (r != null) {
                    // 遇到连接头是电阻的一端的,先创建出一个复合电阻对象
                    if (r.resisRelationWithCR.get(resisRelation) != null) {
                        CR cr = r.resisRelationWithCR.get(resisRelation);
                        isopotential.getCRList().add(cr);
                        cr.setIospo2(isopotential);
                    } else {
                        CR cr = new CR(r);
                        // 设置这个复合电阻的所指代的真实电阻
                        cr.addResisRelation(resisRelation);
                        isopotential.getCRList().add(cr);
                        cr.setIospo1(isopotential);
                        r.resisRelationWithCR.put(resisRelation, cr);
                    }
                }
            }
        }
    }
}
Also used : ResisRelation(com.cas.circuit.vo.ResisRelation) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Wire(com.cas.circuit.vo.Wire) Terminal(com.cas.circuit.vo.Terminal) HashMap(java.util.HashMap) Map(java.util.Map) CR(com.cas.circuit.vo.CR)

Example 5 with Terminal

use of com.cas.circuit.vo.Terminal in project TeachingInSimulation by ScOrPiOzzy.

the class R method shareVoltage.

public void shareVoltage() {
    // 记录当前电路中涉及的连接头lastCircuitTerminal
    List<Terminal> lastCircuitTerminal = new ArrayList<Terminal>();
    for (IP ip : allIsopoList) {
        addNonRepeatListAll(lastCircuitTerminal, ip.getTerminals());
    // lastCircuitTerminal.addAll(ip.getTerminals());
    }
    int count = 0;
    // 真实的分压操作
    while (shareVoltageLocal()) {
        count++;
        if (count > 10) {
            // 防止死循环
            System.out.println("死循环啦");
            break;
        }
    }
    if (startIP == null || endIP == null) {
        return;
    }
    // 找出分压后当前电路中的连接头thisCircuitTerminal
    List<ElecCompDef> elecCompList = new ArrayList<ElecCompDef>();
    List<Terminal> thisCircuitTerminal = new ArrayList<Terminal>();
    for (IP ip : allIsopoList) {
        addNonRepeatListAll(thisCircuitTerminal, ip.getTerminals());
        // thisCircuitTerminal.addAll(ip.getTerminals());
        // 找出所走到的连接头所属元器件,因为有些元器件如:开关电源,可算是一个电源的,当满足输入电压后,将输出电压
        findElecComp(elecCompList, ip.getTerminals(), true);
    }
    // 过滤出电路没有走到的连接头,这些lastCircuitTerminal连接头即将清除电压
    lastCircuitTerminal.removeAll(thisCircuitTerminal);
    // 找出要被清理电压的连接头所属的元器件,因为有些元器件如:开关电源,可算是一个电源的将无法输出电压
    findElecComp(elecCompList, lastCircuitTerminal, false);
    // System.out.println("shareVoltage这些连接头 本次电路中没有走到" + lastCircuitTerminal);
    // 即将清除电压
    IP ip = null;
    for (Terminal terminal : lastCircuitTerminal) {
        // 当前电源的两个输出端,及与输出端子处于同电位的,【不】清除电压
        if (!startIP.hasTerminal(terminal) && !endIP.hasTerminal(terminal)) {
            ip = terminal.getIsopotential(voltage.getEnv());
            if (ip != null) {
                ip.detory();
            }
            terminal.removeVolt(voltage.getEnv());
        }
    }
    for (ElecCompDef elecCompDef : elecCompList) {
        if (elecCompDef != null) {
            elecCompDef.doMagnetism();
        }
    }
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) IP(com.cas.circuit.vo.IP) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Terminal(com.cas.circuit.vo.Terminal)

Aggregations

Terminal (com.cas.circuit.vo.Terminal)25 Jack (com.cas.circuit.vo.Jack)12 ArrayList (java.util.ArrayList)8 R (com.cas.circuit.util.R)7 Spatial (com.jme3.scene.Spatial)7 ElecCompDef (com.cas.circuit.vo.ElecCompDef)6 Wire (com.cas.circuit.vo.Wire)6 GasPort (com.cas.gas.vo.GasPort)5 Cable (com.cas.circuit.vo.Cable)4 Node (com.jme3.scene.Node)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 ResisRelation (com.cas.circuit.vo.ResisRelation)3 HashMap (java.util.HashMap)3 MesureResult (com.cas.circuit.util.MesureResult)2 CR (com.cas.circuit.vo.CR)2 ControlIO (com.cas.circuit.vo.ControlIO)2 IP (com.cas.circuit.vo.IP)2 Pipe (com.cas.gas.vo.Pipe)2 ColorRGBA (com.jme3.math.ColorRGBA)2