View Javadoc

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(short rawPacket[]) {
56  		throw new RuntimeException("Not implemented!");
57  	}
58  
59  	public boolean hasLength() {
60  		return hasLength;
61  	}
62  
63  	public boolean isNack() {
64  		return isNack;
65  	}
66  
67  	public boolean hasSequence() {
68  		return hasSequence;
69  	}
70  
71  	public boolean reserved3() {
72  		return reserved3;
73  	}
74  
75  	public boolean reserved4() {
76  		return reserved4;
77  	}
78  
79  	public boolean reserved5() {
80  		return reserved5;
81  	}
82  
83  	public boolean reserved6() {
84  		return reserved6;
85  	}
86  
87  	public boolean reserved7() {
88  		return reserved7;
89  	}
90  
91  	public short getLength() {
92  		return length;
93  	}
94  
95  	public short getSequence() {
96  		if(hasSequence){
97  			return sequence;
98  		}else{
99  			throw new RuntimeException("Has no sequence!");
100 		}
101 	}
102 
103 	public short getPayloadId() {
104 		return payloadId;
105 	}
106 
107 	public short getErrorId() {
108 		if(isNack){
109 			return errorId;
110 		}else{
111 			throw new RuntimeException("Not a nack!");
112 		}
113 	}
114 
115 	public short[] getPayload() {
116 		return payload;
117 	}
118 
119 	public int getPayloadLength() {
120 		return payload.length;
121 	}
122 
123 	public short getChecksum() {
124 		return checksum;
125 	}
126 
127 }