Commit da412eda by lixinming

no message

parent 97ed2825
No preview for this file type
import { dataCenterInterfaceConfig } from "../config/serverConfig";
import { getInterfaceByInterfaceName } from "../data/cronJob";
import { controlGetOnlieCarList } from "../data/interface/wsData";
import { Socket } from "../net/socket_server";
import { logError } from "../util/log";
let qs = require('qs');
let viewPool = {};//展示端连接池
......
......@@ -234,6 +234,7 @@ export async function carInfo(req, res) {
rtmpAddresss.forEach(info => {
let { channelNo, address } = info;
console.log(address);
监控视频列表.push({
video:address,
img:map[channelNo],
......
......@@ -5,13 +5,65 @@ import { logError } from "../../util/log";
//连接池
let connectionPool = {};
function space(lat1, lng1, lat2, lng2) {
var radLat1 = lat1 * Math.PI / 180.0;
var radLat2 = lat2 * Math.PI / 180.0;
var a = radLat1 - radLat2;
var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * 6378.137;
s = Math.round(s * 10000) / 10000;
return s // 单位千米
}
// 获得角度的函数
function getAngle(start, end) {
var ret
var w1 = start.lat / 180 * Math.PI
var j1 = start.lng / 180 * Math.PI
var w2 = end.lat / 180 * Math.PI
var j2 = end.lng / 180 * Math.PI
ret = 4 * Math.pow(Math.sin((w1 - w2) / 2), 2) - Math.pow(Math.sin((j1 - j2) / 2) * (Math.cos(w1) - Math.cos(w2)), 2)
ret = Math.sqrt(ret)
// var temp = Math.sin(Math.abs(j1 - j2) / 2) * (Math.cos(w1) + Math.cos(w2));
var temp = Math.sin((j1 - j2) / 2) * (Math.cos(w1) + Math.cos(w2))
ret = ret / temp
ret = Math.atan(ret) / Math.PI * 180
ret += 90
// 这里用如此臃肿的if..else是为了判定追踪单个点的具体情况,从而调整ret的值
if (j1 - j2 < 0) {
if (w1 - w2 >= 0) {
ret = -ret + 180
}
} else {
if (w1 - w2 < 0) {
ret = 180 + ret
} else {
ret = -ret
}
}
return ret
}
//广播消息
export function broadcastMsg(data) {
export function broadcastMsg(vin, data) {
let km = space(data.s.lat, data.s.lng, data.e.lat, data.e.lng);
data.v = Math.ceil(km * 1000 / (data.t / 1000) * 1000)/1000;
data.ret = getAngle(data.s, data.e);
if (!data.v) return;
data.vin = vin;
data.show = true;
for (let key in connectionPool) {
let result = {code:200, success:true, data};
try {
// if (data.vin == "LZFH18T19LD019241") console.log(data.lat + "======"+ data.lng)
// console.log(data);
connectionPool[key].send(JSON.stringify(result));
} catch(err) {
logError(`广播消息失败: ${err}`);
......
......@@ -86,7 +86,9 @@ let dp = {};//数据池 {"id":{lastMs:最新的时间, list:[{},{},{}], index:0
let dpNewDate = '';
//结构:{"vid":{s:{lng:, lat:''}, e:{}, t:"" , lastCheckMs:0,}}
let test = {};
// let = 0;
export function stats(data) {
......@@ -99,11 +101,11 @@ export function stats(data) {
let dataJson = JSON.parse(data);
if (dataJson.VehicleLoc) {
let {vin, latitude, longitude, positiontime, vehicleId, velocity} = dataJson.VehicleLoc;
let {vin, latitude, longitude, positionTime, vehicleId, velocity} = dataJson.VehicleLoc;
// console.log("收到小车位置", vin);
broadcastMsg({lng:longitude||0.0, lat:latitude||0.0, vin, vehicleid:vehicleId});
// broadcastMsg({lng:longitude||0.0, lat:latitude||0.0, vin, vehicleid:vehicleId});
//加入到缓存
let lastMs = positiontime || new Date().valueOf();
let lastMs = positionTime || new Date().valueOf();
if ( lastMs ) {//数据包里有时间就缓存
checkData(dateFormat);
if ( !dp[vin] ) dp[vin] = {lastMs, list:[], index:0 };//初始化缓存
......@@ -111,40 +113,32 @@ export function stats(data) {
dp[vin].list[dp[vin].index] = {lng:longitude||0.0, lat:latitude||0.0, vin, lastMs, vehicleid:vehicleId};
dp[vin].index += 1;
if (dp[vin].index > 4) dp[vin].index = 0;
//==测试代码
if (!positionTime) return;
if (!test[vin] ) test[vin] = {s:{lng:longitude||0.0, lat:latitude||0.0}, e:{lng:0, lat:0}, st:positionTime, et:0, lastCheckMs:new Date().valueOf()};
if ( ( new Date().valueOf() - test[vin].lastCheckMs ) >= 1000) {
if ( !test[vin].et ) {
//初始车
test[vin].e = {lng:longitude||0.0, lat:latitude||0.0};
} else {
//非初始车
test[vin].s = test[vin].e;
test[vin].st = test[vin].et;
test[vin].e = {lng:longitude||0.0, lat:latitude||0.0};
}
test[vin].et = positionTime;
test[vin].t = test[vin].et - test[vin].st;
test[vin].lastCheckMs = new Date().valueOf();
//发送消息给小车
broadcastMsg(vin , test[vin]);
}
//==测试代码结束
}
}
// let 变化 = 0;
// let 无变化 = 0;
// let 有速度的车 = 0;
// let 速度为0的车 = 0;
// dataJson.VehicleLoc.forEach(info => {
// // if (velocity != 0 && vin == "LZFH18T13KD005883") {
// // console.log(vin, "车速==",velocity, "经纬度", latitude, longitude);
// // }
// // if (velocity != 0 ) {
// // 有速度的车 += 1;
// // if ( !test[vin] ) test[vin] = {latitude, longitude, type:"无变化"};
// // else {
// // if (latitude != test[vin].latitude || longitude != test[vin].longitude) {
// // test[vin].type = "有变化"
// // test[vin].latitude = latitude;
// // test[vin].longitude = longitude;
// // 变化 += 1;
// // } else {
// // 无变化 += 1;
// // }
// // }
// // } else {
// // 速度为0的车 += 1;
// // }
// });
// console.log(`本次消息总共发了:${有速度的车}辆有速度, 其中变化的 ${变化} 辆;没有变化的${无变化}, 速度为0的车${速度为0的车}`);
} catch(err) {
logHandle("ws 返回数据不是json --> "+ data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment