Commit 09f51911 authored by Andrey Filippov's avatar Andrey Filippov

added actual files

parent 9c355ed3
html/*
attic/*
/.project
/.cproject
/.pydevproject
/.externalToolBuilders
/.settings
.directory
generated*
sysroots
bitbake-logs
/temp
*.o
image
src/nmea2exif
src/log_imu
src/.depend
\ No newline at end of file
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:
{project} Copyright (C) {year} {fullname}
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>.
# Runs 'make', 'make install', and 'make clean' in specified subdirectories
SUBDIRS := src
INSTALLDIRS = $(SUBDIRS:%=install-%)
CLEANDIRS = $(SUBDIRS:%=clean-%)
#TARGETDIR=$(DESTDIR)/www/pages
all: $(SUBDIRS)
@echo "make all top"
$(SUBDIRS):
$(MAKE) -C $@
install: $(INSTALLDIRS)
@echo "make install top"
$(INSTALLDIRS):
$(MAKE) -C $(@:install-%=%) install
clean: $(CLEANDIRS)
@echo "make clean top"
$(CLEANDIRS):
$(MAKE) -C $(@:clean-%=%) clean
.PHONY: all install clean $(SUBDIRS) $(INSTALLDIRS) $(CLEANDIRS)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.1150476775">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.1150476775" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="0.1150476775" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.1150476775." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1042691196" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1042691196.1296727294" name=""/>
<builder arguments="apps-gps" command="${workspace_loc:/elphel-apps-editconf/run_bitbake.sh}" enableCleanBuild="false" id="org.eclipse.cdt.build.core.settings.default.builder.851629087" incrementalBuildTarget="-c compile -f -v" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.2089670226" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.1645067780" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1912421658" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/elphel-apps-gps/sysroots/elphel393/usr/include-uapi}&quot;"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.98116389" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1272302733" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1282220181" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/elphel-apps-gps/sysroots}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/elphel-apps-gps/sysroots/elphel393/usr/include-uapi}&quot;"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1122993166" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.605559330" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.515081863" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/elphel-apps-gps/sysroots}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/elphel-apps-gps/sysroots/elphel393/usr/include-uapi}&quot;"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.899853425" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1363226103" name="LLVM bytecode assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.513031495" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/elphel-apps-gps/sysroots}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/elphel-apps-gps/sysroots/elphel393/usr/include-uapi}&quot;"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.370831508" languageId="org.eclipse.cdt.managedbuilder.llvm.ui.llvmAssembly" languageName="LLVM bytecode assembly" sourceContentType="org.eclipse.cdt.managedbuilder.llvm.ui.llvmAssemblySource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1740441857" name="UPC" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.550102451" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/elphel-apps-gps/sysroots}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/elphel-apps-gps/sysroots/elphel393/usr/include-uapi}&quot;"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1420737322" languageId="org.eclipse.cdt.core.parser.upc.upc" languageName="UPC" sourceContentType="org.eclipse.cdt.core.parser.upc.upcSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="elphel-apps-gps.null.420984123" name="elphel-apps-gps"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.1150476775">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/elphel-apps-gps"/>
</configuration>
</storageModule>
</cproject>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/elphel-apps-gps/run_bitbake.sh}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="apps-gps -c target_scp -f"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>elphel-apps-gps</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/SCP apps-gps to target.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
#!/bin/bash
args="$@"
while (( "$#" )); do
shift
done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Launching bitbake $args"
cd $DIR/../../poky
. ./oe-init-build-env
bitbake $args | sed -u 's@| @@'
exit 0
WWW_PAGES = /www/pages
BINDIR = /usr/bin/
INSTMODE = 0755
INSTDOCS = 0644
INSTOWNER = root
INSTGROUP = root
PROGS = nmea2exif log_imu
SRCS = nmea2exif.c log_imu.c
OBJS = nmea2exif.o
PHPSCRIPTS= logger_launcher.php imu_setup.php start_gps_compass.php
CFLAGS += -Wall -I$(STAGING_DIR_HOST)/usr/include-uapi
LDLIBS += -lm
all: $(PROGS)
log_imu: log_imu.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
nmea2exif: nmea2exif.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
install: $(PROGS)
$(INSTALL) $(OWN) -d $(DESTDIR)
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -d $(DESTDIR)$(WWW_PAGES)
$(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) $(PROGS) $(DESTDIR)$(BINDIR)
$(INSTALL) -o $(INSTOWNER) -m $(INSTDOCS) $(PHPSCRIPTS) $(DESTDIR)$(WWW_PAGES)
clean:
rm -rf $(PROGS) *.o *~
depend: .depend
.depend: $(SRCS)
rm -f ./.depend
$(CC) $(CFLAGS) -MM $^ > ./.depend;
include .depend
#!/usr/bin/env php -q
<?php
/*
*! FILE NAME : imu_setup.php
*! DESCRIPTION: Handles GPS/compass and IMU/logger. Will replace star-compass_gps.php
*!
*! Copyright (C) 2008 Elphel, Inc
*! -----------------------------------------------------------------------------**
*!
*! 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/>.
*! -----------------------------------------------------------------------------**
*! $Log: imu_setup.php,v $
*! Revision 1.8 2012/07/03 20:54:36 elphel
*! bug fix
*!
*! Revision 1.7 2011/12/22 05:40:36 elphel
*! missed revision
*!
*! Revision 1.5 2011/09/06 22:02:49 elphel
*! added 'list' link
*!
*! Revision 1.4 2011/09/06 21:56:31 elphel
*! help typo
*!
*! Revision 1.3 2011/09/06 21:53:49 elphel
*! adding to help
*!
*! Revision 1.2 2011/09/06 21:31:48 elphel
*! added help
*!
*! Revision 1.1 2011/09/06 19:07:50 elphel
*! initial release, based on start_gps_compass.php
*!
*/
#require 'i2c.inc';
set_include_path(get_include_path() . PATH_SEPARATOR . '/www/pages/include');
require 'i2c_include.php';
# $xclk_freq=80000000; // 80 MHz in NC353
$xclk_freq=100000000; // 100 MHz in NC393
$messageOffset=0xb0; // offset to start of "odometer" message in the device driver file
$config_name="/etc/elphel393/imu_logger.xml";
$gps_compass_xml = "/www/pages/gps_compass.xml";
$i2cbus = 4;
if (isset($_SERVER["SERVER_PROTOCOL"])) {
// echo "web server\n";
if (isset($_GET['msg'])) {
setMessage(urldecode($_GET['msg']));
} else if (isset($_GET['lmsg'])) {
setMessage(urldecode($_GET['msg']));
// software toggle input "odometer" line
}
/// modify parameters if specified
$conf=readSettings(init_default_config()); // read current settings
$apply=0;
// echo "<pre>\n";
if (count($_GET)==0) {
help();
exit(0);
}
if (array_key_exists('source',$_GET)) {
$source=file_get_contents ($_SERVER['SCRIPT_FILENAME']);
header("Content-Type: text/php");
header("Content-Length: ".strlen($source)."\n");
header("Pragma: no-cache\n");
echo $source;
exit (0);
}
foreach ($_GET as $key=>$value) {
$access=split(':',$key);
if ($value==='') continue;
if (count($access)<1) continue;
if (!isset($conf[$access[0]])) continue;
if (count($access)==1) {
if (($access[0]=='imu_period') && ($value=='auto')) $value = 0xffffff00;
if (is_string($conf[$access[0]])) $conf[$access[0]]=$value;
else $conf[$access[0]]=$value+0;
$apply++;
} else { // count($access)>1
if (!isset($conf[$access[0]][$access[1]])) continue;
if (count($access)==2) {
if (is_string($conf[$access[0]][$access[1]])) $conf[$access[0]][$access[1]]=$value;
else $conf[$access[0]][$access[1]]=$value+0;
$apply++;
} else { // count($access)>2)
if (count($access)>3) continue;
if ($access[2]=='sentence') $access[2]=0;
else if ($access[2]=='format') $access[2]=1;
if (!isset($conf[$access[0]][$access[1]][$access[2]])) continue;
if (is_string($conf[$access[0]][$access[1]][$access[2]])) $conf[$access[0]][$access[1]][$access[2]]=$value;
else $conf[$access[0]][$access[1]][$access[2]]=$value+0;
$apply++;
}
}
/*
echo 'key='.$key."\n";
print_r($access);
var_dump($value);
*/
}
if ($apply>0) {
echo 'modified '.$apply."parameters<br/>\n";
// print_r($conf);
setup_IMU_logger($conf);
}
if (isset($_GET['save'])) {
// if ($verbose) echo 'Writing IMU logger configuration to '. $config_name."\n";
$conf=readSettings(init_default_config());
$logger_xml=loggerConfigToXML($conf);
$conf_file=fopen($config_name,"w");
fwrite($conf_file,$logger_xml->asXML());
fclose($conf_file);
exec ('sync');
}
if (isset($_GET['list'])) {
$conf=readSettings(init_default_config());
$logger_xml=loggerConfigToXML($conf);
$logger_xml_text=$logger_xml->asXML();
header("Content-Type: text/xml");
header("Content-Length: ".strlen($logger_xml_text)."\n");
header("Pragma: no-cache\n");
printf($logger_xml_text);
} else echo 'OK';
exit(0);
} else {
// echo "CGI\n";
}
/*
echo "<!--\n";
var_dump($_GET);
var_dump($_SERVER);
echo "-->";
echo 'OK';
exit(0);
*/
//! Here comes if CLI
$ids=scanGrandDaughters();
$b_index=indexGrandDaughters($ids);
// print_r($ids);
// print_r($b_index);
$baud=null;
if (isset($b_index[103696])) {
$baud=$ids[$b_index[103696]]['baud'];
if ($baud===0) $baud=='auto';
}
// exit (0);
$wait_time=20; // wait for $wait_time if both devices were not found, retry
$compass=null;
$GPS=null;
$verbose=true;
foreach ($_SERVER['argv'] as $param) {
if ((substr($param,0,2)=="-q") || (substr($param,0,8)=="--silent")){
$verbose=false;
}
}
/// kill those GPS and compass if they are running already
exec('killall -q garminusb2exif');
exec('killall -q nmea2exif');
exec('killall -q compass');
// find_gps_compass();
$devs=find_gps_compass($baud);
// echo "compass: ";var_dump($compass);echo "\n";
// echo "GPS: ";var_dump($GPS);echo "\n";
// if ((!$compass || !$GPS) && ((exec('date +%s')+0) <30)) {
if ((count($devs)==0) && ((exec('date +%s')+0) <30)) {
if ($verbose) echo "waiting $wait_time sec for USB devices to start up\n";
sleep($wait_time);
if ($verbose) echo "Retrying detection\n";
$devs=find_gps_compass($baud);
}
listSensorDevices($devs,$b_index,$ids);
//var_dump($GPS);
// if (file_exists ($sensor_state_file)) $sensor_board=parse_ini_file($sensor_state_file);
// exec ('sync');
$logger_config=null;
$write_config=false;
if (file_exists ($config_name)) {
if ($verbose) echo 'Reading IMU logger configuration from '. $config_name."\n";
$config_xml = simplexml_load_file($config_name);
$logger_config=loggerConfigFromXML($config_xml);
} else if (isset($b_index[103696]) || isset($b_index[103696])) {
if ($verbose) echo "Generating IMU logger configuration\n";
// $default_config=init_default_config();
// $logger_config=init_default_config();
$logger_config=array();
if (isset($GPS) && isset($b_index[103696])) {
$logger_config['baud_rate']=$GPS['baud'];
$logger_config['gps_slot']=$ids[$b_index[103696]]['port'];
$logger_config['gps_mode']=$ids[$b_index[103696]]['sync'];
}
if (isset($b_index[103695])) {
$logger_config['imu_slot']=$ids[$b_index[103695]]['port'];
$logger_config['imu_sa']=$b_index[103695];
}
$write_config=true; // write configuration to /etc after applying defaults
}
if (isset($logger_config)){
// var_dump($logger_config);
$logger_config=combineLoggerConfigs($logger_config,init_default_config());
// var_dump($logger_config);
// var_dump($default_config);
$logger_xml=loggerConfigToXML($logger_config);
$conf_file=fopen('/var/html/logger_config.xml',"w");
fwrite($conf_file,$logger_xml->asXML());
fclose($conf_file);
setup_IMU_logger($logger_config);
if ($write_config) {
if ($verbose) echo 'Writing IMU logger configuration to '. $config_name."\n";
$conf_file=fopen($config_name,"w");
fwrite($conf_file,$logger_xml->asXML());
fclose($conf_file);
exec ('sync');
}
}
// echo "compass: ";var_dump($compass);echo "\n";
// echo "GPS: ";var_dump($GPS);echo "\n";
$noGPS= ($compass || $GPS)?"" : "noGPS";
$nocompass=($compass)?"" : "nocompass";
$cmd="/usr/html/exif.php init $noGPS $nocompass";
if ($verbose) echo "Initializing Exif template: $cmd\n";
exec($cmd);
if ($GPS) {
if ($verbose) echo "Starting ".$GPS["name"]. " as ". $GPS["file"]. "\n";
if (strpos($GPS['name'],'NMEA')!==false) {
$cmd ="/usr/local/bin/nmea2exif ". $GPS["file"]." &";
} else {
$cmd ="/usr/local/bin/garminusb2exif ". $GPS["file"]." &";
}
if ($verbose) echo "exec: $cmd \n";
popen($cmd,"r");
}
if ($compass) {
if ($verbose) echo "Starting ".$compass["name"]. " as ". $compass["file"]. "\n";
exec ("stty -F ".$compass["file"]." -echo speed 19200");
$cmd="/usr/local/bin/compass ". $compass["file"]." &";
if ($verbose) echo "exec: $cmd \n";
popen($cmd,"r");
}
exit ((isset($b_index[103695])?4:0) | ($compass?2:0) | ($GPS?1:0));
function help(){
$GP='$GP';
$GPRMC='$GPRMC';
$GPGGA='$GPGGA';
$GPGSA='$GPGSA';
$GPVTG='$GPVTG';
$script_name=$_SERVER['SCRIPT_NAME'];
$prefix_url='http://'.$_SERVER['SERVER_ADDR'].$_SERVER['SCRIPT_NAME'];
// echo <<<USAGE
// <h4> Control links:</h4>
// <ul>
// <li><a href="?$url_init">Initialization Parameters (i.e. after powerup)</a></li>
echo <<<USAGE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Usage of IMU/GPS logger ($script_name)</title>
</head>
<body>
<h2>Usage of IMU/GPS logger ($script_name)</h2>
<p>This script controls IMU/GPS logger. When the camera starts, the script looks for the <i>/etc/imu_logger.xml</i>" and if it is found, the settings from this file are applied to the logger. If there is no such file (i.e. at first boot after reflashing the camera) script looks for the optional extension boards <a href=""http://wiki.elphel.com/index.php?title=103695>103695</a> and <a href="http://wiki.elphel.com/index.php?title=103696">103696</a> and uses the information from their flash memory (not erased during reflash) combined with the defaults to create initial <i>/etc/imu_logger.xml</i> file that can be modified later</p>
<p>Script receives parameters as HTTP GET request, there are five special parameters:
<ul>
<li><b><a href="$prefix_url?source">source</a></b> - returns the source of this script</li>
<li><b><a href="$prefix_url?list">list</a></b> - returns an XML containing current logger settings, the names of the nodes can be used to modify specific settings</li>
<li><b>save</b> - overwrite <i>/etc/imu_logger.xml</i> with the current settings - they will be used next time camera will boot up</li>
<li><b>msg=url-encoded-text-up-to-56-bytes</b> - set the &quot;odometer&quot; message that will be logged next time the external input is toggled </li>
<li><b>smsg=url-encoded-text-up-to-56-bytes</b> - (not yet implemented) set the &quot;odometer&quot; message and trigger logging immediately</li>
</ul>
Other parameters are just <i>name=value</i> pairs with colons separating names and subnames
<ul>
<li><b>imu_period</b> - set the IMU logging period in SPI SCLK periods, maybe set to <i>auto</i> (default value, same as 0xff000000) to log when the IMU data is ready. Value 0 turns the IMU logging off</li>
<li><b>sclk_freq</b> - set SPI clock frequency, in Hz. Default is 5000000 (5MHz)</li>
<li><b>stall</b> - set SPI 'stall' time, in microseconds. Default is 2 usec</li>
<li><b>baud_rate</b> - set baud rate for the serial GPS, default is 19200</li>
<li><b>imu_slot</b> - specify the IMU board (<a href="http://wiki.elphel.com/index.php?title=103695">103695</a>) connection to the <a href="http://wiki.elphel.com/index.php?title=10369">10369</a> board 0 - none, 1 - J9, 2 - J10, 3 - J11. Default is 1 (J9)</li>
<li><b>gps_slot</b> - specify the GPS board (<a href="http://wiki.elphel.com/index.php?title=103696">103696</a>) connection to the <a href="http://wiki.elphel.com/index.php?title=10369">10369</a> board 0 - none, 1 - J9, 2 - J10, 3 - J11. Default is 2 (J10)</li>
<li><b>gps_mode</b> - synchronization mode for the GPS: 0 - pulse-per-sample external input, negative front, 1 - pps input positive front, 2 - start of a first sentence after pause, 3 - start of each individual sentence. Mode 2 is the default, modes 0 and 1 require that GPS has a dedicated synchro output</li>
<li><b>msg_conf</b> - GPIO number and polarity (+16 - invert polarity) uses to log external events (i.e. odometer pulses from a vehicle wheel sensor). Timestamp uses leading edge, software may write to the 56-byte buffer (see 'msg=' command above) before the trailing edge to attach the message to the event after the event occured. In the case of short external pulses the logged message will be the last written before the event</li>
<li><b>img_sync</b> - 0 - disable logging of the images, 1 - enable. In the case of the multiple synchronized cameras this provides a way to match external (master) camera timestamps transmitted over the synchronization cable, with the local camera timestamps used by the logger - both are logged. Default is 1</li>
<li><b>extra_conf</b> - Development signals (0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev A). Default is 4</li>
<li><b>slow_spi</b> - may be set to 1 for slow SPI devices (other changes may be needed, i.e. changing power from 3.3V to 5.0V selected by a resistor divider). Default is 0 </li>
<li><b>imu_sa</b> - i2c slave address modifier (matches hardware jumpers). Default is 3</li>
<li><b>sleep_busy</b> - setting for the driver. It is a sleep time (in microseconds) before the driver will poll the logger buffer if it does not have the full sample record (64 bytes of data) ready</li>
<li><b>imu_registers</b> - setting the IMU register addresses to be logged (total number of logged registers is 28). You may see the complete list of the registers in the IMU datasheet. The registers are addressed as 'imu_registers:NN', where NN is the register sequnce number, starting with 0. Below are the default values:
<ul>
<li><b>imu_registers:0</b>=0x10 - x gyro low</li>
<li><b>imu_registers:1</b>=0x12 - x gyro high</li>
<li><b>imu_registers:2</b>=0x14 - y gyro low</li>
<li><b>imu_registers:3</b>=0x16 - y gyro high</li>
<li><b>imu_registers:4</b>=0x18 - z gyro low</li>
<li><b>imu_registers:5</b>=0x1a - z gyro high</li>
<li><b>imu_registers:6</b>=0x1c - x accel low</li>
<li><b>imu_registers:7</b>=0x1e - x accel high</li>
<li><b>imu_registers:8</b>=0x20 - y accel low</li>
<li><b>imu_registers:9</b>=0x22 - y accel high</li>
<li><b>imu_registers:10</b>=0x24 - z accel low</li>
<li><b>imu_registers:11</b>=0x26 - z accel high</li>
<li><b>imu_registers:12</b>=0x40 - x delta angle low</li>
<li><b>imu_registers:13</b>=0x42 - x delta angle high</li>
<li><b>imu_registers:14</b>=0x44 - y delta angle low</li>
<li><b>imu_registers:15</b>=0x46 - y delta angle high</li>
<li><b>imu_registers:16</b>=0x48 - z delta angle low</li>
<li><b>imu_registers:17</b>=0x4a - z delta angle high</li>
<li><b>imu_registers:18</b>=0x4c - x delta velocity low</li>
<li><b>imu_registers:19</b>=0x4e - x delta velocity high</li>
<li><b>imu_registers:20</b>=0x50 - y delta velocity low</li>
<li><b>imu_registers:21</b>=0x52 - y delta velocity high</li>
<li><b>imu_registers:22</b>=0x54 - z delta velocity low</li>
<li><b>imu_registers:23</b>=0x56 - z delta velocity high</li>
<li><b>imu_registers:24</b>=0x0e - temperature</li>
<li><b>imu_registers:25</b>=0x70 - time m/s</li>
<li><b>imu_registers:26</b>=0x72 - time d/h</li>
<li><b>imu_registers:27</b>=0x74 - time y/m</li>
</ul></li>
<li><b>nmea</b> - set format of the four logged NMEA sentences. For each sentence two text fields have to be specified - 'sentence' (the three letters following the comman prefix '$GP'), and 'format' that consists of a sequence of 'n' (for number) and 'b' (for bytes), up to 24 total. Numbers consisting of digits, minus sign and decimal point are encoded with 2 digits per byte (to make sure the longest sentence fits into the 56 byte logger payload buffer), followed by the 0xf nibble (half-byte). Bytes are encoded with MSB cleared ( & 0x7f) for all bytes in a field but the last, the last byte has it set (|0x80). Empty byte field is logged as 0xff. Below are the default settings:
<ul>
<li><b>nmea:0:sentence</b>=RMC - sentence $GPRMC</li>
<li><b>nmea:0:format</b>=nbnbnbnnnnb - format for the $GPRMC</li>
<li><b>nmea:1:sentence</b>=GGA - sentence $GPGGA</li>
<li><b>nmea:1:format</b>=nnbnbnnnnbnbbb - format for the $GPGGA</li>
<li><b>nmea:2:sentence</b>=GSA - sentence $GPGSA</li>
<li><b>nmea:2:format</b>=bnnnnnnnnnnnnnnnn - format for the $GPGSA</li>
<li><b>nmea:3:sentence</b>=VTG - sentence $GPVTG</li>
<li><b>nmea:3:format</b>=nbnbnbnb - format for the $GPVTG</li>
</ul>
</li>
</ul>
</p>
<p>You may record the log to a file (i.e. on external USB stick or SSD/HDD) with teh following command:<br/>
<b>cat /dev/imu &gt;<i>log-file-path</i></b></p>
<p>Test logger and GPS:<br/>
<b>fpcf -imu 10000 | grep &quot;1:&quot;</b><p/>
<p>The fpcf output starts the line (logged sample) with the source of the sample:
<ul>
<li><b>0:</b> - IMU (normally 2560 samples/sec)</li>
<li><b>1:</b> - GPS </li>
<li><b>2:</b> - camera images</li>
<li><b>3:</b> - 'odometer' - external events</li>
</ul>
'10000' means that fpcf should output 10000 samples, that takes approximately 4 seconds if IMU output is being logged.
</p>
</body>
USAGE;
}
function scanGrandDaughters() {
global $i2cbus;
$ids = array ();
$id = "";
for($i = 2; $i < 8; $i ++) {
$id = i2c_read256b ( 0xa0 + 2 * $i, $i2cbus );
$xml = simplexml_load_string ( $id );
if (($xml !== false) && ($xml->getName () == 'board')) {
$ids [$i] = array ();
foreach ( $xml->children () as $entry ) {
$ids [$i] [$entry->getName ()] = ( string ) $entry;
}
}
}
return $ids;
}
function indexGrandDaughters($ids) {
$index = array ();
foreach ( $ids as $i => $id )
if (isset ( $id ['model'] )) {
$index [$id ['model']] = $i;
}
return $index;
}
/// compass/GPS programs should be killed before detection
// baud=null - search USB Garmin and compass
// baud=auto - try to autodetect baud rate
// baud=number - used specified baud rate, do not wait for the GPS response
function find_gps_compass($baud=null,$timeout=5) {
global $verbose;
$ttyOptions=array (
'-echo speed 19200', /// maybe other options, like '-echo speed 4800 -ixoff'
'-echo speed 9600',
'-echo speed 4800',
'-echo speed 2400'
);
if (isset($baud) && ($baud!='auto') && ($baud!=0)) {
$ttyOptions=array (
'-echo speed '.$baud);
}
// global $GPS, $compass;
$devices=array(
"compass"=>array(array("name"=>"Ocean Server OS-5000","driver"=>"cp2101")),
"GPS" =>array(array("name"=>"Garmin GPS 18 USB","driver"=>"garmin_gps")));
exec("ls /sys/bus/usb-serial/devices",$usb_ser_devs); // ("ttyUSB0","ttyUSB1")
$devs = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><USB_serial_devices/>");
$serialDevices=array();
$compassPresent=false;
$gpsPresent=false;
$driver=array();
//echo "usb_ser_devs"; var_dump($usb_ser_devs);
foreach ($usb_ser_devs as $dev) {
//echo "dev=$dev\n";
$arr=split("/",exec("ls /sys/bus/usb-serial/devices/".$dev."/driver -l"));
$driver[$dev]=$arr[count($arr)-1];
$serialDevices[$dev]='';
if (!isset($baud)) { // if baud is set (auto or number - skip compass, it is 103696)
foreach ($devices["compass"] as $d) {
if ($d["driver"]==$driver[$dev]) {
$dd=$devs->addChild ('compass');
$dd->addChild ('name',$d["name"]);
$dd->addChild ('driver',$d["driver"]);
$dd->addChild ('file',"/dev/".$dev);
$serialDevices[$dev]='compass';
$compassPresent=true;
}
}
}
if ($serialDevices[$dev]) continue;
foreach ($devices["GPS"] as $d) {
if ($d["driver"]==$driver[$dev]) {
$dd=$devs->addChild ('GPS');
$dd->addChild ('name',$d["name"]);
$dd->addChild ('driver',$d["driver"]);
$dd->addChild ('file',"/dev/".$dev);
$serialDevices[$dev]='gps';
$gpsPresent=true;
}
}
}
/// Do we need to look for a NMEA GPS?
if (!$gpsPresent) foreach ($serialDevices as $dev=>$type) if (!$type && !$gpsPresent) {
if ($verbose) printf ("could be $dev\n");
foreach ($ttyOptions as $ttyOpt) {
$cmd='stty -F /dev/'.$dev.' '.$ttyOpt;
if (count($ttyOptions)==1) { /// single baud option, will not wait for confirmation. Has to be only one serial adapter !!
if ($verbose) echo "Setting: $cmd\n";
exec ($cmd);
$gpsPresent=true;
} else {
if ($verbose) echo "Trying: $cmd\n";
exec ($cmd);
unset ($fullOutput);
exec ('timeout '.$timeout.' cat /dev/'.$dev, $fullOutput); // &$fullOutput - Fatal error: Call-time pass-by-reference has been removed in php
//var_dump($fullOutput);
foreach ($fullOutput as $line) if (strpos ($line, '$GP')===0) {
$gpsPresent=true;
break;
}
}
if ($gpsPresent) {
$dd=$devs->addChild ('GPS');
$dd->addChild ('name','NMEA 0183 GPS receiver');
$dd->addChild ('driver',$driver[$dev]);
$dd->addChild ('file',"/dev/".$dev);
$arr=split(" ",$ttyOpt);
$dd->addChild ('baud',$arr[count($arr)-1]);
$serialDevices[$dev]='gps';
if ($verbose) echo "\nfound NMEA GPS unit\n";
break;
}
// var_dump($fullOutput);
}
}
/// list unused USB serial adapters
foreach ($serialDevices as $dev=>$type) if (!$type) {
$dd=$devs->addChild ('unused');
$dd->addChild ('name','USB serial converter');
$dd->addChild ('driver',$driver[$dev]);
$dd->addChild ('file',"/dev/".$dev);
}
return $devs;
}
function listSensorDevices($devs,$b_index,$ids) {
global $GPS, $compass,$gps_compass_xml;
foreach ($devs->compass as $a) {
$compass=array("file"=>(string) $a->file, "name"=> (string) $a->name);
break; // use first one
}
foreach ($devs->GPS as $a) {
$GPS=array("file"=>(string) $a->file, "name"=> (string) $a->name, "baud"=>(string) $a->baud);
if (isset($b_index[103696])) {
$a->addChild ('part_number',$ids[$b_index[103696]]['part']);
$a->addChild ('port',$ids[$b_index[103696]]['port']);
$a->addChild ('mode',$ids[$b_index[103696]]['mode']);
}
break; // use first one
}
$state_file=fopen($gps_compass_xml,"w");
fwrite($state_file,$devs->asXML());
fclose($state_file);
}
function loggerConfigToXML($conf){
$logger_xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><Logger_configuration/>");
foreach ($conf as $key=>$value) {
switch ($key) {
case 'imu_registers':
$subtree=$logger_xml->addChild ($key);
for ($i=0;$i<count($value);$i++) {
$subtree->addChild ('R_'.sprintf('%02d',$i),sprintf("0x%02x",$value[$i]));
}
break;
case 'nmea':
$subtree=$logger_xml->addChild ($key);
for ($i=0;$i<count($value);$i++) {
$sentence=$subtree->addChild ('S_'.sprintf('%01d',$i));
$sentence->addChild ('sentence',$value[$i][0]);
$sentence->addChild ('format',$value[$i][1]);
}
break;
default:
$logger_xml->addChild ($key,$value);
}
}
return $logger_xml;
}
function loggerConfigFromXML($confXML){
$conf=array();
// var_dump($confXML);
foreach ($confXML as $item) {
// var_dump($item);
$key=$item->getName();
switch ($key) {
case 'imu_registers':
$conf[$key]=array();
foreach ($item as $reg) {
$rname=substr($reg->getName(),2);
$conf[$key][$rname+0]=((string) $reg)+0;
}
break;
case 'nmea':
$conf[$key]=array();
foreach ($item as $reg) {
$rname=substr($reg->getName(),2);
$conf[$key][$rname+0]=array((string) $reg->sentence, (string) $reg->format);
}
break;
case 'imu_period':
$conf[$key]=(string) $item;
if ($conf[$key]!='auto') $conf[$key]+=0;
break;
case 'message':
$conf[$key]=(string) $item;
break;
default:
// $conf[$key]=(int) $item;
$conf[$key]=((string) $item)+0;
}
}
return $conf;
}
function init_default_config(){
$default_config=array(
'imu_period'=>'auto',// 0xFFFFFFFF, // 0 - off, >=0xff000000 - "when ready", else - number of SCLK periods
'sclk_freq'=>5000000, // $clkr_divr= 8, // 80MHz divisor to get half SCLK rate (defaulkt SCLK=5MHz)
'stall' => 2, // SPI stall time in usec
'baud_rate'=>19200, // $rs232_div=80/2/$baud
'imu_slot'=>1,
'gps_slot'=>2,
'gps_mode'=>2, // 0 - pps neg, 1 - pps pos, 2 - start of first sentence after pause, 3 start of sentence
'msg_conf'=>10, // GPIO bit number for external (odometer) input (+16 - invert polarity). Timestamp uses leading edge, software may write to 56-byte buffer before the trailing edge
'img_sync'=>1, // enable logging image acquisition starts (0 - disable)
'extra_conf'=>4, // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A"
'slow_spi'=>0, // set to 1 for slow SPI devices (0 for ADIS-16375)
'imu_sa'=>3, // i2c slave address modifier for the 103695A pca9500
'sleep_busy'=>30000, //microseconds
'imu_registers'=>array( /// Up to 28 total
0x10, // x gyro low
0x12, // x gyro high
0x14, // y gyro low
0x16, // y gyro high
0x18, // z gyro low
0x1a, // z gyro high
0x1c, // x accel low
0x1e, // x accel high
0x20, // y accel low
0x22, // y accel high
0x24, // z accel low
0x26, // z accel high
0x40, // x delta angle low
0x42, // x delta angle high
0x44, // y delta angle low
0x46, // y delta angle high
0x48, // z delta angle low
0x4a, // z delta angle high
0x4c, // x delta velocity low
0x4e, // x delta velocity high
0x50, // y delta velocity low
0x52, // y delta velocity high
0x54, // z delta velocity low
0x56, // z delta velocity high
0x0e, // temperature
0x70, // time m/s
0x72, // time d/h
0x74// time y/m
),
'nmea'=>array(
/// first three letters - sentence to log (letters after "$GP"). next "n"/"b" (up to 24 total) - "n" number (will be encoded 2 digits/byte, follwed by "0xF"
/// "b" - byte - all but last will have MSB 0 (& 0x7f), the last one - with MSB set (| 0x80). If there are no characters in the field 0xff will be output
array('RMC','nbnbnbnnnnb'),
array('GGA','nnbnbnnnnbnbbb'),
array('GSA','bnnnnnnnnnnnnnnnn'),
array('VTG','nbnbnbnb')
),
'message'=>'Odometer message' // Message - up to 56 bytes
);
return $default_config;
}
/**
Combines $conf and $dflt arrays - all driver parameters are overwritten aftre the call
*/
function combineLoggerConfigs($new_conf,$dflt=null){
global $default_config;
# $xclk_freq=80000000; // 80 MHz in NC353
$xclk_freq=100000000; // 100 MHz in NC393
$data=array();
$index=0;
if (!isset ($dflt)) {
$dflt=$default_config;
}
$conf=$dflt;
if (isset($new_conf)) foreach ($conf as $key=>$oldvalue) if (isset($new_conf[$key])) $conf[$key]=$new_conf[$key];
/// fix insufficient data from default
while (count($conf['imu_registers'])<28) $conf['imu_registers'][count($conf['imu_registers'])]=0; // zero pad if less than 28 registers
/// Configure NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults
while (count($conf['nmea'])<4) {
for ($i=0;$i<4;$i++) {
$new=true;
for ($j=0;$j<count($conf['nmea']);$j++) if ($conf['nmea'][$j][0]==$dflt['nmea'][$i][0]){ // compare sentence code last 3 letters
$new=false;
break;
}
if ($new) {
$conf['nmea'][count($conf['nmea'])]=$dflt['nmea'][$i];
break;
}
}
}
for ($i=0;$i<4;$i++) {
while (strlen($conf['nmea'][$i][0])<3) $conf['nmea'][$i][0].="A"; // just to avoid errors - nonexistent sentences will not hurt, just never logged
}
return $conf;
}
function setup_IMU_logger($conf){
global $verbose,$xclk_freq;
$data=array();
$index=0;
/// program period
if (strtolower($conf['imu_period'])=='auto') $conf['imu_period']=0xffffffff;
else $conf['imu_period']+=0;
$data[$index++]= $conf['imu_period'] & 0xff;
$data[$index++]=($conf['imu_period']>> 8) & 0xff;
$data[$index++]=($conf['imu_period']>>16) & 0xff;
$data[$index++]=($conf['imu_period']>>24) & 0xff;
/// program SCLK divisor and SPI stall time
$sclk_div=round($xclk_freq/$conf['sclk_freq']/2);
if ($sclk_div<1) $sclk_div=1;
else if ($sclk_div>255) $sclk_div=255;
$conf['sclk_freq']=$xclk_freq/$sclk_div/2;
$stall=(( $conf['stall'] * ( $xclk_freq / $sclk_div )) / 1000000 );
if ($stall< 1) $stall= 1; /// does 0 work? need to verify
else if ($stall>255) $stall=255;
$conf['stall']=$stall * 1000000 / ($xclk_freq / $sclk_div);
$data[$index++]= $sclk_div;
$data[$index++]= $stall;
$data[$index++]= 0;
$data[$index++]= 0;
/// Program rs232 baud rate
$rs232_div=round($xclk_freq /2/$conf['baud_rate']);
$conf['baud_rate']=$xclk_freq /2/$rs232_div;
$data[$index++]= $rs232_div & 0xff;
$data[$index++]=($rs232_div>> 8) & 0xff;
$data[$index++]=($rs232_div>>16) & 0xff;
$data[$index++]=($rs232_div>>24) & 0xff;
/// Program logger configuration (possible to modify only some fields - maybe support it here?)
$logger_conf=0;
/// #define IMUCR__IMU_SLOT__BITNM 0 // slot, where 103695 (imu) board is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
/// #define IMUCR__IMU_SLOT__WIDTH 2
$logger_conf |= (($conf['imu_slot'] & 0x3) | 0x4 )<< 0; /// "4" (bit 2 set) here means that the data in bits 0,1 will be applied in the FPGA register
/// #define IMUCR__GPS_CONF__BITNM 3 // slot, where 103695 (imu) bnoard is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
/// #define IMUCR__GPS_CONF__WIDTH 4 // bits 0,1 - slot #, same as for IMU_SLOT, bits 2,3:
// 0 - ext pulse, leading edge,
// 1 - ext pulse, trailing edge
// 2 - start of the first rs232 character after pause
// 3 - start of the last "$" character (start of each NMEA sentence)
$logger_conf |= ((($conf['gps_slot'] & 0x3) | (($conf['gps_mode'] & 0x3)<<2) ) | 0x10 )<< 3;
/// #define IMUCR__MSG_CONF__BITNM 8 // source of external pulses to log:
/// #define IMUCR__MSG_CONF__WIDTH 5 // bits 0-3 - number of fpga GPIO input 0..11 (i.e. 0x0a - external optoisolated sync input (J15)
// 0x0f - disable MSG module
// bit 4 - invert polarity: 0 - timestamp leading edge, log at trailing edge, 1 - opposite
// software may set (up to 56 bytes) log message before trailing end of the pulse
$logger_conf |= (($conf['msg_conf'] & 0x1f) | 0x20 )<< 8;
/// #define IMUCR__SYN_CONF__BITNM 14 // logging frame time stamps (may be synchronized by another camera and have timestamp of that camera)
/// #define IMUCR__SYN_CONF__WIDTH 1 // 0 - disable, 1 - enable
$logger_conf |= (($conf['img_sync'] & 0x1) | 0x2 )<< 14;
/// #define IMUCR__RST_CONF__BITNM 16 // reset module
/// #define IMUCR__RST_CONF__WIDTH 1 // 0 - enable, 1 -reset (needs resettimng DMA address in ETRAX also)
/// #define IMUCR__DBG_CONF__BITNM 18 // several extra IMU configuration bits
/// #define IMUCR__DBG_CONF__WIDTH 4 // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A"
$logger_conf |= (($conf['extra_conf'] & 0xf) | 0x10 )<< 18;
/// next bits used by the driver only, not the FPGA
/// ((SLOW_SPI & 1)<<23) | \
/// (DFLT_SLAVE_ADDR << 24))
$logger_conf |= ($conf['slow_spi'] & 0x1)<< 23;
$logger_conf |= ($conf['imu_sa'] & 0x7)<< 24;
$data[$index++]= $logger_conf & 0xff;
$data[$index++]=($logger_conf>> 8) & 0xff;
$data[$index++]=($logger_conf>>16) & 0xff;
$data[$index++]=($logger_conf>>24) & 0xff;
/// Set time driver will go to sleep if the data is not ready yet (less than full sample in the buffer)
$data[$index++]= $conf['sleep_busy'] & 0xff;
$data[$index++]=($conf['sleep_busy']>> 8) & 0xff;
$data[$index++]=($conf['sleep_busy']>>16) & 0xff;
$data[$index++]=($conf['sleep_busy']>>24) & 0xff;
/// Set IMU register addresses to logger
// echo "1\n";
for ($i=0;$i<28;$i++) $data[$index++]= $conf['imu_registers'][$i]; // truncate to 28
/// Configure NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults
// echo "2\n";
for ($i=0;$i<4;$i++) {
$d =str_split($conf['nmea'][$i][0]);
// print_r($d);
for ($j=0;$j<3;$j++) $data[$index++]=ord($d[$j]);
$d =str_split($conf['nmea'][$i][1]);
// print_r($d);
for ($j=0;$j<29;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
}
// echo "3\n";
/// Set default message
$d =str_split($conf['message']);
for ($j=0;$j<56;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
// Print the result array as hex data
/*
print_r($conf);
echo "\n";
for ($i=0;$i<count($data);$i++) {
if (($i & 0xf)==0) printf ("\n%04x:",$i);
printf (" %02x",$data[$i]);
}
echo "\n";
*/
$bindata="";
for($i=0;$i<count($data);$i++) $bindata.=chr($data[$i]);
$dev_imu_ctl = fopen('/dev/imu_ctl', 'w');
fwrite($dev_imu_ctl, $bindata, strlen($bindata));
fseek($dev_imu_ctl,3,SEEK_END); // start IMU
fclose($dev_imu_ctl);
/// Readback - just testing
$bd=file_get_contents('/dev/imu_ctl');
$data =str_split($bd);
if ($verbose) {
echo "\n";
for ($i=0;$i<count($data);$i++) {
if (($i & 0xf)==0) printf ("\n%04x:",$i);
printf (" %02x",ord($data[$i]));
}
echo "\n";
}
}
function setMessage($msg) {
global $messageOffset;
$data=array();
$d =str_split($msg);
$index=0;
for ($j=0;$j<56;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
$bindata="";
for($i=0;$i<count($data);$i++) $bindata.=chr($data[$i]);
$dev_imu_ctl = fopen('/dev/imu_ctl', 'w');
fseek($dev_imu_ctl,$messageOffset,SEEK_SET); // start IMU
echo ftell($dev_imu_ctl)."<br/>\n";
fwrite($dev_imu_ctl, $bindata, strlen($bindata));
// fseek($dev_imu_ctl,3,SEEK_END); // start IMU
fclose($dev_imu_ctl);
var_dump ( $bindata);
}
function readSettings($conf=null) {
global $xclk_freq; // =80000000; // 80 MHz
$bd=file_get_contents('/dev/imu_ctl');
$data =str_split($bd);
for ($i=0;$i<count($data);$i++) $data[$i]=ord($data[$i]);
/*
// if ($verbose) {
echo "\n";
for ($i=0;$i<count($data);$i++) {
if (($i & 0xf)==0) printf ("\n%04x:",$i);
printf (" %02x",$data[$i]);
}
echo "\n";
// }
*/
if ($conf!=null) {
/// read current period
$conf['imu_period'] =$data[$index++];
$conf['imu_period']|=$data[$index++]<<8;
$conf['imu_period']|=$data[$index++]<<16;
$conf['imu_period']|=$data[$index++]<<24;
/// read current SCLK divisor and SPI stall time
$sclk_div =$data[$index++];
$stall =$data[$index++];
$index++;
$index++;
$conf['sclk_freq']=$xclk_freq/$sclk_div/2;
$conf['stall']=$stall * 1000000 / ($xclk_freq / $sclk_div);
/// read current rs232 baud rate
$rs232_div =$data[$index++];
$rs232_div|=$data[$index++]<<8;
$rs232_div|=$data[$index++]<<16;
$rs232_div|=$data[$index++]<<24;
$conf['baud_rate']=$xclk_freq /2/$rs232_div;
/// read current logger configuration (possible to modify only some fields - maybe support it here?)
/// assuming set bits are set, otherwise it is impossible to find out the old value
$logger_conf =$data[$index++];
$logger_conf|=$data[$index++]<<8;
$logger_conf|=$data[$index++]<<16;
$logger_conf|=$data[$index++]<<24;
/// #define IMUCR__IMU_SLOT__BITNM 0 // slot, where 103695 (imu) board is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
/// #define IMUCR__IMU_SLOT__WIDTH 2
$conf['imu_slot']= ($logger_conf>>0) & 3;
/// #define IMUCR__GPS_CONF__BITNM 3 // slot, where 103695 (imu) bnoard is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
/// #define IMUCR__GPS_CONF__WIDTH 4 // bits 0,1 - slot #, same as for IMU_SLOT, bits 2,3:
// 0 - ext pulse, leading edge,
// 1 - ext pulse, trailing edge
// 2 - start of the first rs232 character after pause
// 3 - start of the last "$" character (start of each NMEA sentence)
// $logger_conf |= ((($conf['gps_slot'] & 0x3) | (($conf['gps_mode'] & 0x3)<<2) ) | 0x10 )<< 3;
$conf['gps_slot']= ($logger_conf >> 3) & 3;
$conf['gps_mode']= ($logger_conf >> 5) & 3;
/// #define IMUCR__MSG_CONF__BITNM 8 // source of external pulses to log:
/// #define IMUCR__MSG_CONF__WIDTH 5 // bits 0-3 - number of fpga GPIO input 0..11 (i.e. 0x0a - external optoisolated sync input (J15)
// 0x0f - disable MSG module
// bit 4 - invert polarity: 0 - timestamp leading edge, log at trailing edge, 1 - opposite
// software may set (up to 56 bytes) log message before trailing end of the pulse
// $logger_conf |= (($conf['msg_conf'] & 0x1f) | 0x20 )<< 8;
$conf['msg_conf']= ($logger_conf >> 8) & 0x1f;
/// #define IMUCR__SYN_CONF__BITNM 14 // logging frame time stamps (may be synchronized by another camera and have timestamp of that camera)
/// #define IMUCR__SYN_CONF__WIDTH 1 // 0 - disable, 1 - enable
// $logger_conf |= (($conf['img_sync'] & 0x1) | 0x2 )<< 14;
$conf['img_sync']= ($logger_conf >> 14) & 0x1;
/// #define IMUCR__RST_CONF__BITNM 16 // reset module
/// #define IMUCR__RST_CONF__WIDTH 1 // 0 - enable, 1 -reset (needs resettimng DMA address in ETRAX also)
/// #define IMUCR__DBG_CONF__BITNM 18 // several extra IMU configuration bits
/// #define IMUCR__DBG_CONF__WIDTH 4 // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A"
// $logger_conf |= (($conf['extra_conf'] & 0xf) | 0x10 )<< 18;
$conf['extra_conf']= ($logger_conf >> 18) & 0xf;
/// next bits used by the driver only, not the FPGA
/// ((SLOW_SPI & 1)<<23) | \
/// (DFLT_SLAVE_ADDR << 24))
// $logger_conf |= ($conf['slow_spi'] & 0x1)<< 23;
// $logger_conf |= ($conf['imu_sa'] & 0x7)<< 24;
$conf['slow_spi']= ($logger_conf >> 23) & 0x1;
$conf['imu_sa']= ($logger_conf >> 24) & 0x7;
/// read current time driver will go to sleep if the data is not ready yet (less than full sample in the buffer)
$conf['sleep_busy'] =$data[$index++];
$conf['sleep_busy']|=$data[$index++]<<8;
$conf['sleep_busy']|=$data[$index++]<<16;
$conf['sleep_busy']|=$data[$index++]<<24;
/// read current IMU register addresses to logger
// echo "1\n";
// for ($i=0;$i<28;$i++) $data[$index++]= $conf['imu_registers'][$i]; // truncate to 28
for ($i=0;$i<28;$i++) $conf['imu_registers'][$i]=$data[$index++];
/// read current NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults
// echo "2\n";
$conf['nmea']=array(array("",""),array("",""),array("",""),array("",""));
for ($i=0;$i<count($conf['nmea']);$i++) {
// $d =str_split($conf['nmea'][$i][0]);
// for ($j=0;$j<3;$j++) $data[$index++]=ord($d[$j]);
for ($j=0;$j<3;$j++) $conf['nmea'][$i][0].=chr($data[$index++]);
// $d =str_split($conf['nmea'][$i][1]);
// for ($j=0;$j<29;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
for ($j=0;$j<29;$j++) {
$d=$data[$index++];
if ($d!=0) $conf['nmea'][$i][1].=chr($d);
else {
$index+=(29-1-$j);
break;
}
}
}
/// read current message
// $conf['message_offset']=$index;
// $d =str_split($conf['message']);
// for ($j=0;$j<56;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
$conf['message']="";
for ($j=0;$j<56;$j++) {
$d=$data[$index++];
if ($d!=0) $conf['message'].=chr($d);
else {
$index+=(56-1-$j);
break;
}
}
// var_dump ($conf);
return $conf;
}
}
?>
/*!***************************************************************************
*! FILE NAME : log_imu.c
*! DESCRIPTION: Read IMU data, copy to stdout
*! Copyright (C) 2011 Elphel, Inc.
*! -----------------------------------------------------------------------------**
*! 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/>.
*! -----------------------------------------------------------------------------**
*! $Log: log_imu.c,v $
*! Revision 1.4 2012/04/14 05:51:19 elphel
*! lseek->lseek64
*!
*! Revision 1.3 2012/04/14 03:53:09 elphel
*! Added parameter to specify how much ahead of the current write pointer to open /dev/imu
*!
*! Revision 1.2 2012/04/13 00:49:59 dzhimiev
*! 1. added 'starting index' to logger
*!
*! Revision 1.1 2012/04/12 00:18:38 elphel
*! simple log program for IMU/GPS/camera output
*!
*/
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <errno.h>
#include <elphel/exifa.h>
#include <signal.h>
#include <asm/byteorder.h> //endians
//#include <elphel/c313a.h>
#include <elphel/x393_devices.h>
//#include "exifgen.h"
//#define EXIF_DEV "/dev/imu"
#define D(x) x
int fd_imu=-1;
int fd_out=-1;
char outFileName [256];
const char dev_path[]=DEV393_PATH(DEV393_LOGGER);
void signalHandler (int signum){
printf ("Received signal %d\n",signum);
if (fd_imu>=0) {
printf ("Closing %s\n",dev_path);
close (fd_imu);
fd_imu=-1;
}
if (fd_out>=0) {
printf ("Closing output file %s\n",outFileName);
close (fd_out);
fd_out=-1;
}
exit(0);
}
int main(int argc, char *argv[]) {
const char usage[]= "Usage:\n%s outfile [start_file_index [number_of_records_per_file] [rewind_by_samples]]\n\n"
"Copy IMU data to the output files, start new file after i/o error or specified number_of_records_per_file (64 bytes each)\n"
"rewind_by_samples - start reading specified number of samples earlier than the last recorded (~2500 samples/sec,\n"
" each sample size is 64-byte, rewind is limited by the 1MB buffer).\n"
"Five-digit file number will be added to the specified output file name.\n\n";
int numFile=1;
int rewindSamples=2500; //~1 sec back
int buf_records=64;
char buffer[buf_records*64];
if (argc < 2) {
printf (usage,argv[0]);
return 0;
}
int numRecords=1000000; // 1 million records (64MB, ~400 seconds)
if (argc >2) numFile= strtol(argv[2], NULL, 10);
if (argc >3) numRecords= strtol(argv[3], NULL, 10);
if (argc >4) rewindSamples= strtol(argv[4], NULL, 10);
strncpy(outFileName,argv[1],249);
outFileName[249]='\0';
char * suffixP=&outFileName[strlen(outFileName)];
int readRecords;
off_t position;
signal (SIGINT,signalHandler);
signal (SIGHUP,signalHandler);
signal (SIGTERM,signalHandler);
while (1) {
if ((fd_imu = open(dev_path, O_RDONLY))<0) {printf("error opening %s\n",dev_path); return -1;}
position= lseek64(fd_imu,0,SEEK_CUR);
if (position == (off_t) -1) {
printf("Error in lseek %s, returned %d, errno=%d - %s, position=0x%llx\n",dev_path,(int) position,errno,strerror(errno), (long long) position);
} else {
printf("Opened %s at position 0x%llx\n",dev_path, (long long) position);
int thisRewind=(position<(64*rewindSamples))?position:(64*rewindSamples);
position= lseek64(fd_imu,-thisRewind,SEEK_CUR);
printf("Rewind back by %d to 0x%llx\r\n",thisRewind, (long long) position);
}
int imu_OK=1;
while (imu_OK) { // will break on error
sprintf(suffixP,"-%05d",numFile);
fd_out=open(outFileName,O_WRONLY | O_CREAT, 0777);
if (fd_out<0) {printf("error opening %s for writing\n",outFileName); return -1;}
int records_left;
for (records_left=numRecords;records_left>0;records_left-=readRecords) {
readRecords=(records_left>buf_records)?buf_records:records_left;
int readBytes=64*readRecords;
int gotBytes=0;
int bp;
for (bp=0;bp<readBytes; bp+=gotBytes) {
gotBytes=read (fd_imu,&buffer[bp], readBytes-bp);
if (gotBytes<0) {
printf("Error reading %s, returned %d, errno=%d - %s, position=0x%llx\r\n", dev_path, gotBytes,errno,strerror(errno), (long long) lseek(fd_imu,0,SEEK_CUR));
imu_OK=0;
break;
}
}
if (!imu_OK) break;
write(fd_out,buffer,readBytes);
}
close (fd_out); // error or end of file
fd_out=-1;
numFile++;
if (!imu_OK) break;
}
close (fd_imu); // after errors
fd_imu=-1;
}
return 0;
}
<?php
/*!***************************************************************************
*! FILE NAME : logger_launcher.php
*! DESCRIPTION: launches the event logger (IMU/GPS/External trigger/Other sensor) a dies
*! Copyright (C) 2012 Elphel, Inc
*! -----------------------------------------------------------------------------**
*!
*! 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/>.
*! -----------------------------------------------------------------------------**
*! $Log: logger_launcher.php,v $
*! Revision 1.6 2013/05/29 18:43:01 dzhimiev
*! 1. sync instead of unmount at stop
*!
*! Revision 1.4 2012/10/10 22:44:52 dzhimiev
*! 1. added _help & _usage
*!
*! Revision 1.3 2012/07/09 23:49:26 dzhimiev
*! 1. added mount/umount options
*!
*! Revision 1.2 2012/04/13 00:49:59 dzhimiev
*! 1. added 'starting index' to logger
*!
*!
*! Revision 1.1 2012/04/13 00:22:51 dzhimiev
*! 1. added logger_launcher.php
*!
*!
*/
include 'show_source.inc';
//default parameters
$cmd = "start";
$file = "/usr/html/CF/imu_log.log";
$index = 1;
$n = 5000000;
$mount_point = "/usr/html/CF";
$force_dev = false;
$xml = "<Document>\n";
//get parameters
if (isset($_GET['cmd'])) $cmd = $_GET['cmd'];
if (isset($_GET['file'])) $file = $_GET['file'];
if (isset($_GET['index'])) $index = $_GET['index'];
if (isset($_GET['n'])) $n = $_GET['n'];
if (isset($_GET['mount_point'])) $mount_point = $_GET['mount_point'];
if (isset($_GET['dev'])) {
$dev = $_GET['dev'];
$force_dev = true;
}
if ($cmd=="start") {
if (!is_dir($mount_point)) mkdir($mount_point);
//detect devices
//$dev = "/dev/hda1";
if (!$force_dev) {
$hda1 = exec("cat /proc/diskstats | grep 'hda1'");
$hdb1 = exec("cat /proc/diskstats | grep 'hdb1'");
if (strlen($hda1)>0) $dev = "/dev/hda1";
else if (strlen($hdb1)>0) $dev = "/dev/hdb1";
else {
$xml .= "\t<error>CF cards not found</error>\n";
send_response($xml);
}
}
exec("mount $dev $mount_point");
exec("/usr/local/bin/log_imu $file $index $n >/dev/null 2>&1 &");
$xml .= "\t<result>ok</result>\n";
}
if ($cmd=="stop") {
exec("killall -1 log_imu");
//unmount
//exec("umount $mount_point");
exec("sync");
$xml .= "\t<result>ok</result>\n";
}
$xml .= "</Document>";
send_response($xml);
function send_response($xml){
header("Content-Type: text/xml");
header("Content-Length: ".strlen($xml)."\n");
header("Pragma: no-cache\n");
printf("%s", $xml);
flush();
}
function _help(){
echo "<pre>\n";
echo "Usage example: 'http://192.168.0.9/logger_launcher.php?file=/usr/html/CF/test.log&index=1&n=1000000&dev=/dev/hdb1', where\n";
echo "'file'- log name (includes absolute path), '/usr/html/CF/' is the 'dev's mount point\n";
echo "'index'- index added to the log name\n";
echo "'n'- max number of records in a single log file\n";
echo "'dev'- device name: '/dev/hda1' or '/dev/hdb1'\n";
}
function _usage(){
_help();
}
?>
\ No newline at end of file
/*!***************************************************************************
*! FILE NAME : nmea2exif.c
*! DESCRIPTION: converts GPS NMEA output (just $GPRMC, $GPGGA) to Exif
*! in Elphel cameras
*! Copyright (C) 2009 Elphel, Inc.
*! -----------------------------------------------------------------------------**
*! 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/>.
*! -----------------------------------------------------------------------------**
*! $Log: nmea2exif.c,v $
*! Revision 1.4 2011/01/15 23:22:46 elphel
*! fixed reporting fraction of second in GPS timestamp
*!
*! Revision 1.3 2009/02/19 09:09:30 elphel
*! Bug fix in GPS seconds
*!
*! Revision 1.2 2009/02/19 09:02:39 elphel
*! added GPGGA
*!
*! Revision 1.1 2009/02/19 08:24:07 elphel
*! added nmea2exif that processes NMEA $GPRMC sentences and encodes them in Exif headers
*!
*!
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <elphel/exifa.h>
#include <asm/byteorder.h> //endians
#include <elphel/x393_devices.h>
#include <elphel/c313a.h>
//#include "exifgen.h"
//#define EXIF_DEV "/dev/exif_meta"
#define PROGRAM_SERIAL 0
//#define D(x)
#define D(x) x
// TODO: use only existing sensor channels?
const char *exif_paths[SENSOR_PORTS] = {
DEV393_PATH(DEV393_EXIF_META0),
DEV393_PATH(DEV393_EXIF_META1),
DEV393_PATH(DEV393_EXIF_META2),
DEV393_PATH(DEV393_EXIF_META3)};
void exif_init_meta(struct meta_GPSInfo_t *meta) {
meta->GPSLatitudeRef= 'N';
meta->GPSLatitude_deg_nom= __cpu_to_be32((int) 0);
meta->GPSLatitude_deg_denom= __cpu_to_be32((int) 1);
meta->GPSLatitude_min_nom= __cpu_to_be32((int) 0);
meta->GPSLatitude_min_denom= __cpu_to_be32((int) EXIF_GPS_MIN_DENOM);
meta->GPSLongitudeRef= 'W';
meta->GPSLongitude_deg_nom= __cpu_to_be32((int) 0);
meta->GPSLongitude_deg_denom=__cpu_to_be32((int) 1);
meta->GPSLongitude_min_nom= __cpu_to_be32((int) 0);
meta->GPSLongitude_min_denom=__cpu_to_be32((int) EXIF_GPS_MIN_DENOM);
meta->GPSAltitudeRef= 0; //byte, not ascii 0 - above sea level, 1 - below
meta->GPSAltitude_nom= __cpu_to_be32((int) 0); //in meters
meta->GPSAltitude_denom= __cpu_to_be32((int) EXIF_GPS_METERS_DENOM);
meta->GPSTimeStamp_hrs_nom= __cpu_to_be32((int) 0);
meta->GPSTimeStamp_hrs_denom=__cpu_to_be32((int) 1);
meta->GPSTimeStamp_min_nom= __cpu_to_be32((int) 0);
meta->GPSTimeStamp_min_denom=__cpu_to_be32((int) 1);
meta->GPSTimeStamp_sec_nom= __cpu_to_be32((int) 0);
meta->GPSMeasureMode= '0';
meta->GPSTimeStamp_sec_denom=__cpu_to_be32((int) EXIF_GPS_TIMESEC_DENOM);
// meta->GPSDateStamp[10]; //1 less than defined - no '\0';
}
/*
eg2. $GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68
225446 Time of fix 22:54:46 UTC
A Navigation receiver warning A = OK, V = warning
4916.45,N Latitude 49 deg. 16.45 min North
12311.12,W Longitude 123 deg. 11.12 min West
000.5 Speed over ground, Knots
054.7 Course Made Good, True
191194 Date of fix 19 November 1994
020.3,E Magnetic variation 20.3 deg East
*68 mandatory checksum
*/
void process_GPRMC(char*response, struct meta_GPSInfo_t *meta) {
char * cp;
int h, m, s, isOK,idg,imn,mm,dd,yy;
double lld;
double ds;
cp=strchr(response,',');
/// Read UTC time hhmmss
if (cp) {
cp++; /// first charater in time
// s=strtol(cp, &cp,10); ///cp now "," after time s=hhmmss
ds=strtod(cp, &cp); ///cp now "," after time s=hhmmss.sss
s=(int) ds;
ds-=s;
h=s/10000; s-=h*10000;
m=s/100; s-=m*100;
ds+=s;
// D(printf ("%02d:%02d:%02d\n",h,m,s));
// D(printf ("%02d:%02d:%05d (%f)\n",h,m,(int) (ds*EXIF_GPS_TIMESEC_DENOM+0.5), ds));
meta->GPSTimeStamp_hrs_nom= __cpu_to_be32((int) h);
meta->GPSTimeStamp_min_nom= __cpu_to_be32((int) m);
meta->GPSTimeStamp_sec_nom= __cpu_to_be32((int) (ds*EXIF_GPS_TIMESEC_DENOM+0.5));
cp=strchr(cp,',');
}
///Read is OK use as fix/no fix?
isOK=0;
if (cp) {
cp++; /// first charater
isOK=(cp[0]=='A')?1:0;
meta->GPSMeasureMode= (isOK)?'3':'2'; /// '0' is not allowed
cp=strchr(cp,',');
}
/// Read latitude
if (cp) {
cp++; /// first character
lld=strtod(cp, &cp); ///cp now "," dddmm.mmmmm
idg=lld/100;
lld-=100*idg;
imn=lld*EXIF_GPS_MIN_DENOM+0.5;
meta->GPSLatitude_deg_nom= __cpu_to_be32(idg);
meta->GPSLatitude_min_nom= __cpu_to_be32(imn);
cp=strchr(cp,',');
}
/// Read latitude reference (N/S)
if (cp) {
cp++; /// first character
if (cp[0]=='S') meta->GPSLatitudeRef='S';
else meta->GPSLatitudeRef='N';
cp=strchr(cp,',');
}
/// Read longitude
if (cp) {
cp++; /// first character
lld=strtod(cp, &cp); ///cp now "," dddmm.mmmmm
idg=lld/100;
lld-=100*idg;
imn=lld*EXIF_GPS_MIN_DENOM+0.5;
meta->GPSLongitude_deg_nom= __cpu_to_be32(idg);
meta->GPSLongitude_min_nom= __cpu_to_be32(imn);
cp=strchr(cp,',');
}
/// Read longitude reference (E/W)
if (cp) {
cp++; /// first character
if (cp[0]=='W') meta->GPSLongitudeRef='W';
else meta->GPSLongitudeRef='E';
cp=strchr(cp,',');
}
/// Skip Speed, Course,
if (cp) {
cp++; /// first character
cp=strchr(cp,',');
}
if (cp) {
cp++; /// first character
cp=strchr(cp,',');
}
/// Read date DDMMYY
if (cp) {
cp++; /// first character in time
yy=strtol(cp, &cp,10); ///cp now ","yy=DDMMYY
dd=yy/10000; yy-=dd*10000;
mm=yy/100; yy-=mm*100;
sprintf((char *) (meta->GPSDateStamp), "20%02d:%02d:%02d", yy, mm,dd);
cp=strchr(cp,',');
}
/// skip the rest - magnetic variation and it's direction (E/W)
}
/*
$GPGGA
Global Positioning System Fix Data
Name Example Data Description
Sentence Identifier $GPGGA Global Positioning System Fix Data
Time 170834 17:08:34 Z
Latitude 4124.8963, N 41d 24.8963' N or 41d 24' 54" N
Longitude 08151.6838, W 81d 51.6838' W or 81d 51' 41" W
Fix Quality:
- 0 = Invalid
- 1 = GPS fix
- 2 = DGPS fix 1 Data is from a GPS fix
Number of Satellites 05 5 Satellites are in view
Horizontal Dilution of Precision (HDOP) 1.5 Relative accuracy of horizontal position
Altitude 280.2, M 280.2 meters above mean sea level
Height of geoid above WGS84 ellipsoid -34.0, M -34.0 meters
Time since last DGPS update blank No last update
DGPS reference station id blank No station id
Checksum *75 Used by program to check for transmission errors
---
eg3. $GPGGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh
1 = UTC of Position
2 = Latitude
3 = N or S
4 = Longitude
5 = E or W
6 = GPS quality indicator (0=invalid; 1=GPS fix; 2=Diff. GPS fix)
7 = Number of satellites in use [not those in view]
8 = Horizontal dilution of position
9 = Antenna altitude above/below mean sea level (geoid)
10 = Meters (Antenna height unit)
11 = Geoidal separation (Diff. between WGS-84 earth ellipsoid and
mean sea level. -=geoid is below WGS-84 ellipsoid)
12 = Meters (Units of geoidal separation)
13 = Age in seconds since last update from diff. reference station
14 = Diff. reference station ID#
15 = Checksum
*/
void process_GPGGA(char*response, struct meta_GPSInfo_t *meta) {
char * cp;
int h, m, s, isOK,idg,imn;
double lld;
double ds;
cp=strchr(response,',');
/// Read UTC time hhmmss
if (cp) {
cp++; /// first character in time
// s=strtol(cp, &cp,10); ///cp now "," after time s=hhmmss
ds=strtod(cp, &cp); ///cp now "," after time s=hhmmss.sss
s=(int) ds;
ds-=s;
h=s/10000; s-=h*10000;
m=s/100; s-=m*100;
ds+=s;
meta->GPSTimeStamp_hrs_nom= __cpu_to_be32((int) h);
meta->GPSTimeStamp_min_nom= __cpu_to_be32((int) m);
meta->GPSTimeStamp_sec_nom= __cpu_to_be32((int) (ds*EXIF_GPS_TIMESEC_DENOM+0.5));
cp=strchr(cp,',');
}
/// Read latitude
if (cp) {
cp++; /// first character
lld=strtod(cp, &cp); ///cp now "," dddmm.mmmmm
idg=lld/100;
lld-=100*idg;
imn=lld*EXIF_GPS_MIN_DENOM+0.5;
meta->GPSLatitude_deg_nom= __cpu_to_be32(idg);
meta->GPSLatitude_min_nom= __cpu_to_be32(imn);
cp=strchr(cp,',');
}
/// Read latitude reference (N/S)
if (cp) {
cp++; /// first character
if (cp[0]=='S') meta->GPSLatitudeRef='S';
else meta->GPSLatitudeRef='N';
cp=strchr(cp,',');
}
/// Read longitude
if (cp) {
cp++; /// first character
lld=strtod(cp, &cp); ///cp now "," dddmm.mmmmm
idg=lld/100;
lld-=100*idg;
imn=lld*EXIF_GPS_MIN_DENOM+0.5;
meta->GPSLongitude_deg_nom= __cpu_to_be32(idg);
meta->GPSLongitude_min_nom= __cpu_to_be32(imn);
cp=strchr(cp,',');
}
/// Read longitude reference (E/W)
if (cp) {
cp++; /// first character
if (cp[0]=='W') meta->GPSLongitudeRef='W';
else meta->GPSLongitudeRef='E';
cp=strchr(cp,',');
}
///6 = GPS quality indicator (0=invalid; 1=GPS fix; 2=Diff. GPS fix)
isOK=0;
if (cp) {
cp++; /// first character
isOK=(cp[0]=='0')?0:1;
meta->GPSMeasureMode= (isOK)?'3':'2'; /// '0' is not allowed
cp=strchr(cp,',');
}
/*
7 = Number of satellites in use [not those in view]
8 = Horizontal dilution of position
9 = Antenna altitude above/below mean sea level (geoid)
*/
/// Skip 7 = Number of satellites in use [not those in view]
if (cp) {
cp++; /// first character
cp=strchr(cp,',');
}
/// Skip 8 = Horizontal dilution of position
if (cp) {
cp++; /// first character
cp=strchr(cp,',');
}
/// Read 9 = Antenna altitude above/below mean sea level (geoid)
if (cp) {
cp++; /// first character
idg=EXIF_GPS_METERS_DENOM*strtod(cp, &cp)+0.5; ///cp now "," +/-mm.mmmmm
if (idg <0) {
idg=-idg;
meta->GPSAltitudeRef=1;
} else {
meta->GPSAltitudeRef=0;
}
meta->GPSAltitude_nom= __cpu_to_be32(idg); /// in meters
cp=strchr(cp,',');
}
/// Skip 10 = Meters (Antenna height unit) 'M'
if (cp) {
cp++; /// first character
cp=strchr(cp,',');
}
/// Skip 11 = Geoidal separation (Diff. between WGS-84 earth ellipsoid and mean sea level. -=geoid is below WGS-84 ellipsoid)
if (cp) {
cp++; /// first character
cp=strchr(cp,',');
}
/// Skip 12 = Meters (Antenna height unit) 'M'
if (cp) {
cp++; /// first character
cp=strchr(cp,',');
}
/// skip the rest:
/// Skip 13 = Age in seconds since last update from diff. reference station
/// Skip 14 = Diff. reference station ID#
}
int main(int argc, char *argv[]) {
FILE *fgps;
int i,chn, good_chns;
int fd_exif[SENSOR_PORTS];
char response[256];
int response_len;
char * cp, *cp_cs;
unsigned char cs_calc, cs_read;
struct meta_GPSInfo_t meta;
#if PROGRAM_SERIAL
int fd_gps;
struct termios termio;
#endif
exif_init_meta(&meta);
if (argc < 2) {
printf("Usage: %s GPS_device\n", argv[0]);
exit (-1);
}
good_chns=0;
for (chn =0; chn < SENSOR_PORTS; chn++){
if (exif_paths[chn]) { // make them null if inactive
fd_exif[chn] = open(exif_paths[chn], O_RDWR);
if (fd_exif[chn] < 0) {
fprintf(stderr,"Can not open device file %s\n",exif_paths[chn]);
}
} else good_chns++;
}
if (!good_chns){
fprintf(stderr,"Could not open any of EXIF channel device files, aborting\n");
exit (-1);
}
#if PROGRAM_SERIAL
fd_gps = open(argv[1], O_RDWR);
if (fd_gps == -1) {
perror("Cannot open gps device");
for (chn =0; chn < SENSOR_PORTS; chn++) if (fd_exif[chn]>=0){
close(fd_exif[chn]);
}
exit (-1);
}
tcgetattr(fd_gps, &termio);
/// exec ("stty -F $ser_port onlcr -echo speed 19200");
//int cfsetispeed(struct termios *termios_p, speed_t speed);
//int cfsetospeed(struct termios *termios_p, speed_t speed);
//B19200
///TODO: use xml configuration file for different devices. Or just move it out of this program?
cfsetospeed(&termio, B19200);
tcsetattr(fd_gps, TCIOFLUSH, &termio);
#endif
#if PROGRAM_SERIAL
fgps=fopen(argv[1], "r+"); // probably "r" is enough - we do not want to control it here
#else
fgps=fopen(argv[1], "r");
#endif
if (!fgps) {
perror("Cannot open gps device!");
exit (-1);
}
while (1) {
fgets(response,sizeof(response),fgps);
if ((cp=strchr(response,'\n'))) cp[0]='\0';
if ((cp=strchr(response,'\r'))) cp[0]='\0';
// D(printf("response: >>%s<<\n",response));
///verify NMEA $...*HH
response_len=strlen(response);
if (response_len>0) {
if (response_len>4) {
if ((cp_cs=strchr(response,'*'))) {
cp_cs[0]='\0';
cp_cs++;
cs_read= strtol(cp_cs, NULL, 16);
cs_calc=0;
for (i=1; response[i]; i++) cs_calc^=response[i];
// unsigned char cs_calc, cs_read;
if (cs_calc==cs_read ) {
// D(printf ("Got NMEA string >>%s<<\n",response+1));
/// Is it $GPRMC string?
// if (!strncmp(response+1,"GPRMC", sizeof("GPRMC"))) {
if (!memcmp(response+1,"GPRMC", sizeof("GPRMC")-1)) {
// D(printf ("Got GPRMC\n"));
D(printf ("Got NMEA string >>%s<<\n",response+1));
process_GPRMC(response, &meta);
for (chn =0; chn < SENSOR_PORTS; chn++) if (fd_exif[chn]>=0){
lseek (fd_exif[chn],Exif_GPSInfo_GPSLatitudeRef,SEEK_END); /// position file pointer at the beginning of the data field for GPSLatitudeRef
write (fd_exif[chn], &meta, sizeof(meta));
}
} else if (!memcmp(response+1,"GPGGA", sizeof("GPGGA")-1)) {
// D(printf ("Got GPRMC\n"));
D(printf ("Got NMEA string >>%s<<\n",response+1));
process_GPGGA(response, &meta);
for (chn =0; chn < SENSOR_PORTS; chn++) if (fd_exif[chn]>=0){
lseek (fd_exif[chn],Exif_GPSInfo_GPSLatitudeRef,SEEK_END); /// position file pointer at the beginning of the data field for GPSLatitudeRef
write (fd_exif[chn], &meta, sizeof(meta));
}
} else {
// D(printf ("Got other NMEA string >>%s<<\n",response+1));
}
} else D(printf("Checksum mismatch: read 0x%x, calculated 0x%x\n",(int)cs_read,(int)cs_calc));
} else D(printf("No '*' in response, ignoring\n"));
} else D(printf("response to short (%d), ignoring\n",response_len));
}
}
return 0;
}
#!/usr/bin/env php -q
<?php
/*
*! FILE NAME : start_gps_compass.php
*! DESCRIPTION: Looks for USB GPS (currently Garmin GPS 18 USB) and compass
*! (currently Ocean Server OS-5000), re-initializes Exif header
*! and starts the devices if found
*!
*! Copyright (C) 2008 Elphel, Inc
*! -----------------------------------------------------------------------------**
*!
*! 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/>.
*! -----------------------------------------------------------------------------**
*! $Log: start_gps_compass.php,v $
*! Revision 1.6 2012/03/14 00:05:41 elphel
*! 8.2.1 - GPS speed, x353.bit file tested on Eyesis
*!
*! Revision 1.5 2011/08/13 00:55:14 elphel
*! support for detection 103595 and 103696 boards, programming the logger
*!
*! Revision 1.4 2011/01/15 23:22:10 elphel
*! added 19200
*!
*! Revision 1.3 2009/02/20 21:49:52 elphel
*! bugfix - was killing daemons after detection, not before (as should)
*!
*! Revision 1.2 2009/02/19 22:38:37 elphel
*! 8.0.2.3 - added several USB serial adapters, nmea->exif support, detection of NMEA GPS at boot
*!
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*!
*!
*! Revision 1.2 2008/11/20 07:03:40 elphel
*! exit value now encodes detected devices
*!
*! Revision 1.1 2008/04/07 09:14:47 elphel
*! Discover/startup GPS and compass
*!
*/
//look uptime, sleep if just started (no USB yet)
//require '/usr/html/includes/i2c.inc';
#require 'i2c.inc';
set_include_path(get_include_path() . PATH_SEPARATOR . '/www/pages/include');
require 'i2c_include.php';
$config_name = "/etc/elphel393/imu_logger.xml";
$gps_compass_xml = "/www/pages/gps_compass.xml";
$i2cbus = 4;
$ids=scanGrandDaughters();
$b_index=indexGrandDaughters($ids);
// print_r($ids);
// print_r($b_index);
$baud=null;
if (isset($b_index[103696])) {
$baud=$ids[$b_index[103696]]['baud'];
if ($baud===0) $baud=='auto';
}
// exit (0);
$wait_time=20; // wait for $wait_time if both devices were not found, retry
$compass=null;
$GPS=null;
$verbose=true;
foreach ($_SERVER['argv'] as $param) {
if ((substr($param,0,2)=="-q") || (substr($param,0,8)=="--silent")){
$verbose=false;
}
}
/// kill those GPS and compass if they are running already
exec('killall -q garminusb2exif');
exec('killall -q nmea2exif');
exec('killall -q compass');
// find_gps_compass();
$devs=find_gps_compass($baud);
// echo "compass: ";var_dump($compass);echo "\n";
// echo "GPS: ";var_dump($GPS);echo "\n";
// if ((!$compass || !$GPS) && ((exec('date +%s')+0) <30)) {
if ((count($devs)==0) && ((exec('date +%s')+0) <30)) {
if ($verbose) echo "waiting $wait_time sec for USB devices to start up\n";
sleep($wait_time);
if ($verbose) echo "Retrying detection\n";
$devs=find_gps_compass($baud);
}
listSensorDevices($devs,$b_index,$ids);
//var_dump($GPS);
// if (file_exists ($sensor_state_file)) $sensor_board=parse_ini_file($sensor_state_file);
// exec ('sync');
$logger_config=null;
$write_config=false;
if (file_exists ($config_name)) {
if ($verbose) echo 'Reading IMU logger configuration from '. $config_name."\n";
$config_xml = simplexml_load_file($config_name);
$logger_config=loggerConfigFromXML($config_xml);
} else if (isset($b_index[103696]) || isset($b_index[103696])) {
if ($verbose) echo "Generating IMU logger configuration\n";
// $default_config=init_default_config();
// $logger_config=init_default_config();
$logger_config=array();
if (isset($GPS) && isset($b_index[103696])) {
$logger_config['baud_rate']=$GPS['baud'];
$logger_config['gps_slot']=$ids[$b_index[103696]]['port'];
$logger_config['gps_mode']=$ids[$b_index[103696]]['sync'];
}
if (isset($b_index[103695])) {
$logger_config['imu_slot']=$ids[$b_index[103695]]['port'];
$logger_config['imu_sa']=$b_index[103695];
}
$write_config=true; // write configuration to /etc after applying defaults
}
if (isset($logger_config)){
// var_dump($logger_config);
$logger_config=combineLoggerConfigs($logger_config,init_default_config());
// var_dump($logger_config);
// var_dump($default_config);
$logger_xml=loggerConfigToXML($logger_config);
$conf_file=fopen('/var/html/logger_config.xml',"w");
fwrite($conf_file,$logger_xml->asXML());
fclose($conf_file);
setup_IMU_logger($logger_config);
if ($write_config) {
if ($verbose) echo 'Writing IMU logger configuration to '. $config_name."\n";
$conf_file=fopen($config_name,"w");
fwrite($conf_file,$logger_xml->asXML());
fclose($conf_file);
exec ('sync');
}
}
// echo "compass: ";var_dump($compass);echo "\n";
// echo "GPS: ";var_dump($GPS);echo "\n";
$noGPS= ($compass || $GPS)?"" : "noGPS";
$nocompass=($compass)?"" : "nocompass";
$cmd="/usr/html/exif.php init $noGPS $nocompass";
if ($verbose) echo "Initializing Exif template: $cmd\n";
exec($cmd);
if ($GPS) {
if ($verbose) echo "Starting ".$GPS["name"]. " as ". $GPS["file"]. "\n";
if (strpos($GPS['name'],'NMEA')!==false) {
$cmd ="/usr/local/bin/nmea2exif ". $GPS["file"]." &";
} else {
$cmd ="/usr/local/bin/garminusb2exif ". $GPS["file"]." &";
}
if ($verbose) echo "exec: $cmd \n";
popen($cmd,"r");
}
if ($compass) {
if ($verbose) echo "Starting ".$compass["name"]. " as ". $compass["file"]. "\n";
exec ("stty -F ".$compass["file"]." -echo speed 19200");
$cmd="/usr/local/bin/compass ". $compass["file"]." &";
if ($verbose) echo "exec: $cmd \n";
popen($cmd,"r");
}
exit ((isset($b_index[103695])?4:0) | ($compass?2:0) | ($GPS?1:0));
function scanGrandDaughters(){
global $i2cbus;
$ids=array();
$id="";
for ($i=2;$i<8;$i++) {
$id=i2c_read256b(0xa0+2*$i,$i2cbus);
$xml=simplexml_load_string($id);
if (($xml!==false) && ($xml->getName()=='board')) {
$ids[$i]=array();
foreach ($xml->children() as $entry) {
$ids[$i][$entry->getName()]=(string) $entry ;
}
}
}
return $ids;
}
function indexGrandDaughters($ids) {
$index=array();
foreach($ids as $i=>$id) if (isset($id['model'])) {
$index[$id['model']]=$i;
}
return $index;
}
/// compass/GPS programs should be killed before detection
// baud=null - search USB Garmin and compass
// baud=auto - try to autodetect baud rate
// baud=number - used specified baud rate, do not wait for the GPS response
function find_gps_compass($baud=null,$timeout=5) {
global $verbose;
$ttyOptions=array (
'-echo speed 115200',
'-echo speed 57600',
'-echo speed 56000',
'-echo speed 38400',
'-echo speed 19200', /// maybe other options, like '-echo speed 4800 -ixoff'
'-echo speed 9600',
'-echo speed 4800',
'-echo speed 2400'
);
if (isset($baud) && ($baud!='auto') && ($baud!=0)) {
$ttyOptions=array (
'-echo speed '.$baud);
}
// global $GPS, $compass;
$devices=array(
"compass"=>array(array("name"=>"Ocean Server OS-5000","driver"=>"cp2101")),
"GPS" =>array(array("name"=>"Garmin GPS 18 USB","driver"=>"garmin_gps")));
exec("ls /sys/bus/usb-serial/devices",$usb_ser_devs); // ("ttyUSB0","ttyUSB1")
$devs = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><USB_serial_devices/>");
$serialDevices=array();
$compassPresent=false;
$gpsPresent=false;
$driver=array();
//echo "usb_ser_devs"; var_dump($usb_ser_devs);
foreach ($usb_ser_devs as $dev) {
//echo "dev=$dev\n";
$arr=split("/",exec("ls /sys/bus/usb-serial/devices/".$dev."/driver -l"));
$driver[$dev]=$arr[count($arr)-1];
$serialDevices[$dev]='';
if (!isset($baud)) { // if baud is set (auto or number - skip compass, it is 103696)
foreach ($devices["compass"] as $d) {
if ($d["driver"]==$driver[$dev]) {
$dd=$devs->addChild ('compass');
$dd->addChild ('name',$d["name"]);
$dd->addChild ('driver',$d["driver"]);
$dd->addChild ('file',"/dev/".$dev);
$serialDevices[$dev]='compass';
$compassPresent=true;
}
}
}
if ($serialDevices[$dev]) continue;
foreach ($devices["GPS"] as $d) {
if ($d["driver"]==$driver[$dev]) {
$dd=$devs->addChild ('GPS');
$dd->addChild ('name',$d["name"]);
$dd->addChild ('driver',$d["driver"]);
$dd->addChild ('file',"/dev/".$dev);
$serialDevices[$dev]='gps';
$gpsPresent=true;
}
}
}
/// Do we need to look for a NMEA GPS?
if (!$gpsPresent) foreach ($serialDevices as $dev=>$type) if (!$type && !$gpsPresent) {
if ($verbose) printf ("could be $dev\n");
foreach ($ttyOptions as $ttyOpt) {
$cmd='stty -F /dev/'.$dev.' '.$ttyOpt;
if (count($ttyOptions)==1) { /// single baud option, will not wait for confirmation. Has to be only one serial adapter !!
if ($verbose) echo "Setting: $cmd\n";
exec ($cmd);
$gpsPresent=true;
} else {
if ($verbose) echo "Trying: $cmd\n";
exec ($cmd);
unset ($fullOutput);
exec ('timeout '.$timeout.' cat /dev/'.$dev, $fullOutput); // &$fullOutput - Fatal error: Call-time pass-by-reference has been removed in php
//var_dump($fullOutput);
foreach ($fullOutput as $line) if (strpos ($line, '$GP')===0) {
$gpsPresent=true;
break;
}
}
if ($gpsPresent) {
$dd=$devs->addChild ('GPS');
$dd->addChild ('name','NMEA 0183 GPS receiver');
$dd->addChild ('driver',$driver[$dev]);
$dd->addChild ('file',"/dev/".$dev);
$arr=split(" ",$ttyOpt);
$dd->addChild ('baud',$arr[count($arr)-1]);
$serialDevices[$dev]='gps';
if ($verbose) echo "\nfound NMEA GPS unit\n";
break;
}
// var_dump($fullOutput);
}
}
/// list unused USB serial adapters
foreach ($serialDevices as $dev=>$type) if (!$type) {
$dd=$devs->addChild ('unused');
$dd->addChild ('name','USB serial converter');
$dd->addChild ('driver',$driver[$dev]);
$dd->addChild ('file',"/dev/".$dev);
}
return $devs;
}
function listSensorDevices($devs,$b_index,$ids) {
global $GPS, $compass,$gps_compass_xml;
foreach ($devs->compass as $a) {
$compass=array("file"=>(string) $a->file, "name"=> (string) $a->name);
break; // use first one
}
foreach ($devs->GPS as $a) {
$GPS=array("file"=>(string) $a->file, "name"=> (string) $a->name, "baud"=>(string) $a->baud);
if (isset($b_index[103696])) {
$a->addChild ('part_number',$ids[$b_index[103696]]['part']);
$a->addChild ('port',$ids[$b_index[103696]]['port']);
$a->addChild ('mode',$ids[$b_index[103696]]['mode']);
}
break; // use first one
}
$state_file=fopen($gps_compass_xml,"w");
fwrite($state_file,$devs->asXML());
fclose($state_file);
}
function loggerConfigToXML($conf){
$logger_xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><Logger_configuration/>");
foreach ($conf as $key=>$value) {
switch ($key) {
case 'imu_registers':
$subtree=$logger_xml->addChild ($key);
for ($i=0;$i<count($value);$i++) {
$subtree->addChild ('R_'.sprintf('%02d',$i),sprintf("0x%02x",$value[$i]));
}
break;
case 'nmea':
$subtree=$logger_xml->addChild ($key);
for ($i=0;$i<count($value);$i++) {
$sentence=$subtree->addChild ('S_'.sprintf('%01d',$i));
$sentence->addChild ('sentence',$value[$i][0]);
$sentence->addChild ('format',$value[$i][1]);
}
break;
default:
$logger_xml->addChild ($key,$value);
}
}
return $logger_xml;
}
function loggerConfigFromXML($confXML){
$conf=array();
// var_dump($confXML);
foreach ($confXML as $item) {
// var_dump($item);
$key=$item->getName();
switch ($key) {
case 'imu_registers':
$conf[$key]=array();
foreach ($item as $reg) {
$rname=substr($reg->getName(),2);
$conf[$key][$rname+0]=((string) $reg)+0;
}
break;
case 'nmea':
$conf[$key]=array();
foreach ($item as $reg) {
$rname=substr($reg->getName(),2);
$conf[$key][$rname+0]=array((string) $reg->sentence, (string) $reg->format);
}
break;
case 'imu_period':
$conf[$key]=(string) $item;
if ($conf[$key]!='auto') $conf[$key]+=0;
break;
case 'message':
$conf[$key]=(string) $item;
break;
default:
// $conf[$key]=(int) $item;
$conf[$key]=((string) $item)+0;
}
}
return $conf;
}
function init_default_config(){
$default_config=array(
'imu_period'=>'auto',// 0xFFFFFFFF, // 0 - off, >=0xff000000 - "when ready", else - number of SCLK periods
'sclk_freq'=>5000000, // $clkr_divr= 8, // 80MHz divisor to get half SCLK rate (defaulkt SCLK=5MHz)
'stall' => 2, // SPI stall time in usec
'baud_rate'=>19200, // $rs232_div=80/2/$baud
'imu_slot'=>1,
'gps_slot'=>2,
'gps_mode'=>2, // 0 - pps pos, 1 - pps neg, 2 - start of first sesntence after pause, 3 start of sentence
'msg_conf'=>10, // GPIO bit number for external (odometer) input (+16 - invert polarity). Timestamp uses leading edge, software may write to 56-byte buffer before the trailing edge
'img_sync'=>1, // enable logging image acquisition starts (0 - disable)
'extra_conf'=>4, // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A"
'slow_spi'=>0, // set to 1 for slow SPI devices (0 for ADIS-16375)
'imu_sa'=>3, // i2c slave address modifier for the 103695A pca9500
'sleep_busy'=>30000, //microseconds
'imu_registers'=>array( /// Up to 28 total
0x10, // x gyro low
0x12, // x gyro high
0x14, // y gyro low
0x16, // y gyro high
0x18, // z gyro low
0x1a, // z gyro high
0x1c, // x accel low
0x1e, // x accel high
0x20, // y accel low
0x22, // y accel high
0x24, // z accel low
0x26, // z accel high
0x40, // x delta angle low
0x42, // x delta angle high
0x44, // y delta angle low
0x46, // y delta angle high
0x48, // z delta angle low
0x4a, // z delta angle high
0x4c, // x delta velocity low
0x4e, // x delta velocity high
0x50, // y delta velocity low
0x52, // y delta velocity high
0x54, // z delta velocity low
0x56, // z delta velocity high
0x0e, // temperature
0x70, // time m/s
0x72, // time d/h
0x74// time y/m
),
'nmea'=>array(
/// first three letters - sentence to log (letters after "$GP"). next "n"/"b" (up to 24 total) - "n" number (will be encoded 4 digits/byte, follwed by "0xF"
/// "b" - byte - all but last will have MSB 0 (& 0x7f), the last one - with MSB set (| 0x80). If there are no characters in the field 0xff will be output
array('RMC','nbnbnbnnnnb'),
array('GGA','nnbnbnnnnbnbbb'),
array('GSA','bnnnnnnnnnnnnnnnn'),
array('VTG','nbnbnbnb')
),
'message'=>'Odometer message' // Message - up to 56 bytes
);
return $default_config;
}
/**
Combines $conf and $dflt arrays - all driver parameters are overwritten aftre the call
*/
function combineLoggerConfigs($new_conf,$dflt=null){
global $default_config;
// $xclk_freq=80000000; // 80 MHz in NC353
$xclk_freq=100000000; // 100 MHz in NC393
$data=array();
$index=0;
if (!isset ($dflt)) {
$dflt=$default_config;
}
$conf=$dflt;
if (isset($new_conf)) foreach ($conf as $key=>$oldvalue) if (isset($new_conf[$key])) $conf[$key]=$new_conf[$key];
/// fix insufficient data from default
while (count($conf['imu_registers'])<28) $conf['imu_registers'][count($conf['imu_registers'])]=0; // zero pad if less than 28 registers
/// Configure NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults
while (count($conf['nmea'])<4) {
for ($i=0;$i<4;$i++) {
$new=true;
for ($j=0;$j<count($conf['nmea']);$j++) if ($conf['nmea'][$j][0]==$dflt['nmea'][$i][0]){ // compare sentence code last 3 letters
$new=false;
break;
}
if ($new) {
$conf['nmea'][count($conf['nmea'])]=$dflt['nmea'][$i];
break;
}
}
}
for ($i=0;$i<4;$i++) {
while (strlen($conf['nmea'][$i][0])<3) $conf['nmea'][$i][0].="A"; // just to avoid errors - nonexistent sentences will not hurt, just never logged
}
return $conf;
}
function setup_IMU_logger($conf){
global $verbose;
// $xclk_freq=80000000; // 80 MHz in NC353
$xclk_freq=100000000; // 100 MHz in NC393
$data=array();
$index=0;
/// program period
if (strtolower($conf['imu_period'])=='auto') $conf['imu_period']=0xffffffff;
else $conf['imu_period']+=0;
$data[$index++]= $conf['imu_period'] & 0xff;
$data[$index++]=($conf['imu_period']>> 8) & 0xff;
$data[$index++]=($conf['imu_period']>>16) & 0xff;
$data[$index++]=($conf['imu_period']>>24) & 0xff;
/// program SCLK divisor and SPI stall time
$sclk_div=round($xclk_freq/$conf['sclk_freq']/2);
if ($sclk_div<1) $sclk_div=1;
else if ($sclk_div>255) $sclk_div=255;
$conf['sclk_freq']=$xclk_freq/$sclk_div/2;
$stall=(( $conf['stall'] * ( $xclk_freq / $sclk_div )) / 1000000 );
if ($stall< 1) $stall= 1; /// does 0 work? need to verify
else if ($stall>255) $stall=255;
$conf['stall']=$stall * 1000000 / ($xclk_freq / $sclk_div);
$data[$index++]= $sclk_div;
$data[$index++]= $stall;
$data[$index++]= 0;
$data[$index++]= 0;
/// Program rs232 baud rate
$rs232_div=round($xclk_freq /2/$conf['baud_rate']);
$conf['baud_rate']=$xclk_freq /2/$rs232_div;
$data[$index++]= $rs232_div & 0xff;
$data[$index++]=($rs232_div>> 8) & 0xff;
$data[$index++]=($rs232_div>>16) & 0xff;
$data[$index++]=($rs232_div>>24) & 0xff;
/// Program logger configuration (possible to modify only some fields - maybe support it here?)
$logger_conf=0;
/// #define IMUCR__IMU_SLOT__BITNM 0 // slot, where 103695 (imu) board is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
/// #define IMUCR__IMU_SLOT__WIDTH 2
$logger_conf |= (($conf['imu_slot'] & 0x3) | 0x4 )<< 0; /// "4" (bit 2 set) here means that the data in bits 0,1 will be applied in the FPGA register
/// #define IMUCR__GPS_CONF__BITNM 3 // slot, where 103695 (imu) bnoard is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
/// #define IMUCR__GPS_CONF__WIDTH 4 // bits 0,1 - slot #, same as for IMU_SLOT, bits 2,3:
// 0 - ext pulse, leading edge,
// 1 - ext pulse, trailing edge
// 2 - start of the first rs232 character after pause
// 3 - start of the last "$" character (start of each NMEA sentence)
$logger_conf |= ((($conf['gps_slot'] & 0x3) | (($conf['gps_mode'] & 0x3)<<2) ) | 0x10 )<< 3;
/// #define IMUCR__MSG_CONF__BITNM 8 // source of external pulses to log:
/// #define IMUCR__MSG_CONF__WIDTH 5 // bits 0-3 - number of fpga GPIO input 0..11 (i.e. 0x0a - external optoisolated sync input (J15)
// 0x0f - disable MSG module
// bit 4 - invert polarity: 0 - timestamp leading edge, log at trailing edge, 1 - opposite
// software may set (up to 56 bytes) log message before trailing end of the pulse
$logger_conf |= (($conf['msg_conf'] & 0x1f) | 0x20 )<< 8;
/// #define IMUCR__SYN_CONF__BITNM 14 // logging frame time stamps (may be synchronized by another camera and have timestamp of that camera)
/// #define IMUCR__SYN_CONF__WIDTH 1 // 0 - disable, 1 - enable
$logger_conf |= (($conf['img_sync'] & 0x1) | 0x2 )<< 14;
/// #define IMUCR__RST_CONF__BITNM 16 // reset module
/// #define IMUCR__RST_CONF__WIDTH 1 // 0 - enable, 1 -reset (needs resettimng DMA address in ETRAX also)
/// #define IMUCR__DBG_CONF__BITNM 18 // several extra IMU configuration bits
/// #define IMUCR__DBG_CONF__WIDTH 4 // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A"
$logger_conf |= (($conf['extra_conf'] & 0xf) | 0x10 )<< 18;
/// next bits used by the driver only, not the FPGA
/// ((SLOW_SPI & 1)<<23) | \
/// (DFLT_SLAVE_ADDR << 24))
$logger_conf |= ($conf['slow_spi'] & 0x1)<< 23;
$logger_conf |= ($conf['imu_sa'] & 0x7)<< 24;
$data[$index++]= $logger_conf & 0xff;
$data[$index++]=($logger_conf>> 8) & 0xff;
$data[$index++]=($logger_conf>>16) & 0xff;
$data[$index++]=($logger_conf>>24) & 0xff;
/// Set time driver will go to sleep if the data is not ready yet (less than full sample in the buffer)
$data[$index++]= $conf['sleep_busy'] & 0xff;
$data[$index++]=($conf['sleep_busy']>> 8) & 0xff;
$data[$index++]=($conf['sleep_busy']>>16) & 0xff;
$data[$index++]=($conf['sleep_busy']>>24) & 0xff;
/// Set IMU register addresses to logger
// echo "1\n";
for ($i=0;$i<28;$i++) $data[$index++]= $conf['imu_registers'][$i]; // truncate to 28
/// Configure NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults
// echo "2\n";
for ($i=0;$i<4;$i++) {
$d =str_split($conf['nmea'][$i][0]);
// print_r($d);
for ($j=0;$j<3;$j++) $data[$index++]=ord($d[$j]);
$d =str_split($conf['nmea'][$i][1]);
// print_r($d);
for ($j=0;$j<29;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
}
// echo "3\n";
/// Set default message
$d =str_split($conf['message']);
for ($j=0;$j<56;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
// Print the result array as hex data
/*
print_r($conf);
echo "\n";
for ($i=0;$i<count($data);$i++) {
if (($i & 0xf)==0) printf ("\n%04x:",$i);
printf (" %02x",$data[$i]);
}
echo "\n";
*/
$bindata="";
for($i=0;$i<count($data);$i++) $bindata.=chr($data[$i]);
$dev_imu_ctl = fopen('/dev/imu_ctl', 'w');
fwrite($dev_imu_ctl, $bindata, strlen($bindata));
fseek($dev_imu_ctl,3,SEEK_END); // start IMU
fclose($dev_imu_ctl);
/// Readback - just testing
$bd=file_get_contents('/dev/imu_ctl');
$data =str_split($bd);
if ($verbose) {
echo "\n";
for ($i=0;$i<count($data);$i++) {
if (($i & 0xf)==0) printf ("\n%04x:",$i);
printf (" %02x",ord($data[$i]));
}
echo "\n";
}
}
//ls /sys/bus/usb-serial/devices/ttyUSB0/driver -l
// $xml->addChild ('error','No sync capable board detected, use "role=self" for the onboard timer');
// $sxml=$xml->asXML();
?>
#!/usr/bin/env python
# encoding: utf-8
from __future__ import division
from __future__ import print_function
"""
# @file used_files.py
# @brief Extract file access data after build, modify CDT project configuration
# (.cproject) accordingly
# @copyright Copyright (C) 2016, Elphel.inc.
# @param <b>License</b>
# 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/>.
@author: Andrey Filippov
@license: GPLv3.0+
@contact: andrey@elphel.coml
@deffield updated: Updated
"""
__author__ = "Andrey Filippov"
__copyright__ = "Copyright 2016, Elphel, Inc."
__license__ = "GPL"
__version__ = "3.0+"
__maintainer__ = "Andrey Filippov"
__email__ = "andrey@elphel.com"
__status__ = "Development"
import sys
import os
import time
import xml.etree.ElementTree as ET
'''
TODO:Automate, find out why separate touch commands are needed
Run this program twice:
1-st run ./used_files.py linux -1
and save shown timestamp
Then run (some mystery here)
touch src/drivers/ata/ahci_elphel.c
touch src/drivers/elphel/sensor_common.c
Wait 5 seconds and run (in a different console with appropriate sourcing)
bitbake linux-xlnx -c compile -f
Then again
./used_files.py linux <timestamp_from_the_first_run>
If somethong went wrong you will need to resore .cproject from eclipse_project_setup directory
For php:
bitbake php -c cleansstate
bitbake php -c unpack -f
bitbake php -c configure -f
./used_files.py php -1
bitbake php -c compile -f
./used_files.py php 1471044836.8
Doing:
bitbake php -c compile -f
./used_files.py php -1
bitbake php -c compile -f
./used_files.py php 1471044836.8
Corrupts make process
'''
def file_tree(flist): # Each file in list is a file, no directories
ftree={}
for p in flist:
node = ftree
seg_list=p.split(os.sep)
last_i=len(seg_list)-1
for i,segm in enumerate(seg_list):
if not segm in node:
if i == last_i:
node[segm] = None
else:
node[segm] = {}
node=node[segm]
return ftree
def exclude_list(ftree, flist):
mark = "*" # no file/dir name can be "*"
def list_tree_recursive(root):
rslt = []
if not mark in root:
return [[""]] # convert to trailing "/" for directories
for n in root:
if not n == mark:
if root[n] is None:
rslt.append([n])
else:
for l in list_tree_recursive(root[n]):
rslt.append([n]+l)
return rslt
ftree[mark]=None # mark top level dir
for p in flist:
node = ftree
for segm in p.split(os.sep)[:-1]:
node=node[segm]
node[mark]=None # [mark] means used in flist
del node[p.split(os.sep)[-1]]
#print (ftree)
# for k in ftree:
# print(k)
#Now prune unused directories
#prune_recursive(ftree) # (assuming root is used)
# now create list
files_list_list = list_tree_recursive(ftree)
# print (files_list_list)
#converrt to file paths
pl = []
for l in files_list_list:
pl.append(os.path.join(*(l[1:])))
pl = sorted (pl)
return pl
def proc_tree():
DEBUG = True
extensions = [".h",".c",".cpp"]
exclude_start = ["linux"+os.sep+"scripts"+os.sep,"linux"+os.sep+"source"+os.sep+"scripts"+os.sep]
delta_t = 3 # seconds
try:
root_path = sys.argv[1]
except:
print ("Calling %s <root directory path> [timestamp]"%(os.path.basename(sys.argv[0])))
try:
start_time = float(sys.argv[2])
except:
start_time = 0.0
touch_files= start_time < 0.0
print ("root_path = %s"%(root_path))
# root_path = "/home/eyesis/git/poky/linux-elphel/linux/"
lstFiles = []
# Append files to a list
for path, _, files in os.walk(root_path, followlinks = True):
for f in files:
for ext in extensions:
if f.endswith(ext):
lstFiles.append(os.path.join(path, f))
break
all_tree= file_tree(sorted(lstFiles))
include_lst=[]
lst_a = []
latest_at=0
for p in lstFiles:
if touch_files:
if os.path.islink(p):
try:
os.utime(os.path.realpath(p), None)
except:
print("missing linked file: %s"%(os.path.realpath(p)))
else:
os.utime(p, None)
else:
# at = time.ctime(os.stat(p).st_atime)
try:
at = os.stat(p).st_atime
l = None
except:
at = 0
if os.path.islink(p):
try:
l = os.path.realpath(p)
at = os.stat(l).st_atime
except:
at = 0 # missing file
latest_at = max((latest_at,at))
if at > (start_time + delta_t):
#Scripts/lexers result in problems
exclude=False
for exStr in exclude_start:
if p.startswith(exStr):
exclude=True
break
if exclude:
break
#exclude_start
lst_a.append([p,at,l])
include_lst.append(p)
if touch_files:
print (len(lstFiles), "last time = ", time.time())
return
excluding = exclude_list(all_tree, include_lst)
# print (all_tree)
# print (sorted(include_lst))
# print ("|".join(excluding))
if DEBUG:
with open("all_sources.lst","w" ) as f:
for p in sorted(lstFiles):
try:
at = os.stat(p).st_atime
except:
at = 0
lnk=""
if os.path.islink(p):
try:
at = os.stat(os.path.realpath(p)).st_atime
except:
at = 0
lnk = os.path.realpath(p)
print (p,at,lnk, file=f)
with open("excluding.lst","w" ) as f:
for p in excluding:
print (p, file=f)
with open("including.lst","w" ) as f:
for p in include_lst:
print (p, file=f)
# include_tree= file_tree(sorted(include_lst))
# print(include_tree)
root_dir=include_lst[0].split(os.sep)[0]
print ("root_dir=",root_dir)
xml= ET.parse(".cproject")
root=xml.getroot()
# for child in root:
# print(child.tag, child.attrib)
for child in root.iter('sourceEntries'):
for gchild in child:
print(gchild.tag)
for child in root.iter('sourceEntries'):
for gchild in child:
if gchild.tag == 'entry':
attr = gchild.attrib
try:
if (attr['kind'] == 'sourcePath') and (attr['name'] == root_dir):
child.remove (gchild)
print ("Removed existing entry ",gchild.tag)
break
except:
print ("error matching attributes for ",gchild.tag)
pass
break #after first 'sourceEntries' - should be just one?
ET.SubElement(child, 'entry', {"flags":"VALUE_WORKSPACE_PATH", "kind":"sourcePath", "name":root_dir, "excluding":"|".join(excluding)})
for child in root.iter('sourceEntries'):
for gchild in child:
print(gchild.tag)
oneliner= ET.tostring(root)
#overwrites original .cproject, may change to somethong different
with open(".cproject", "wr") as f:
f.write("""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?>""")
f.write(oneliner)
print (len(lstFiles), len(lst_a), "last access time = ",latest_at)
if __name__ == '__main__':
proc_tree()
"""
Usage for new applications:
1) add src to sources, remove root folder
2) Do not add sysroots to sources, just add include directory (sysroots/elphel393/usr/include-uapi) - sysroot created with 'bitbake -c unpack'
3) run following steps - they will add sysroots to .cproject, together with the exclude filter
make clean # otherwise compiled files are preserved
bitbake apps-editconf -c cleansstate
bitbake apps-editconf -c unpack -f
bitbake apps-editconf -c configure -f
./used_files.py sysroots -1
bitbake apps-editconf -c compile -f
./used_files.py sysroots 1473297567.42 # result of previous run
4)Add SCP <name> to target in "builders" "new" "program".
5) remove "configuration builder' in 2 steps - remove it from .externalToolBuilders, run Eclipse again and then remove from builders.
6) copy .externalToolBuilders (just 1 entry), .project and .cproject to eclipse_project_setup
7) make sure .gitignore ignores all what it should
"""
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment