Debian Codegraph @

src/uk/me/parabola/imgfmt/app/mdr/MDRHeader.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2009.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13 package uk.me.parabola.imgfmt.app.mdr;
14
15 import uk.me.parabola.imgfmt.app.CommonHeader;
16 import uk.me.parabola.imgfmt.app.ImgFileReader;
17 import uk.me.parabola.imgfmt.app.ImgFileWriter;
18 import uk.me.parabola.imgfmt.app.Section;
19 import uk.me.parabola.imgfmt.app.srt.Sort;
20
21 /**
22 * The header of the MDR file.
23 *
24 * Note that there are many possible sections in this file and that
25 * only a certain number of them are needed. There are also many
26 * different lengths for the record sizes of the sections. Finally
27 * there are different sections and record sizes for the version
28 * that gets loaded into the gmapsupp.
29 *
30 * @author Steve Ratcliffe
31 */
32 public class MDRHeader extends CommonHeader {
33
34 private static final int MAX_SECTIONS = 40;
35 private final Section[] sections = new Section[MAX_SECTIONS+1];
36
37 private Sort sort;
38
39 public MDRHeader(int headerLen) {
40 super(headerLen, "GARMIN MDR");
41
42 // Do a quick initialisation. Link every section to the
43 // previous one so that all the positions are correct.
44 for (int i = 1; i < sections.length; i++) {
45 Section prev = (i == 0) ? null : sections[i - 1];
46 sections[i] = new Section(prev);
47 }
48 sections[1].setPosition(getHeaderLength());
49 }
50
51 protected void readFileHeader(ImgFileReader reader) {
52 throw new UnsupportedOperationException("not implemented yet");
53 }
54
55 /**
56 * Write out the application header.
57 */
58 protected void writeFileHeader(ImgFileWriter writer) {
59 writer.put2u(sort.getCodepage());
60 writer.put2u(sort.getId1());
61 writer.put2u(sort.getId2());
62 writer.put2u(14);
63
64 sections[1].writeSectionInfo(writer, true, true);
65 sections[2].writeSectionInfo(writer, true, true);
66 sections[3].writeSectionInfo(writer, true, true);
67 sections[4].writeSectionInfo(writer, true, true);
68 sections[5].writeSectionInfo(writer, true, true);
69 sections[6].writeSectionInfo(writer, true, true);
70 sections[7].writeSectionInfo(writer, true, true);
71 sections[8].writeSectionInfo(writer, true, true);
72 sections[9].writeSectionInfo(writer, true, true);
73 sections[10].writeSectionInfo(writer, false, true);
74 sections[11].writeSectionInfo(writer, true, true);
75 sections[12].writeSectionInfo(writer, true, true);
76 sections[13].writeSectionInfo(writer, true, true);
77 sections[14].writeSectionInfo(writer, true, true);
78 sections[15].writeSectionInfo(writer);
79 writer.put1u(0);
80
81 sections[16].writeSectionInfo(writer, true, true);
82 sections[17].writeSectionInfo(writer, false, true);
83 for (int n = 18; n <= 30; n++)
84 sections[n].writeSectionInfo(writer, true, true);
85 }
86
87 public void setItemSize(int sectionNumber, int itemSize) {
88 Section section = sections[sectionNumber];
89 section.setItemSize((char) itemSize);
90 }
91
92 public void setExtraValue(int sectionNumber, int extraValue) {
93 Section section = sections[sectionNumber];
94 section.setExtraValue(extraValue);
95 }
96
97 public void setPosition(int sectionNumber, int position) {
98 sections[sectionNumber].setPosition(position);
99 }
100
101 public void setEnd(int sectionNumber, int position) {
102 Section s = sections[sectionNumber];
103 s.setSize(position - s.getPosition());
104 }
105
106 public Sort getSort() {
107 return sort;
108 }
109
110 public void setSort(Sort sort) {
111 this.sort = sort;
112 }
113 }