Search in sources :

Example 1 with SerialPortProxyEvent

use of com.infiniteautomation.mango.io.serial.SerialPortProxyEvent in project ma-modules-public by infiniteautomation.

the class SerialDataSourceTest method testCustomPoint.

/**
 * TODO Break this into pieces to be re-usable
 */
@Test
public void testCustomPoint() {
    String message = "000005,Fri 11 January 2013 15:18:55,\u0002Q,244,000.03,1017.3,049.2,+021.4,+10.3,+040.50,+000.06,+000.04,0000.000,+11.6,00,\u000277\r\n";
    String[] expected = { "244", "000.03", "+000.06" };
    // Setup Data Source
    String dataSourceMessageRegex = "()[\\d\\D\\s\\S\\w\\W]*";
    int dataSourcePointIdentifierIndex = 1;
    boolean dataSourceUseTerminator = true;
    String dataSourceMessageTerminator = "\n";
    SerialDataSourceVO vo = SerialDataSourceTestData.getStandardDataSourceVO();
    vo.setMessageRegex(dataSourceMessageRegex);
    vo.setPointIdentifierIndex(dataSourcePointIdentifierIndex);
    vo.setUseTerminator(dataSourceUseTerminator);
    vo.setMessageTerminator(dataSourceMessageTerminator);
    SerialDataSourceRT rt = (SerialDataSourceRT) vo.createDataSourceRT();
    // Setup Data Point RTs
    // String pointIdentifier = "";
    // "([\\d\\D\\s\\S\\w\\W]*),[\\d\\D\\s\\S\\w\\W]*";
    String windDirectionRegex = "[\\d]*,[\\w\\s:]*,[\u0002\\w]*,([\\w]*),[\\d\\D\\s\\S\\w\\W]*";
    // "([\\d\\D\\s\\S\\w\\W]*),[\\d\\D\\s\\S\\w\\W]*";
    String windSpeedRegex = "[\\d]*,[\\w\\s:]*,[\u0002\\w]*,[\\w]*,([\\d\\.]*),[\\d\\D\\s\\S\\w\\W]*";
    // "([\\d\\D\\s\\S\\w\\W]*),[\\d\\D\\s\\S\\w\\W]*";
    String ip1Regex = "[\\d]*,[\\w\\s:]*,[\u0002\\w]*,[\\w]*,[\\d\\.]*,[\\d\\.]*,[\\d\\.]*,[\\d\\.+-]*,[\\d\\.+-]*,[\\d\\.+-]*,([\\d\\.+-]*),[\\d\\D\\s\\S\\w\\W]*";
    DataPointRT windDirection = SerialDataSourceTestData.getCustomPoint("windDirection", "windDirection", windDirectionRegex, 1, "", vo);
    rt.addDataPoint(windDirection);
    DataPointRT windSpeed = SerialDataSourceTestData.getCustomPoint("windSpeed", "windSpeed", windSpeedRegex, 1, "", vo);
    rt.addDataPoint(windSpeed);
    DataPointRT ip1 = SerialDataSourceTestData.getCustomPoint("ip1", "ip1", ip1Regex, 1, "", vo);
    rt.addDataPoint(ip1);
    // Connect
    try {
        assertTrue(rt.connect());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    vo.setMessageTerminator("\n");
    vo.setUseTerminator(true);
    // load a test input
    proxy.getTestInputStream().pushToMockStream(message);
    // Create an event to force the Data Source to read the port
    SerialPortProxyEvent evt = new SerialPortProxyEvent(System.currentTimeMillis());
    rt.serialEvent(evt);
    // test the return value(s), reverse list because Mango stores latest value at [0]
    List<PointValueTime> windSpeedValues = Lists.reverse(windSpeed.getLatestPointValues(1));
    List<PointValueTime> windDirectionValues = Lists.reverse(windDirection.getLatestPointValues(1));
    List<PointValueTime> ip1Values = Lists.reverse(ip1.getLatestPointValues(1));
    List<PointValueTime> received = new ArrayList<PointValueTime>();
    received.addAll(windSpeedValues);
    received.addAll(windDirectionValues);
    received.addAll(ip1Values);
    boolean found;
    for (int k = 0; k < expected.length; k += 1) {
        found = false;
        for (int i = 0; i < received.size(); i += 1) {
            if (expected[k].equals(received.get(i).getStringValue()))
                found = true;
        }
        if (!found)
            fail("No value match found for: '" + expected[k] + "' point value");
    }
}
Also used : SerialDataSourceVO(com.infiniteautomation.serial.vo.SerialDataSourceVO) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) SerialPortProxyEvent(com.infiniteautomation.mango.io.serial.SerialPortProxyEvent) Test(org.junit.Test)

Example 2 with SerialPortProxyEvent

use of com.infiniteautomation.mango.io.serial.SerialPortProxyEvent in project ma-modules-public by infiniteautomation.

the class SerialDataSourceTest method testReadPointValue.

@Test
public void testReadPointValue() {
    // Connect
    try {
        assertTrue(rt.connect());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    for (String s : testCases.keySet()) {
        SerialDataSourceTestCase stc = testCases.get(s);
        rt.addDataPoint(stc.getTargetPoint());
        if (stc.getCondition().equals("terminator")) {
            vo.setMessageTerminator(stc.getTerminator());
            vo.setUseTerminator(true);
        } else if (stc.getCondition().equals("timeout")) {
            vo.setUseTerminator(false);
        }
        // load a test input
        proxy.getTestInputStream().pushToMockStream(s);
        // Create an event to force the Data Source to read the port
        SerialPortProxyEvent evt = new SerialPortProxyEvent(timer.currentTimeMillis());
        rt.serialEvent(evt);
        // Fast Forward to fire any events
        time = time + 5;
        timer.fastForwardTo(time);
        List<PointValueTime> pvts = Lists.reverse(stc.getTargetPoint().getLatestPointValues(stc.getNewValueCount()));
        boolean found;
        for (int k = 0; k < stc.getResults().length; k += 1) {
            found = false;
            for (int i = 0; i < pvts.size(); i += 1) {
                if (stc.getResult(k).equals(pvts.get(i).getStringValue()))
                    found = true;
            }
            if (!found)
                fail("No value match found for: '" + stc.getResult(k) + "' point value");
        }
        // Remove the point for the next test
        rt.removeDataPoint(stc.getTargetPoint());
    }
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) SerialDataSourceTestCase(com.infiniteautomation.serial.SerialDataSourceTestCase) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) SerialPortProxyEvent(com.infiniteautomation.mango.io.serial.SerialPortProxyEvent) Test(org.junit.Test)

Aggregations

SerialPortException (com.infiniteautomation.mango.io.serial.SerialPortException)2 SerialPortProxyEvent (com.infiniteautomation.mango.io.serial.SerialPortProxyEvent)2 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)2 Test (org.junit.Test)2 SerialDataSourceTestCase (com.infiniteautomation.serial.SerialDataSourceTestCase)1 SerialDataSourceVO (com.infiniteautomation.serial.vo.SerialDataSourceVO)1 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)1 ArrayList (java.util.ArrayList)1