Search in sources :

Example 6 with ProcessVar

use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.

the class PvTreeNode method setUserObject.

/*
	   * (non-Javadoc)
	   *
	   * @see
	   * javax.swing.tree.DefaultMutableTreeNode#setUserObject(java.lang.Object)
	   */
@SuppressWarnings("unchecked")
@Override
public void setUserObject(Object userObject) {
    super.setUserObject(userObject);
    if (userObject instanceof ProcessVar) {
        Object currVal;
        ProcessVar pv = (ProcessVar) userObject;
        // loop through attributes
        Iterator<Object> it = pv.values().iterator();
        while (it.hasNext()) {
            currVal = it.next();
            // if there is a child PV, then add it as a tree node
            if (currVal instanceof ProcessVar)
                add(new PvTreeNode(currVal));
        }
        pv.addPvChangeListener(this, PvChangeEvent.PV_ADDED | PvChangeEvent.PV_DELETED | PvChangeEvent.PV_CLEARED | PvChangeEvent.PV_ELIMINATED);
    }
}
Also used : ProcessVar(com.fr3ts0n.pvs.ProcessVar)

Example 7 with ProcessVar

use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.

the class PvXMLWriter method writePv.

/**
 * write a process variable as XML to an output stream
 *
 * @param pv             processVar to write
 * @param recursiveDepth Depth of recursive PV writing
 * @param completeDoc    if TRUE, XML document will be initialized before,
 *                       and finalized after writing this PV
 */
@SuppressWarnings("rawtypes")
public void writePv(ProcessVar pv, int recursiveDepth, boolean completeDoc) {
    Object currKey;
    Object currVal;
    // Initialize XML-Document
    if (completeDoc || !documentStarted) {
        startDocument();
    }
    try {
        AttributesImpl attrs = new AttributesImpl();
        attrs.addAttribute("", ATTR_TYPE, ATTR_TYPE, "CDATA", pv.getClass().getName());
        attrs.addAttribute("", ATTR_KEY, ATTR_KEY, "CDATA", String.valueOf(pv.getKeyValue()));
        handler.startElement("", TAG_PROCESSVAR, TAG_PROCESSVAR, attrs);
        if (// Loop through all PV-Attributes
        recursiveDepth > 0) {
            Iterator it = pv.keySet().iterator();
            while (it.hasNext()) {
                currKey = it.next();
                currVal = pv.get(currKey);
                attrs.clear();
                attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDADTA", currKey.toString());
                handler.startElement("", TAG_PVATTRIBUTE, TAG_PVATTRIBUTE, attrs);
                if (currVal != null) {
                    // If current value is a PV itself ...
                    if (currVal instanceof ProcessVar) {
                        // write recursively
                        writePv((ProcessVar) currVal, recursiveDepth - 1, false);
                    } else {
                        // Otherwise write PV-Data as attribute
                        String currStr = currVal.toString();
                        handler.characters(currStr.toCharArray(), 0, currStr.length());
                    }
                }
                // finish attribute XML-element
                handler.endElement("", TAG_PVATTRIBUTE, TAG_PVATTRIBUTE);
            }
        }
        // finish PV XNL-element
        handler.endElement("", TAG_PROCESSVAR, TAG_PROCESSVAR);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    // Finalize XML document
    if (completeDoc) {
        endDocument();
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) ProcessVar(com.fr3ts0n.pvs.ProcessVar) Iterator(java.util.Iterator)

Example 8 with ProcessVar

use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.

the class ObdGaugeAdapter method pvChanged.

@Override
public void pvChanged(PvChangeEvent event) {
    ProcessVar currPv = (ProcessVar) event.getSource();
    CategorySeries series = (CategorySeries) currPv.get(FID_GAUGE_SERIES);
    series.set(0, String.valueOf(currPv.get(EcuDataPv.FID_UNITS)), ((Number) event.getValue()).doubleValue());
}
Also used : ProcessVar(com.fr3ts0n.pvs.ProcessVar) CategorySeries(org.achartengine.model.CategorySeries)

Example 9 with ProcessVar

use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.

the class ObdDataPanel method pvChanged.

/**
 * handle changes in the process var(s)
 *
 * @param event Process var event to be handled
 */
public void pvChanged(PvChangeEvent event) {
    TimeSeries ts;
    EcuDataPv pv;
    switch(event.getType()) {
        case PvChangeEvent.PV_MODIFIED:
            pv = (EcuDataPv) event.getValue();
            if ((ts = selPids.get(getPvId(pv))) != null)
                try {
                    ts.addOrUpdate(new Second(), ((Number) pv.get(EcuDataPv.FID_VALUE)).floatValue());
                } catch (Exception e) {
                    ProcessVar.log.log(Level.SEVERE, "", e);
                }
            break;
        case PvChangeEvent.PV_DELETED:
            // remove from selectable PIDs
            pv = (EcuDataPv) event.getValue();
            selPids.remove(pv);
            break;
        case PvChangeEvent.PV_CLEARED:
            // remove all from selectable PIDs
            selPids.clear();
            break;
        case PvChangeEvent.PV_ADDED:
            if ((event.getValue() instanceof EcuDataPv)) {
                pv = (EcuDataPv) event.getValue();
                addDataSeries(pv);
            } else if ((event.getValue() instanceof Object[])) {
                for (Object currPv : (Object[]) event.getValue()) {
                    addDataSeries((ProcessVar) currPv);
                }
            }
            break;
    }
    // update table column widths
    updateColumnWidths();
}
Also used : EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) TimeSeries(org.jfree.data.time.TimeSeries) ProcessVar(com.fr3ts0n.pvs.ProcessVar) Second(org.jfree.data.time.Second)

Aggregations

ProcessVar (com.fr3ts0n.pvs.ProcessVar)9 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 JTree (javax.swing.JTree)2 TreePath (javax.swing.tree.TreePath)2 EcuDataPv (com.fr3ts0n.ecu.EcuDataPv)1 PvChangeEvent (com.fr3ts0n.pvs.PvChangeEvent)1 PvList (com.fr3ts0n.pvs.PvList)1 GridBagConstraints (java.awt.GridBagConstraints)1 Point (java.awt.Point)1 Transferable (java.awt.datatransfer.Transferable)1 ArrayList (java.util.ArrayList)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 CategorySeries (org.achartengine.model.CategorySeries)1 Second (org.jfree.data.time.Second)1 TimeSeries (org.jfree.data.time.TimeSeries)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1