GpsEntity.java
4.89 KB
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
package com.bsth.entity;
import com.bsth.client.pd.protocol.BasicInfo;
import org.apache.commons.lang3.StringUtils;
/**
* @author PanZhao
* @ClassName: GpsRealData
* @Description: TODO(HTTP接口的实时GPS数据)
* @date 2016年5月11日 下午4:32:07
*/
public class GpsEntity {
/**
* 公司代码
*/
private Short companyCode;
/**
* 线路编码
*/
private String lineId;
/**
* 设备编码
*/
private String deviceId;
/**
* 经度
*/
private Float lon;
/**
* 纬度
*/
private Float lat;
/**
* 发送时间戳
*/
private Long timestamp;
/**
* 速度
*/
private Float speed;
/**
* 方向(角度)
*/
private float direction;
/**
* 营运状态( 0 营运 ,1 非营运, -1 无效)
*/
private Integer state;
/**
* 上下行(0 上行 , 1 下行 , -1 无效)
*/
private Byte upDown;
private int version;
/**
* gps是否有效 设备端发送的状态
*/
private int valid;
/**
* 数据来源
* 1:网关
* 0:转发
*/
private int source;
/** 网关收到时间 */
private Long serverTimestamp;
public static GpsEntity getInstance(BasicInfo basicInfo, int version, int source){
if(StringUtils.isBlank(basicInfo.getDeviceId()))
return null;
//接受 5 分钟内的补传数据
byte cacheData = getCacheState(basicInfo.getServiceState());
if(cacheData == 1 && Math.abs(basicInfo.getTimestamp() - System.currentTimeMillis()) > 1000 * 60 * 5)
return null;
GpsEntity gps = new GpsEntity();
gps.setDeviceId(basicInfo.getDeviceId());
gps.setTimestamp(basicInfo.getTimestamp());
gps.setLat(basicInfo.getLat());
gps.setLon(basicInfo.getLon());
gps.setDirection((float)basicInfo.getDirection() / 10);
gps.setValid(basicInfo.getGpsValid());
gps.setCompanyCode(basicInfo.getCompanyCode());
gps.setUpDown(basicInfo.getUpOrDown());
gps.setSpeed((float)basicInfo.getSpeedGps() / 10);
gps.setLineId(String.valueOf(basicInfo.getLineId()));
gps.setState((int) getService(basicInfo.getServiceState()));
gps.setVersion(version);
gps.setSource(source);
gps.setServerTimestamp(System.currentTimeMillis());
return gps;
}
public static byte getCacheState(long serviceState) {
return (byte)(((serviceState & 0x00100000) == 0x00100000) ? 1 : 0);
}
/**
* 获取运营状态
*
* @return -1无效 0运营 1未运营
*/
public static byte getService(long serviceState) {
if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000)
return -1;
return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public Float getLon() {
return lon;
}
public void setLon(Float lon) {
this.lon = lon;
}
public Float getLat() {
return lat;
}
public void setLat(Float lat) {
this.lat = lat;
}
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
public String getLineId() {
return lineId;
}
public void setLineId(String lineId) {
this.lineId = lineId;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public int getValid() {
return valid;
}
public void setValid(int valid) {
this.valid = valid;
}
public short getCompanyCode() {
return companyCode;
}
public void setCompanyCode(short companyCode) {
this.companyCode = companyCode;
}
public Byte getUpDown() {
return upDown;
}
public void setUpDown(Byte upDown) {
this.upDown = upDown;
}
public float getDirection() {
return direction;
}
public void setDirection(float direction) {
this.direction = direction;
}
public Float getSpeed() {
return speed;
}
public void setSpeed(Float speed) {
this.speed = speed;
}
public int getSource() {
return source;
}
public void setSource(int source) {
this.source = source;
}
public Long getServerTimestamp() {
return serverTimestamp;
}
public void setServerTimestamp(Long serverTimestamp) {
this.serverTimestamp = serverTimestamp;
}
}