1 /* Open Log Viewer
2 *
3 * Copyright 2011 Fred Cooke
4 *
5 * This file is part of the OpenLogViewer project.
6 *
7 * OpenLogViewer software is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * OpenLogViewer software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with any OpenLogViewer software. If not, see http://www.gnu.org/licenses/
19 *
20 * I ask that if you make any changes to this file you fork the code on github.com!
21 *
22 */
23
24 package org.diyefi.openlogviewer.decoder;
25
26 /**
27 * Data storage for a generic FreeEMS packet.
28 *
29 * @author Fred Cooke
30 */
31 public class FreeEmsPacket {
32
33 // Flags from header flags byte
34 private boolean hasLength;
35 private boolean isNack;
36 private boolean hasSequence;
37 // private boolean reserved3;
38 // private boolean reserved4;
39 // private boolean reserved5;
40 // private boolean reserved6;
41 // private boolean reserved7;
42
43 // Fields from header
44 private short length; // original packet length, which by now, is correct - always valid, regardless of flag
45 private short sequence;
46 private short payloadId;
47
48 // Data from payload
49 private short errorId; // only populated if isNack is true;
50 private short[] payload;
51
52 // Checksum from footer
53 private short checksum; // included and calculated were the same, or this object would not have been created
54
55 public FreeEmsPacket(final short[] rawPacket) {
56 throw new RuntimeException("Not implemented!");
57 }
58
59 public final boolean hasLength() {
60 return hasLength;
61 }
62
63 public final boolean isNack() {
64 return isNack;
65 }
66
67 public final boolean hasSequence() {
68 return hasSequence;
69 }
70
71
72 public final short getLength() {
73 return length;
74 }
75
76 public final short getSequence() {
77 if (hasSequence) {
78 return sequence;
79 } else {
80 throw new RuntimeException("Has no sequence!");
81 }
82 }
83
84 public final short getPayloadId() {
85 return payloadId;
86 }
87
88 public final short getErrorId() {
89 if (isNack) {
90 return errorId;
91 } else {
92 throw new RuntimeException("Not a nack!");
93 }
94 }
95
96 public final short[] getPayload() {
97 return payload;
98 }
99
100 public final int getPayloadLength() {
101 return payload.length;
102 }
103
104 public final short getChecksum() {
105 return checksum;
106 }
107 }