UpstreamEntrance.java
2.22 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
package com.bsth.vehicle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bsth.vehicle.directive.buffer.DirectiveBuffer;
import com.bsth.vehicle.directive.entity.DirectiveReply;
import com.bsth.vehicle.directive.entity.Directive80;
/**
*
* @ClassName: UpstreamEntrance
* @Description: TODO(车载网关HTTP上行入口)
* @author PanZhao
* @date 2016年6月7日 下午3:00:01
*
*/
@RestController
@RequestMapping("/control")
public class UpstreamEntrance {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
DirectiveBuffer directiveBuffer;
@RequestMapping(value = "/upstream", method = RequestMethod.POST)
public String main(@RequestParam String json) {
logger.info("upstream: " + json);
try {
JSONObject jsonParam = JSONObject.parseObject(json);
// 46和47 调度指令确认
if (jsonParam.getInteger("operCode") == null && jsonParam.getInteger("status") != null) {
try {
DirectiveReply reply = JSON.toJavaObject(jsonParam, DirectiveReply.class);
directiveBuffer.reply(reply);
} catch (NumberFormatException e) {
logger.error("NumberFormatException ,,,,一般是老数据,msgId太大");
}
}
// 80协议
else if (jsonParam.getInteger("operCode") == 0X80) {
try {
Directive80 report = JSON.toJavaObject(jsonParam, Directive80.class);
// 驾驶员上报
if (report.getData().getOperCode2() == 0x26)
directiveBuffer.jsyReport(report);
} catch (Exception e) {
logger.error("", e);
}
}
// 64协议 线路切换回复
else if (jsonParam.getInteger("operCode") == 0X64) {
directiveBuffer.reply64(jsonParam);
} else
logger.warn("未知的上行数据,p: " + json);
} catch (Exception e) {
logger.error("", e);
}
return "{\"errCode\":0}";
}
}