use of com.fr3ts0n.ecu.EcuDataItem 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();
}
Aggregations