UpstreamEntrance.java 2.11 KB
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 int main(@RequestParam String json){
		logger.info("upstream: " + json);
		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);
		
		return 0;
	}
}