Rev 222 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2007 Steve Ratcliffe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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.
*
*
* Author: Steve Ratcliffe
* Create date: Dec 16, 2007
*/
package test.display;
/**
* Standalone program to display the TYP file as it is worked out.
*
* The names and lengths of the fields were obtained from the program gpsexplorer
* by the author identified as 'garminmaploader@yahoo.com' and released
* under GPL2+.
*
* @author Steve Ratcliffe
*/
public class MpsDisplay
extends CommonDisplay
{
protected void print
() {
while (reader.
position() < filelen
) {
printSection
();
}
}
private void printSection
() {
Displayer d =
new Displayer
(reader
);
d.
setTitle("Section");
DisplayItem item = d.
item();
byte type = reader.
get();
item.
setBytes(type
);
int len
;
switch (type
) {
case 0x46:
printHeader
(d, item,
"Product entry", type
);
printProduct
();
break;
case 0x4c:
printHeader
(d, item,
"Map entry", type
);
printFile
();
break;
case 0x50:
// Don't really know what this is, so feel to change description.
printHeader
(d, item,
"Map details", type
);
printDetails
();
break;
case 0x55:
len = printHeader
(d, item,
"Unlock entry", type
);
printBuffer
(len
);
break;
case 0x56:
printHeader
(d, item,
"Map set entry", type
);
printMapSet
();
break;
default:
len = printHeader
(d, item,
"Unknown section type", type
);
printUnknown
(len
);
break;
}
}
/**
* So ok its not much of a header, but print the value separately anyway.
* @param d The displayer
* @param item The display item that already contains the byte.
* @param text Stuff to display, the kind of section.
* @param type
*/
private int printHeader
(Displayer d, DisplayItem item,
String text,
int type
) {
d.
setTitle(text
);
item.
addText(text +
" id byte %c",
(char) type
);
int len = d.
charValue("Body length %d");
d.
print(outStream
);
return len
;
}
private void printProduct
() {
Displayer d =
new Displayer
(reader
);
printProductFamily
(d
);
d.
zstringValue("Description: %s");
d.
print(outStream
);
}
private void printDetails
() {
Displayer d =
new Displayer
(reader
);
printProductFamily
(d
);
d.
rawValue(6); // unknown
d.
print(outStream
);
}
private void printProductFamily
(Displayer d
) {
d.
charValue("Product %d");
d.
charValue("Family %d");
}
private void printMapSet
() {
Displayer d =
new Displayer
(reader
);
d.
zstringValue("Map set name: %s");
d.
byteValue("???");
d.
print(outStream
);
}
private void printFile
() {
Displayer d =
new Displayer
(reader
);
printProductFamily
(d
);
d.
intValue("map id: %d");
d.
zstringValue("series name: %s");
d.
zstringValue("map name: %s");
d.
zstringValue("area name: %s");
d.
intValue("mapname, hex style: %x");
d.
intValue("???");
d.
print(outStream
);
}
private void printBuffer
(int len
) {
// Not really interested in this section, but needed for completeness.
// Its not tested as I don't have any maps that need unlocking.
Displayer d =
new Displayer
(reader
);
// This may not work anyway... untested.
int count =
0;
while (count
< len
) {
String val = d.
zstringValue("String: %s");
count += val.
length() +
1;
}
d.
print(outStream
);
}
private void printUnknown
(int len
) {
Displayer d =
new Displayer
(reader
);
d.
rawValue(len,
"Unknown");
d.
print(outStream
);
}
public static void main
(String[] args
) {
if (args.
length < 1) {
System.
err.
println("Usage: mpsdisplay <filename>");
System.
exit(1);
}
CommonDisplay cd =
new MpsDisplay
();
cd.
display(args
[0],
"MPS");
}
}