summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/uic/barcode/ssbFrame/SsbPass.java
blob: a26fb61085448878805e9b198e3c6f008adcbdba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package org.uic.barcode.ssbFrame;

import org.uic.barcode.asn1.uper.BitBuffer;
import org.uic.barcode.asn1.uper.ByteBitBuffer;
import org.uic.barcode.ticket.EncodingFormatException;

public class SsbPass extends SsbCommonTicketPart {
	
	/*
	 * RPT sub ticket type	3 values	2	2 bit	1 = INTERRAIL, 2 = EURAIL EUROPE, 3 = EURAIL OVERSEAS
       First day of validity from the issuing date	Num (<367)	9 bit 000 = open date for regular Eurail pass to be activated
       Maximum duration from the issuing date for OVERSEAS; otherwise, last day of validity	Num (<278)	9 bit 9 months max. validity
       Number of days of travel allowed	Num (<93)	7	bit	
       Country code 1	Num (<100)	7	0.875	100 = all countries
       Country code 2	Num (<99)	7	0.875	If country code 1 is 100, then 00
       Country code 3	Num (<99)	7	0.875	If country code 1 is 100, then 00
       Country code 4	Num (<99)	7	0.875	If country code 1 is 100, then 00
       Country code 5	Num (<99)	7	0.875	If country code 1 is 100, then 00
       Second page	Bit flag	1	0.125	For a two-page pass
       Information messages	Num (<9999)	14	1.75	
       Open text	6-bit ASCII (40 Char)	240	30	
	 */


	private int passSubType = 0;
	private int firstDayOfValidity = 0;
	private int maximumValidityDuration = 0;
	private int numberOfTravels = 0;
	private int country_1 = 0;
	private int country_2 = 0;
	private int country_3 = 0;
	private int country_4 = 0;
	private int country_5 = 0;
	private boolean hasSecondPage = false;
	private int infoCode = 0;
	private String text = null;
	
	@Override
	protected int decodeContent(byte[] bytes, int offset) {
		
		offset = offset + decodeCommonPart(bytes);
		
		BitBuffer bits = new ByteBitBuffer(bytes);
		
		passSubType = bits.getInteger(offset, 2);
		offset = offset + 2;
		
		firstDayOfValidity = bits.getInteger(offset, 9);
		offset = offset + 9;

		maximumValidityDuration = bits.getInteger(offset, 9);
		offset = offset + 9;

		numberOfTravels = bits.getInteger(offset, 7);
		offset = offset + 7;
		
		country_1 = bits.getInteger(offset, 7);
		offset = offset + 7;

		country_2 = bits.getInteger(offset, 7);
		offset = offset + 7;
		
		country_3 = bits.getInteger(offset, 7);
		offset = offset + 7;
		
		country_4 = bits.getInteger(offset, 7);
		offset = offset + 7;
		
		country_5 = bits.getInteger(offset, 7);
		offset = offset + 7;
		
		hasSecondPage = bits.get(offset);
		offset++;
		
		infoCode = bits.getInteger(offset, 14);
		offset = offset + 14;
		
		text = bits.getChar6String(offset, 240);
		offset = offset + 240;
		
		return offset;
	}

	@Override
	protected int encodeContent(byte[] bytes, int offset) throws EncodingFormatException {
		
		offset = offset + encodeCommonPart(bytes, offset);
		
		BitBuffer bits = new ByteBitBuffer(bytes);
		
		if (passSubType < 0 || passSubType > 3) {
			throw new EncodingFormatException("SSB pass type too big");
		}
		bits.putInteger(offset, 2,passSubType);
		offset = offset + 2;
		
		if (firstDayOfValidity < 0 || firstDayOfValidity > 511) {
			throw new EncodingFormatException("SSB first day of validity too big");
		}
		bits.putInteger(offset, 9,firstDayOfValidity);
		offset = offset + 9;

		if (maximumValidityDuration < 0 || maximumValidityDuration > 511) {
			throw new EncodingFormatException("SSB validity duration too big");
		}
		bits.putInteger(offset, 9,maximumValidityDuration);
		offset = offset + 9;

		if (numberOfTravels < 0 || numberOfTravels > 94) {
			throw new EncodingFormatException("SSB number of travels too big");
		}
		bits.putInteger(offset, 7, numberOfTravels);
		offset = offset + 7;
		
		if (country_1 < 0 || country_1 > 100) {
			throw new EncodingFormatException("SSB country 1 too big");
		}
		bits.putInteger(offset, 7,country_1);
		offset = offset + 7;

		if (country_2 < 0 || country_2 > 99) {
			throw new EncodingFormatException("SSB country 2 too big");
		}
		bits.putInteger(offset, 7,country_2);
		offset = offset + 7;
		
		if (country_3 < 0 || country_3 > 99) {
			throw new EncodingFormatException("SSB country 3 too big");
		}
		bits.putInteger(offset, 7,country_3);
		offset = offset + 7;
		
		if (country_4 < 0 || country_4 > 99) {
			throw new EncodingFormatException("SSB country 4 too big");
		}
		bits.putInteger(offset, 7,country_4);
		offset = offset + 7;
		
		if (country_5 < 0 || country_5 > 99) {
			throw new EncodingFormatException("SSB country 5 too big");
		}
		bits.putInteger(offset, 7,country_5);
		offset = offset + 7;
		
		bits.put(offset, hasSecondPage);
		offset++;
		
		if (infoCode < 0 || infoCode > 9999) {
			throw new EncodingFormatException("SSB info code too big");
		}
		bits.putInteger(offset, 14, infoCode);
		offset = offset + 14;
		
		if (text.length() > 40) {
			throw new EncodingFormatException("SSB text too big");
		}
		bits.putChar6String(offset, 240,text);
		offset = offset + 240;		
		
		return offset;
	}

	public int getPassSubType() {
		return passSubType;
	}

	public void setPassSubType(int passSubType) {
		this.passSubType = passSubType;
	}

	public int getFirstDayOfValidity() {
		return firstDayOfValidity;
	}

	public void setFirstDayOfValidity(int firstDayOfValidity) {
		this.firstDayOfValidity = firstDayOfValidity;
	}

	public int getMaximumValidityDuration() {
		return maximumValidityDuration;
	}

	public void setMaximumValidityDuration(int maximumValidityDuration) {
		this.maximumValidityDuration = maximumValidityDuration;
	}

	public int getNumberOfTravels() {
		return numberOfTravels;
	}

	public void setNumberOfTravels(int numberOfTravels) {
		this.numberOfTravels = numberOfTravels;
	}

	public int getCountry_1() {
		return country_1;
	}

	public void setCountry_1(int country_1) {
		this.country_1 = country_1;
	}

	public int getCountry_2() {
		return country_2;
	}

	public void setCountry_2(int country_2) {
		this.country_2 = country_2;
	}

	public int getCountry_3() {
		return country_3;
	}

	public void setCountry_3(int country_3) {
		this.country_3 = country_3;
	}

	public int getCountry_4() {
		return country_4;
	}

	public void setCountry_4(int country_4) {
		this.country_4 = country_4;
	}

	public int getCountry_5() {
		return country_5;
	}

	public void setCountry_5(int country_5) {
		this.country_5 = country_5;
	}

	public boolean isHasSecondPage() {
		return hasSecondPage;
	}

	public void setHasSecondPage(boolean hasSecondPage) {
		this.hasSecondPage = hasSecondPage;
	}

	public int getInfoCode() {
		return infoCode;
	}

	public void setInfoCode(int infoCode) {
		this.infoCode = infoCode;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
	
	


}