Search in sources :

Example 11 with EcuDataPv

use of com.fr3ts0n.ecu.EcuDataPv in project AndrOBD by fr3ts0n.

the class ObdProt method preparePidPvs.

/**
 * prepare process variables for each PID
 * @param pvList list of process vars
 */
public void preparePidPvs(int obdService, PvList pvList) {
    // reset fixed PIDs
    resetFixedPid();
    HashMap<String, EcuDataPv> newList = new HashMap<String, EcuDataPv>();
    for (Integer currPid : pidSupported) {
        Vector<EcuDataItem> items = dataItems.getPidDataItems(obdService, currPid);
        // if no items defined, create dummy item
        if (items == null) {
            log.warning(String.format("unknown PID %02X", currPid));
            // create new dummy item / OneToOne conversion
            Conversion[] dummyCnvs = { EcuConversions.dfltCnv, EcuConversions.dfltCnv };
            EcuDataItem newItem = new EcuDataItem(currPid, 0, 0, 0, 32, 0xFFFFFFFF, dummyCnvs, "%#08x", null, null, String.format("PID %02X", currPid), String.format("PID_%02X", currPid));
            dataItems.appendItemToService(obdService, newItem);
            // re-load data items for this PID
            items = dataItems.getPidDataItems(obdService, currPid);
        }
        // loop through all items found ...
        for (EcuDataItem pidPv : items) {
            if (pidPv != null) {
                newList.put(pidPv.toString(), pidPv.pv);
            }
        }
    }
    pvList.putAll(newList, PvChangeEvent.PV_ADDED, false);
}
Also used : EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) HashMap(java.util.HashMap) Conversion(com.fr3ts0n.ecu.Conversion) EcuDataItem(com.fr3ts0n.ecu.EcuDataItem)

Example 12 with EcuDataPv

use of com.fr3ts0n.ecu.EcuDataPv in project AndrOBD by fr3ts0n.

the class Kw1281Prot method savePreset.

/**
 * save current preset data
 */
protected void savePreset() {
    Thread saveThd = new Thread() {

        @Override
        public void run() {
            EcuDataPv vid = (EcuDataPv) VidPvs.get(0);
            String fileName = vid.get(EcuDataPv.FID_VALUE).toString().trim() + ".prs";
            // notify about property change
            firePropertyChange(new PropertyChangeEvent(this, "preset", lastPresetName, fileName));
            // remember preset
            lastPresetName = fileName;
            // 1st VID is used as preset filename
            File pstFile = new File(fileName);
            // if file aleady exists, we don't save it
            if (!pstFile.exists()) {
                log.info("Save Preset: " + fileName);
                FileWriter wtr = null;
                try {
                    wtr = new FileWriter(pstFile);
                    // Loop through all known data grous
                    Iterator<Entry<Integer, Vector<EcuDataItem>>> it = knownGrpItems.entrySet().iterator();
                    while (it.hasNext()) {
                        Entry<Integer, Vector<EcuDataItem>> itmSet = it.next();
                        // write group number
                        wtr.write(String.format("%02X\t", itmSet.getKey()));
                        // loop through all items within data group
                        Vector<EcuDataItem> itms = itmSet.getValue();
                        Iterator<EcuDataItem> itItm = itms.iterator();
                        while (itItm.hasNext()) {
                            EcuDataItem currItm = itItm.next();
                            // write PID of item
                            wtr.write(String.format("%02X\t", currItm.pid));
                        }
                        // finish data group entry
                        wtr.write("\n");
                    }
                    log.info("Preset saved: " + fileName);
                } catch (IOException ex) {
                    log.severe("SavePreset: " + ex.toString());
                } finally {
                    try {
                        wtr.close();
                    } catch (IOException ex) {
                        log.severe("SavePreset: " + ex.toString());
                    }
                }
            } else {
                log.info("Preset saving skipped: " + fileName);
            }
        }
    };
    // MIN priority to NOT disturb communication
    saveThd.setPriority(Thread.MIN_PRIORITY);
    saveThd.start();
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) FileWriter(java.io.FileWriter) IOException(java.io.IOException) EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) Entry(java.util.Map.Entry) File(java.io.File) Vector(java.util.Vector) EcuDataItem(com.fr3ts0n.ecu.EcuDataItem)

Example 13 with EcuDataPv

use of com.fr3ts0n.ecu.EcuDataPv in project AndrOBD by fr3ts0n.

the class MainActivity method setFiltered.

/**
 * Filter display items to just the selected ones
 */
private void setFiltered(boolean filtered) {
    if (filtered) {
        PvList filteredList = new PvList();
        TreeSet<Integer> selPids = new TreeSet<Integer>();
        for (int pos : getSelectedPositions()) {
            EcuDataPv pv = (EcuDataPv) mPidAdapter.getItem(pos);
            selPids.add(pv.getAsInt(EcuDataPv.FID_PID));
            filteredList.put(pv.toString(), pv);
        }
        mPidAdapter.setPvList(filteredList);
        setFixedPids(selPids);
    } else {
        ObdProt.resetFixedPid();
        mPidAdapter.setPvList(ObdProt.PidPvs);
    }
}
Also used : PvList(com.fr3ts0n.pvs.PvList) EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) TreeSet(java.util.TreeSet)

Example 14 with EcuDataPv

use of com.fr3ts0n.ecu.EcuDataPv in project AndrOBD by fr3ts0n.

the class MainActivity method onItemLongClick.

/**
 * Handle long licks on OBD data list items
 */
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    Intent intent;
    switch(CommService.elm.getService()) {
        /* if we are in OBD data mode:
		     * ->Long click on an item starts the single item dashboard activity
		     */
        case ObdProt.OBD_SVC_DATA:
            EcuDataPv pv = (EcuDataPv) getListAdapter().getItem(position);
            /* only numeric values may be shown as graph/dashboard */
            if (pv.get(EcuDataPv.FID_VALUE) instanceof Number) {
                DashBoardActivity.setAdapter(getListAdapter());
                intent = new Intent(this, DashBoardActivity.class);
                intent.putExtra(DashBoardActivity.POSITIONS, new int[] { position });
                startActivity(intent);
            }
            break;
        /* If we are in DFC mode of any kind
			 * -> Long click leads to a web search for selected DFC
			 */
        case ObdProt.OBD_SVC_READ_CODES:
        case ObdProt.OBD_SVC_PERMACODES:
        case ObdProt.OBD_SVC_PENDINGCODES:
            try {
                intent = new Intent(Intent.ACTION_WEB_SEARCH);
                EcuCodeItem dfc = (EcuCodeItem) getListAdapter().getItem(position);
                intent.putExtra(SearchManager.QUERY, "OBD " + String.valueOf(dfc.get(EcuCodeItem.FID_CODE)));
                startActivity(intent);
            } catch (Exception e) {
                log.log(Level.SEVERE, "WebSearch DFC", e);
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
            }
            break;
    }
    return true;
}
Also used : EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) Intent(android.content.Intent) EcuCodeItem(com.fr3ts0n.ecu.EcuCodeItem) IOException(java.io.IOException)

Example 15 with EcuDataPv

use of com.fr3ts0n.ecu.EcuDataPv 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

EcuDataPv (com.fr3ts0n.ecu.EcuDataPv)16 EcuDataItem (com.fr3ts0n.ecu.EcuDataItem)4 Conversion (com.fr3ts0n.ecu.Conversion)3 IOException (java.io.IOException)3 Vector (java.util.Vector)3 TimeSeries (org.jfree.data.time.TimeSeries)3 EcuCodeItem (com.fr3ts0n.ecu.EcuCodeItem)2 PvList (com.fr3ts0n.pvs.PvList)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 Intent (android.content.Intent)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 NumericConversion (com.fr3ts0n.ecu.NumericConversion)1 VagConversion (com.fr3ts0n.ecu.VagConversion)1 ProcessVar (com.fr3ts0n.pvs.ProcessVar)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 HashMap (java.util.HashMap)1