1 package org.diyefi.openlogviewer.decoder;
2
3 public class LogField{
4 public enum types{
5 UINT8 (1),
6 UINT16 (2),
7 UINT32 (4),
8 BITS8 (1),
9 BITS16 (2),
10 BITS32 (4),
11 SINT8 (1),
12 SINT16 (2),
13 SINT32 (4);
14
15 public final int width;
16
17 private types(int width){
18 this.width = width;
19 }
20 }
21
22
23 static final double divideByOne = 1.0;
24 static final double addToZero = 0.0;
25
26 public LogField(String ID){
27 this(ID, types.UINT16, divideByOne, addToZero);
28 }
29 public LogField(String ID, types type){
30 this(ID, type, divideByOne, addToZero);
31 }
32 public LogField(String ID, types type, double divBy){
33 this(ID, type ,divBy, addToZero);
34 }
35
36 public LogField(String ID, double divBy){
37 this(ID, types.UINT16, divBy, addToZero);
38 }
39 public LogField(String ID, double divBy, double addTo){
40 this(ID, types.UINT16, divBy, addTo);
41 }
42
43 public LogField(String ID, types type, double divBy, double addTo){
44 this.ID = ID;
45 this.type = type;
46 this.divBy = divBy;
47 this.addTo = addTo;
48
49 if(ID == null){
50 throw new RuntimeException("ID is null, needs to be a valid string!");
51 }else if(type == null){
52 throw new RuntimeException("Type must be specified!");
53 }else if((this.type == types.BITS8) || (this.type == types.BITS16) || (this.type == types.BITS32)){
54 throw new RuntimeException("This constructor must NOT be used with flag variables");
55 }else if(this.divBy == addToZero){
56 throw new RuntimeException("Divide by zero not possible, don't be silly!");
57 }
58 }
59
60 public LogField(String ID, types type, String[] bitFieldNames){
61 this.ID = ID;
62 this.type = type;
63 this.bitFieldNames = bitFieldNames;
64
65 if(ID == null){
66 throw new RuntimeException("ID is null, needs to be a valid string!");
67 }else if(this.type != types.BITS8 && this.type != types.BITS16 && this.type != types.BITS32){
68 throw new RuntimeException("This constructor can only be used with flag variables!");
69 }
70
71 if(this.bitFieldNames == null){
72 throw new IllegalArgumentException("bitFieldNames is null!");
73 }else if((this.type == types.BITS8) && (bitFieldNames.length != 8)){
74 throw new IllegalArgumentException("BITS8 requires 8 flag names!");
75 }else if((this.type == types.BITS16) && (bitFieldNames.length != 16)){
76 throw new IllegalArgumentException("BITS16 requires 16 flag names!");
77 }else if((this.type == types.BITS32) && (bitFieldNames.length != 32)){
78 throw new IllegalArgumentException("BITS16 requires 32 flag names!");
79 }
80 }
81
82 String ID;
83 types type;
84 String[] bitFieldNames;
85
86
87 String description;
88 String unit;
89
90
91 double divBy = divideByOne;
92 double addTo = addToZero;
93
94 public String getID() {
95 return ID;
96 }
97 public types getType() {
98 return type;
99 }
100 public String[] getBitFieldNames() {
101 return bitFieldNames;
102 }
103 public double getDivBy() {
104 return divBy;
105 }
106 public double getAddTo() {
107 return addTo;
108 }
109 public void setID(String iD) {
110 ID = iD;
111 }
112 public void setType(types type) {
113 this.type = type;
114 }
115 public void setBitFieldNames(String[] bitFieldNames) {
116 this.bitFieldNames = bitFieldNames;
117 }
118 public void setDivBy(double divBy) {
119 this.divBy = divBy;
120 }
121 public void setAddTo(double addTo) {
122 this.addTo = addTo;
123 }
124 public String getDescription() {
125 return description;
126 }
127 public String getUnit() {
128 return unit;
129 }
130 public void setDescription(String description) {
131 this.description = description;
132 }
133 public void setUnit(String unit) {
134 this.unit = unit;
135 }
136 }