Commit graph

18715 commits

Author SHA1 Message Date
Linus Torvalds
2cd2cafdf4 Generate 'watertemp' field from samples if required
Sure, it's redundant, but it's convenient for the general dive info.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 22:21:16 -07:00
Linus Torvalds
f7fb74f3a7 Fix wrongly nested watertemp xml entry
Too much cut-and-paste: the ending tag said "airtemp".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 22:18:44 -07:00
Linus Torvalds
bafc7e771e We can't save escape characters.
I think it should be legal xml, but whatever.  libxml2 is very unhappy,
and complains when loading - even if I escape them.  So let's just
replace the low escape characters with '?'.

The only thing to ever care was my test-case, I suspect.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:28:17 -07:00
Linus Torvalds
22fcef2ec7 Save and parse notes and locations
It's pretty rough, but it seems to work.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 19:56:04 -07:00
Linus Torvalds
0189de695c Do gasmix as an empty element XML too
Let's make it a goal that the XML we output is pretty.  That clearly was
never a goal for the Suunto XML, but we can be oh-so-much-better than that.

I still don't love XML, but let's try to make the best of a bad situation,
and take pride in what we do.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 17:44:13 -07:00
Linus Torvalds
c139aa8d51 Clean up save-file output a bit
Use the "empty element" form for samples that don't have any events
associated with them (and none do, right now).  This avoids that
annoying "</sample>" crud.

And output the units in the output helpers, so that you can't forget
them even if you try.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 17:37:41 -07:00
Linus Torvalds
adc92d6de2 Always use proper units when saving.
When we see a number like 23.145, we'd better always also see a unit.
It's just good practice.  So add 'min' to duration (and use only two
digits for number of seconds), and 'm' to depth.

And write the date in international standard format.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 17:17:19 -07:00
Linus Torvalds
5001ab66cb Teach the date parser to also parse the international standard date format
The standard way to write a date is yyyy-mm-dd, which is unambiguous and
sorts correctly.

We parsed that right in the 'datetime' case, but not in the normal date
case.  And we do want to use that in our output format, exactly because
it's standard.

And also parse 'duration' for the dive duration.  It's what we use when
saving, it just so happened that we ended up not parsing it right, but
then picking it up from the samples instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 17:13:39 -07:00
Linus Torvalds
1376712f0b Save everything in our current dives and samples into the xml file
Now, as we start parsing more, we just need to also add the code to save
it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 16:59:10 -07:00
Linus Torvalds
99c111e348 Fix up small details in input/output
Be more careful with FP conversions, and with the Kelvin<->C offset.
And make sure to use the same names when saving as when parsing.

Now when we save a set of dives, then re-load them, and save again, the
second save image is identical to the first one.

Of course, we don't actually save everything we load, so we still do
lose information when we load and then save the result.  But at least we
now don't lose the information that we *do* save.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 16:41:10 -07:00
Linus Torvalds
1155ad3f0f Add ability to 'save' dives
This just generates another xml file.  Don't get me wrong: I still don't
like xml, but this way we can save in the same format we load things
from.  Except the save-format is a *lot* cleaner than the abortion that
is Suunto or libdivecomputer xml.

Don't bother with some crazy xml library crap for saving. Just do it!

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 16:27:52 -07:00
Linus Torvalds
d5e42d485e gasmix: stop tracking nitrogen percentages
The only thing you can do with that thing is screw things up (like
libdivecomputer did).  There's no value in tracking the "filler" gas,
since you can always just calculate it from the gases that actually
matter.

So just track Oxygen and Helium - and make sure they have sane values.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 16:26:11 -07:00
Linus Torvalds
adc7280c02 libdivecomputer does crazy gas mixes too
Did I just say "In comparison, the libdivecomputer output is nice and
sane"?

It turns out that libdivecomputer has been doing some drugs too when it
comes to gas mixes.  Like showing O2 percentages as 255.0% and N2
percentages as -155.0%.

Clearly libdivecomputer uses a 'unsigned char' for oxygen percentage,
and makes "-1" be "undefined".  And then it prints that non-existing mix
out, and in the process does MATH on the damn thing ("100-O2") to
"calculate" the nitrogen percentage.

Christ.

Just make the parser silently ignore the craziness, because printing out
"Strange percentage reading -155.0" a few hundred times just doesn't
make anything any better.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 13:46:24 -07:00
Linus Torvalds
9741913124 Start parsing gas mixes
The suunto xml is just completely crazy.  What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".

Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist.  And they clearly
started their indexing with 0.  So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?

Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2".  So the O2 percentages are one-based, with an
implicit one.  But the He percentages are zero-based with an explicit
zero.  So the second mix is "o2pct_2" and "hepct_1".

I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company.  No need to ask.  Vodka explains everything.  LOTS AND LOTS OF
VODKA.

In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node.  Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces.  That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.

The "type of file" thing is probably a good idea for deciding on default
units too. Some day.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 13:32:52 -07:00
Linus Torvalds
14d7601cdf Get rid of our 'ignore' rules
I'll start doing some kind of "save unparsed things as extended items"
thing, and the ignore rules were just there to get rid of some of the
noise from early parsing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 12:35:04 -07:00
Linus Torvalds
da4edbcce8 xml parsing: start traversing properties too
This requires us to change the way we match things up, because now we
can have things like

   dives.dive.sample.event.time

and

   dives.dive.sample.time

and they are different things (that "sample.event.time" is a 'time'
property of the 'event').

Now, this is always going to be ambiguous, since our linearized name of
the xml doesn't really care whether it's a xml node "child" or a
"property", but quite frankly, I don't care. XML just isn't worth the pain.

In fact, maybe this ambiguity can end up being a good thing.  We will
parse these two different lines of XML the same way:

  <dive><sample><time>50</time><depth>10.8</depth></sample></dive>

  <dive><sample time="50" depth="10.8"></sample></dive>

and the attribute approach seems to be the nicer one.  Maybe I'll use
that for the output format.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 11:22:05 -07:00
Linus Torvalds
4350a75b94 Rename some files to be more appropriate
The executable is now called 'divelog'.  If this gets useful enough to
actually *use*, I guess I'll have to come up with a real name some day.

Add a silly README, rename 'parse' to 'parse-xml'.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 10:09:53 -07:00
Linus Torvalds
feec555040 Add some extended dive info fields
.. and tweak the basic info layout a bit.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 20:36:51 -07:00
Linus Torvalds
23c6a42b08 Make the main display saner
This tweaks:
 - packing to be what you'd kind of expect
 - makes the "summary info" always visible
 - the "extended info" is now on a notebook page of its own
 - dive profile the first notebook page, since the summary
   information is visible regardless.
which all just seems a lot more logical.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 18:30:42 -07:00
Linus Torvalds
3d01a5f71a Boiler-plate code for opening/saving a file
All just copied from the gtk docs.  No actual loading or saving is
taking place, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 18:04:25 -07:00
Linus Torvalds
1c010afc88 Add a top 'File' menu
It doesn't actually *do* anything, but what else is new?

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 16:54:13 -07:00
Linus Torvalds
968aa28155 Do something half-way sane (no SIGSEGV) when there are no dives
It just leaves ugly blank areas, but whatever.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 16:40:22 -07:00
Linus Torvalds
00d798854a Start cleaning up dive accessors
I'm going to add a menu to import (and eventually export) dives, and so
we'd like to be able to start out with no dives at all.  Right now we
croak if that happens - it's not like the code has been written with
actual end users in mind.

So start cleaning things up.  First make the 'current_dive' macro work
right even for invalid dives.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 16:33:20 -07:00
Linus Torvalds
c17300cfaa Use a 'notebook' for Info vs Profile
I dunno.  This seems a better interface at least if we get more info for
the dive, but I suspect I'll want to the add basic info to the profile
page too.

This makes the 'table' approach to layout be kind of pointless again,
and the table has become a fancy vbox.  Maybe I'll put the core info
back, and use the notebook 'Info' page for extended information.

I should just bite the bullet and start saving the dive data, and adding
editing functions for adding information.  But instead I'm playing
around with random gtk widgets.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 16:10:11 -07:00
Linus Torvalds
a39b2ee220 Add some more dive info - and actually update it
It's still the ugliest application ever, but now it at least gives you
some basic dive info.

I'd love to add a way to edit the dives to add new data (name, buddies,
location etc), but that would also require the ability to save the end
result.  Maybe some day.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 15:35:28 -07:00
Linus Torvalds
c7e2906372 dive parsing: enforce maxdepth and dive duration
If we see samples from past the dive duration, update the dive duration.
Likewise with maxdepth.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 14:36:53 -07:00
Linus Torvalds
ee56021dfb dive profile plot: use saner minimum limits
The time minimum was in seconds, not minutes, and we really do want to
show at least to 90ft to make shallow dives look shallow rather than
scaled to some full depth.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 14:35:31 -07:00
Linus Torvalds
059f047788 plot a fancier 'filled' depth profile
Now I'm just dicking around with cairo.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 14:23:35 -07:00
Linus Torvalds
eed9538101 Plot dive profile slightly more intelligently.
This actually creates a bounding box and some scale markers.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 14:15:50 -07:00
Linus Torvalds
a11dbbdb18 Add fake 'info' frame contents
It should have depth, time, place etc information, but right now it only
has a fake depth that doesn't even get updated.  Just to show the idea
of the table usage.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 12:09:19 -07:00
Linus Torvalds
7017d17562 Use a gtk table instead of hbox
We'll want to add various dive statistics, so...  Without them, it all
looks pretty much the same, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 11:52:16 -07:00
Linus Torvalds
6cc122f491 Add 'repaint_dive()' prototype, and fix dependencies
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 11:10:17 -07:00
Linus Torvalds
2044dabc81 Teach the thing to actually track the currently selected dive
.. and repaint the profile when the selection changes.

Now, if it just wasn't so ugly, it might even be useful.  Except it
obviously needs to also show all the other dive information.  And allow
the user to fill in details.  And save the end results.

So no, it's not useful.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 11:07:31 -07:00
Linus Torvalds
23e831a6ed Re-do the tree selection code with a selection callback
Learnign gtk by looking at cairo examples? It's one way.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 10:46:28 -07:00
Linus Torvalds
de8dc53f75 Don't newline-terminate the dive name
That resulted in ugly lists, and it was wrong to begin with.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 10:45:29 -07:00
Linus Torvalds
77cfe07c52 Split up divelist scroll window generation into its own file
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 10:27:58 -07:00
Linus Torvalds
1d69524a78 Get rid of now unused 'show_dive()' function
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 10:22:08 -07:00
Linus Torvalds
8e95ded57b Split up profile frame generation into its own file.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 10:20:46 -07:00
Linus Torvalds
3aa54e206a Draw some kind of profile for the (first) dive
This is all kinds of broken: it doesn't actually follow the selected
dive, and the profile isn't scaled properly etc.  But it shows something
new, and not just text.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 08:47:13 -07:00
Linus Torvalds
446e51ccf0 Fix depth parsing
The "decimal: it's meters, integer: it's feet" logic doesn't work.  It's
just always meters, because the xml ends up sometimes having whole meters.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 08:45:43 -07:00
Linus Torvalds
5625b31873 Make the dive list scrollable (and put it in a vbox)
This means you can actually see them all, and walk through them.

It doesn't make any of this *useful*, but whatever.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 21:18:47 -07:00
Linus Torvalds
d1ae1c4830 Show the dives as a gtk list/tree widget
Ok, so I'm not very good at this.  I'll need to enclose the dang thing
in a scrollable window, and then make that scrollable thing just part of
the whole window.

But hey, it's pixels on the screen.  Pixels that show the names of the
dives we've parsed.  At least as many as will fit on screen at one time ;)

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 20:56:01 -07:00
Linus Torvalds
3aa02ccba9 Generate a default name for a dive, if it doesn't have one already
The name is a string containint date, time, depth and length.  So it's
useful even with nothing else going on.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 20:54:43 -07:00
Linus Torvalds
0ca546b31e Create a gtk window
It doesn't *do* anything, but some day it will.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 19:48:00 -07:00
Linus Torvalds
19e670a23b Add .gitignore file for current state
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 18:42:57 -07:00
Linus Torvalds
5c4cc39c56 Start moving some of the non-parsing stuff out of 'parse.c'
Create a 'main.c' with the main routine and argument "parsing" etc.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 18:40:25 -07:00
Linus Torvalds
f3a338a9af Split up dive data structure declarations into 'dive.h'
The dive parser should eventually be just a part of the program, not the
whole thing. So start preparing for that.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 18:23:59 -07:00
Linus Torvalds
17fcb3d32d Clean up dive reporting
Show date, max depth, and time by default.  The stuff that matters and
should always exist.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 17:51:35 -07:00
Linus Torvalds
fc38f4f0c4 Add some more parsing functions
.. and fix the 'duration' parsing: it can be either in seconds, or in
mm:ss format.  Floating point doesn't make any sense.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 17:45:03 -07:00
Linus Torvalds
048a5a2b32 Don't report dives as they are parsed: sort them at the end and report them then
This makes it much easier to see the duplicates, but more importantly,
we do need to actually save the dives off to do any real work with them.

Also, require a verbosity level of 1 (-v) to show all the samples.
While (-vv) shows unparsed entries.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 17:18:33 -07:00