Commit eb220b3d authored by duwei's avatar duwei

优化路口灯态倒计时,用kafka消费

parent ea29bad8
utc.service.url=http://192.168.208.43:32000/utc
utc.dt.service.url=http://192.168.208.43:39002/utc-dt
utc.hisense.service.url=http://192.168.208.43:39003/utc-hisense
control.url=http://192.168.208.43:32001/web
spring:
cloud:
nacos:
config:
server-addr: 10.102.1.163:8848
file-extension: yaml
group: signal
namespace: signal
username: nacos
password: Wgzonal0sowQjm9
application:
# dubbo启动需要程序名称
name: signal-optimize-service
main:
allow-circular-references: true
spring: spring:
profiles: profiles:
active: docker #docker是武汉环境,demo是北京环境
\ No newline at end of file active: demo
\ No newline at end of file
...@@ -167,6 +167,11 @@ ...@@ -167,6 +167,11 @@
<groupId>javax.el</groupId> <groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId> <artifactId>javax.el-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>net.jodah</groupId>
<artifactId>expiringmap</artifactId>
<version>0.5.10</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -119,7 +119,11 @@ public class RedisConfig extends CachingConfigurerSupport { ...@@ -119,7 +119,11 @@ public class RedisConfig extends CachingConfigurerSupport {
@Bean @Bean
public Jedis jedis() { public Jedis jedis() {
Jedis jedis = new Jedis(redisHost, redisPort); Jedis jedis = new Jedis(redisHost, redisPort);
if (password != null && !"".equals(password)) {
jedis.auth(password);
}else {
jedis.auth("Wanji300552"); jedis.auth("Wanji300552");
}
return jedis; return jedis;
} }
......
package net.wanji.utc.dto.twinspat;
import lombok.Data;
import java.util.List;
/**
* 路口信息
*/
@Data
public class Intersection {
// 路口id (这个id需要与库表中路口id要映射)
private int nodeId;
private List<Phase> phases;
}
\ No newline at end of file
package net.wanji.utc.dto.twinspat;
import lombok.Data;
/**
* 相位信息
* 解释名词:
* 相位是指在一个信号灯周期中,某一组特定方向的交通流获得通行权(如绿灯)的状态。
* “相位”就是信号灯在某个时间段内允许某些方向车辆通行的一种状态。
* “当前相位”是指当前正在运行的信号灯状态,决定了哪些方向可以通行、哪些需要等待。
*
*/
@Data
public class Phase {
private String id; // 唯一值 phaseId + "_" + laneId
private int phaseId; // 相位ID [1-16], 控制一个灯组
private int laneId; // 车道编号
private int state; // 转向(灯组状态 [参考表E.3])
private int importDirect; // 进口方向 [参考表E.2]
private int turn; // 车道转向
private int light; // 信号灯颜色 [0..8]
private int limitEndTime; // 信号灯倒计时, 单位:秒
private String log; // 经度
private String lat; // 纬度
private float angle; // 信号灯角度
}
\ No newline at end of file
package net.wanji.utc.dto.twinspat;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import java.util.List;
/**
* 孪生专用信号灯数据
*/
@Data
public class WHSpatData {
private String rsuId;//要配映射路口id
private int msgCnt;
private long timestamp;
private String uuid;
private String msgType;
/**
* 路口列表
*/
private List<Intersection> intersections;
public static void main(String[] args) {
String json = "{\"intersections\":[{\"nodeId\":15,\"phases\":[{\"angle\":261.0,\"id\":\"4_1\",\"importDirect\":0,\"laneId\":1,\"lat\":\"30.4518233\",\"light\":3,\"limitEndTime\":28,\"log\":\"114.0926314\",\"phaseId\":4,\"state\":4},{\"angle\":261.0,\"id\":\"4_2\",\"importDirect\":0,\"laneId\":2,\"lat\":\"30.4518180\",\"light\":3,\"limitEndTime\":28,\"log\":\"114.0925986\",\"phaseId\":4,\"state\":4},{\"angle\":348.0,\"id\":\"66_1\",\"importDirect\":4,\"laneId\":1,\"lat\":\"30.4516888\",\"light\":3,\"limitEndTime\":5,\"log\":\"114.0930230\",\"phaseId\":66,\"state\":2},{\"angle\":348.0,\"id\":\"65_3\",\"importDirect\":4,\"laneId\":3,\"lat\":\"30.4517495\",\"light\":4,\"limitEndTime\":2,\"log\":\"114.0930097\",\"phaseId\":65,\"state\":1},{\"angle\":348.0,\"id\":\"65_2\",\"importDirect\":4,\"laneId\":2,\"lat\":\"30.4517189\",\"light\":4,\"limitEndTime\":2,\"log\":\"114.0930162\",\"phaseId\":65,\"state\":1},{\"angle\":91.0,\"id\":\"132_1\",\"importDirect\":8,\"laneId\":1,\"lat\":\"30.4511704\",\"light\":3,\"limitEndTime\":28,\"log\":\"114.0927570\",\"phaseId\":132,\"state\":4},{\"angle\":91.0,\"id\":\"132_2\",\"importDirect\":8,\"laneId\":2,\"lat\":\"30.4511697\",\"light\":3,\"limitEndTime\":28,\"log\":\"114.0927937\",\"phaseId\":132,\"state\":4},{\"angle\":169.0,\"id\":\"194_1\",\"importDirect\":12,\"laneId\":1,\"lat\":\"30.4515106\",\"light\":3,\"limitEndTime\":5,\"log\":\"114.0924748\",\"phaseId\":194,\"state\":2},{\"angle\":169.0,\"id\":\"193_2\",\"importDirect\":12,\"laneId\":2,\"lat\":\"30.4514799\",\"light\":4,\"limitEndTime\":2,\"log\":\"114.0924808\",\"phaseId\":193,\"state\":1},{\"angle\":170.0,\"id\":\"193_3\",\"importDirect\":12,\"laneId\":3,\"lat\":\"30.4514491\",\"light\":4,\"limitEndTime\":2,\"log\":\"114.0924865\",\"phaseId\":193,\"state\":1}]}],\"msgCnt\":92,\"msgType\":\"spat\",\"rsuId\":\"R-081507\",\"timestamp\":1746685493855,\"uuid\":\"R-081507_1746685493855\"}";
WHSpatData whSpatData = JSONObject.parseObject(json, WHSpatData.class);
System.out.println(whSpatData);
}
}
package net.wanji.utc.util;
/**
* 灯态的16个方向转换为8个方向类型
* 注:用于计算空放
*/
public class DirectionConverter {
/**
* 将0~15的进口方向编号转换为1~8的方向类型
* @param directionCode 0~15的输入方向编号
* @return 1~8的输出方向类型
*/
public static int convertDirection(int directionCode) {
if (directionCode < 0 || directionCode > 15) {
throw new IllegalArgumentException("directionCode must be between 0 and 15");
}
switch (directionCode) {
case 15:
case 0:
return 1; // 北
case 1:
case 2:
return 2; // 东北
case 3:
case 4:
return 3; // 东
case 5:
case 6:
return 4; // 东南
case 7:
case 8:
return 5; // 南
case 9:
case 10:
return 6; // 西南
case 11:
case 12:
return 7; // 西
case 13:
case 14:
return 8; // 西北
}
return 0; // 未知方向
}
public static void main(String[] args) {
for (int i = 0; i <= 15; i++) {
System.out.println("Input: " + i + " → Output: " + convertDirection(i));
}
}
}
package net.wanji.utc.util;
/**
* 灯态车道转向映射器
*/
public class TurnDirectionMapper {
// 定义映射关系,索引为源头转向值,值为目标转向值
private static final int[] DIRECTION_MAP = {
1, // 源头值 0 -> 目标值 1(左转)
2, // 源头值 1 -> 目标值 2(直行)
1, // 源头值 2 -> 目标值 1(左转)
5, // 源头值 3 -> 目标值 5(直左)
3, // 源头值 4 -> 目标值 3(右转)
6, // 源头值 5 -> 目标值 6(直右)
8, // 源头值 6 -> 目标值 8(左右)
7, // 源头值 7 -> 目标值 7(左直右)
4, // 源头值 8 -> 目标值 4(掉头)
10, // 源头值 9 -> 目标值 10(直行掉头)
9, // 源头值 10 -> 目标值 9(左转掉头)
12, // 源头值 11 -> 目标值 12(左直掉头)
11, // 源头值 12 -> 目标值 11(右转掉头)
13, // 源头值 13 -> 目标值 13(直右掉头)
15, // 源头值 14 -> 目标值 15(左右掉头)
14 // 源头值 15 -> 目标值 14(左直右掉头)
};
/**
* 转换源头转向值到目标转向值
*
* @param sourceValue 源头转向值 (0-15)
* @return 目标转向值 (1-15)
*/
public static int mapToTargetValue(int sourceValue) {
if (sourceValue < 0 || sourceValue >= DIRECTION_MAP.length) {
throw new IllegalArgumentException("非法源头转向值: " + sourceValue);
}
return DIRECTION_MAP[sourceValue];
}
public static void main(String[] args) {
for (int i = 0; i < 16; i++) {
System.out.println("源头值 " + i + " 映射的目标值为: " + mapToTargetValue(i));
}
}
}
spring:
application:
# dubbo启动需要程序名称
name: utc
main:
allow-circular-references: true
cloud:
nacos:
config:
server-addr: 10.102.1.163:8848
file-extension: yaml
group: signal
namespace: signal
username: nacos
password: Wgzonal0sowQjm9
\ No newline at end of file
spring: spring:
profiles: profiles:
active: dev #demo 北京环境
\ No newline at end of file active: demo
\ No newline at end of file
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