package promauto.jroboplc.roboplant;
import static org.junit.Assert.*;
import org.junit.Test;
import promauto.jroboplc.JRoboUtils;
import promauto.jroboplc.Module;
import promauto.jroboplc.Tag;
import promauto.jroboplc.roboplant.Mchb;
import promauto.jroboplc.roboplant.MchbInit;
import promauto.jroboplc.roboplant.MchbMdta;
import promauto.jroboplc.roboplant.Mdta;
import promauto.jroboplc.roboplant.MdtaInit;
import promauto.jroboplc.roboplant.RoboplantAddressConvertor;
public class MchbMdtaTest {
@Test
public void test() {
System.out.println("\n\n\n===== MchbMdtaTest");
// emulating io modules
RoboplantAddressConvertor.add(1, "mod1", "Input%02d", true);
RoboplantAddressConvertor.add(1, "mod2", "Output%02d", false);
Module m0 = new Module();
m0.moduleName = "mod0";
Module m1 = new Module();
m1.moduleName = "mod1";
Module m2 = new Module();
m2.moduleName = "mod2";
try {
JRoboUtils.clearModules();
JRoboUtils.addModules(m0);
JRoboUtils.addModules(m1);
JRoboUtils.addModules(m2);
} catch (Exception e) {
}
Tag in0 = m1.tagTable.createTag("Input00", 0);
Tag in1 = m1.tagTable.createTag("Input01", 0);
Tag in2 = m1.tagTable.createTag("Input02", 0);
Tag in3 = m1.tagTable.createTag("Input03", 0);
Tag out0 = m2.tagTable.createTag("Output00", 0);
Tag out1 = m2.tagTable.createTag("Output01", 0);
Tag out2 = m2.tagTable.createTag("Output02", 0);
// initializers
MchbInit _mchb = new MchbInit() { // _mchb
@Override
public void init(Mchb mchb) {
mchb.tagTimeStart.set( 3 );
mchb.tagFlags.set( 0x81 );
}
};
MdtaInit _Pdp = new MdtaInit("_Pdp", "Подпор"); // _Pdp
MdtaInit _RKS = new MdtaInit("_RKS", "РКС") { // _RKS
@Override
public void init(Mdta mdta) {
mdta.flagUseMchaSost = true;
mdta.flagUseTrigres = true;
mdta.flagCanSuspend = true;
mdta.tagFlags.set(3);
}
};
// MchbMdta testing
MchbMdta m = new MchbMdta(m0, "444", "Нория", _mchb, _Pdp, _RKS);
Mchb mchb = m.mchb;
mchb.channelOut.tagChannel.set( 0x100 );
Mdta d1 = m.getMdta("_Pdp");
d1.channel.tagChannel.set( 0x101 );
Mdta d2 = m.createMdta("_Tok", "Ток", true, true, false);
d2.channel.tagChannel.set( 0x102 );
d2.tagFlags.set( 2 );
Mdta d3 = m.getMdta("_RKS");
d3.channel.tagChannel.set( 0x103 );
m.execute();
assertEquals(mchb.channelOut.tagName.getString(), "mod2@Output00");
assertEquals(mchb.channelIn.tagName.getString(), "mod1@Input00");
assertEquals(d1.channel.tagName.getString(), "mod1@Input01");
assertEquals(d2.channel.tagName.getString(), "mod1@Input02");
assertEquals(d3.channel.tagName.getString(), "mod1@Input03");
assertEquals(mchb.tagSost.getName(), "MCHB_444_Sost");
assertEquals(d1.tagSost.getName(), "MDTA_444_Pdp_Sost");
assertEquals(d2.tagSost.getName(), "MDTA_444_Tok_Sost");
assertEquals(d3.tagSost.getName(), "MDTA_444_RKS_Sost");
assertEquals(mchb.channelOut.tagChannel.getName(), "MCHB_444_Channel1");
assertEquals(mchb.channelIn.tagChannel.getName(), "MCHB_444_Channel2");
assertEquals(d1.channel.tagChannel.getName(), "MDTA_444_Pdp_Channel");
// Everything = off, mchb=stopped
assertEquals(mchb.tagSost.get(), 0);
assertEquals(d1.tagOutput.get(), 0);
assertEquals(d2.tagOutput.get(), 0);
assertEquals(d3.tagOutput.get(), 0);
assertEquals(d1.tagSost.get(), 0);
assertEquals(d2.tagSost.get(), 0);
assertEquals(d3.tagSost.get(), 0);
// Pdp = On, mchb=stopped
in1.set(1);
m.execute();
assertEquals(mchb.tagSost.get(), 0);
assertEquals(d1.tagOutput.get(), 1);
assertEquals(d2.tagOutput.get(), 0);
assertEquals(d3.tagOutput.get(), 0);
assertEquals(d1.tagSost.get(), 3);
assertEquals(d2.tagSost.get(), 0);
assertEquals(d3.tagSost.get(), 0);
// Tok = On, mchb=stopped
in2.set(1);
m.execute();
assertEquals(mchb.tagSost.get(), 0);
assertEquals(d1.tagOutput.get(), 1);
assertEquals(d2.tagOutput.get(), 0);
assertEquals(d3.tagOutput.get(), 0);
assertEquals(d1.tagSost.get(), 3);
assertEquals(d2.tagSost.get(), 1);
assertEquals(d3.tagSost.get(), 0);
// Rks = On, mchb=stopped
in3.set(1);
m.execute();
assertEquals(mchb.tagSost.get(), 0);
assertEquals(d1.tagOutput.get(), 1);
assertEquals(d2.tagOutput.get(), 0);
assertEquals(d3.tagOutput.get(), 0);
assertEquals(d1.tagSost.get(), 3);
assertEquals(d2.tagSost.get(), 1);
assertEquals(d3.tagSost.get(), 1);
// Everything = On, mchb=started
mchb.tagControl.set( 3 );
m.execute();
m.execute();
m.execute();
assertEquals(mchb.tagMasterOut.get(), 0);
assertEquals(mchb.tagSost.get(), 2);
assertEquals(d1.tagOutput.get(), 1);
assertEquals(d2.tagOutput.get(), 0);
assertEquals(d3.tagOutput.get(), 0);
assertEquals(d1.tagSost.get(), 3);
assertEquals(d2.tagSost.get(), 1);
assertEquals(d3.tagSost.get(), 1);
in0.set(1);
m.execute();
assertEquals(mchb.tagMasterOut.get(), 0);
assertEquals(mchb.tagSost.get(), 1);
assertEquals(d1.tagOutput.get(), 1);
assertEquals(d2.tagOutput.get(), 0);
assertEquals(d3.tagOutput.get(), 0);
assertEquals(d1.tagSost.get(), 3);
assertEquals(d2.tagSost.get(), 1);
assertEquals(d3.tagSost.get(), 1);
m.execute();
assertEquals(mchb.tagMasterOut.get(), 0);
assertEquals(mchb.tagSost.get(), 5);
assertEquals(d1.tagOutput.get(), 1);
assertEquals(d2.tagOutput.get(), 1);
assertEquals(d3.tagOutput.get(), 1);
assertEquals(d1.tagSost.get(), 3);
assertEquals(d2.tagSost.get(), 3);
assertEquals(d3.tagSost.get(), 3);
mchb.tagControl.set( 3 + 4 );
m.execute();
m.execute();
m.execute();
m.execute();
assertEquals(mchb.tagMasterOut.get(), 0);
assertEquals(mchb.tagSost.get(), 2);
assertEquals(d1.tagOutput.get(), 1);
assertEquals(d2.tagOutput.get(), 0);
assertEquals(d3.tagOutput.get(), 0);
assertEquals(d1.tagSost.get(), 3);
assertEquals(d2.tagSost.get(), 1);
assertEquals(d3.tagSost.get(), 1);
in3.set(0);
m.execute();
assertEquals(mchb.tagMasterOut.get(), 0);
assertEquals(mchb.tagSost.get(), 1);
assertEquals(d1.tagOutput.get(), 1);
assertEquals(d2.tagOutput.get(), 0);
assertEquals(d3.tagOutput.get(), 0);
assertEquals(d1.tagSost.get(), 3);
assertEquals(d2.tagSost.get(), 1);
assertEquals(d3.tagSost.get(), 0);
m.execute();
assertEquals(mchb.tagMasterOut.get(), 0);
assertEquals(mchb.tagSost.get(), 1);
assertEquals(d1.tagOutput.get(), 1);
assertEquals(d2.tagOutput.get(), 1);
assertEquals(d3.tagOutput.get(), 0);
assertEquals(d1.tagSost.get(), 3);
assertEquals(d2.tagSost.get(), 3);
assertEquals(d3.tagSost.get(), 0);
}
}