Initial commit
9
.classpath
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="com/fr3ts0n/pvs/gui/|com/fr3ts0n/ecu/gui/application/|com/fr3ts0n/ecu/prot/Kw1281Prot.java|com/fr3ts0n/prot/gui/" kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
bin/*
|
||||
gen/*
|
||||
.idea/*
|
||||
|
||||
*~
|
||||
/doc
|
||||
/bin
|
||||
33
.project
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>AndrOBD</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
4
.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
65
AndroidManifest.xml
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.fr3ts0n.ecu.gui.androbd"
|
||||
android:versionCode="1"
|
||||
android:versionName="@string/app_version" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="11"
|
||||
android:targetSdkVersion="17" />
|
||||
|
||||
<!-- start/stop bluetooth adapter -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<!-- connect/disconnect bluetooth devices -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<!-- to keep Bluetooth measurement running even when screen is inactive -->
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<!-- allow saving screenshots -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:name="com.fr3ts0n.ecu.gui.androbd.MainActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppBaseTheme" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter
|
||||
android:icon='@drawable/ic_launcher'
|
||||
android:label='OBD data file'
|
||||
android:priority='1'>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<data android:scheme="file" />
|
||||
<data android:scheme="content" />
|
||||
<data android:pathPattern=".*\\.obd" />
|
||||
<data android:mimeType="*/*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="DeviceListActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:label="@string/select_BTdevice"
|
||||
android:textColor="#ecad14"
|
||||
android:theme="@android:style/Theme.Holo.Dialog"
|
||||
/>
|
||||
<activity
|
||||
android:name="ChartActivity"
|
||||
android:label="OBD chart"
|
||||
android:configChanges="touchscreen|orientation|screenSize"
|
||||
/>
|
||||
<activity
|
||||
android:name="DashBoardActivity"
|
||||
android:label="DashBoard"
|
||||
android:configChanges="touchscreen|orientation|screenSize"
|
||||
/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
BIN
libs/achartengine-1.2.0.jar
Normal file
BIN
libs/android-logging-log4j-1.0.3.jar
Normal file
BIN
libs/log4j-1.2-1.2.17.jar
Normal file
14
project.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-17
|
||||
BIN
res/drawable-hdpi/action_connect.png
Normal file
|
After Width: | Height: | Size: 410 B |
BIN
res/drawable-hdpi/ic_action_dashboard.png
Normal file
|
After Width: | Height: | Size: 564 B |
BIN
res/drawable-hdpi/ic_action_graph.png
Normal file
|
After Width: | Height: | Size: 311 B |
BIN
res/drawable-hdpi/ic_action_load.png
Normal file
|
After Width: | Height: | Size: 359 B |
BIN
res/drawable-hdpi/ic_action_obd_service.png
Normal file
|
After Width: | Height: | Size: 661 B |
BIN
res/drawable-hdpi/ic_action_save.png
Normal file
|
After Width: | Height: | Size: 318 B |
BIN
res/drawable-hdpi/ic_action_share.png
Normal file
|
After Width: | Height: | Size: 445 B |
BIN
res/drawable-hdpi/ic_action_snapshot.png
Normal file
|
After Width: | Height: | Size: 547 B |
BIN
res/drawable-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
BIN
res/drawable-hdpi/ic_stat_obd_data.png
Normal file
|
After Width: | Height: | Size: 216 B |
BIN
res/drawable-mdpi/action_connect.png
Normal file
|
After Width: | Height: | Size: 274 B |
BIN
res/drawable-mdpi/ic_action_dashboard.png
Normal file
|
After Width: | Height: | Size: 379 B |
BIN
res/drawable-mdpi/ic_action_graph.png
Normal file
|
After Width: | Height: | Size: 241 B |
BIN
res/drawable-mdpi/ic_action_load.png
Normal file
|
After Width: | Height: | Size: 261 B |
BIN
res/drawable-mdpi/ic_action_obd_service.png
Normal file
|
After Width: | Height: | Size: 428 B |
BIN
res/drawable-mdpi/ic_action_save.png
Normal file
|
After Width: | Height: | Size: 254 B |
BIN
res/drawable-mdpi/ic_action_share.png
Normal file
|
After Width: | Height: | Size: 295 B |
BIN
res/drawable-mdpi/ic_action_snapshot.png
Normal file
|
After Width: | Height: | Size: 379 B |
BIN
res/drawable-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
res/drawable-mdpi/ic_stat_obd_data.png
Normal file
|
After Width: | Height: | Size: 188 B |
BIN
res/drawable-xhdpi/action_connect.png
Normal file
|
After Width: | Height: | Size: 484 B |
BIN
res/drawable-xhdpi/ic_action_dashboard.png
Normal file
|
After Width: | Height: | Size: 792 B |
BIN
res/drawable-xhdpi/ic_action_graph.png
Normal file
|
After Width: | Height: | Size: 375 B |
BIN
res/drawable-xhdpi/ic_action_load.png
Normal file
|
After Width: | Height: | Size: 458 B |
BIN
res/drawable-xhdpi/ic_action_obd_service.png
Normal file
|
After Width: | Height: | Size: 925 B |
BIN
res/drawable-xhdpi/ic_action_save.png
Normal file
|
After Width: | Height: | Size: 344 B |
BIN
res/drawable-xhdpi/ic_action_share.png
Normal file
|
After Width: | Height: | Size: 548 B |
BIN
res/drawable-xhdpi/ic_action_snapshot.png
Normal file
|
After Width: | Height: | Size: 694 B |
BIN
res/drawable-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 9.4 KiB |
BIN
res/drawable-xhdpi/ic_stat_obd_data.png
Normal file
|
After Width: | Height: | Size: 255 B |
BIN
res/drawable-xxhdpi/action_connect.png
Normal file
|
After Width: | Height: | Size: 746 B |
BIN
res/drawable-xxhdpi/ic_action_dashboard.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
res/drawable-xxhdpi/ic_action_graph.png
Normal file
|
After Width: | Height: | Size: 555 B |
BIN
res/drawable-xxhdpi/ic_action_load.png
Normal file
|
After Width: | Height: | Size: 684 B |
BIN
res/drawable-xxhdpi/ic_action_obd_service.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
res/drawable-xxhdpi/ic_action_save.png
Normal file
|
After Width: | Height: | Size: 463 B |
BIN
res/drawable-xxhdpi/ic_action_share.png
Normal file
|
After Width: | Height: | Size: 911 B |
BIN
res/drawable-xxhdpi/ic_action_snapshot.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
res/drawable-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
res/drawable-xxhdpi/ic_stat_obd_data.png
Normal file
|
After Width: | Height: | Size: 288 B |
BIN
res/drawable/sunfire.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
14
res/layout/dashboard.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<GridView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:choiceMode="none"
|
||||
android:numColumns="auto_fit" />
|
||||
|
||||
</RelativeLayout>
|
||||
42
res/layout/device_list.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
<TextView android:id="@+id/title_paired_devices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_paired_devices"
|
||||
android:visibility="gone"
|
||||
android:background="#666"
|
||||
android:textColor="#fff"
|
||||
android:paddingLeft="5dp"
|
||||
/>
|
||||
<ListView android:id="@+id/paired_devices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stackFromBottom="true"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
<TextView android:id="@+id/title_new_devices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_other_devices"
|
||||
android:visibility="gone"
|
||||
android:background="#666"
|
||||
android:textColor="#fff"
|
||||
android:paddingLeft="5dp"
|
||||
/>
|
||||
<ListView android:id="@+id/new_devices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stackFromBottom="true"
|
||||
android:layout_weight="2"
|
||||
/>
|
||||
<Button android:id="@+id/button_scan"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_scan"
|
||||
/>
|
||||
</LinearLayout>
|
||||
8
res/layout/device_name.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:padding="5dp"
|
||||
/>
|
||||
14
res/layout/head_up.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.fr3ts0n.ecu.gui.androbd.MirrorRelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<GridView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:choiceMode="none"
|
||||
android:numColumns="auto_fit" />
|
||||
|
||||
</com.fr3ts0n.ecu.gui.androbd.MirrorRelativeLayout>
|
||||
24
res/layout/obd_gauge.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="top" >
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/gauge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="top" >
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="TextView" />
|
||||
|
||||
</RelativeLayout>
|
||||
57
res/layout/obd_item.xml
Normal file
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<com.fr3ts0n.ecu.gui.androbd.CheckableRelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:com.fr3ts0n.tools="http://schemas.android.com/com.fr3ts0n.tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
com.fr3ts0n.tools:context=".MainActivity" >
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/check"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="10"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/obd_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/obd_units"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="10"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/obd_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</com.fr3ts0n.ecu.gui.androbd.CheckableRelativeLayout>
|
||||
27
res/layout/obd_list.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/obd_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="#808080"
|
||||
android:gravity="center"
|
||||
android:text="@string/title"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:choiceMode="multipleChoice"
|
||||
android:dividerHeight="2dp"
|
||||
android:fastScrollEnabled="true" />
|
||||
|
||||
</LinearLayout>
|
||||
49
res/layout/startup_layout.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/startup_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="@dimen/activity_horizontal_margin"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:alpha="1"
|
||||
android:contentDescription="@string/logo"
|
||||
android:src="@drawable/sunfire" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TextView01"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/app_version"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/copyright_c_2014_erwin_scheuch_heilig"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:visibility="invisible" />
|
||||
|
||||
</LinearLayout>
|
||||
12
res/menu/chart.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/snapshot"
|
||||
android:title="@string/snapshot"
|
||||
android:showAsAction="ifRoom"
|
||||
android:icon="@drawable/ic_action_snapshot"/>
|
||||
<item
|
||||
android:id="@+id/share"
|
||||
android:title="@string/share"
|
||||
android:showAsAction="ifRoom"
|
||||
android:icon="@drawable/ic_action_share"/>
|
||||
</menu>
|
||||
84
res/menu/main.xml
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/secure_connect_scan"
|
||||
android:icon="@drawable/action_connect"
|
||||
android:showAsAction="always"
|
||||
android:title="@string/action_connect"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/graph_actions"
|
||||
android:icon="@drawable/ic_action_graph"
|
||||
android:menuCategory="container"
|
||||
android:showAsAction="always"
|
||||
android:title="@string/graph_actions">
|
||||
<menu><group
|
||||
android:id="@+id/grp_graph_actions"
|
||||
android:menuCategory="container" >
|
||||
<item
|
||||
android:id="@+id/chart_selected"
|
||||
android:icon="@drawable/ic_action_graph"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/chart"/>
|
||||
<item
|
||||
android:id="@+id/dashboard_selected"
|
||||
android:icon="@drawable/ic_action_dashboard"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/dashboard"/>
|
||||
<item
|
||||
android:id="@+id/hud_selected"
|
||||
android:icon="@drawable/ic_action_dashboard"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/hud"/>
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/save"
|
||||
android:icon="@drawable/ic_action_save"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/save"/>
|
||||
<item
|
||||
android:id="@+id/load"
|
||||
android:icon="@drawable/ic_action_load"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/load"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/obd_services"
|
||||
android:icon="@drawable/ic_action_obd_service"
|
||||
android:menuCategory="container"
|
||||
android:showAsAction="always"
|
||||
android:title="@string/obd_services">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/service_none"
|
||||
android:title="@string/obd_none"
|
||||
android:visible="false"/>
|
||||
<item
|
||||
android:id="@+id/service_vid_data"
|
||||
android:title="@string/obd_veh_info"/>
|
||||
<item
|
||||
android:id="@+id/service_data"
|
||||
android:title="@string/obd_data"/>
|
||||
<item
|
||||
android:id="@+id/service_freezeframes"
|
||||
android:title="@string/service_freezeframes"/>
|
||||
<item
|
||||
android:id="@+id/service_codes"
|
||||
android:title="@string/obd_codes"/>
|
||||
<item
|
||||
android:id="@+id/service_permacodes"
|
||||
android:title="@string/obd_permanentcodes"/>
|
||||
<item
|
||||
android:id="@+id/service_pendingcodes"
|
||||
android:title="@string/obd_pendingcodes"/>
|
||||
<item
|
||||
android:id="@+id/service_clearcodes"
|
||||
android:title="@string/obd_clearcodes"/>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
</menu>
|
||||
63
res/values-de/strings.xml
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="action_connect">Verbinden</string>
|
||||
<string name="action_settings">Einstellungen</string>
|
||||
<string name="app_description">Android OBD Fahrzeugdisagnose für ELM327 Bluetooth Adapter</string>
|
||||
<string name="back_again_to_exit">Nochmal zurück um zu beenden</string>
|
||||
<string name="button_scan">Geräte suchen</string>
|
||||
<string name="chart">Vergleichsgraphik</string>
|
||||
<string name="logo">Logo</string>
|
||||
<string name="none_found">Keine Geräte gefunden</string>
|
||||
<string name="none_paired">Keine Geräte gepaart</string>
|
||||
<string name="not_connected">Es ist kein Gerät verbunden</string>
|
||||
<string name="obd_clearcodes">Fehlercodes löschen</string>
|
||||
<string name="obd_codes">OBD Fehlercodes</string>
|
||||
<string name="obd_data">OBD Daten</string>
|
||||
<string name="obd_none">KEIN Dienst</string>
|
||||
<string name="obd_pendingcodes">OBD Fehlercodes (drohend)</string>
|
||||
<string name="obd_permanentcodes">OBD Fehlercodes (permanent)</string>
|
||||
<string name="obd_services">OBD Dienste</string>
|
||||
<string name="obd_veh_info">OBD Fahrzeug Info</string>
|
||||
<string name="scanning">Suche…</string>
|
||||
<string name="select_BTdevice">Wähle BT Gerät</string>
|
||||
<string name="send">Senden</string>
|
||||
<string name="send_to">Senden an</string>
|
||||
<string name="service_freezeframes">OBD Freeze Frames</string>
|
||||
<string name="share">teilen</string>
|
||||
<string name="time">Zeit [s]</string>
|
||||
<string name="title">titel</string>
|
||||
<string name="title_connected_to">Verbunden %s</string>
|
||||
<string name="title_connecting">Verbinde…</string>
|
||||
<string name="title_not_connected">Nicht verbunden</string>
|
||||
<string name="title_other_devices">Andere verfügbare Geräte</string>
|
||||
<string name="title_paired_devices">Gepaarte Geräte</string>
|
||||
<string name="welcome_to">Willkommen zu</string>
|
||||
<string name="obd_clear_info">
|
||||
Dies wird die MIL zurücksetzen und löscht alle abgasrelevanten Diagnoseinformationen, inklusive:\n
|
||||
- Diagnose-Fehlercodes\n
|
||||
- Freeze Frame Daten\n
|
||||
- Lambdasonden Testdaten\n
|
||||
- Status der System-Tests\n
|
||||
- Status der On-board Tests\n
|
||||
- Fahrstrecke seit MIL aktiv\n
|
||||
- Warmläufe seit MIL aktiv\n
|
||||
- Motorlaufzeit seit MIL aktiv\n
|
||||
- Zeit seit Löschung\n
|
||||
- Fahrstrecke seit Löschung\n
|
||||
Andere, herstellerspezifische Einstellungen können dadurch verloren gehen.\n
|
||||
Dadurch kann eine Lernphase nötig werden, während welcher der Motor ungleichmässig läuft.</string>
|
||||
<string name="demo_started">DEMO gestartet</string>
|
||||
<string name="demo_stopped">DEMO beendet</string>
|
||||
<string name="load">Messung laden</string>
|
||||
<string name="save">Messung speichern</string>
|
||||
<string name="saved_data">Gespeicherte Daten</string>
|
||||
<string name="snapshot">Schnappschuss</string>
|
||||
<string name="loaded">geladen</string>
|
||||
<string name="saved">gespeichert</string>
|
||||
<string name="connected_to">Verbunden mit</string>
|
||||
<string name="demo">Demo ...</string>
|
||||
<string name="saving_data">Daten speichern ...</string>
|
||||
<string name="dashboard">Instrumententafel</string>
|
||||
<string name="graph_actions">Graphische Aktionen</string>
|
||||
<string name="hud">Head Up Anzeige</string>
|
||||
</resources>
|
||||
12
res/values-large/refs.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Layout alias to replace the single-pane version of the layout with a
|
||||
two-pane version on Large screens.
|
||||
|
||||
For more on layout aliases, see:
|
||||
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters
|
||||
-->
|
||||
|
||||
</resources>
|
||||
8
res/values-sw600dp/dimens.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Customize dimensions originally defined in res/values/dimens.xml (such as
|
||||
screen margins) for sw600dp devices (e.g. 7" tablets) here.
|
||||
-->
|
||||
|
||||
</resources>
|
||||
12
res/values-sw600dp/refs.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Layout alias to replace the single-pane version of the layout with a
|
||||
two-pane version on Large screens.
|
||||
|
||||
For more on layout aliases, see:
|
||||
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters
|
||||
-->
|
||||
|
||||
</resources>
|
||||
9
res/values-sw720dp-land/dimens.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Customize dimensions originally defined in res/values/dimens.xml (such as
|
||||
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
|
||||
-->
|
||||
<dimen name="activity_horizontal_margin">128dp</dimen>
|
||||
|
||||
</resources>
|
||||
11
res/values-v11/styles.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 11+. This theme completely replaces
|
||||
AppBaseTheme from res/values/styles.xml on API 11+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
|
||||
<!-- API 11 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
12
res/values-v14/styles.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 14+. This theme completely replaces
|
||||
AppBaseTheme from BOTH res/values/styles.xml and
|
||||
res/values-v11/styles.xml on API 14+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
|
||||
<!-- API 14 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
7
res/values/dimens.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<resources>
|
||||
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
|
||||
</resources>
|
||||
12
res/values/refs.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Layout alias to replace the single-pane version of the layout with a
|
||||
two-pane version on Large screens.
|
||||
|
||||
For more on layout aliases, see:
|
||||
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters
|
||||
-->
|
||||
|
||||
</resources>
|
||||
77
res/values/strings.xml
Normal file
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!-- AndrOBD -->
|
||||
<string name="app_name" translatable="false">AndrOBD</string>
|
||||
<string name="app_version" translatable="false">V1.0.0</string>
|
||||
<string name="copyright_c_2014_erwin_scheuch_heilig" translatable="false">© 2014 fr3ts0n</string>
|
||||
<string name="app_description">Android OBD vehicle diagnostics app for ELM327 bluetooth adapter</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="send">Send</string>
|
||||
<string name="not_connected">You are not connected to a device</string>
|
||||
<string name="title_connecting">Connecting…</string>
|
||||
<string name="title_connected_to">Connected %s</string>
|
||||
<string name="title_not_connected">Not Connected</string>
|
||||
<string name="title">title</string>
|
||||
<string name="welcome_to">Welcome to</string>
|
||||
<string name="logo">Logo</string>
|
||||
<string name="back_again_to_exit">Press back again to close this app</string>
|
||||
<!-- menu -->
|
||||
<string name="action_connect">Connect</string>
|
||||
<string name="obd_none">NO service</string>
|
||||
<string name="obd_services">OBD Services</string>
|
||||
<string name="obd_veh_info">OBD Vehicle Info</string>
|
||||
<string name="obd_data">OBD Data</string>
|
||||
<string name="service_freezeframes">OBD Freeze Frames</string>
|
||||
<string name="obd_codes">OBD fault codes</string>
|
||||
<string name="obd_permanentcodes">OBD fault codes (permanent)</string>
|
||||
<string name="obd_pendingcodes">OBD fault codes (pending)</string>
|
||||
<string name="obd_clearcodes">Clear fault codes</string>
|
||||
<string name="obd_clear_info">
|
||||
This will reset the MIL and clear all emission-related diagnostic\n
|
||||
information, including:\n
|
||||
- Diagnostic trouble codes\n
|
||||
- Freeze frame data\n
|
||||
- Oxygen sensor test data\n
|
||||
- Status of system monitoring tests\n
|
||||
- On-board monitoring tests results\n
|
||||
- Distance travelled while MIL activated\n
|
||||
- Number of warm-ups since DTCs cleared\n
|
||||
- Distance travelled since DTCs cleared\n
|
||||
- Engine run time while MIL activated\n
|
||||
- Time since DTCs cleared\n\n
|
||||
Other manufacturer-specific clearing/resetting actions may occur.\n
|
||||
The loss of data may cause the vehicle to run poorly for a short \n
|
||||
period of time while the ECU recalibrates itself.
|
||||
</string>
|
||||
|
||||
<!-- DeviceListActivity -->
|
||||
<string name="scanning">Scanning…</string>
|
||||
<string name="select_BTdevice">Select a Device</string>
|
||||
<string name="none_paired">No Devices Paired</string>
|
||||
<string name="none_found">No Devices Found</string>
|
||||
<string name="title_paired_devices">Paired Devices</string>
|
||||
<string name="title_other_devices">Other Available Devices</string>
|
||||
<string name="button_scan">Scan for Devices</string>
|
||||
|
||||
<!-- ExportTask -->
|
||||
<string name="send_to">Send to</string>
|
||||
<string name="share">share</string>
|
||||
<string name="time">Time [s]</string>
|
||||
<string name="chart">Chart</string>
|
||||
<string name="demo_stopped">DEMO mode stopped</string>
|
||||
<string name="demo_started">DEMO mode started</string>
|
||||
<string name="snapshot">snapshot</string>
|
||||
<string name="save">save Measurement</string>
|
||||
<string name="load">load Measurement</string>
|
||||
<string name="saved_data">Saved Data</string>
|
||||
<string name="loaded">loaded</string>
|
||||
<string name="saved">saved</string>
|
||||
<string name="connected_to">"Connected to "</string>
|
||||
<string name="demo">Demo...</string>
|
||||
<string name="saving_data">Saving data ...</string>
|
||||
<string name="dashboard">Dashboard</string>
|
||||
<string name="graph_actions">Graph actions</string>
|
||||
<string name="hud">Head Up Display</string>
|
||||
|
||||
</resources>
|
||||
20
res/values/styles.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme, dependent on API level. This theme is replaced
|
||||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Light">
|
||||
<!--
|
||||
Theme customizations available in newer API levels can go in
|
||||
res/values-vXX/styles.xml, while customizations related to
|
||||
backward-compatibility can go here.
|
||||
-->
|
||||
</style>
|
||||
|
||||
<!-- Application theme. -->
|
||||
<style name="AppTheme" parent="AppBaseTheme">
|
||||
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
4
src/JObd.bat
Executable file
@@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
mode %1 38400,n,8,1
|
||||
java -cp .;AgnisServer.jar com.fr3ts0n.ecu.ObdTestFrame %1 %2 %3 %4 %5
|
||||
|
||||
9
src/JObd.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
export JARFILE=$HOME/src/j/info-proxy/AgnisServer/dist/AgnisServer.jar
|
||||
if [ "$1" != "" ]; then
|
||||
# stty -F $1 38400 sane ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
|
||||
stty -F $1 38400 sane ignbrk -brkint -icrnl -imaxbel -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
|
||||
else
|
||||
echo "NO serial port specified, starting in DEMO-Mode"
|
||||
fi
|
||||
java -cp .:$JARFILE com.fr3ts0n.ecu.ObdTestFrame $*
|
||||
144
src/com/fr3ts0n/ecu/BitmapConversion.java
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* conversion of numeric values based on a Bitmap
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class BitmapConversion extends NumericConversion
|
||||
{
|
||||
/** SerialVersion UID */
|
||||
private static final long serialVersionUID = -8498739122873083420L;
|
||||
/* the HashMap Data */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private HashMap hashData = new HashMap();
|
||||
String units = "-";
|
||||
|
||||
/**
|
||||
* create a new Instance
|
||||
*/
|
||||
public BitmapConversion()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new hash converter which is initialized with values from map data
|
||||
* The map data needs to contain Bit position and the meaning of it
|
||||
*
|
||||
* @param data map data for conversions
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public BitmapConversion(Map data)
|
||||
{
|
||||
hashData.putAll(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new hash converter which is initialized with avlues from an array
|
||||
* of strings in the format "BitPos=value"
|
||||
*
|
||||
* @param initData initializer strings for conversions in the format "BitPos=value[;BitPos=value[...]]"
|
||||
*/
|
||||
public BitmapConversion(String[] initData)
|
||||
{
|
||||
initFromStrings(initData);
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize hash map with values from an array of strings in the format "BitPos=value"
|
||||
*
|
||||
* @param initData initializer strings for conversions in the format "BitPos=value[;BitPos=value[...]]"
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initFromStrings(String[] initData)
|
||||
{
|
||||
Long key;
|
||||
String value;
|
||||
String[] data;
|
||||
// clear old hash data
|
||||
hashData.clear();
|
||||
|
||||
// loop through all string entries ...
|
||||
for (int i = 0; i < initData.length; i++)
|
||||
{
|
||||
data = initData[i].split(";");
|
||||
for (int j = 0; j < data.length; j++)
|
||||
{
|
||||
// ... split key and value ...
|
||||
String[] words = data[j].split("=");
|
||||
key = Long.valueOf(words[0]);
|
||||
value = words[1];
|
||||
// TODO: if( key >= 64 )
|
||||
// ... and enter into hash map
|
||||
hashData.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Number memToPhys(long value)
|
||||
{
|
||||
return (value);
|
||||
}
|
||||
|
||||
public Number physToMem(Number value)
|
||||
{
|
||||
return (value);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a numerical physical value into a formatted string
|
||||
*
|
||||
* @param physVal physical value
|
||||
* @param decimals number of decimals for formatting
|
||||
* @return formatted String
|
||||
*/
|
||||
@Override
|
||||
public String physToPhysFmtString(Number physVal, int decimals)
|
||||
{
|
||||
String result = null;
|
||||
long val = physVal.longValue();
|
||||
long currBitVal;
|
||||
// loop through all bits
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
currBitVal = 1 << i;
|
||||
if ((val & currBitVal) != 0)
|
||||
{
|
||||
// check if we have a meaning for this bit
|
||||
String bitRslt = (String) hashData.get(i);
|
||||
// yes, then add the meaning to result string
|
||||
if (bitRslt != null)
|
||||
{
|
||||
// if this is NOT the first entry, then add a new line
|
||||
if (result != null) result += "\n";
|
||||
// now add the result
|
||||
result += bitRslt;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if we haven't found a string representation, return numeric value
|
||||
if (result == null) result = String.valueOf(physVal);
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
70
src/com/fr3ts0n/ecu/Conversion.java
Executable file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* interface for various Data conversion types
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public interface Conversion extends Serializable
|
||||
{
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*
|
||||
* @param value memory value
|
||||
* @return physical value
|
||||
*/
|
||||
public Number memToPhys(long value);
|
||||
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*
|
||||
* @param value physical value
|
||||
* @return memory value
|
||||
*/
|
||||
public Number physToMem(Number value);
|
||||
|
||||
/**
|
||||
* convert a numerical physical value into a formatted string
|
||||
*
|
||||
* @param physVal physical value
|
||||
* @param decimals number of decimals for formatting
|
||||
* @return formatted String
|
||||
*/
|
||||
public String physToPhysFmtString(Number physVal, int decimals);
|
||||
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*
|
||||
* @param value memory value
|
||||
* @param numDecimals number of decimal for string formatting of numbers
|
||||
* @return string representation of numeric value
|
||||
*/
|
||||
public String memToString(Number value, int numDecimals);
|
||||
|
||||
/**
|
||||
* return physical units of this conversion
|
||||
*
|
||||
* @return physical units of this conversion
|
||||
*/
|
||||
public String getUnits();
|
||||
}
|
||||
200
src/com/fr3ts0n/ecu/Conversions.java
Executable file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import com.fr3ts0n.pvs.PvLimits;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
|
||||
/**
|
||||
* Collection of all known OBD data conversions.
|
||||
* This collection implements conversions to metric and imperial system
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class Conversions
|
||||
{
|
||||
|
||||
public static final int SYSTEM_METRIC = 0;
|
||||
public static final int SYSTEM_IMPERIAL = 1;
|
||||
public static final int SYSTEM_TYPES = 2;
|
||||
|
||||
// current conversion system
|
||||
public static int cnvSystem = SYSTEM_METRIC;
|
||||
/**
|
||||
* ID's of Conversions
|
||||
* These ID's are used as index into table below
|
||||
* Please take care of the order
|
||||
*/
|
||||
public static final int CNV_ID_ONETOONE = 0;
|
||||
public static final int CNV_ID_PERCENT = 1;
|
||||
public static final int CNV_ID_PERCENT_REL = 2;
|
||||
public static final int CNV_ID_PERCENT7 = 3;
|
||||
public static final int CNV_ID_PERCENT7_REL = 4;
|
||||
public static final int CNV_ID_RPM = 5;
|
||||
public static final int CNV_ID_VEHSPEED = 6;
|
||||
public static final int CNV_ID_TEMPERATURE = 7;
|
||||
public static final int CNV_ID_TEMP_WIDERANGE = 8;
|
||||
public static final int CNV_ID_AIRFLOW = 9;
|
||||
public static final int CNV_ID_PRESS = 10;
|
||||
public static final int CNV_ID_PRESS_AIR = 11;
|
||||
public static final int CNV_ID_PRESS_REL = 12;
|
||||
public static final int CNV_ID_PRESS_WIDERANGE = 13;
|
||||
public static final int CNV_ID_PRESS_VAPOR = 14;
|
||||
public static final int CNV_ID_ANGLE = 15;
|
||||
public static final int CNV_ID_VOLTAGE = 16;
|
||||
public static final int CNV_ID_VOLTAGE_HIGHRES = 17;
|
||||
public static final int CNV_ID_RATIO = 18;
|
||||
public static final int CNV_ID_RATIO_WIDERANGE = 19;
|
||||
public static final int CNV_ID_DISTANCE = 20;
|
||||
public static final int CNV_ID_HOURS = 21;
|
||||
public static final int CNV_ID_SPEED_HIGHRES = 22;
|
||||
public static final int CNV_ID_TORQUE = 23;
|
||||
public static final int CNV_ID_RATIO_RELATIVE = 24;
|
||||
public static final int CNV_ID_OBD_TYPE = 25;
|
||||
public static final int CNV_ID_OBD_CODELIST = 26;
|
||||
public static final int CNV_ID_MAX = 27;// This needs to be last entry
|
||||
|
||||
public static final ObdCodeList obdCodeList = new ObdCodeList();
|
||||
|
||||
static final HashConversion cnvObdType = new HashConversion(new String[]{
|
||||
"1=OBD II",
|
||||
"2=OBD Federal EPA",
|
||||
"3=OBD and OBD II",
|
||||
"4=OBD I",
|
||||
"5=Not OBD compliant",
|
||||
"6=EOBD",
|
||||
"7=EOBD and OBD II",
|
||||
"8=EOBD and OBD",
|
||||
"9=EOBD, OBD and OBD II",
|
||||
"10=JOBD",
|
||||
"11=JOBD and OBD II",
|
||||
"12=JOBD and EOBD",
|
||||
"13=JOBD, EOBD and OBD II"
|
||||
});
|
||||
|
||||
/** limits for RPM display */
|
||||
public static PvLimits rpmLimits = new PvLimits(0.0f, 6000.0f);
|
||||
|
||||
static final Conversion[][] cnvFactors =
|
||||
{
|
||||
// METRIC , IMPERIAL
|
||||
// FACT, DIV, OFFS, PhOf, UNIT , FACT, DIV, OFFS, PhOf, UNIT
|
||||
{new LinearConversion(1, 1, 0, 0, "-"), new LinearConversion(1, 1, 0, 0, "-")}, // OneToOne
|
||||
{new LinearConversion(100, 255, 0, 0, "%"), new LinearConversion(100, 255, 0, 0, "%")}, // Percent
|
||||
{new LinearConversion(100, 255, -128, 0, "%"), new LinearConversion(100, 255, -128, 0, "%")}, // Percent relative
|
||||
{new LinearConversion(100, 128, 0, 0, "%"), new LinearConversion(100, 128, 0, 0, "%")}, // Percent 7Bit (Fuel Trim)
|
||||
{new LinearConversion(100, 128, -128, 0, "%"), new LinearConversion(100, 128, -128, 0, "%")}, // Percent 7Bit relative)
|
||||
{new LinearConversion(1, 4, 0, 0, "/min", rpmLimits), new LinearConversion(1, 4, 0, 0, "/min", rpmLimits)}, // RPM
|
||||
{new LinearConversion(1, 1, 0, 0, "km/h"), new LinearConversion(1000, 1609, 0, 0, "mph")}, // vehicle speed
|
||||
{new LinearConversion(1, 1, -40, 0, "°C"), new LinearConversion(9, 5, -40, 32, "°F")}, // Temperature
|
||||
{new LinearConversion(1, 10, -40, 0, "°C"), new LinearConversion(9, 50, -40, 32, "°F")}, // Temperature (wide range)
|
||||
{new LinearConversion(1, 100, 0, 0, "g/s"), new LinearConversion(1, 756, 0, 0, "lb/min")}, // Air Flow
|
||||
{new LinearConversion(3, 1, 0, 0, "kPa"), new LinearConversion(4351, 10000, 0, 0, "PSI")}, // Pressure
|
||||
{new LinearConversion(1, 1, 0, 0, "kPa"), new LinearConversion(2953, 10000, 0, 0, "inHg")}, // Pressure (intake)
|
||||
{new LinearConversion(79, 1000, 0, 0, "kPa"), new LinearConversion(100, 8727, 0, 0, "PSI")}, // Pressure (relative)
|
||||
{new LinearConversion(10, 1, 0, 0, "kPa"), new LinearConversion(14504, 10000, 0, 0, "PSI")}, // Pressure (wide range)
|
||||
{new LinearConversion(1, 4, 0, 0, "Pa"), new LinearConversion(100, 99635, 0, 0, "in H2O")}, // Pressure (Vapor)
|
||||
{new LinearConversion(1, 2, -128, 0, "°"), new LinearConversion(1, 2, -128, 0, "°")}, // Angle (Timing adv)
|
||||
{new LinearConversion(1, 1000, 0, 0, "V"), new LinearConversion(1, 1000, 0, 0, "V")}, // Voltage
|
||||
{new LinearConversion(10, 81967, 0, 0, "V"), new LinearConversion(10, 81967, 0, 0, "V")}, // Voltage (high resolution)
|
||||
{new LinearConversion(100, 32768, 0, 0, "%"), new LinearConversion(100, 32768, 0, 0, "%")}, // Ratio
|
||||
{new LinearConversion(100, 256, -32768, 0, "%"), new LinearConversion(100, 256, -32768, 0, "%")}, // Ratio (wide range)
|
||||
{new LinearConversion(1, 1, 0, 0, "km"), new LinearConversion(1000, 1609, 0, 0, "miles")}, // Distance
|
||||
{new LinearConversion(1, 3600, 0, 0, "h"), new LinearConversion(1, 3600, 0, 0, "h")}, // Time (hours)
|
||||
{new LinearConversion(1, 128, 0, 0, "km/h"), new LinearConversion(100, 20595, 0, 0, "mph")}, // vehicle speed
|
||||
{new LinearConversion(1, 1, 0, 0, "Nm"), new LinearConversion(1, 1, 0, 0, "Nm")}, // Torque
|
||||
{new LinearConversion(100, 65535, 0, 0, "%"), new LinearConversion(100, 65535, 0, 0, "%")}, // Ratio relative
|
||||
{cnvObdType, cnvObdType},
|
||||
{obdCodeList, obdCodeList},
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new instance of Conversions
|
||||
*/
|
||||
public Conversions()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*/
|
||||
public static float memToPhys(long value, int cnvID)
|
||||
{
|
||||
return (cnvFactors[cnvID][cnvSystem].memToPhys(value).floatValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*/
|
||||
public static long physToMem(float value, int cnvID)
|
||||
{
|
||||
return (cnvFactors[cnvID][cnvSystem].physToMem(value).longValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*/
|
||||
public static String getUnits(int cnvID)
|
||||
{
|
||||
return (cnvFactors[cnvID][cnvSystem].getUnits());
|
||||
}
|
||||
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*/
|
||||
public static String memToString(long value, int cnvID, int decimals)
|
||||
{
|
||||
return (cnvFactors[cnvID][cnvSystem].memToString(value, decimals));
|
||||
}
|
||||
|
||||
/** object to be used for parsing and formatting decimal numbers */
|
||||
protected static DecimalFormat decimalFormat;
|
||||
public static final DecimalFormat formats[] =
|
||||
{
|
||||
new DecimalFormat("0;-#"),
|
||||
new DecimalFormat("0.0;-#"),
|
||||
new DecimalFormat("0.00;-#"),
|
||||
new DecimalFormat("0.000;-#"),
|
||||
new DecimalFormat("0.0000;-#")
|
||||
};
|
||||
|
||||
/**
|
||||
* Format physical value to physical value string
|
||||
*
|
||||
* @param physVal physical value
|
||||
* @param cnvId ID of conversion to be used
|
||||
* @param decimals number of decimals for formatting
|
||||
* @return physical value as formatted string
|
||||
*/
|
||||
public static String physToPhysFmtString(Float physVal, int cnvId, int decimals)
|
||||
{
|
||||
String result = "";
|
||||
if (decimals >= 0)
|
||||
{
|
||||
decimalFormat = formats[decimals];
|
||||
result = decimalFormat.format(physVal);
|
||||
} else
|
||||
{
|
||||
result = Conversions.memToString(physVal.longValue(), cnvId, decimals);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
103
src/com/fr3ts0n/ecu/EcuCodeItem.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import com.fr3ts0n.pvs.IndexedProcessVar;
|
||||
|
||||
/**
|
||||
* ECU fault code
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class EcuCodeItem extends IndexedProcessVar
|
||||
implements Comparable<EcuCodeItem>
|
||||
{
|
||||
/** unique class id*/
|
||||
public static final long serialVersionUID = -1;
|
||||
// Field IDs
|
||||
public static final int FID_CODE = 0;
|
||||
public static final int FID_DESCRIPT = 1;
|
||||
public static final int FID_STATUS = 2;
|
||||
|
||||
public static final String[] FIELDS =
|
||||
{
|
||||
"CODE",
|
||||
"DESCRIPTION",
|
||||
"STATUS",
|
||||
};
|
||||
|
||||
public EcuCodeItem()
|
||||
{
|
||||
}
|
||||
|
||||
/** Creates a new instance of EcuCodeItem
|
||||
* @param code String representation of DFC
|
||||
* @param description descriptive text of DFC
|
||||
*/
|
||||
public EcuCodeItem(String code, String description)
|
||||
{
|
||||
put(FID_CODE, code);
|
||||
put(FID_DESCRIPT, description);
|
||||
}
|
||||
|
||||
/** Creates a new instance of ObdCodeItem
|
||||
* @param numericCode numeric code ID
|
||||
* @param description descriptive text of DFC
|
||||
*/
|
||||
public EcuCodeItem(int numericCode, String description)
|
||||
{
|
||||
put(FID_CODE, String.valueOf(numericCode));
|
||||
put(FID_DESCRIPT, description);
|
||||
}
|
||||
|
||||
public String[] getFields()
|
||||
{
|
||||
return ObdCodeItem.FIELDS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return String representation of Code item
|
||||
* @return String representation of code
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result = "";
|
||||
for(int i=0; i<FIELDS.length; i++)
|
||||
{
|
||||
Object val = get(i);
|
||||
if(val != null)
|
||||
{
|
||||
result += String.valueOf(val)+" ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of Comparable to allow sorting
|
||||
* @param o the other object
|
||||
* @return result of comparison
|
||||
*/
|
||||
public int compareTo(EcuCodeItem o)
|
||||
{
|
||||
return toString().compareTo(o.toString());
|
||||
}
|
||||
|
||||
}
|
||||
162
src/com/fr3ts0n/ecu/EcuCodeList.java
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Vehicle fault code list
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class EcuCodeList extends HashMap<Integer, EcuCodeItem>
|
||||
implements Conversion
|
||||
{
|
||||
private static final long serialVersionUID = 219865459629423028L;
|
||||
|
||||
/**
|
||||
* construct a new code list
|
||||
*/
|
||||
public EcuCodeList()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new code list and initialize it with ressources files
|
||||
*
|
||||
* @param ressources Array of ressources file names
|
||||
*/
|
||||
public EcuCodeList(String[] ressources)
|
||||
{
|
||||
// init from ressources list
|
||||
for (int i = 0; i < ressources.length; i++)
|
||||
{
|
||||
initFromRessource(ressources[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new code list and initialize it with ressources files
|
||||
*
|
||||
* @param ressources Array of ressources file names
|
||||
* @param idRadix radix of numeric code id
|
||||
*/
|
||||
public EcuCodeList(String[] ressources, int idRadix)
|
||||
{
|
||||
// init from ressources list
|
||||
for (int i = 0; i < ressources.length; i++)
|
||||
{
|
||||
initFromRessource(ressources[i], idRadix);
|
||||
}
|
||||
}
|
||||
|
||||
public String getUnits()
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize list from ressource file (tab delimited)
|
||||
*
|
||||
* @param ressource name of ressource to be loaded
|
||||
*/
|
||||
protected void initFromRessource(String ressource)
|
||||
{
|
||||
initFromRessource(ressource, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize list from ressource file (tab delimited)
|
||||
*
|
||||
* @param ressource name of ressource to be loaded
|
||||
* @param idRadix radix of numeric code id
|
||||
*/
|
||||
protected void initFromRessource(String ressource, int idRadix)
|
||||
{
|
||||
BufferedReader rdr;
|
||||
String currLine;
|
||||
String[] params;
|
||||
|
||||
try
|
||||
{
|
||||
rdr = new BufferedReader(new InputStreamReader(getClass().getResource(ressource).openStream()));
|
||||
// loop through all lines of the file ...
|
||||
while ((currLine = rdr.readLine()) != null)
|
||||
{
|
||||
// if line is not empty and is not a remark
|
||||
if (currLine.trim().length() > 0 && !currLine.startsWith("#") && !currLine.startsWith("//"))
|
||||
{
|
||||
// repalce all optional quotes from CSV code list
|
||||
currLine = currLine.replaceAll("\"", "");
|
||||
// split CSV line into parameters
|
||||
params = currLine.split("\t");
|
||||
// insert fault code element
|
||||
put(Integer.valueOf(params[0], idRadix), new EcuCodeItem(params[0], params[1]));
|
||||
}
|
||||
}
|
||||
rdr.close();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Number memToPhys(long value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public String memToString(Number value, int numDecimals)
|
||||
{
|
||||
return physToPhysFmtString(memToPhys(value.longValue()), numDecimals);
|
||||
}
|
||||
|
||||
public Number physToMem(Number value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a numerical physical value into a formatted string
|
||||
*
|
||||
* @param value physical value
|
||||
* @param decimals number of decimals for formatting
|
||||
* @return formatted String
|
||||
*/
|
||||
public String physToPhysFmtString(Number value, int decimals)
|
||||
{
|
||||
String result;
|
||||
EcuCodeItem code = get(value.intValue());
|
||||
if (code != null)
|
||||
{
|
||||
result = code.get(ObdCodeItem.FID_CODE).toString()
|
||||
+ " - "
|
||||
+ code.get(ObdCodeItem.FID_DESCRIPT).toString();
|
||||
} else
|
||||
{
|
||||
result = value.toString() + " - Fault code unknown";
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
}
|
||||
180
src/com/fr3ts0n/ecu/EcuConversions.java
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Diagnostic data conversions
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class EcuConversions extends HashMap<String, Conversion[]>
|
||||
{
|
||||
/** SerialVersion UID */
|
||||
private static final long serialVersionUID = 273813879102783740L;
|
||||
/// conversion systems METRIC and IMPERIAL
|
||||
public static final int SYSTEM_METRIC = 0;
|
||||
public static final int SYSTEM_IMPERIAL = 1;
|
||||
public static final int SYSTEM_TYPES = 2;
|
||||
// names of conversion types
|
||||
public static final String[] cnvSystems =
|
||||
{
|
||||
"METRIC",
|
||||
"IMPERIAL",
|
||||
};
|
||||
|
||||
/** CSV field positions */
|
||||
static final int FLD_NAME = 0;
|
||||
static final int FLD_TYPE = 1;
|
||||
static final int FLD_VARIANT = 2;
|
||||
static final int FLD_SYSTEM = 3;
|
||||
static final int FLD_FACTOR = 4;
|
||||
static final int FLD_DIVIDER = 5;
|
||||
static final int FLD_OFFSET = 6;
|
||||
static final int FLD_PHOFFSET = 7;
|
||||
static final int FLD_UNITS = 8;
|
||||
static final int FLD_DESCRIPTION = 9;
|
||||
|
||||
// the data logger
|
||||
static Logger log = Logger.getLogger("data.cnv");
|
||||
|
||||
// current conversion system
|
||||
public static int cnvSystem = SYSTEM_METRIC;
|
||||
|
||||
// DEFAULT type conversion
|
||||
static final LinearConversion dfltCnv = new LinearConversion(1, 1, 0, 0, "DFLT");
|
||||
// codelist conversion
|
||||
public static final ObdCodeList obdCodeList = new ObdCodeList();
|
||||
// OBD type conversion
|
||||
static final HashConversion cnvObdType = new HashConversion(new String[]{
|
||||
"1=OBD II",
|
||||
"2=OBD Federal EPA",
|
||||
"3=OBD and OBD II",
|
||||
"4=OBD I",
|
||||
"5=Not OBD compliant",
|
||||
"6=EOBD",
|
||||
"7=EOBD and OBD II",
|
||||
"8=EOBD and OBD",
|
||||
"9=EOBD, OBD and OBD II",
|
||||
"10=JOBD",
|
||||
"11=JOBD and OBD II",
|
||||
"12=JOBD and EOBD",
|
||||
"13=JOBD, EOBD and OBD II"
|
||||
});
|
||||
|
||||
|
||||
public EcuConversions()
|
||||
{
|
||||
// add static conversions
|
||||
// name METRIC IMPERIAL
|
||||
put("DEFAULT", new Conversion[]{dfltCnv, dfltCnv});
|
||||
put("OBD_CODELIST", new Conversion[]{obdCodeList, obdCodeList});
|
||||
put("OBD_TYPE", new Conversion[]{cnvObdType, cnvObdType});
|
||||
// add dynamic entris from csv file(s)
|
||||
initFromRessource("res/conversions.csv");
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize list from ressource file (tab delimited)
|
||||
*
|
||||
* @param ressource name of ressource to be loaded
|
||||
*/
|
||||
private void initFromRessource(String ressource)
|
||||
{
|
||||
BufferedReader rdr;
|
||||
String currLine;
|
||||
String[] params;
|
||||
Conversion[] currCnvSet;
|
||||
Conversion newCnv;
|
||||
int line = 0;
|
||||
|
||||
try
|
||||
{
|
||||
rdr = new BufferedReader(new InputStreamReader(getClass().getResource(ressource).openStream()));
|
||||
// loop through all lines of the file ...
|
||||
while ((currLine = rdr.readLine()) != null)
|
||||
{
|
||||
// ignore line 1
|
||||
if (++line == 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// repalce all optional quotes from CSV code list
|
||||
currLine = currLine.replaceAll("\"", "");
|
||||
// split CSV line into parameters
|
||||
params = currLine.split("\t");
|
||||
if (params[FLD_TYPE].equals("LINEAR"))
|
||||
{
|
||||
// create linear conversion
|
||||
newCnv = new LinearConversion(Integer.parseInt(params[FLD_FACTOR]),
|
||||
Integer.parseInt(params[FLD_DIVIDER]),
|
||||
Integer.parseInt(params[FLD_OFFSET]),
|
||||
Integer.parseInt(params[FLD_PHOFFSET]),
|
||||
params[FLD_UNITS]);
|
||||
} else
|
||||
{
|
||||
// create VAG conversion
|
||||
newCnv = new VagConversion(Integer.parseInt(params[FLD_VARIANT]),
|
||||
Double.parseDouble(params[FLD_FACTOR]) / Integer.parseInt(params[FLD_DIVIDER]),
|
||||
Double.parseDouble(params[FLD_OFFSET]),
|
||||
params[FLD_UNITS]);
|
||||
}
|
||||
// insert fault code element
|
||||
currCnvSet = get(params[FLD_NAME]);
|
||||
// if this conversion does not exist yet ...
|
||||
if (currCnvSet == null)
|
||||
{
|
||||
// create new set for metric and imperial
|
||||
currCnvSet = new Conversion[SYSTEM_TYPES];
|
||||
// and initialize both systems with this data
|
||||
for (int i = 0; i < SYSTEM_TYPES; i++)
|
||||
{
|
||||
currCnvSet[i] = newCnv;
|
||||
log.debug("+" + params[FLD_NAME] + "/" + params[FLD_SYSTEM] + " - " + newCnv.toString());
|
||||
}
|
||||
} else
|
||||
{
|
||||
// if it is known already, then only update the matching system
|
||||
for (int i = 0; i < SYSTEM_TYPES; i++)
|
||||
{
|
||||
if (cnvSystems[i].equals(params[FLD_SYSTEM]))
|
||||
{
|
||||
currCnvSet[i] = newCnv;
|
||||
log.debug("+" + params[FLD_NAME] + "/" + params[FLD_SYSTEM] + " - " + newCnv.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
// (re-)enter the updated conversion set into map
|
||||
put(params[FLD_NAME], currCnvSet);
|
||||
}
|
||||
rdr.close();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
139
src/com/fr3ts0n/ecu/EcuDataItem.java
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import com.fr3ts0n.prot.ProtoHeader;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Definition of a single ECU Data item (EcuDataItem)
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class EcuDataItem
|
||||
extends Object
|
||||
implements Cloneable
|
||||
{
|
||||
public int pid; // pid
|
||||
public int bytes; // number of data bytes expected from vehicle
|
||||
public int ofs; // Offset within message
|
||||
public Conversion[] cnv; // type of conversion
|
||||
public int decimals; // number of decimal digits
|
||||
public String label; // text label
|
||||
public EcuDataPv pv; // the process variable for displaying
|
||||
// Logger object
|
||||
public static final Logger log = Logger.getLogger("data.ecu");
|
||||
|
||||
/**
|
||||
* Creates a new instance of EcuDataItem
|
||||
*/
|
||||
public EcuDataItem()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of EcuDataItem
|
||||
*
|
||||
* @param pid
|
||||
* @param offset
|
||||
* @param bytes
|
||||
* @param cnv
|
||||
* @param decimals
|
||||
* @param label
|
||||
*/
|
||||
public EcuDataItem(int pid, int offset, int bytes, Conversion[] cnv, int decimals, String label)
|
||||
{
|
||||
this.pid = pid;
|
||||
this.ofs = offset;
|
||||
this.bytes = bytes;
|
||||
this.cnv = cnv;
|
||||
this.decimals = decimals;
|
||||
this.label = label;
|
||||
this.pv = new EcuDataPv();
|
||||
|
||||
// initialize new PID with current data
|
||||
this.pv.put(EcuDataPv.FID_PID, new Integer(pid));
|
||||
this.pv.put(EcuDataPv.FID_DESCRIPT, label);
|
||||
this.pv.put(EcuDataPv.FID_UNITS, cnv != null ? cnv[EcuConversions.cnvSystem].getUnits() : "");
|
||||
this.pv.put(EcuDataPv.FID_VALUE, new Float(0));
|
||||
this.pv.put(EcuDataPv.FID_DECIMALS, new Integer(decimals));
|
||||
this.pv.put(EcuDataPv.FID_CNVID, cnv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return (String.format("%02d.%d", pid, ofs));
|
||||
}
|
||||
|
||||
/**
|
||||
* get physical value from buffer
|
||||
*
|
||||
* @param buffer
|
||||
* @return physical value
|
||||
*/
|
||||
Object physFromBuffer(char[] buffer)
|
||||
{
|
||||
Object result;
|
||||
if (cnv != null)
|
||||
{
|
||||
result = cnv[EcuConversions.cnvSystem].memToPhys(ProtoHeader.getParamInt(ofs, bytes, buffer).longValue());
|
||||
} else
|
||||
{
|
||||
result = ProtoHeader.getParamString(ofs, bytes, buffer);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update process var from Buffer value
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void updatePvFomBuffer(char[] buffer)
|
||||
{
|
||||
// get physical value
|
||||
Object result = physFromBuffer(buffer);
|
||||
pv.put(EcuDataPv.FID_VALUE, result);
|
||||
log.debug(String.format("%02X %-30s %16s %s",
|
||||
pid,
|
||||
label,
|
||||
pv.get(EcuDataPv.FID_VALUE),
|
||||
pv.get(EcuDataPv.FID_UNITS)));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone()
|
||||
{
|
||||
EcuDataItem result = null;
|
||||
try
|
||||
{
|
||||
result = (EcuDataItem) super.clone();
|
||||
result.pv = (EcuDataPv) pv.clone();
|
||||
} catch (CloneNotSupportedException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
}
|
||||
189
src/com/fr3ts0n/ecu/EcuDataItems.java
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Collection of all known data items:
|
||||
* <pre>
|
||||
* The data structure looks as follows:
|
||||
* Service -- PID -- EcuDataItem
|
||||
* | |- EcuDataItem
|
||||
* | |- ...
|
||||
* ... |- PID -- EcuDataItem
|
||||
* | |- ...
|
||||
* |- ... -- ...
|
||||
* Service ...
|
||||
* </pre>
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class EcuDataItems extends HashMap<Integer, HashMap<Integer, Vector<EcuDataItem>>>
|
||||
{
|
||||
/** SerialVerion UID */
|
||||
private static final long serialVersionUID = 5525561909111851836L;
|
||||
/** CSV field positions */
|
||||
static final int FLD_SVC = 0;
|
||||
static final int FLD_PID = 1;
|
||||
static final int FLD_OFS = 2;
|
||||
static final int FLD_LEN = 3;
|
||||
static final int FLD_FORMULA = 4;
|
||||
static final int FLD_DIGITS = 5;
|
||||
static final int FLD_LABEL = 6;
|
||||
static final int FLD_DESCRIPTION = 7;
|
||||
|
||||
// set of all conversions
|
||||
static EcuConversions cnv = new EcuConversions();
|
||||
// the data logger
|
||||
static Logger log = Logger.getLogger("data.items");
|
||||
|
||||
public EcuDataItems()
|
||||
{
|
||||
initFromRessource("res/pids.csv");
|
||||
}
|
||||
|
||||
/**
|
||||
* read data from ressource file into data structure
|
||||
*
|
||||
* @param ressource the ressource file (csv)
|
||||
*/
|
||||
private void initFromRessource(String ressource)
|
||||
{
|
||||
BufferedReader rdr;
|
||||
String currLine;
|
||||
String[] params;
|
||||
Conversion[] currCnvSet;
|
||||
EcuDataItem newItm;
|
||||
int line = 0;
|
||||
try
|
||||
{
|
||||
rdr = new BufferedReader(new InputStreamReader(getClass().getResource(ressource).openStream()));
|
||||
// loop through all lines of the file ...
|
||||
while ((currLine = rdr.readLine()) != null)
|
||||
{
|
||||
// ignore first line
|
||||
if (++line == 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// repalce all optional quotes from CSV code list
|
||||
currLine = currLine.replaceAll("\"", "");
|
||||
// split CSV line into parameters
|
||||
params = currLine.split("\t");
|
||||
|
||||
currCnvSet = cnv.get(params[FLD_FORMULA]);
|
||||
if (currCnvSet == null)
|
||||
{
|
||||
log.warn("Conversion not found: " + params[FLD_FORMULA] + " " + currLine);
|
||||
}
|
||||
// create linear conversion
|
||||
newItm = new EcuDataItem(Integer.decode(params[FLD_PID]).intValue(),
|
||||
Integer.parseInt(params[FLD_OFS]),
|
||||
Integer.parseInt(params[FLD_LEN]),
|
||||
currCnvSet,
|
||||
Integer.parseInt(params[FLD_DIGITS]),
|
||||
params[FLD_LABEL]);
|
||||
|
||||
// enter data item for all specified services
|
||||
String[] services = params[FLD_SVC].split(",");
|
||||
for (int i = 0; i < services.length; i++)
|
||||
{
|
||||
int svcId = Integer.decode(services[i]).intValue();
|
||||
// check if service existes already
|
||||
HashMap<Integer, Vector<EcuDataItem>> currSvc = get(svcId);
|
||||
// if not - create it
|
||||
if (currSvc == null)
|
||||
{
|
||||
currSvc = new HashMap<Integer, Vector<EcuDataItem>>();
|
||||
log.debug("+SVC: " + services[i] + " - " + currSvc);
|
||||
}
|
||||
|
||||
// check if item list exists for current PID
|
||||
Vector<EcuDataItem> currVec = currSvc.get(newItm.pid);
|
||||
// if not -- create it
|
||||
if (currVec == null)
|
||||
{
|
||||
currVec = new Vector<EcuDataItem>();
|
||||
log.debug("+PID: " + newItm.pid + " - " + currVec);
|
||||
}
|
||||
// enter data item into list of items / PID
|
||||
currVec.add(newItm);
|
||||
// and update list in into the pid map for corresponding service
|
||||
currSvc.put(newItm.pid, currVec);
|
||||
// update map of services
|
||||
put(svcId, currSvc);
|
||||
// debug message of new enty
|
||||
log.debug("+" + services[i] + "/" + params[FLD_PID] + " - " + currVec);
|
||||
}
|
||||
}
|
||||
rdr.close();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get all data items for selected service and PID
|
||||
*
|
||||
* @param service service to search data items for
|
||||
* @param pid pid to search data items for
|
||||
* @return Vector to data items - or null if no data items exist
|
||||
*/
|
||||
public Vector<EcuDataItem> getPidDataItems(int service, int pid)
|
||||
{
|
||||
Vector<EcuDataItem> currVec = null;
|
||||
HashMap<Integer, Vector<EcuDataItem>> currSvc = get(service);
|
||||
if (currSvc != null)
|
||||
{
|
||||
currVec = currSvc.get(pid);
|
||||
}
|
||||
return (currVec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all EcuDataItems with new data from buffer
|
||||
*
|
||||
* @param service service of current data
|
||||
* @param pid pid of current data
|
||||
* @param buffer data buffer to do conversions on
|
||||
*/
|
||||
void updateDataItems(int service, int pid, char[] buffer)
|
||||
{
|
||||
EcuDataItem currItm;
|
||||
Vector<EcuDataItem> currItms = getPidDataItems(service, pid);
|
||||
|
||||
Iterator<EcuDataItem> it = currItms.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
currItm = it.next();
|
||||
currItm.updatePvFomBuffer(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
65
src/com/fr3ts0n/ecu/EcuDataPv.java
Executable file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import com.fr3ts0n.pvs.IndexedProcessVar;
|
||||
|
||||
/**
|
||||
* Process variable which contains a single OBD data item
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class EcuDataPv extends IndexedProcessVar
|
||||
{
|
||||
/** UID for serialisation */
|
||||
private static final long serialVersionUID = -7787217159439147214L;
|
||||
|
||||
// Field IDs
|
||||
public static final int FID_PID = 0;
|
||||
public static final int FID_DESCRIPT = 1;
|
||||
public static final int FID_VALUE = 2;
|
||||
public static final int FID_UNITS = 3;
|
||||
// optional Field IDs which will be invisible for table display
|
||||
public static final String FID_DECIMALS = "DECIMALS";
|
||||
public static final String FID_CNVID = "CNV_ID";
|
||||
public static final String FID_MIN = "MIN";
|
||||
public static final String FID_MAX = "MAX";
|
||||
|
||||
public static final String[] FIELDS =
|
||||
{
|
||||
"PID",
|
||||
"DESCRIPTION",
|
||||
"VALUE",
|
||||
"UNITS",
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new instance of EcuDataPv
|
||||
*/
|
||||
public EcuDataPv()
|
||||
{
|
||||
super();
|
||||
this.setKeyAttribute(FIELDS[0]);
|
||||
}
|
||||
|
||||
public String[] getFields()
|
||||
{
|
||||
return (FIELDS);
|
||||
}
|
||||
}
|
||||
125
src/com/fr3ts0n/ecu/HashConversion.java
Executable file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* conversion of numeric values based on a hash map
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class HashConversion extends NumericConversion
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1077047688974749271L;
|
||||
/* the HashMap Data */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private HashMap hashData = new HashMap();
|
||||
String units = "-";
|
||||
|
||||
/**
|
||||
* create a new Instance
|
||||
*/
|
||||
public HashConversion()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new hash converter which is initialized with values from map data
|
||||
*
|
||||
* @param data map data for conversions
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public HashConversion(Map data)
|
||||
{
|
||||
hashData.putAll(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new hash converter which is initialized with avlues from an array
|
||||
* of strings in the format "key=value"
|
||||
*
|
||||
* @param initData initializer strings for conversions in the format "key=value[;key=value[...]]"
|
||||
*/
|
||||
public HashConversion(String[] initData)
|
||||
{
|
||||
initFromStrings(initData);
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize hash map with values from an array of strings in the format "key=value"
|
||||
*
|
||||
* @param initData initializer strings for conversions in the format "key=value[;key=value[...]]"
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initFromStrings(String[] initData)
|
||||
{
|
||||
Long key;
|
||||
String value;
|
||||
String[] data;
|
||||
// clear old hash data
|
||||
hashData.clear();
|
||||
|
||||
// loop through all strin entries ...
|
||||
for (int i = 0; i < initData.length; i++)
|
||||
{
|
||||
data = initData[i].split(";");
|
||||
for (int j = 0; j < data.length; j++)
|
||||
{
|
||||
// ... split key and value ...
|
||||
String[] words = data[j].split("=");
|
||||
key = Long.valueOf(words[0]);
|
||||
value = words[1];
|
||||
// ... and enter into hash map
|
||||
hashData.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Number memToPhys(long value)
|
||||
{
|
||||
return (value);
|
||||
}
|
||||
|
||||
public Number physToMem(Number value)
|
||||
{
|
||||
return (value);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a numerical physical value into a formatted string
|
||||
*
|
||||
* @param physVal physical value
|
||||
* @param decimals number of decimals for formatting
|
||||
* @return formatted String
|
||||
*/
|
||||
@Override
|
||||
public String physToPhysFmtString(Number physVal, int decimals)
|
||||
{
|
||||
String result = (String) hashData.get(physVal);
|
||||
// if we haven't found a string representation, return numeric value
|
||||
if (result == null) result = String.valueOf(physVal);
|
||||
return (result);
|
||||
}
|
||||
|
||||
}
|
||||
108
src/com/fr3ts0n/ecu/LinearConversion.java
Executable file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import com.fr3ts0n.pvs.PvLimits;
|
||||
|
||||
/**
|
||||
* Definition of a single OBD data conversion
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class LinearConversion extends NumericConversion
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 7409621816599441879L;
|
||||
int factor = 1;
|
||||
int divider = 1;
|
||||
int offset = 0;
|
||||
int offsetPhys = 0;
|
||||
PvLimits limits = null;
|
||||
|
||||
/**
|
||||
* Creates a new instance of Conversion
|
||||
*/
|
||||
public LinearConversion()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of Conversion
|
||||
*
|
||||
* @param factor conversion factor (integer part)
|
||||
* @param divider conversion divider (integer part)
|
||||
* @param offset linear offset to be added to raw memory value before conversion
|
||||
* @param offsetPhys physical offset to be added after converting raw value
|
||||
* @param units physical units for this conversion
|
||||
*/
|
||||
public LinearConversion(int factor, int divider, int offset, int offsetPhys,
|
||||
String units)
|
||||
{
|
||||
this.offset = offset;
|
||||
this.factor = factor;
|
||||
this.divider = divider;
|
||||
this.offsetPhys = offsetPhys;
|
||||
this.units = units;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of Conversion
|
||||
*
|
||||
* @param factor conversion factor (integer part)
|
||||
* @param divider conversion divider (integer part)
|
||||
* @param offset linear offset to be added to raw memory value before conversion
|
||||
* @param offsetPhys physical offset to be added after converting raw value
|
||||
* @param units physical units for this conversion
|
||||
*/
|
||||
public LinearConversion(int factor, int divider, int offset, int offsetPhys,
|
||||
String units, PvLimits limits)
|
||||
{
|
||||
this(factor, divider, offset, offsetPhys, units);
|
||||
this.limits = limits;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*
|
||||
* @param value raw memory value to be converted
|
||||
*/
|
||||
public Number memToPhys(long value)
|
||||
{
|
||||
float result = ((float) (value + offset) * factor / divider + offsetPhys);
|
||||
if (limits != null)
|
||||
{
|
||||
result = (Float) limits.limitedValue(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert measurement item from physical value to raw storage format
|
||||
*
|
||||
* @param value physical value to be converted
|
||||
*/
|
||||
public Number physToMem(Number value)
|
||||
{
|
||||
return ((long) java.lang.Math.round((value.floatValue() - offsetPhys)
|
||||
* divider / factor - offset));
|
||||
}
|
||||
}
|
||||
103
src/com/fr3ts0n/ecu/NumericConversion.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* Base class for numeric diagnostic data conversions
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public abstract class NumericConversion implements Conversion
|
||||
{
|
||||
/** fixed serial version id */
|
||||
private static final long serialVersionUID = 5506104864792893549L;
|
||||
/** Formatter to format numeric values to strings */
|
||||
protected static DecimalFormat decimalFormat = new DecimalFormat();
|
||||
/** format templates to format numeric values to strings */
|
||||
static String[] formats = {"0;-#", "0.0;-#",
|
||||
"0.00;-#", "0.000;-#", "0.0000;-#"};
|
||||
|
||||
/** physical units of data item */
|
||||
String units = "";
|
||||
|
||||
/**
|
||||
* convert a numerical physical value into a formatted string
|
||||
*
|
||||
* @param physVal physical value
|
||||
* @param decimals number of decimals for formatting
|
||||
* @return formatted String
|
||||
*/
|
||||
public String physToPhysFmtString(Number physVal, int decimals)
|
||||
{
|
||||
String result = "";
|
||||
if (decimals >= 0)
|
||||
{
|
||||
LinearConversion.decimalFormat
|
||||
.applyPattern(LinearConversion.formats[decimals]);
|
||||
result = LinearConversion.decimalFormat.format(physVal);
|
||||
} else
|
||||
{
|
||||
result = String.valueOf(physVal);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public NumericConversion()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* return physical units of measurement
|
||||
*
|
||||
* @return physical units
|
||||
*/
|
||||
public String getUnits()
|
||||
{
|
||||
return units;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*
|
||||
* @param value memory value
|
||||
* @param numDecimals number of decimal for string formatting of numbers
|
||||
* @return string representation of numeric value
|
||||
*/
|
||||
public String memToString(Number value, int numDecimals)
|
||||
{
|
||||
return physToPhysFmtString(memToPhys(value.longValue()), numDecimals);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert measurement item from storage format to physical value
|
||||
*
|
||||
* @param value raw memory value to be converted
|
||||
*/
|
||||
public abstract Number memToPhys(long value);
|
||||
|
||||
/**
|
||||
* convert measurement item from physical value to raw storage format
|
||||
*
|
||||
* @param value physical value to be converted
|
||||
*/
|
||||
public abstract Number physToMem(Number value);
|
||||
|
||||
}
|
||||
114
src/com/fr3ts0n/ecu/ObdCodeItem.java
Executable file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import com.fr3ts0n.prot.ProtoHeader;
|
||||
|
||||
/**
|
||||
* Definition of a single OBD failure code
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class ObdCodeItem extends EcuCodeItem
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3976920283943009811L;
|
||||
|
||||
/** code types */
|
||||
public static final String codeTypes = "PCBU";
|
||||
|
||||
public static final int ID_CODE_TYPE = 0;
|
||||
public static final int ID_CODE_VALUE = 1;
|
||||
|
||||
/**
|
||||
* List of telegram parameters in order of appearance
|
||||
*/
|
||||
static final int TC_PARAMETERS[][] =
|
||||
/* START, LEN, PARAM-TYPE // REMARKS */
|
||||
/* ------------------------------------------- */
|
||||
{{0, 1, ProtoHeader.PT_ALPHA}, // ID_CODE_TYPE
|
||||
{1, 4, ProtoHeader.PT_HEX}, // ID_CODE_VALUE
|
||||
};
|
||||
|
||||
/** Creates a new instance of ObdCodeItem */
|
||||
public ObdCodeItem()
|
||||
{
|
||||
setKeyAttribute(FIELDS[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of ObdCodeItem
|
||||
*
|
||||
* @param code String representation of DFC
|
||||
* @param description descriptive text of DFC
|
||||
*/
|
||||
public ObdCodeItem(String code, String description)
|
||||
{
|
||||
setKeyAttribute(FIELDS[0]);
|
||||
put(FID_CODE, code);
|
||||
put(FID_DESCRIPT, description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of ObdCodeItem
|
||||
*
|
||||
* @param numericCode numeric code ID
|
||||
* @param description descriptive text of DFC
|
||||
*/
|
||||
public ObdCodeItem(int numericCode, String description)
|
||||
{
|
||||
setKeyAttribute(FIELDS[0]);
|
||||
put(FID_CODE, getPCode(numericCode));
|
||||
put(FID_DESCRIPT, description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return numeric code representation from P/C/B/U-Code String
|
||||
*
|
||||
* @param pCode P/C/B/U-Code String
|
||||
* @return numeric code value for corresponding code
|
||||
*/
|
||||
protected static int getNumericCode(String pCode)
|
||||
{
|
||||
// get code number
|
||||
int numCode = Integer.valueOf(pCode.substring(1), 16).intValue();
|
||||
int typIdx = codeTypes.indexOf(pCode.charAt(0));
|
||||
numCode |= (typIdx << 14);
|
||||
|
||||
return (numCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return P/C/B/U-Code String representation from numeric code
|
||||
*
|
||||
* @param numericCode numeric code value for corresponding code
|
||||
* @return P/C/B/U-Code String
|
||||
*/
|
||||
protected static String getPCode(int numericCode)
|
||||
{
|
||||
char[] buffer = new char[5];
|
||||
int codeType = numericCode >> 14;
|
||||
int codeVal = numericCode & 0x3FFF;
|
||||
ProtoHeader.setParamValue(ID_CODE_TYPE, TC_PARAMETERS, buffer, codeTypes.substring(codeType, codeType + 1));
|
||||
ProtoHeader.setParamValue(ID_CODE_VALUE, TC_PARAMETERS, buffer, new Integer(codeVal));
|
||||
return (new String(buffer));
|
||||
}
|
||||
}
|
||||
98
src/com/fr3ts0n/ecu/ObdCodeList.java
Executable file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
|
||||
/**
|
||||
* List of all known OBD failure codes
|
||||
* This list is initialized by reading data files 'res/pcodes' and 'res/ucodes'
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class ObdCodeList
|
||||
extends EcuCodeList
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2198654596294230437L;
|
||||
|
||||
/** Creates a new instance of ObdCodeList */
|
||||
public ObdCodeList()
|
||||
{
|
||||
// load code list from text files
|
||||
initFromRessource("prot/res/pcodes");
|
||||
initFromRessource("prot/res/ucodes");
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize list from ressource file (tab delimited)
|
||||
*
|
||||
* @param ressource name of ressource to be loaded
|
||||
*/
|
||||
protected void initFromRessource(String ressource)
|
||||
{
|
||||
BufferedReader rdr;
|
||||
String currLine;
|
||||
String[] params;
|
||||
|
||||
try
|
||||
{
|
||||
rdr = new BufferedReader(new InputStreamReader(getClass().getResource(ressource).openStream()));
|
||||
// loop through all lines of the file ...
|
||||
while ((currLine = rdr.readLine()) != null)
|
||||
{
|
||||
// repalce all optional quotes from CSV code list
|
||||
currLine = currLine.replaceAll("\"", "");
|
||||
// split CSV line into parameters
|
||||
params = currLine.split("\t");
|
||||
// insert fault code element
|
||||
put(ObdCodeItem.getNumericCode(params[0]), new ObdCodeItem(params[0], params[1]));
|
||||
}
|
||||
rdr.close();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a numerical physical value into a formatted string
|
||||
*
|
||||
* @param value physical value
|
||||
* @param decimals number of decimals for formatting
|
||||
* @return formatted String
|
||||
*/
|
||||
public String physToPhysFmtString(Number value, int decimals)
|
||||
{
|
||||
String result = "Fault code unknown";
|
||||
EcuCodeItem code = get(value.intValue());
|
||||
if (code != null)
|
||||
{
|
||||
result = code.get(ObdCodeItem.FID_DESCRIPT).toString();
|
||||
}
|
||||
result = ObdCodeItem.getPCode(value.intValue()) + " - " + result;
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
91
src/com/fr3ts0n/ecu/ObdVidItem.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import com.fr3ts0n.pvs.IndexedProcessVar;
|
||||
|
||||
/**
|
||||
* OBD Vehicle identification Item
|
||||
* The VID item does not contain any units, since it is all alphanumeric IDs
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class ObdVidItem
|
||||
extends IndexedProcessVar
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 955050909875054165L;
|
||||
public static final int FID_DESCRIPT = 0;
|
||||
public static final int FID_VALUE = 1;
|
||||
|
||||
/**
|
||||
* description of all relevant fields for VID item
|
||||
*/
|
||||
static final String[] fields =
|
||||
{
|
||||
"Description",
|
||||
"Value"
|
||||
};
|
||||
|
||||
@Override
|
||||
public String[] getFields()
|
||||
{
|
||||
return (fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Descriptions of mode 9 PIDs
|
||||
*/
|
||||
private static String descriptions[] =
|
||||
{
|
||||
/* PID 0 */ "Supported PIDs",
|
||||
/* PID 1 */ "VIN Count",
|
||||
/* PID 2 */ "Vehicle ID Number",
|
||||
/* PID 3 */ "Cal ID Count",
|
||||
/* PID 4 */ "Calibration ID",
|
||||
/* PID 5 */ "Cal Version Count",
|
||||
/* PID 6 */ "Cal Version",
|
||||
/* PID 7 */ "IPT Count",
|
||||
/* PID 8 */ "IPT",
|
||||
/* PID 9 */ "Control System count",
|
||||
/* PID A */ "Control System ID",
|
||||
};
|
||||
|
||||
/**
|
||||
* Return description for Mode $09 PID
|
||||
*
|
||||
* @param pid
|
||||
* @return description for selected PID
|
||||
*/
|
||||
public static String getPidDescription(int pid)
|
||||
{
|
||||
String result;
|
||||
try
|
||||
{
|
||||
result = descriptions[pid];
|
||||
} catch (Exception e)
|
||||
{
|
||||
// PID is not defined -> create dummy
|
||||
result = String.format("PID %02X", pid);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
60
src/com/fr3ts0n/ecu/Pid.java
Executable file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
/**
|
||||
* Definition of a single OBD Data item (PID)
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class Pid
|
||||
{
|
||||
public int pid; // PID
|
||||
public int bytes; // number of data bytes expected from vehicle
|
||||
public int ofs; // Offset within message
|
||||
public int cnv; // type of conversion
|
||||
public int decimals; // number of decimal digits
|
||||
public String label; // text label
|
||||
|
||||
/**
|
||||
* Creates a new instance of Pid
|
||||
*/
|
||||
public Pid()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of Pid
|
||||
*/
|
||||
public Pid(int pid, int offset, int bytes, int cnv, int decimals, String label)
|
||||
{
|
||||
this.pid = pid;
|
||||
this.ofs = offset;
|
||||
this.bytes = bytes;
|
||||
this.cnv = cnv;
|
||||
this.decimals = decimals;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return (String.format("%02X", pid));
|
||||
}
|
||||
}
|
||||
208
src/com/fr3ts0n/ecu/Pids.java
Executable file
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Collection of all known OBD data items (PIDs)
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class Pids
|
||||
{
|
||||
|
||||
// maximum values / bitmasks per affected byte
|
||||
public static final long[] valueMask =
|
||||
{
|
||||
0x00,
|
||||
0xFF,
|
||||
0xFFFF,
|
||||
0xFFFFFF,
|
||||
0xFFFFFFFF
|
||||
};
|
||||
|
||||
/* PID definitions */
|
||||
public static final Pid[] PIDs =
|
||||
{
|
||||
// pid,ofs,len, formula digits label
|
||||
new Pid(0x01, 0, 1, Conversions.CNV_ID_ONETOONE, 0, "Number of Fault Codes"), // fuel_system1_status_formula // fuel_system2_status_formula
|
||||
new Pid(0x02, 0, 2, Conversions.CNV_ID_OBD_CODELIST, -1, "DTC-Fault location"), // fault location conversion
|
||||
new Pid(0x03, 0, 2, Conversions.CNV_ID_ONETOONE, 0, "Fuel System Status"), // fuel_system1_status_formula // fuel_system2_status_formula
|
||||
new Pid(0x04, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Calculated Load Value"),
|
||||
new Pid(0x05, 0, 1, Conversions.CNV_ID_TEMPERATURE, 1, "Coolant Temperature"),
|
||||
new Pid(0x06, 0, 2, Conversions.CNV_ID_PERCENT7_REL, 1, "Short Term Fuel Trim (Bank 1)"), // short_term_fuel_trim
|
||||
new Pid(0x07, 0, 2, Conversions.CNV_ID_PERCENT7_REL, 1, "Long Term Fuel Trim (Bank 1)"), // long_term_fuel_trim
|
||||
new Pid(0x08, 0, 2, Conversions.CNV_ID_PERCENT7_REL, 1, "Short Term Fuel Trim (Bank 2)"), // short_term_fuel_trim
|
||||
new Pid(0x09, 0, 2, Conversions.CNV_ID_PERCENT7_REL, 1, "Long Term Fuel Trim (Bank 2)"), // long_term_fuel_trim
|
||||
new Pid(0x0A, 0, 1, Conversions.CNV_ID_PRESS, 1, "Fuel Pressure (gauge)"),
|
||||
new Pid(0x0B, 0, 1, Conversions.CNV_ID_PRESS_AIR, 1, "Intake Manifold Pressure"),
|
||||
new Pid(0x0C, 0, 2, Conversions.CNV_ID_RPM, 0, "Engine RPM"),
|
||||
new Pid(0x0D, 0, 1, Conversions.CNV_ID_VEHSPEED, 0, "Vehicle Speed"),
|
||||
new Pid(0x0E, 0, 1, Conversions.CNV_ID_ANGLE, 2, "Timing Advance (Cyl. #1)"),
|
||||
new Pid(0x0F, 0, 1, Conversions.CNV_ID_TEMPERATURE, 1, "Intake Air Temperature"),
|
||||
new Pid(0x10, 0, 2, Conversions.CNV_ID_AIRFLOW, 2, "Air Flow Rate (MAF sensor)"),
|
||||
new Pid(0x11, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Absolute Throttle Position"),
|
||||
new Pid(0x12, 0, 1, Conversions.CNV_ID_ONETOONE, 0, "Secondary air status"), // secondary_air_status_formula,
|
||||
new Pid(0x13, 0, 1, Conversions.CNV_ID_ONETOONE, 0, "Location of O2 Sensor(s)"), // o2_sensor_formula,
|
||||
new Pid(0x14, 0, 2, Conversions.CNV_ID_ONETOONE, 0, "O2 Sensor 1, Bank 1"), // o2_sensor_formula,
|
||||
new Pid(0x15, 0, 2, Conversions.CNV_ID_ONETOONE, 0, "O2 Sensor 2, Bank 1"), // o2_sensor_formula,
|
||||
new Pid(0x16, 0, 2, Conversions.CNV_ID_ONETOONE, 0, "O2 Sensor 3, Bank 1"), // o2_sensor_formula,
|
||||
new Pid(0x17, 0, 2, Conversions.CNV_ID_ONETOONE, 0, "O2 Sensor 4, Bank 1"), // o2_sensor_formula,
|
||||
new Pid(0x18, 0, 2, Conversions.CNV_ID_ONETOONE, 0, "O2 Sensor 1, Bank 2"), // o2_sensor_formula,
|
||||
new Pid(0x19, 0, 2, Conversions.CNV_ID_ONETOONE, 0, "O2 Sensor 2, Bank 2"), // o2_sensor_formula,
|
||||
new Pid(0x1A, 0, 2, Conversions.CNV_ID_ONETOONE, 0, "O2 Sensor 3, Bank 2"), // o2_sensor_formula,
|
||||
new Pid(0x1B, 0, 2, Conversions.CNV_ID_ONETOONE, 0, "O2 Sensor 4, Bank 2"), // o2_sensor_formula,
|
||||
new Pid(0x1C, 0, 1, Conversions.CNV_ID_OBD_TYPE, -1, "OBD conforms to"), // obd_requirements_formula,
|
||||
new Pid(0x1D, 0, 1, Conversions.CNV_ID_ONETOONE, 0, "Location of O2 Sensor(s)"), // o2_sensor_formula,
|
||||
new Pid(0x1E, 0, 1, Conversions.CNV_ID_ONETOONE, 0, "Power Take-Off Status"), // pto_status_formula,
|
||||
new Pid(0x1F, 0, 2, Conversions.CNV_ID_HOURS, 2, "Time Since Engine Start"),
|
||||
new Pid(0x21, 0, 2, Conversions.CNV_ID_DISTANCE, 0, "Distance since MIL activated"),
|
||||
new Pid(0x22, 0, 2, Conversions.CNV_ID_PRESS_REL, 3, "FRP rel. to manifold vacuum"), // fuel rail pressure relative to manifold vacuum
|
||||
new Pid(0x23, 0, 2, Conversions.CNV_ID_PRESS_WIDERANGE, 1, "Fuel Pressure (gauge)"), // fuel rail pressure (gauge), wide range
|
||||
new Pid(0x24, 0, 2, Conversions.CNV_ID_VOLTAGE_HIGHRES, 3, "O2 Sensor 1, Bank 1 (WR)"), // o2_sensor_wrv_formula, // o2 sensors (wide range), voltage
|
||||
new Pid(0x25, 0, 2, Conversions.CNV_ID_VOLTAGE_HIGHRES, 3, "O2 Sensor 2, Bank 1 (WR)"), // o2_sensor_wrv_formula,
|
||||
new Pid(0x26, 0, 2, Conversions.CNV_ID_VOLTAGE_HIGHRES, 3, "O2 Sensor 3, Bank 1 (WR)"), // o2_sensor_wrv_formula,
|
||||
new Pid(0x27, 0, 2, Conversions.CNV_ID_VOLTAGE_HIGHRES, 3, "O2 Sensor 4, Bank 1 (WR)"), // o2_sensor_wrv_formula,
|
||||
new Pid(0x28, 0, 2, Conversions.CNV_ID_VOLTAGE_HIGHRES, 3, "O2 Sensor 1, Bank 2 (WR)"), // o2_sensor_wrv_formula,
|
||||
new Pid(0x29, 0, 2, Conversions.CNV_ID_VOLTAGE_HIGHRES, 3, "O2 Sensor 2, Bank 2 (WR)"), // o2_sensor_wrv_formula,
|
||||
new Pid(0x2A, 0, 2, Conversions.CNV_ID_VOLTAGE_HIGHRES, 3, "O2 Sensor 3, Bank 2 (WR)"), // o2_sensor_wrv_formula,
|
||||
new Pid(0x2B, 0, 2, Conversions.CNV_ID_VOLTAGE_HIGHRES, 3, "O2 Sensor 4, Bank 2 (WR)"), // o2_sensor_wrv_formula,
|
||||
new Pid(0x2C, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Commanded EGR"),
|
||||
new Pid(0x2D, 0, 1, Conversions.CNV_ID_PERCENT_REL, 2, "EGR Error"),
|
||||
new Pid(0x2E, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Commanded Evaporative Purge"),
|
||||
new Pid(0x2F, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Fuel Level Input"),
|
||||
new Pid(0x30, 0, 1, Conversions.CNV_ID_ONETOONE, 0, "Warm-ups since ECU reset"),
|
||||
new Pid(0x31, 0, 2, Conversions.CNV_ID_DISTANCE, 0, "Distance since ECU reset"),
|
||||
new Pid(0x32, 0, 2, Conversions.CNV_ID_PRESS_VAPOR, 2, "Evap System Vapor Pressure"),
|
||||
new Pid(0x33, 0, 1, Conversions.CNV_ID_PRESS_AIR, 1, "Barometric Pressure (absolute)"),
|
||||
new Pid(0x34, 0, 2, Conversions.CNV_ID_RATIO_WIDERANGE, 1, "O2 Sensor 1, Bank 1 (WR)"), // o2_sensor_wrc_formula, // o2 sensors (wide range), current
|
||||
new Pid(0x35, 0, 2, Conversions.CNV_ID_RATIO_WIDERANGE, 1, "O2 Sensor 2, Bank 1 (WR)"), // o2_sensor_wrc_formula,
|
||||
new Pid(0x36, 0, 2, Conversions.CNV_ID_RATIO_WIDERANGE, 1, "O2 Sensor 3, Bank 1 (WR)"), // o2_sensor_wrc_formula,
|
||||
new Pid(0x37, 0, 2, Conversions.CNV_ID_RATIO_WIDERANGE, 1, "O2 Sensor 4, Bank 1 (WR)"), // o2_sensor_wrc_formula,
|
||||
new Pid(0x38, 0, 2, Conversions.CNV_ID_RATIO_WIDERANGE, 1, "O2 Sensor 1, Bank 2 (WR)"), // o2_sensor_wrc_formula,
|
||||
new Pid(0x39, 0, 2, Conversions.CNV_ID_RATIO_WIDERANGE, 1, "O2 Sensor 2, Bank 2 (WR)"), // o2_sensor_wrc_formula,
|
||||
new Pid(0x3A, 0, 2, Conversions.CNV_ID_RATIO_WIDERANGE, 1, "O2 Sensor 3, Bank 2 (WR)"), // o2_sensor_wrc_formula,
|
||||
new Pid(0x3B, 0, 2, Conversions.CNV_ID_RATIO_WIDERANGE, 1, "O2 Sensor 4, Bank 2 (WR)"), // o2_sensor_wrc_formula,
|
||||
new Pid(0x3C, 0, 2, Conversions.CNV_ID_TEMP_WIDERANGE, 1, "CAT Temperature, B1S1"),
|
||||
new Pid(0x3D, 0, 2, Conversions.CNV_ID_TEMP_WIDERANGE, 1, "CAT Temperature, B2S1"),
|
||||
new Pid(0x3E, 0, 2, Conversions.CNV_ID_TEMP_WIDERANGE, 1, "CAT Temperature, B1S2"),
|
||||
new Pid(0x3F, 0, 2, Conversions.CNV_ID_TEMP_WIDERANGE, 1, "CAT Temperature, B2S2"),
|
||||
new Pid(0x41, 0, 4, Conversions.CNV_ID_ONETOONE, 0, "Monitor status for current driving cycle"),
|
||||
new Pid(0x42, 0, 2, Conversions.CNV_ID_VOLTAGE, 3, "ECU voltage"),
|
||||
new Pid(0x43, 0, 2, Conversions.CNV_ID_PERCENT, 1, "Absolute Engine Load"),
|
||||
new Pid(0x44, 0, 2, Conversions.CNV_ID_RATIO, 3, "Commanded Equivalence Ratio"),
|
||||
new Pid(0x45, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Relative Throttle Position"),
|
||||
new Pid(0x46, 0, 1, Conversions.CNV_ID_TEMPERATURE, 1, "Ambient Air Temperature"), // same scaling as $0F
|
||||
new Pid(0x47, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Absolute Throttle Position B"),
|
||||
new Pid(0x48, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Absolute Throttle Position C"),
|
||||
new Pid(0x49, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Accelerator Pedal Position D"),
|
||||
new Pid(0x4A, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Accelerator Pedal Position E"),
|
||||
new Pid(0x4B, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Accelerator Pedal Position F"),
|
||||
new Pid(0x4C, 0, 1, Conversions.CNV_ID_PERCENT, 1, "Comm. Throttle Actuator Cntrl"), // commanded TAC
|
||||
new Pid(0x4D, 0, 2, Conversions.CNV_ID_HOURS, 2, "Engine running while MIL on"), // minutes run by the engine while MIL activated
|
||||
new Pid(0x4E, 0, 2, Conversions.CNV_ID_HOURS, 2, "Time since DTCs cleared"),
|
||||
new Pid(0x4F, 0, 4, Conversions.CNV_ID_ONETOONE, 0, "Maximum values for Equivalence Ratio, Oxygen Sensor Voltage, Oxygen Sensor Current and Intake Manifold Absolute Pressure"),
|
||||
};
|
||||
/**
|
||||
* Comparator object to compare Pid objects
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
static Comparator pidComparator = new Comparator()
|
||||
{
|
||||
|
||||
public int compare(Object o1, Object o2)
|
||||
{
|
||||
int pid1 = o1 instanceof Pid ? ((Pid) o1).pid : Integer.valueOf(String.valueOf(o1)).intValue();
|
||||
int pid2 = o2 instanceof Pid ? ((Pid) o2).pid : Integer.valueOf(String.valueOf(o2)).intValue();
|
||||
return (pid1 - pid2);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new instance of Pids
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Pids()
|
||||
{
|
||||
// ensure Array ist sorted
|
||||
Arrays.sort(PIDs, pidComparator);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the Pid-Object to numeric PID
|
||||
*
|
||||
* @param pidNum numeric PID to get PID-Object for
|
||||
* @return PID-Object or NULL if no object available for specified PID
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Pid getPid(int pidNum)
|
||||
{
|
||||
// default result = NOT FOUND
|
||||
Pid currPid = null;
|
||||
// search list
|
||||
int i = Arrays.binarySearch(PIDs, pidNum, pidComparator);
|
||||
// if found, set result
|
||||
if (i >= 0)
|
||||
{
|
||||
currPid = PIDs[i];
|
||||
}
|
||||
// and return it
|
||||
return (currPid);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert memory/protocol value to physical value
|
||||
*
|
||||
* @param memVal value in memory/protocol format
|
||||
* @param pidNum PID to use for conversion
|
||||
* @return physical value
|
||||
*/
|
||||
public static float memToPhys(long memVal, int pidNum)
|
||||
{
|
||||
float result = 0;
|
||||
Pid currPid = getPid(pidNum);
|
||||
if (currPid != null)
|
||||
{
|
||||
long mskdVal = memVal & valueMask[currPid.bytes];
|
||||
result = Conversions.memToPhys(mskdVal, currPid.cnv);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert physical value to memory/protocol value
|
||||
*
|
||||
* @param physVal physical value
|
||||
* @param pidNum PID to use for conversion
|
||||
* @return value in memory/protocol layout
|
||||
*/
|
||||
public static long physToMem(float physVal, int pidNum)
|
||||
{
|
||||
long result = 0;
|
||||
Pid currPid = getPid(pidNum);
|
||||
if (currPid != null)
|
||||
{
|
||||
result = java.lang.Math.min(Conversions.physToMem(physVal, currPid.cnv),
|
||||
valueMask[currPid.bytes]);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
336
src/com/fr3ts0n/ecu/VagConversion.java
Normal file
@@ -0,0 +1,336 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu;
|
||||
|
||||
/**
|
||||
* VAG data conversions (used by Kw1281 ...)
|
||||
*
|
||||
* @author Erwin Scheuch-Heilig
|
||||
*/
|
||||
public class VagConversion extends NumericConversion
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 9130358043909319282L;
|
||||
|
||||
|
||||
/*
|
||||
* Formulas:
|
||||
*
|
||||
* 0 : Tabelle
|
||||
* 10 : (MW+Offset)*NW*Faktor
|
||||
* 11 : (MW.NW+Offset)*Faktor
|
||||
* 12 : (NW.MW+Offset)*Faktor
|
||||
* 13 : (NW*255+MW+Offset)*Faktor
|
||||
* 14 : (MW+Offset)/NW*Faktor
|
||||
* 15 : MW*Faktor+NW*Offset
|
||||
* 16 : (MW+Offset)*Faktor
|
||||
* 17 : 1+(MW+Offset)*NW*Faktor
|
||||
* 18 : (MW*NW*Faktor)+Offset
|
||||
* 20 : Bitdarstellung
|
||||
* 21 : 2 Ascii-Zeichen
|
||||
* 22 : Ascii-Text
|
||||
* 23 : Uhrzeit
|
||||
* 24 : Hexdarstellung
|
||||
*/
|
||||
public static final int CNV_ID_TBL = 0;
|
||||
|
||||
|
||||
int cnvId = 10;
|
||||
double factor = 1.0;
|
||||
double offset = 0.0;
|
||||
/** table values as they come from the meta package */
|
||||
/** Value 2 for calcualtion as it comes from meta package */
|
||||
private char metaNw = 0;
|
||||
/** table values as they come from the meta package */
|
||||
private char[] metaTblValues = {0, 255};
|
||||
|
||||
public VagConversion()
|
||||
{
|
||||
}
|
||||
|
||||
public VagConversion(int cnvId, double factor, double offset, String units)
|
||||
{
|
||||
this.cnvId = cnvId;
|
||||
this.factor = factor;
|
||||
this.offset = offset;
|
||||
this.units = units;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param metaNw the metaNw to set
|
||||
*/
|
||||
public void setMetaNw(char metaNw)
|
||||
{
|
||||
this.metaNw = metaNw;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param metaTblValues the metaTblValues to set
|
||||
*/
|
||||
public void setMetaTblValues(char[] metaTblValues)
|
||||
{
|
||||
this.metaTblValues = metaTblValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of interpolated table value
|
||||
* table values are transferred with the meta package
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double tableValue(int mw, int nw)
|
||||
{
|
||||
// mask value to 1 byte
|
||||
int internalVal = mw & 0xFF;
|
||||
// get position into table
|
||||
double stepwidth = (double) 0xFF / (metaTblValues.length - 1);
|
||||
int pos = (int) (internalVal / stepwidth);
|
||||
int ofs = (int) (internalVal % stepwidth);
|
||||
// get both table values
|
||||
int valBefore = metaTblValues[pos];
|
||||
int valAfter = pos < metaTblValues.length - 1 ? metaTblValues[pos + 1] : valBefore;
|
||||
// interpolate value between table entries
|
||||
return ((valBefore + (valAfter - valBefore) * ofs / stepwidth) + offset - nw) * factor;
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of formula ID 10
|
||||
* <pre>(MW+Offset)*NW*Faktor</pre>
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double formula10Value(int mw, int nw)
|
||||
{
|
||||
return ((mw + offset) * nw * factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of formula ID 11
|
||||
* <pre>(MW.NW+Offset)*Faktor</pre>
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double formula11Value(int mw, int nw)
|
||||
{
|
||||
return ((Double.parseDouble(String.format("%d.%d", mw, nw)) + offset) * factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of formula ID 12
|
||||
* <pre>(NW.MW+Offset)*Faktor</pre>
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double formula12Value(int mw, int nw)
|
||||
{
|
||||
return ((Double.parseDouble(String.format("%d.%d", nw, mw)) + offset) * factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of formula ID 13
|
||||
* <pre>(NW*255+MW+Offset)*Faktor</pre>
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double formula13Value(int mw, int nw)
|
||||
{
|
||||
return ((nw * 255 + mw + offset) * factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of formula ID 14
|
||||
* <pre>(MW+Offset)/NW*Faktor</pre>
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double formula14Value(int mw, int nw)
|
||||
{
|
||||
return ((mw + offset) / nw * factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of formula ID 15
|
||||
* <pre>MW*Faktor+NW*Offset</pre>
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double formula15Value(int mw, int nw)
|
||||
{
|
||||
return (mw * factor + nw * offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of formula ID 16
|
||||
* <pre>(MW+Offset)*Faktor</pre>
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double formula16Value(int mw, int nw)
|
||||
{
|
||||
return ((mw + offset) * factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of formula ID 17
|
||||
* <pre>1+(MW+Offset)*NW*Faktor</pre>
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double formula17Value(int mw, int nw)
|
||||
{
|
||||
return (1 + (mw + offset) * nw * factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* calculation of formula ID 18
|
||||
* <pre>(MW*NW*Faktor)+Offset</pre>
|
||||
*
|
||||
* @param mw value 1 for calculation
|
||||
* @param nw value 2 for calcualtion
|
||||
* @return result of calculation
|
||||
*/
|
||||
double formula18Value(int mw, int nw)
|
||||
{
|
||||
return (mw * nw * factor + offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert memory value to physical value
|
||||
*
|
||||
* @param value memory value
|
||||
* @return physical value
|
||||
*/
|
||||
public Number memToPhys(long value)
|
||||
{
|
||||
double result = 0;
|
||||
int mw = (int) (value % 0x100);
|
||||
// if meta value is set, then it will be used
|
||||
int nw = metaNw != 0 ? metaNw : (int) (value / 0x100);
|
||||
switch (cnvId)
|
||||
{
|
||||
case 0:
|
||||
result = tableValue(mw, nw);
|
||||
break;
|
||||
case 10:
|
||||
result = formula10Value(mw, nw);
|
||||
break;
|
||||
case 11:
|
||||
result = formula11Value(mw, nw);
|
||||
break;
|
||||
case 12:
|
||||
result = formula12Value(mw, nw);
|
||||
break;
|
||||
case 13:
|
||||
result = formula13Value(mw, nw);
|
||||
break;
|
||||
case 14:
|
||||
result = formula14Value(mw, nw);
|
||||
break;
|
||||
case 15:
|
||||
result = formula15Value(mw, nw);
|
||||
break;
|
||||
case 16:
|
||||
result = formula16Value(mw, nw);
|
||||
break;
|
||||
case 17:
|
||||
result = formula17Value(mw, nw);
|
||||
break;
|
||||
case 18:
|
||||
result = formula18Value(mw, nw);
|
||||
break;
|
||||
case 20:
|
||||
result = mw & nw;
|
||||
break;
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
result = nw << 8 | mw;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new UnsupportedOperationException(String.format("Unsupported Formula: ID=%d", cnvId));
|
||||
}
|
||||
return (float) result;
|
||||
}
|
||||
|
||||
public Number physToMem(Number value)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Format physical value to physical value string
|
||||
*
|
||||
* @param physValue physical value
|
||||
* @param decimals number of decimals for formatting
|
||||
* @return physical value as formatted string
|
||||
*/
|
||||
@Override
|
||||
public String physToPhysFmtString(Number physValue, int decimals)
|
||||
{
|
||||
String result = null;
|
||||
switch (cnvId)
|
||||
{
|
||||
case 20: // * 20 : Bitdarstellung
|
||||
result = Integer.toBinaryString(physValue.intValue());
|
||||
break;
|
||||
|
||||
case 21: // * 21 : 2 Ascii-Zeichen
|
||||
case 22: // * 22 : Ascii-Text
|
||||
result = String.format("%c%c",
|
||||
physValue.intValue() / 0x100,
|
||||
physValue.intValue() % 0x100);
|
||||
break;
|
||||
|
||||
case 23: // * 23 : Uhrzeit
|
||||
result = String.format("%02d:%02d",
|
||||
physValue.intValue() / 0x100,
|
||||
physValue.intValue() % 0x100);
|
||||
break;
|
||||
|
||||
case 24: // * 24 : Hexdarstellung
|
||||
result = String.format("%04X", physValue.intValue());
|
||||
break;
|
||||
|
||||
default:
|
||||
result = super.physToPhysFmtString(physValue, decimals);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
276
src/com/fr3ts0n/ecu/gui/androbd/ChartActivity.java
Normal file
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu.gui.androbd;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.fr3ts0n.ecu.EcuDataPv;
|
||||
import com.fr3ts0n.ecu.prot.ObdProt;
|
||||
|
||||
import org.achartengine.ChartFactory;
|
||||
import org.achartengine.GraphicalView;
|
||||
import org.achartengine.model.XYMultipleSeriesDataset;
|
||||
import org.achartengine.model.XYSeries;
|
||||
import org.achartengine.renderer.BasicStroke;
|
||||
import org.achartengine.renderer.XYMultipleSeriesRenderer;
|
||||
import org.achartengine.renderer.XYSeriesRenderer;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* <code>Activity</code> that displays the readout of one <code>Sensor</code>.
|
||||
* This <code>Activity</code> must be started with an <code>Intent</code> that
|
||||
* passes in the number of the <code>Sensor</code>(s) to display. If none is
|
||||
* passed, the first available <code>Sensor</code> is used.
|
||||
*/
|
||||
public class ChartActivity extends Activity
|
||||
{
|
||||
|
||||
/**
|
||||
* minimum time between screen updates
|
||||
*/
|
||||
public static final long MIN_UPDATE_TIME = 1000;
|
||||
|
||||
/**
|
||||
* For passing the index number of the <code>Sensor</code> in its
|
||||
* <code>SensorManager</code>
|
||||
*/
|
||||
public static final String PID = "PID";
|
||||
|
||||
/**
|
||||
* List of colors to be used for series
|
||||
*/
|
||||
public static final int[] colors =
|
||||
{
|
||||
Color.RED,
|
||||
Color.YELLOW,
|
||||
Color.BLUE,
|
||||
Color.GREEN,
|
||||
Color.MAGENTA,
|
||||
Color.CYAN,
|
||||
Color.WHITE,
|
||||
Color.LTGRAY,
|
||||
};
|
||||
|
||||
/**
|
||||
* list of colors to be used for series
|
||||
*/
|
||||
public static final BasicStroke stroke[] =
|
||||
{
|
||||
BasicStroke.SOLID,
|
||||
BasicStroke.DASHED,
|
||||
BasicStroke.DOTTED,
|
||||
};
|
||||
|
||||
/**
|
||||
* The displaying component
|
||||
*/
|
||||
private GraphicalView chartView;
|
||||
|
||||
/**
|
||||
* Dataset of the graphing component
|
||||
*/
|
||||
private XYMultipleSeriesDataset sensorData;
|
||||
|
||||
/**
|
||||
* Renderer for actually drawing the graph
|
||||
*/
|
||||
private XYMultipleSeriesRenderer renderer;
|
||||
|
||||
/**
|
||||
* the wake lock to keep app communication alive
|
||||
*/
|
||||
private static WakeLock wakeLock;
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.chart, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
// prevent activity from falling asleep
|
||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||
getString(R.string.app_name));
|
||||
wakeLock.acquire();
|
||||
|
||||
setTitle("OBD data graph");
|
||||
|
||||
/* get PIDs to be shown */
|
||||
int pids[] = getIntent().getIntArrayExtra(PID);
|
||||
|
||||
// set up overall chart properties
|
||||
sensorData = new XYMultipleSeriesDataset();
|
||||
renderer = new XYMultipleSeriesRenderer(pids.length);
|
||||
chartView = ChartFactory.getTimeChartView(this, sensorData, renderer, "H:mm:ss");
|
||||
// set up global renderer
|
||||
renderer.setXTitle(getString(R.string.time));
|
||||
renderer.setXLabels(5);
|
||||
renderer.setYLabels(5);
|
||||
renderer.setGridColor(Color.DKGRAY);
|
||||
renderer.setShowGrid(true);
|
||||
renderer.setFitLegend(true);
|
||||
renderer.setClickEnabled(false);
|
||||
// set up chart data
|
||||
setUpChartData(pids);
|
||||
// make chart visible
|
||||
setContentView(chartView);
|
||||
// limit selected PIDs to selection
|
||||
ObdProt.setFixedPid(pids);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle menu selections
|
||||
*
|
||||
* @param item selected menu item
|
||||
* @return result of super call
|
||||
*/
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.share:
|
||||
new ExportTask(this).execute(sensorData);
|
||||
break;
|
||||
|
||||
case R.id.snapshot:
|
||||
Screenshot.takeScreenShot(this, getWindow().peekDecorView());
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle destroy of the Activity
|
||||
*/
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
ObdProt.resetFixedPid();
|
||||
// allow sleeping again
|
||||
wakeLock.release();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
Timer refreshTimer = new Timer();
|
||||
|
||||
/**
|
||||
* Timer Task to cyclically update data screen
|
||||
*/
|
||||
private TimerTask updateTask = new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
/* update chart */
|
||||
chartView.repaint();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Activity#onStart()
|
||||
*/
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
// start display update task
|
||||
try
|
||||
{
|
||||
refreshTimer.schedule(updateTask, 0, 1000);
|
||||
} catch (Exception e)
|
||||
{
|
||||
// exception ignored here ...
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Activity#onStop()
|
||||
*/
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
refreshTimer.purge();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up all the charting data series
|
||||
*
|
||||
* @param pids PIDs to be used for chart data
|
||||
*/
|
||||
private void setUpChartData(int[] pids)
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
int i = 0;
|
||||
EcuDataPv currPv;
|
||||
XYSeries currSeries;
|
||||
// loop through all PIDs
|
||||
for (int pid : pids)
|
||||
{
|
||||
// get corresponding Process variable
|
||||
currPv = (EcuDataPv) ObdProt.PidPvs.get(pid);
|
||||
if (currPv == null) continue;
|
||||
// get contained data series
|
||||
currSeries = (XYSeries) currPv.get(ObdItemAdapter.FID_DATA_SERIES);
|
||||
if (currSeries == null) continue;
|
||||
// add initial measurement to series data to ensure
|
||||
// at least one measurement is available
|
||||
if (currSeries.getItemCount() < 1)
|
||||
currSeries.add(startTime, (Float) currPv.get(EcuDataPv.FID_VALUE));
|
||||
|
||||
// set scale to display series
|
||||
currSeries.setScaleNumber(i);
|
||||
// register series to graph
|
||||
sensorData.addSeries(i, currSeries);
|
||||
/* set up series visual parameters */
|
||||
renderer.setYTitle(String.valueOf(currPv.get(EcuDataPv.FID_UNITS)), i);
|
||||
renderer.setYAxisAlign(((i % 2) == 0) ? Align.LEFT : Align.RIGHT, i);
|
||||
renderer.setYLabelsAlign(((i % 2) == 0) ? Align.LEFT : Align.RIGHT, i);
|
||||
renderer.setYLabelsColor(i, colors[i % colors.length]);
|
||||
/* set up new line renderer */
|
||||
XYSeriesRenderer r = new XYSeriesRenderer();
|
||||
r.setColor(colors[i % colors.length]);
|
||||
r.setStroke(stroke[(i / colors.length) % stroke.length]);
|
||||
// register line renderer
|
||||
renderer.addSeriesRenderer(i, r);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
136
src/com/fr3ts0n/ecu/gui/androbd/CheckableRelativeLayout.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu.gui.androbd;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Checkable;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Extension of a relative layout to provide a checkable behaviour
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class CheckableRelativeLayout extends RelativeLayout implements
|
||||
Checkable
|
||||
{
|
||||
|
||||
private boolean isChecked;
|
||||
private List<Checkable> checkableViews;
|
||||
|
||||
public CheckableRelativeLayout(Context context, AttributeSet attrs,
|
||||
int defStyle)
|
||||
{
|
||||
super(context, attrs, defStyle);
|
||||
initialise(attrs);
|
||||
}
|
||||
|
||||
public CheckableRelativeLayout(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
initialise(attrs);
|
||||
}
|
||||
|
||||
public CheckableRelativeLayout(Context context, int checkableId)
|
||||
{
|
||||
super(context);
|
||||
initialise(null);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see android.widget.Checkable#isChecked()
|
||||
*/
|
||||
public boolean isChecked()
|
||||
{
|
||||
return isChecked;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see android.widget.Checkable#setChecked(boolean)
|
||||
*/
|
||||
public void setChecked(boolean isChecked)
|
||||
{
|
||||
this.isChecked = isChecked;
|
||||
for (Checkable c : checkableViews)
|
||||
{
|
||||
c.setChecked(isChecked);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see android.widget.Checkable#toggle()
|
||||
*/
|
||||
public void toggle()
|
||||
{
|
||||
this.isChecked = !this.isChecked;
|
||||
for (Checkable c : checkableViews)
|
||||
{
|
||||
c.toggle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate()
|
||||
{
|
||||
super.onFinishInflate();
|
||||
|
||||
final int childCount = this.getChildCount();
|
||||
for (int i = 0; i < childCount; ++i)
|
||||
{
|
||||
findCheckableChildren(this.getChildAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the custom XML attributes
|
||||
*/
|
||||
private void initialise(AttributeSet attrs)
|
||||
{
|
||||
this.isChecked = false;
|
||||
this.checkableViews = new ArrayList<Checkable>(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to our checkable list all the children of the view that implement the
|
||||
* interface Checkable
|
||||
*/
|
||||
private void findCheckableChildren(View v)
|
||||
{
|
||||
if (v instanceof Checkable)
|
||||
{
|
||||
this.checkableViews.add((Checkable) v);
|
||||
}
|
||||
|
||||
if (v instanceof ViewGroup)
|
||||
{
|
||||
final ViewGroup vg = (ViewGroup) v;
|
||||
final int childCount = vg.getChildCount();
|
||||
for (int i = 0; i < childCount; ++i)
|
||||
{
|
||||
findCheckableChildren(vg.getChildAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
198
src/com/fr3ts0n/ecu/gui/androbd/DashBoardActivity.java
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu.gui.androbd;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.PowerManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.GridView;
|
||||
|
||||
import com.fr3ts0n.ecu.EcuDataPv;
|
||||
import com.fr3ts0n.ecu.prot.ObdProt;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
||||
/**
|
||||
* Created by erwin on 06.12.14.
|
||||
*/
|
||||
public class DashBoardActivity extends Activity
|
||||
{
|
||||
/**
|
||||
* For passing the index number of the <code>Sensor</code> in its
|
||||
* <code>SensorManager</code>
|
||||
*/
|
||||
public static final String PID = "PID";
|
||||
/**
|
||||
* For passing the resource id of the <code>dashboard display</code>
|
||||
*/
|
||||
public static final String RES_ID = "RES_ID";
|
||||
|
||||
/**
|
||||
* Minimum size for gauges to be displayed
|
||||
*/
|
||||
public static final int MIN_GAUGE_SIZE = 300; /* dp */
|
||||
|
||||
/**
|
||||
* the wake lock to keep app communication alive
|
||||
*/
|
||||
private static PowerManager.WakeLock wakeLock;
|
||||
ObdGaugeAdapter adapter;
|
||||
|
||||
public static final int MESSAGE_UPDATE_VIEW = 7;
|
||||
|
||||
/**
|
||||
* Handle message requests
|
||||
*/
|
||||
private transient final Handler mHandler = new Handler()
|
||||
{
|
||||
@Override
|
||||
public void handleMessage(Message msg)
|
||||
{
|
||||
|
||||
switch (msg.what)
|
||||
{
|
||||
case MESSAGE_UPDATE_VIEW:
|
||||
adapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Timer refreshTimer = new Timer();
|
||||
|
||||
/**
|
||||
* Timer Task to cyclically update data screen
|
||||
*/
|
||||
private TimerTask updateTask = new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
/* forward message to update the view */
|
||||
Message msg = mHandler.obtainMessage(MainActivity.MESSAGE_UPDATE_VIEW);
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
EcuDataPv currPv;
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
// set to full screen
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
// keep display on
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
// hide the action bar
|
||||
getActionBar().hide();
|
||||
|
||||
// prevent activity from falling asleep
|
||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||
getString(R.string.app_name));
|
||||
wakeLock.acquire();
|
||||
|
||||
/* get PIDs to be shown */
|
||||
int pids[] = getIntent().getIntArrayExtra(PID);
|
||||
|
||||
// set the desired content screen
|
||||
int resId = getIntent().getIntExtra(RES_ID, R.layout.dashboard);
|
||||
setContentView(resId);
|
||||
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
int height = metrics.heightPixels;
|
||||
int width = metrics.widthPixels;
|
||||
int numColumns = Math.min(pids.length, Math.max(1, width / MIN_GAUGE_SIZE));
|
||||
int numRows = Math.min(pids.length, Math.max(1, height / MIN_GAUGE_SIZE));
|
||||
|
||||
int minWidth = width / numColumns;
|
||||
int minHeight = height / numRows;
|
||||
|
||||
GridView grid = (GridView) findViewById(android.R.id.list);
|
||||
grid.setColumnWidth(minWidth);
|
||||
|
||||
|
||||
// set data adapter
|
||||
adapter = new ObdGaugeAdapter(this, R.layout.obd_gauge, minWidth, minHeight);
|
||||
grid.setAdapter(adapter);
|
||||
|
||||
for (int pid : pids)
|
||||
{
|
||||
// get corresponding Process variable
|
||||
currPv = (EcuDataPv) ObdProt.PidPvs.get(pid);
|
||||
if (currPv != null)
|
||||
{
|
||||
adapter.add(currPv);
|
||||
}
|
||||
}
|
||||
|
||||
// limit selected PIDs to selection
|
||||
ObdProt.setFixedPid(pids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle destroy of the Activity
|
||||
*/
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
// reset PID limiting
|
||||
ObdProt.resetFixedPid();
|
||||
adapter.clear();
|
||||
// allow sleeping again
|
||||
wakeLock.release();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Activity#onStart()
|
||||
*/
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
// start display update task
|
||||
try
|
||||
{
|
||||
refreshTimer.schedule(updateTask, 0, 100);
|
||||
} catch (Exception e)
|
||||
{
|
||||
// exception ignored here ...
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Activity#onStop()
|
||||
*/
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
refreshTimer.purge();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
}
|
||||
223
src/com/fr3ts0n/ecu/gui/androbd/DeviceListActivity.java
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu.gui.androbd;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This Activity appears as a dialog. It lists any paired devices and
|
||||
* devices detected in the area after discovery. When a device is chosen
|
||||
* by the user, the MAC address of the device is sent back to the parent
|
||||
* Activity in the result Intent.
|
||||
*/
|
||||
public class DeviceListActivity extends Activity
|
||||
{
|
||||
// Debugging
|
||||
private static final String TAG = "DeviceListActivity";
|
||||
private static final boolean D = true;
|
||||
|
||||
// Return Intent extra
|
||||
public static String EXTRA_DEVICE_ADDRESS = "device_address";
|
||||
|
||||
// Member fields
|
||||
private BluetoothAdapter mBtAdapter;
|
||||
private ArrayAdapter<String> mNewDevicesArrayAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Setup the window
|
||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||
setContentView(R.layout.device_list);
|
||||
|
||||
// Set result CANCELED in case the user backs out
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
|
||||
// Initialize the button to perform device discovery
|
||||
Button scanButton = (Button) findViewById(R.id.button_scan);
|
||||
scanButton.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
doDiscovery();
|
||||
v.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize array adapters. One for already paired devices and
|
||||
// one for newly discovered devices
|
||||
ArrayAdapter<String> mPairedDevicesArrayAdapter =
|
||||
new ArrayAdapter<String>(this, R.layout.device_name);
|
||||
mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);
|
||||
|
||||
// Find and set up the ListView for paired devices
|
||||
ListView pairedListView = (ListView) findViewById(R.id.paired_devices);
|
||||
pairedListView.setAdapter(mPairedDevicesArrayAdapter);
|
||||
pairedListView.setOnItemClickListener(mDeviceClickListener);
|
||||
|
||||
// Find and set up the ListView for newly discovered devices
|
||||
ListView newDevicesListView = (ListView) findViewById(R.id.new_devices);
|
||||
newDevicesListView.setAdapter(mNewDevicesArrayAdapter);
|
||||
newDevicesListView.setOnItemClickListener(mDeviceClickListener);
|
||||
|
||||
// Register for broadcasts when a device is discovered
|
||||
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
|
||||
this.registerReceiver(mReceiver, filter);
|
||||
|
||||
// Register for broadcasts when discovery has finished
|
||||
filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
|
||||
this.registerReceiver(mReceiver, filter);
|
||||
|
||||
// Get the local Bluetooth adapter
|
||||
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
// Get a set of currently paired devices
|
||||
Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();
|
||||
|
||||
// If there are paired devices, add each one to the ArrayAdapter
|
||||
if (pairedDevices.size() > 0)
|
||||
{
|
||||
findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
|
||||
for (BluetoothDevice device : pairedDevices)
|
||||
{
|
||||
mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
|
||||
}
|
||||
} else
|
||||
{
|
||||
String noDevices = getResources().getText(R.string.none_paired).toString();
|
||||
mPairedDevicesArrayAdapter.add(noDevices);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
super.onDestroy();
|
||||
|
||||
// Make sure we're not doing discovery anymore
|
||||
if (mBtAdapter != null)
|
||||
{
|
||||
mBtAdapter.cancelDiscovery();
|
||||
}
|
||||
|
||||
// Unregister broadcast listeners
|
||||
this.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start device discover with the BluetoothAdapter
|
||||
*/
|
||||
private void doDiscovery()
|
||||
{
|
||||
if (D) Log.d(TAG, "doDiscovery()");
|
||||
|
||||
// Indicate scanning in the title
|
||||
setProgressBarIndeterminateVisibility(true);
|
||||
setTitle(R.string.scanning);
|
||||
|
||||
// Turn on sub-title for new devices
|
||||
findViewById(R.id.title_new_devices).setVisibility(View.VISIBLE);
|
||||
|
||||
// If we're already discovering, stop it
|
||||
if (mBtAdapter.isDiscovering())
|
||||
{
|
||||
mBtAdapter.cancelDiscovery();
|
||||
}
|
||||
|
||||
// Request discover from BluetoothAdapter
|
||||
mBtAdapter.startDiscovery();
|
||||
}
|
||||
|
||||
// The on-click listener for all devices in the ListViews
|
||||
private OnItemClickListener mDeviceClickListener = new OnItemClickListener()
|
||||
{
|
||||
public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3)
|
||||
{
|
||||
// Cancel discovery because it's costly and we're about to connect
|
||||
mBtAdapter.cancelDiscovery();
|
||||
|
||||
// Get the device MAC address, which is the last 17 chars in the View
|
||||
String info = ((TextView) v).getText().toString();
|
||||
String address = info.substring(info.length() - 17);
|
||||
//String address = "00:0D:18:A0:4E:35"; //FORCE OBD MAC Address
|
||||
// Create the result Intent and include the MAC address
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_DEVICE_ADDRESS, address);
|
||||
|
||||
// Set result and finish this Activity
|
||||
setResult(Activity.RESULT_OK, intent);
|
||||
Log.d("Terminal", "Sending Result...");
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
// The BroadcastReceiver that listens for discovered devices and
|
||||
// changes the title when discovery is finished
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver()
|
||||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
String action = intent.getAction();
|
||||
|
||||
// When discovery finds a device
|
||||
if (BluetoothDevice.ACTION_FOUND.equals(action))
|
||||
{
|
||||
// Get the BluetoothDevice object from the Intent
|
||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
// If it's already paired, skip it, because it's been listed already
|
||||
if (device.getBondState() != BluetoothDevice.BOND_BONDED)
|
||||
{
|
||||
mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
|
||||
}
|
||||
// When discovery is finished, change the Activity title
|
||||
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
|
||||
{
|
||||
setProgressBarIndeterminateVisibility(false);
|
||||
setTitle(R.string.select_BTdevice);
|
||||
if (mNewDevicesArrayAdapter.getCount() == 0)
|
||||
{
|
||||
String noDevices = getResources().getText(R.string.none_found).toString();
|
||||
mNewDevicesArrayAdapter.add(noDevices);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
63
src/com/fr3ts0n/ecu/gui/androbd/DfcItemAdapter.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu.gui.androbd;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.fr3ts0n.ecu.EcuCodeItem;
|
||||
import com.fr3ts0n.pvs.IndexedProcessVar;
|
||||
import com.fr3ts0n.pvs.PvList;
|
||||
|
||||
/**
|
||||
* Adapter to display OBD DFCs
|
||||
*
|
||||
* @author erwin
|
||||
*/
|
||||
public class DfcItemAdapter extends ObdItemAdapter
|
||||
{
|
||||
public DfcItemAdapter(Context context, int resource, PvList pvs)
|
||||
{
|
||||
super(context, resource, pvs);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.fr3ts0n.ecu.gui.androbd.ObdItemAdapter#getView(int, android.view.View, android.view.ViewGroup)
|
||||
*/
|
||||
@Override
|
||||
public View getView(int position, View v, ViewGroup parent)
|
||||
{
|
||||
// get data PV
|
||||
IndexedProcessVar currPv = (IndexedProcessVar) getItem(position);
|
||||
|
||||
if (v == null)
|
||||
{
|
||||
v = mInflater.inflate(R.layout.obd_item, parent, false);
|
||||
}
|
||||
TextView tvDescr = (TextView) v.findViewById(R.id.obd_label);
|
||||
TextView tvValue = (TextView) v.findViewById(R.id.obd_units);
|
||||
|
||||
tvValue.setText(String.valueOf(currPv.get(EcuCodeItem.FID_CODE)));
|
||||
tvDescr.setText(String.valueOf(currPv.get(EcuCodeItem.FID_DESCRIPT)));
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
136
src/com/fr3ts0n/ecu/gui/androbd/ExportTask.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu.gui.androbd;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import org.achartengine.model.XYMultipleSeriesDataset;
|
||||
import org.achartengine.model.XYSeries;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.SortedMap;
|
||||
|
||||
/**
|
||||
* Builds the CSV dump for sharing.
|
||||
*
|
||||
* @author Erwin Scheuch-Heilig
|
||||
*/
|
||||
class ExportTask extends AsyncTask<XYMultipleSeriesDataset, Integer, String>
|
||||
{
|
||||
|
||||
private Activity activity;
|
||||
private static DateFormat tagFormat = new SimpleDateFormat("yyyyMMddkkmmss");
|
||||
|
||||
public static final String CSV_FIELD_DELIMITER = ",";
|
||||
public static final String CSV_LINE_DELIMITER = "\n";
|
||||
|
||||
public ExportTask(Activity activity)
|
||||
{
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(XYMultipleSeriesDataset... params)
|
||||
{
|
||||
double currX;
|
||||
double currY;
|
||||
int maxCounts = 0;
|
||||
int highestResChannel = 0; /* channel id with highest x-resolution */
|
||||
|
||||
XYSeries series[] = params[0].getSeries();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// find channel with highest x-resolution
|
||||
for (int i = 0; i < series.length; i++)
|
||||
{
|
||||
if (maxCounts < series[i].getItemCount())
|
||||
{
|
||||
maxCounts = series[i].getItemCount();
|
||||
highestResChannel = i;
|
||||
}
|
||||
}
|
||||
// create measurement header (may be used as filename)
|
||||
long startTime = (long) series[highestResChannel].getX(0);
|
||||
sb.append(activity.getString(R.string.app_name)).append(".");
|
||||
sb.append(tagFormat.format(startTime)).append(".csv");
|
||||
sb.append(CSV_LINE_DELIMITER);
|
||||
|
||||
// create header line
|
||||
sb.append(activity.getString(R.string.time));
|
||||
sb.append(CSV_FIELD_DELIMITER);
|
||||
for (XYSeries sery : series)
|
||||
{
|
||||
sb.append("\"").append(sery.getTitle()).append("\"");
|
||||
sb.append(CSV_FIELD_DELIMITER);
|
||||
}
|
||||
sb.append(CSV_LINE_DELIMITER);
|
||||
|
||||
// generate data
|
||||
int samples = maxCounts;
|
||||
for (int i = 0; i < samples; i++)
|
||||
{
|
||||
currX = series[highestResChannel].getX(i);
|
||||
sb.append((currX - startTime) / 1000);
|
||||
sb.append(CSV_FIELD_DELIMITER);
|
||||
for (XYSeries sery : series)
|
||||
{
|
||||
try
|
||||
{
|
||||
SortedMap<Double, Double> map = sery.getRange(currX, currX, true);
|
||||
currY = map.get(map.firstKey());
|
||||
sb.append(currY);
|
||||
sb.append(CSV_FIELD_DELIMITER);
|
||||
} catch (Exception ex)
|
||||
{
|
||||
// do nothing, just catch the error
|
||||
}
|
||||
}
|
||||
sb.append(CSV_LINE_DELIMITER);
|
||||
publishProgress(10000 * i / samples);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreExecute()
|
||||
{
|
||||
activity.setProgressBarVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressUpdate(Integer... values)
|
||||
{
|
||||
activity.setProgress(values[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute(String result)
|
||||
{
|
||||
activity.setProgressBarVisibility(false);
|
||||
Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, result);
|
||||
sendIntent.setType("text/plain");
|
||||
activity.startActivity(Intent.createChooser(sendIntent, activity
|
||||
.getResources().getText(R.string.send_to)));
|
||||
}
|
||||
}
|
||||
205
src/com/fr3ts0n/ecu/gui/androbd/FileHelper.java
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu.gui.androbd;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fr3ts0n.ecu.prot.ElmProt;
|
||||
import com.fr3ts0n.ecu.prot.ObdProt;
|
||||
import com.fr3ts0n.pvs.PvList;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* Task to save measurements
|
||||
*
|
||||
* @author Erwin Scheuch-Heilig
|
||||
*/
|
||||
class FileHelper
|
||||
{
|
||||
/** Date Formatter used to generate file name */
|
||||
private static final SimpleDateFormat dateFmt = new SimpleDateFormat("yyyy.MM.dd-HH.mm.ss");
|
||||
private static ProgressDialog progress;
|
||||
|
||||
private Context context;
|
||||
private ElmProt elm;
|
||||
|
||||
/**
|
||||
* Initialize static data for static calls
|
||||
*
|
||||
* @param context APP context
|
||||
* @param elm Elm protocol data to be stored
|
||||
*/
|
||||
public FileHelper(Context context, ElmProt elm)
|
||||
{
|
||||
this.context = context;
|
||||
this.elm = elm;
|
||||
}
|
||||
|
||||
/**
|
||||
* get default path for load/store operation
|
||||
* * path is based on configured <user data location>/<package name>
|
||||
*
|
||||
* @return default path for current app context
|
||||
*/
|
||||
public static String getPath(Context context)
|
||||
{
|
||||
// generate file name
|
||||
return Environment.getExternalStorageDirectory()
|
||||
+ File.separator
|
||||
+ context.getPackageName();
|
||||
}
|
||||
|
||||
/**
|
||||
* get filename (w/o extension) based on current date & time
|
||||
*
|
||||
* @return file name
|
||||
*/
|
||||
public static String getFileName()
|
||||
{
|
||||
return dateFmt.format(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save all data in a independent thread
|
||||
*/
|
||||
public void saveDataThreaded()
|
||||
{
|
||||
// generate file name
|
||||
final String mPath = getPath(context);
|
||||
final String mFileName = mPath
|
||||
+ File.separator
|
||||
+ getFileName()
|
||||
+ ".obd";
|
||||
|
||||
// create progress dialog
|
||||
progress = ProgressDialog.show(context,
|
||||
context.getString(R.string.saving_data),
|
||||
mFileName,
|
||||
true);
|
||||
|
||||
Thread saveTask = new Thread()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Looper.prepare();
|
||||
saveData(mPath, mFileName);
|
||||
progress.dismiss();
|
||||
Looper.loop();
|
||||
}
|
||||
};
|
||||
saveTask.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all data
|
||||
*/
|
||||
public synchronized void saveData(String mPath, String mFileName)
|
||||
{
|
||||
File outFile;
|
||||
|
||||
// ensure the path is created
|
||||
new File(mPath).mkdirs();
|
||||
outFile = new File(mFileName);
|
||||
|
||||
// prevent data updates for saving period
|
||||
ObdItemAdapter.allowDataUpdates = false;
|
||||
|
||||
try
|
||||
{
|
||||
outFile.createNewFile();
|
||||
FileOutputStream fStr = new FileOutputStream(outFile);
|
||||
ObjectOutputStream oStr = new ObjectOutputStream(fStr);
|
||||
oStr.writeInt(elm.getService());
|
||||
oStr.writeObject(ObdProt.PidPvs);
|
||||
oStr.writeObject(ObdProt.VidPvs);
|
||||
oStr.writeObject(ObdProt.tCodes);
|
||||
|
||||
oStr.close();
|
||||
fStr.close();
|
||||
|
||||
String msg = String.format("%s %d Bytes to %s",
|
||||
context.getString(R.string.saved),
|
||||
outFile.length(),
|
||||
mPath);
|
||||
Log.i(context.getString(R.string.saved), msg);
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
} catch (Exception e)
|
||||
{
|
||||
Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// we are done saving, allow data updates again
|
||||
ObdItemAdapter.allowDataUpdates = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data from file into data sructures
|
||||
*
|
||||
* @param inStr Input stream
|
||||
*/
|
||||
public synchronized int loadData(InputStream inStr)
|
||||
{
|
||||
int numBytesLoaded = 0;
|
||||
String msg;
|
||||
try
|
||||
{
|
||||
numBytesLoaded = inStr.available();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
msg = String.format("%d Bytes", numBytesLoaded);
|
||||
|
||||
try
|
||||
{
|
||||
ObjectInputStream oIn = new ObjectInputStream(inStr);
|
||||
/* ensure that measurement page is activated
|
||||
to avoid deletion of loaded data afterwards */
|
||||
int currService = oIn.readInt();
|
||||
elm.setService(currService);
|
||||
/* read in the data */
|
||||
ObdProt.PidPvs = (PvList) oIn.readObject();
|
||||
ObdProt.VidPvs = (PvList) oIn.readObject();
|
||||
ObdProt.tCodes = (PvList) oIn.readObject();
|
||||
oIn.close();
|
||||
|
||||
Log.i(context.getString(R.string.load), context.getString(R.string.loaded).concat(" ").concat(msg));
|
||||
Toast.makeText(context, context.getString(R.string.loaded).concat(" ").concat(msg), Toast.LENGTH_SHORT).show();
|
||||
} catch (Exception ex)
|
||||
{
|
||||
Toast.makeText(context, ex.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
|
||||
Log.e(context.getString(R.string.load), ex.getMessage());
|
||||
}
|
||||
return numBytesLoaded;
|
||||
}
|
||||
}
|
||||
838
src/com/fr3ts0n/ecu/gui/androbd/MainActivity.java
Normal file
@@ -0,0 +1,838 @@
|
||||
/*
|
||||
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.fr3ts0n.ecu.gui.androbd;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.app.SearchManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fr3ts0n.ecu.EcuCodeItem;
|
||||
import com.fr3ts0n.ecu.EcuDataPv;
|
||||
import com.fr3ts0n.ecu.prot.ElmProt;
|
||||
import com.fr3ts0n.ecu.prot.ObdProt;
|
||||
import com.fr3ts0n.pvs.PvChangeEvent;
|
||||
import com.fr3ts0n.pvs.PvChangeListener;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import de.mindpipe.android.logging.log4j.LogConfigurator;
|
||||
|
||||
/**
|
||||
* Main Activity for AndrOBD app
|
||||
*/
|
||||
public class MainActivity extends ListActivity
|
||||
implements PvChangeListener, AdapterView.OnItemLongClickListener
|
||||
{
|
||||
/** Key names received from the BluetoothChatService Handler */
|
||||
public static final String DEVICE_NAME = "device_name";
|
||||
public static final String TOAST = "toast";
|
||||
/** Message types sent from the BluetoothChatService Handler */
|
||||
public static final int MESSAGE_STATE_CHANGE = 1;
|
||||
public static final int MESSAGE_READ = 2;
|
||||
public static final int MESSAGE_WRITE = 3;
|
||||
public static final int MESSAGE_DEVICE_NAME = 4;
|
||||
public static final int MESSAGE_TOAST = 5;
|
||||
public static final int MESSAGE_DATA_ITEMS_CHANGED = 6;
|
||||
public static final int MESSAGE_UPDATE_VIEW = 7;
|
||||
private static final String TAG = "AndrOBD";
|
||||
/** internal Intent request codes */
|
||||
private static final int REQUEST_CONNECT_DEVICE_SECURE = 1;
|
||||
private static final int REQUEST_CONNECT_DEVICE_INSECURE = 2;
|
||||
private static final int REQUEST_ENABLE_BT = 3;
|
||||
private static final int REQUEST_SELECT_FILE = 4;
|
||||
/**
|
||||
* app exit parameters
|
||||
*/
|
||||
private static final int EXIT_TIMEOUT = 2500;
|
||||
/** time between display updates to represent data changes */
|
||||
private static final int DISPLAY_UPDATE_TIME = 1000;
|
||||
/** Member object for the BT comm services */
|
||||
private static ObdCommService mCommService = null;
|
||||
/** Local Bluetooth adapter */
|
||||
private static BluetoothAdapter mBluetoothAdapter = null;
|
||||
|
||||
/** Name of the connected BT device */
|
||||
private static String mConnectedDeviceName = null;
|
||||
/** log4j configurator */
|
||||
private static LogConfigurator logCfg;
|
||||
private static Menu menu;
|
||||
|
||||
/** Data list adapters */
|
||||
private static ObdItemAdapter mPidAdapter;
|
||||
private static VidItemAdapter mVidAdapter;
|
||||
private static DfcItemAdapter mDfcAdapter;
|
||||
private static ObdItemAdapter currDataAdapter;
|
||||
/** Timer for display updates */
|
||||
private static Timer updateTimer = new Timer();
|
||||
/* is demo mode enabled? */
|
||||
private static boolean demoMode = false;
|
||||
/* initial state of bluetooth adapter */
|
||||
private static boolean initialBtStateEnabled = false;
|
||||
/** last time of back key pressed */
|
||||
private static long lastBackPressTime = 0;
|
||||
/** toast for showing exit message */
|
||||
private static Toast exitToast = null;
|
||||
private static FileHelper fileHelper;
|
||||
|
||||
/**
|
||||
* Timer Task to cyclically update data screen
|
||||
*/
|
||||
private transient final TimerTask updateTask = new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
/* forward message to update the view */
|
||||
Message msg = mHandler.obtainMessage(MainActivity.MESSAGE_UPDATE_VIEW);
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle message requests
|
||||
*/
|
||||
private transient final Handler mHandler = new Handler()
|
||||
{
|
||||
@Override
|
||||
public void handleMessage(Message msg)
|
||||
{
|
||||
|
||||
switch (msg.what)
|
||||
{
|
||||
case MESSAGE_STATE_CHANGE:
|
||||
switch (msg.arg1)
|
||||
{
|
||||
case ObdCommService.STATE_CONNECTED:
|
||||
onConnect();
|
||||
break;
|
||||
|
||||
case ObdCommService.STATE_CONNECTING:
|
||||
setStatus(R.string.title_connecting);
|
||||
break;
|
||||
|
||||
case ObdCommService.STATE_LISTEN:
|
||||
case ObdCommService.STATE_NONE:
|
||||
onDisconnect();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MESSAGE_WRITE:
|
||||
break;
|
||||
|
||||
case MESSAGE_READ:
|
||||
break;
|
||||
|
||||
case MESSAGE_DEVICE_NAME:
|
||||
// save the connected device's name
|
||||
mConnectedDeviceName = msg.getData().getString(DEVICE_NAME);
|
||||
Toast.makeText(getApplicationContext(),
|
||||
getString(R.string.connected_to) + mConnectedDeviceName,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
|
||||
case MESSAGE_TOAST:
|
||||
Toast.makeText(getApplicationContext(),
|
||||
msg.getData().getString(TOAST),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
|
||||
case MESSAGE_DATA_ITEMS_CHANGED:
|
||||
PvChangeEvent event = (PvChangeEvent) msg.obj;
|
||||
switch (event.getType())
|
||||
{
|
||||
case PvChangeEvent.PV_ADDED:
|
||||
currDataAdapter.setPvList(currDataAdapter.pvs);
|
||||
try
|
||||
{
|
||||
updateTimer.schedule(updateTask, 0, DISPLAY_UPDATE_TIME);
|
||||
} catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
break;
|
||||
|
||||
case PvChangeEvent.PV_CLEARED:
|
||||
currDataAdapter.clear();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MESSAGE_UPDATE_VIEW:
|
||||
currDataAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
// requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
// set up action bar
|
||||
ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null)
|
||||
{
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
// actionBar.setDisplayOptions(ActionBar.NAVIGATION_MODE_TABS);
|
||||
}
|
||||
|
||||
setContentView(R.layout.startup_layout);
|
||||
|
||||
// set up log4j logging ...
|
||||
logCfg = new LogConfigurator();
|
||||
logCfg.setUseLogCatAppender(true);
|
||||
logCfg.setUseFileAppender(true);
|
||||
logCfg.setFileName(FileHelper.getPath(this).concat(File.separator).concat("log/AndrOBD.log"));
|
||||
logCfg.setLevel("com.fr3ts0n.prot", Level.DEBUG);
|
||||
logCfg.setRootLevel(Level.INFO);
|
||||
logCfg.configure();
|
||||
|
||||
// Set up all data adapters
|
||||
mCommService = new ObdCommService(this, mHandler);
|
||||
mPidAdapter = new ObdItemAdapter(this, R.layout.obd_item, ObdProt.PidPvs);
|
||||
mVidAdapter = new VidItemAdapter(this, R.layout.obd_item, ObdProt.VidPvs);
|
||||
mDfcAdapter = new DfcItemAdapter(this, R.layout.obd_item, ObdProt.tCodes);
|
||||
currDataAdapter = mPidAdapter;
|
||||
// create file helper instance
|
||||
fileHelper = new FileHelper(this, mCommService.elm);
|
||||
// set listeners for data structure changes
|
||||
setDataListeners();
|
||||
|
||||
// check if this is a VIEW action from file manager
|
||||
if (Intent.ACTION_VIEW.equals(getIntent().getAction()))
|
||||
{
|
||||
demoMode = true;
|
||||
// set OBD data mode
|
||||
setObdService(ObdProt.OBD_SVC_DATA, getString(R.string.saved_data));
|
||||
// handle activity result of a file selection
|
||||
onActivityResult(REQUEST_SELECT_FILE, RESULT_OK, getIntent());
|
||||
}
|
||||
|
||||
// Get local Bluetooth adapter
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
Log.d(TAG, "Adapter: " + mBluetoothAdapter);
|
||||
// If BT is not on, request that it be enabled.
|
||||
if (!demoMode && mBluetoothAdapter != null)
|
||||
{
|
||||
// remember initial bluetooth state
|
||||
initialBtStateEnabled = mBluetoothAdapter.isEnabled();
|
||||
if (!initialBtStateEnabled)
|
||||
{
|
||||
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set listeners for data structure changes
|
||||
*/
|
||||
private void setDataListeners()
|
||||
{
|
||||
// add pv change listeners to trigger model updates
|
||||
ObdProt.PidPvs.addPvChangeListener(this,
|
||||
PvChangeEvent.PV_ADDED
|
||||
| PvChangeEvent.PV_CLEARED
|
||||
);
|
||||
ObdProt.VidPvs.addPvChangeListener(this,
|
||||
PvChangeEvent.PV_ADDED
|
||||
| PvChangeEvent.PV_CLEARED
|
||||
);
|
||||
ObdProt.tCodes.addPvChangeListener(this,
|
||||
PvChangeEvent.PV_ADDED
|
||||
| PvChangeEvent.PV_CLEARED
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for options menu creation event
|
||||
*/
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
MainActivity.menu = menu;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the PIDs of items which are checked in the list view
|
||||
*
|
||||
* @return Array of selected PIDs
|
||||
*/
|
||||
private int[] getSelectedPids()
|
||||
{
|
||||
int selectedPids[];
|
||||
// SparseBoolArray - what a garbage data type to return ...
|
||||
final SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();
|
||||
// get number of items
|
||||
int checkedItemsCount = checkedItems.size();
|
||||
// dimension array
|
||||
selectedPids = new int[checkedItemsCount];
|
||||
// loop through findings
|
||||
for (int i = 0; i < checkedItemsCount; ++i)
|
||||
{
|
||||
// Item position in adapter
|
||||
int position = checkedItems.keyAt(i);
|
||||
// Add team if item is checked == TRUE!
|
||||
if (checkedItems.valueAt(i))
|
||||
{
|
||||
// get measurement ...
|
||||
EcuDataPv pv = (EcuDataPv) getListAdapter().getItem(position);
|
||||
// ... and add it's PID
|
||||
selectedPids[i] = (Integer) pv.get(EcuDataPv.FID_PID);
|
||||
}
|
||||
}
|
||||
return selectedPids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for Options menu selection
|
||||
*/
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
// Handle presses on the action bar items
|
||||
Intent serverIntent;
|
||||
updateTimer.purge();
|
||||
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.secure_connect_scan:
|
||||
// Launch the DeviceListActivity to see devices and do scan
|
||||
serverIntent = new Intent(this, DeviceListActivity.class);
|
||||
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
|
||||
return true;
|
||||
|
||||
case R.id.chart_selected:
|
||||
/* if we are in OBD data mode:
|
||||
* -> Short click on an item starts the readout activity
|
||||
*/
|
||||
if (mCommService.elm.getService() == ObdProt.OBD_SVC_DATA)
|
||||
{
|
||||
int selectedPids[] = getSelectedPids();
|
||||
if (selectedPids.length > 0)
|
||||
{
|
||||
Intent intent = new Intent(this, ChartActivity.class);
|
||||
intent.putExtra(ChartActivity.PID, selectedPids);
|
||||
startActivity(intent);
|
||||
} else
|
||||
{
|
||||
setMenuItemEnable(R.id.chart_selected, false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.hud_selected:
|
||||
case R.id.dashboard_selected:
|
||||
/* if we are in OBD data mode:
|
||||
* -> Short click on an item starts the readout activity
|
||||
*/
|
||||
if (mCommService.elm.getService() == ObdProt.OBD_SVC_DATA)
|
||||
{
|
||||
int selectedPids[] = getSelectedPids();
|
||||
if (selectedPids.length > 0)
|
||||
{
|
||||
Intent intent = new Intent(this, DashBoardActivity.class);
|
||||
intent.putExtra(DashBoardActivity.PID, selectedPids);
|
||||
intent.putExtra(DashBoardActivity.RES_ID, item.getItemId() == R.id.dashboard_selected ? R.layout.dashboard : R.layout.head_up);
|
||||
startActivity(intent);
|
||||
} else
|
||||
{
|
||||
setMenuItemEnable(R.id.graph_actions, false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.save:
|
||||
// save recorded data (threaded)
|
||||
fileHelper.saveDataThreaded();
|
||||
return true;
|
||||
|
||||
case R.id.load:
|
||||
selectFileToLoad();
|
||||
return true;
|
||||
|
||||
case R.id.service_none:
|
||||
setObdService(ObdProt.OBD_SVC_NONE, item.getTitle());
|
||||
return true;
|
||||
|
||||
case R.id.service_data:
|
||||
setObdService(ObdProt.OBD_SVC_DATA, item.getTitle());
|
||||
return true;
|
||||
|
||||
case R.id.service_vid_data:
|
||||
setObdService(ObdProt.OBD_SVC_VEH_INFO, item.getTitle());
|
||||
return true;
|
||||
|
||||
case R.id.service_freezeframes:
|
||||
setObdService(ObdProt.OBD_SVC_FREEZEFRAME, item.getTitle());
|
||||
return true;
|
||||
|
||||
case R.id.service_codes:
|
||||
setObdService(ObdProt.OBD_SVC_READ_CODES, item.getTitle());
|
||||
return true;
|
||||
|
||||
case R.id.service_permacodes:
|
||||
setObdService(ObdProt.OBD_SVC_PERMACODES, item.getTitle());
|
||||
return true;
|
||||
|
||||
case R.id.service_pendingcodes:
|
||||
setObdService(ObdProt.OBD_SVC_PENDINGCODES, item.getTitle());
|
||||
return true;
|
||||
|
||||
case R.id.service_clearcodes:
|
||||
clearObdFaultCodes();
|
||||
setObdService(ObdProt.OBD_SVC_READ_CODES, item.getTitle());
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select file to be loaded
|
||||
*/
|
||||
public void selectFileToLoad()
|
||||
{
|
||||
stopDemoService();
|
||||
// set OBD data mode
|
||||
setObdService(ObdProt.OBD_SVC_DATA, getString(R.string.saved_data));
|
||||
|
||||
File file = new File(FileHelper.getPath(this));
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
Uri data = Uri.fromFile(file);
|
||||
String type = "*/*";
|
||||
intent.setDataAndType(data, type);
|
||||
startActivityForResult(intent, REQUEST_SELECT_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for result messages from other activities
|
||||
*/
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
switch (requestCode)
|
||||
{
|
||||
case REQUEST_CONNECT_DEVICE_SECURE:
|
||||
// When DeviceListActivity returns with a device to connect
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
connectDevice(data, true);
|
||||
break;
|
||||
|
||||
case REQUEST_CONNECT_DEVICE_INSECURE:
|
||||
// When DeviceListActivity returns with a device to connect
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
connectDevice(data, false);
|
||||
break;
|
||||
|
||||
case REQUEST_ENABLE_BT:
|
||||
// When the request to enable Bluetooth returns
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
// Launch the DeviceListActivity to see devices and do scan
|
||||
Intent serverIntent = new Intent(this, DeviceListActivity.class);
|
||||
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
|
||||
} else
|
||||
{
|
||||
// Start demo service Thread
|
||||
startDemoService();
|
||||
}
|
||||
break;
|
||||
|
||||
case REQUEST_SELECT_FILE:
|
||||
if (resultCode == RESULT_OK)
|
||||
{
|
||||
// Get the Uri of the selected file
|
||||
Uri uri = data.getData();
|
||||
Log.d(TAG, "Load content: " + uri);
|
||||
// load data ...
|
||||
try
|
||||
{
|
||||
InputStream inStr = getContentResolver().openInputStream(uri);
|
||||
fileHelper.loadData(inStr);
|
||||
} catch (FileNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
// don't allow saving it again
|
||||
setMenuItemEnable(R.id.save, false);
|
||||
// set listeners for data structure changes
|
||||
setDataListeners();
|
||||
// set adapters data source to loaded list instances
|
||||
mPidAdapter.setPvList(ObdProt.PidPvs);
|
||||
mVidAdapter.setPvList(ObdProt.VidPvs);
|
||||
mDfcAdapter.setPvList(ObdProt.tCodes);
|
||||
// set OBD data mode to the one selected by input file
|
||||
setObdService(mCommService.elm.getService(), getString(R.string.saved_data));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handle pressing of the BACK-KEY
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
if (mCommService.elm.getService() != ObdProt.OBD_SVC_NONE)
|
||||
{
|
||||
setObdService(ObdProt.OBD_SVC_NONE, null);
|
||||
} else
|
||||
{
|
||||
if (lastBackPressTime < System.currentTimeMillis() - EXIT_TIMEOUT)
|
||||
{
|
||||
exitToast = Toast.makeText(this, R.string.back_again_to_exit, Toast.LENGTH_SHORT);
|
||||
exitToast.show();
|
||||
lastBackPressTime = System.currentTimeMillis();
|
||||
} else
|
||||
{
|
||||
if (exitToast != null)
|
||||
{
|
||||
exitToast.cancel();
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for application start event
|
||||
*/
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
// If the adapter is null, then Bluetooth is not supported
|
||||
if (mBluetoothAdapter == null)
|
||||
{
|
||||
// start ELM protocol demo loop
|
||||
startDemoService();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see android.app.Activity#onDestroy()
|
||||
*/
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
// stop demo service if it was started
|
||||
stopDemoService();
|
||||
|
||||
// if bluetooth adapter was switched OFF before ...
|
||||
if (mBluetoothAdapter != null && !initialBtStateEnabled)
|
||||
{
|
||||
// ... turn it OFF again
|
||||
mBluetoothAdapter.disable();
|
||||
}
|
||||
// TODO: save current adjustments
|
||||
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle short clicks in OBD data list items
|
||||
*/
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id)
|
||||
{
|
||||
super.onListItemClick(l, v, position, id);
|
||||
// enable graphic actions only on DATA service if min 1 item selected
|
||||
setMenuItemEnable(R.id.graph_actions,
|
||||
((mCommService.elm.getService() == ObdProt.OBD_SVC_DATA)
|
||||
&& (getListView().getCheckedItemCount() > 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle long licks on OBD data list items
|
||||
*/
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
Intent intent;
|
||||
|
||||
switch (mCommService.elm.getService())
|
||||
{
|
||||
/* if we are in OBD data mode:
|
||||
* ->Long click on an item starts the single item chart activity
|
||||
*/
|
||||
case ObdProt.OBD_SVC_DATA:
|
||||
intent = new Intent(this, DashBoardActivity.class);
|
||||
EcuDataPv currPid = (EcuDataPv) getListAdapter().getItem(position);
|
||||
intent.putExtra(ChartActivity.PID,
|
||||
new int[]{Integer.valueOf(String.valueOf(currPid.get(EcuDataPv.FID_PID)))});
|
||||
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:
|
||||
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);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate desired OBD service
|
||||
*
|
||||
* @param obdService OBD service ID to be activated
|
||||
*/
|
||||
public void setObdService(int obdService, CharSequence menuTitle)
|
||||
{
|
||||
setContentView(R.layout.obd_list);
|
||||
TextView title = (TextView) findViewById(R.id.title);
|
||||
title.setText(menuTitle);
|
||||
setMenuItemEnable(R.id.graph_actions, false);
|
||||
getListView().setOnItemLongClickListener(this);
|
||||
mCommService.elm.setService(obdService);
|
||||
switch (obdService)
|
||||
{
|
||||
case ObdProt.OBD_SVC_DATA:
|
||||
case ObdProt.OBD_SVC_FREEZEFRAME:
|
||||
currDataAdapter = mPidAdapter;
|
||||
break;
|
||||
|
||||
case ObdProt.OBD_SVC_PENDINGCODES:
|
||||
case ObdProt.OBD_SVC_PERMACODES:
|
||||
case ObdProt.OBD_SVC_READ_CODES:
|
||||
currDataAdapter = mDfcAdapter;
|
||||
break;
|
||||
|
||||
case ObdProt.OBD_SVC_NONE:
|
||||
setContentView(R.layout.startup_layout);
|
||||
// intentionally no break to initialize adapter
|
||||
case ObdProt.OBD_SVC_VEH_INFO:
|
||||
currDataAdapter = mVidAdapter;
|
||||
break;
|
||||
}
|
||||
setListAdapter(currDataAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set enabled state for a specified menu item
|
||||
* * this includes shading disabled items to visualize state
|
||||
*
|
||||
* @param id ID of menu item
|
||||
* @param enabled flag if to be enabled/disabled
|
||||
*/
|
||||
private void setMenuItemEnable(int id, boolean enabled)
|
||||
{
|
||||
if (menu != null)
|
||||
{
|
||||
MenuItem item = menu.findItem(id);
|
||||
item.setEnabled(enabled);
|
||||
item.getIcon().setAlpha(enabled ? 255 : 127);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start demo mode Thread
|
||||
*/
|
||||
private void startDemoService()
|
||||
{
|
||||
if (!demoMode)
|
||||
{
|
||||
demoMode = true;
|
||||
setStatus(getString(R.string.demo));
|
||||
Toast.makeText(this, getString(R.string.demo_started), Toast.LENGTH_SHORT).show();
|
||||
setMenuItemEnable(R.id.secure_connect_scan, false);
|
||||
setMenuItemEnable(R.id.obd_services, true);
|
||||
setMenuItemEnable(R.id.graph_actions, false);
|
||||
/* The Thread object for processing the demo mode loop */
|
||||
Thread demoThread = new Thread(mCommService.elm);
|
||||
demoThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop demo mode Thread
|
||||
*/
|
||||
private void stopDemoService()
|
||||
{
|
||||
if (demoMode)
|
||||
{
|
||||
demoMode = false;
|
||||
ElmProt.runDemo = false;
|
||||
Toast.makeText(this, getString(R.string.demo_stopped), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set status message in status bar
|
||||
*
|
||||
* @param resId Resource ID of the text to be displayed
|
||||
*/
|
||||
private void setStatus(int resId)
|
||||
{
|
||||
final ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null)
|
||||
{
|
||||
actionBar.setSubtitle(resId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set status message in status bar
|
||||
*
|
||||
* @param subTitle status text to be set
|
||||
*/
|
||||
private void setStatus(CharSequence subTitle)
|
||||
{
|
||||
final ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null)
|
||||
{
|
||||
actionBar.setSubtitle(subTitle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate a connect to the selected bluetooth device
|
||||
*
|
||||
* @param data Intent data which contains the bluetooth device address
|
||||
* @param secure flag to indicate if the connection shall be secure, or not
|
||||
*/
|
||||
private void connectDevice(Intent data, boolean secure)
|
||||
{
|
||||
// Get the device MAC address
|
||||
String address = data.getExtras().getString(
|
||||
DeviceListActivity.EXTRA_DEVICE_ADDRESS);
|
||||
// Get the BluetoothDevice object
|
||||
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
|
||||
// Attempt to connect to the device
|
||||
mCommService.connect(device, secure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle bluetooth connection established ...
|
||||
*/
|
||||
private void onConnect()
|
||||
{
|
||||
// handle further initialisations
|
||||
setMenuItemEnable(R.id.secure_connect_scan, false);
|
||||
setMenuItemEnable(R.id.obd_services, true);
|
||||
setMenuItemEnable(R.id.graph_actions, false);
|
||||
// display connection status
|
||||
setStatus(getString(R.string.title_connected_to, mConnectedDeviceName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle bluetooth connection lost ...
|
||||
*/
|
||||
private void onDisconnect()
|
||||
{
|
||||
// handle further initialisations
|
||||
setMenuItemEnable(R.id.secure_connect_scan, true);
|
||||
setMenuItemEnable(R.id.obd_services, false);
|
||||
setMenuItemEnable(R.id.graph_actions, false);
|
||||
// display connection status
|
||||
setStatus(R.string.title_not_connected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for PV change events This handler just forwards the PV change
|
||||
* events to the android handler, since all adapter / GUI actions have to be
|
||||
* performed from the main handler
|
||||
*
|
||||
* @param event PvChangeEvent which is reported
|
||||
*/
|
||||
@Override
|
||||
public synchronized void pvChanged(PvChangeEvent event)
|
||||
{
|
||||
// forward PV change to the UI Activity
|
||||
Message msg = mHandler.obtainMessage(MainActivity.MESSAGE_DATA_ITEMS_CHANGED);
|
||||
msg.obj = event;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear OBD fault codes after a warning
|
||||
* confirmation dialog is shown and the operation is confirmed
|
||||
*/
|
||||
protected void clearObdFaultCodes()
|
||||
{
|
||||
new AlertDialog.Builder(this)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setTitle(R.string.obd_clearcodes)
|
||||
.setMessage(R.string.obd_clear_info)
|
||||
.setPositiveButton(android.R.string.yes,
|
||||
new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
// set service CLEAR_CODES to clear the codes
|
||||
mCommService.elm.setService(ObdProt.OBD_SVC_CLEAR_CODES);
|
||||
// set service READ_CODES to re-read the codes
|
||||
mCommService.elm.setService(ObdProt.OBD_SVC_READ_CODES);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
}
|
||||