Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions monicar-control-center/src/main/resources/data/init-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ VALUES (1, '카카오', '123-45-67890', '2025-01-01 09:00:00', '2025-01-01 09:00

INSERT INTO vehicle_information
(vehicle_id, company_id, vehicle_type_id, vehicle_number, mdn, tid, mid, pv, did, driving_days, sum, lat, lng, status, delivery_date, created_at, updated_at, deleted_at)
values (1, 1, 2, '123나1234', 1234567890, 'TID002', 4, 6, 6, 360, 0, 37565557, 127018624, 'NOT_DRIVEN', '2025-02-06', '2025-02-06 02:31:59', '2025-02-06 02:31:59', null),
(2, 1, 1, '657가5202', 2254690422, 'TID003', 3, 1, 5, 927, 0, 37567987, 127014246, 'NOT_DRIVEN', '2025-02-06', '2025-02-06 20:25:59', '2025-02-06 20:25:59', null),
(3, 1, 2, '309가9777', 5246479703, 'TID004', 5, 8, 5, 20, 73907, 37559948, 126968317, 'NOT_REGISTERED', '2025-02-06', '2025-02-06 03:20:59', '2025-02-06 03:20:59', null),
(4, 1, 2, '530가4820', 6459804235, 'TID005', 8, 10, 7, 142, 86586, 37561026, 126977640, 'NOT_DRIVEN', '2025-02-06', '2025-02-06 04:19:59', '2025-02-06 04:19:59', null),
values (1, 1, 2, '123나1234', 1234567890, 'TID002', 4, 6, 6, 360, 0, 37565557, 127018624, 'NOT_DRIVEN', '2025-02-06','2025-02-06 02:31:59', '2025-02-06 02:31:59', null),
(2, 1, 1, '657가5202', 1234567891, 'TID003', 3, 1, 5, 927, 0, 37567987, 127014246, 'NOT_DRIVEN', '2025-02-06','2025-02-06 20:25:59', '2025-02-06 20:25:59', null),
(3, 1, 2, '309가9777', 1234567892, 'TID004', 5, 8, 5, 20, 0, 37559948, 126968317, 'NOT_DRIVEN', '2025-02-06','2025-02-06 03:20:59', '2025-02-06 03:20:59', null),
(4, 1, 2, '530가4820', 1234567893, 'TID005', 8, 10, 7, 142, 0, 37561026, 126977640, 'NOT_DRIVEN', '2025-02-06','2025-02-06 04:19:59', '2025-02-06 04:19:59', null),
(5, 1, 2, '762나5310', 4443625351, 'TID006', 5, 3, 8, 986, 72284, 37577531, 126988260, 'NOT_REGISTERED', '2025-02-06', '2025-02-06 23:00:59', '2025-02-06 23:00:59', null),
(6, 1, 1, '302가5423', 4214563846, 'TID007', 4, 5, 5, 13, 58468, 37572557, 127014216, 'NOT_DRIVEN', '2025-02-06', '2025-02-06 10:08:59', '2025-02-06 10:08:59', null),
(7, 1, 2, '655가8023', 5698741960, 'TID008', 3, 8, 1, 125, 34811, 37560109, 126936964, 'NOT_REGISTERED', '2025-02-06', '2025-02-06 07:15:59', '2025-02-06 07:15:59', null),
Expand Down
5 changes: 5 additions & 0 deletions monicar-emulator/simulation/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:21-jdk-slim
ARG JAR_FILE=../build/libs/*.jar
COPY ${JAR_FILE} /app/app.jar
WORKDIR /app
ENTRYPOINT ["java", "-jar", "app.jar"]
30 changes: 30 additions & 0 deletions monicar-emulator/simulation/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
container1:
container_name: tomato
build:
context: ../
dockerfile: simulation/Dockerfile
ports:
- "8091:8091"
environment:
- SPRING_PROFILES_ACTIVE=tomato

container2:
container_name: banana
build:
context: ../
dockerfile: simulation/Dockerfile
ports:
- "8092:8092"
environment:
- SPRING_PROFILES_ACTIVE=banana

container3:
container_name: apple
build:
context: ../
dockerfile: simulation/Dockerfile
ports:
- "8093:8093"
environment:
- SPRING_PROFILES_ACTIVE=apple
18 changes: 18 additions & 0 deletions monicar-emulator/simulation/start-one-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e

echo "🛠️ Gradle 프로젝트 빌드 중..."
../../gradlew :monicar-emulator:build --project-dir ../.. -x test

# .yml 확인하여 원하는 profile 이름으로 -f 뒤 값 수정 예) tomato -> banana
docker rm -f tomato 2>/dev/null || true

# 선택한 profile로 -t 뒤 값 수정 예) tomato-image -> banana-image
docker build -t tomato-image -f Dockerfile ../

# 선택한 profile로 --name 뒤 값과 마지막 xx-image 값 수정하기
docker run -d --name tomato \
-p 8091:8091 \
-e SPRING_PROFILES_ACTIVE=tomato \
tomato-image
9 changes: 9 additions & 0 deletions monicar-emulator/simulation/start-three-containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

echo "🛠️ Gradle 프로젝트 빌드 중..."
../../gradlew :monicar-emulator:build --project-dir ../..

echo "🐳 Docker Compose 빌드 및 컨테이너 실행..."
docker compose up --build
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import org.emulator.device.common.exception.BusinessException;
import org.emulator.device.common.response.ErrorCode;

public final class VehicleConstant {
public static final long VEHICLE_PRIMARY_KEY = 1234567890L;
public static final String VEHICLE_NUMBER = "123나1234";
public class VehicleInfoConstant {
public static final String TERMINAL_ID = "TID001";
public static final long MANUFACTURER_ID = 1L;
public static final int PACKET_VERSION = 1;
Expand All @@ -15,7 +13,7 @@ public final class VehicleConstant {

public static final long MIL = 1_000_000;

private VehicleConstant() {
private VehicleInfoConstant() {
throw new BusinessException(ErrorCode.ILLEGAL_UTILITY_CLASS_ACCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.emulator.device;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public record VehicleInfoDynamic(
@Value("${fixed.vehicle-mdn}")
long vehicleMdn,
@Value("${fixed.vehicle-number}")
String vehicleNumber
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public enum ErrorCode {
DATA_PROCESSING_ERROR(400, "An error occurred while processing data."),
UNDEFINED_ERROR(500, "An undefined error has occurred"),

/* api 관련 */
UNSUPPORTED_HEADER(1002, "지원하지 않는 헤더입니다"),
ILLEGAL_UTILITY_CLASS_ACCESS(1003, "유틸리티 클래스에 대한 잘못된 접근입니다"),
INTERNAL_SERVER_ERROR(1004, "서버 오류가 발생하였습니다"),
UNSUPPORTED_RESPONSE(1005, "지원하지 않는 응답입니다"),
UTILITY_CLASS_NOT_INITIALIZED_YET(1004, "유틸리티 클래스가 초기화되지 않았습니다"),

/* api 관련 */
NO_GPS_DATA_FOUND(1006, "GPS 데이터 생성이 실패했습니다"),
FAIL_RESPONSE_DELIVERED(1007, "요청 보낸 서버로부터 온 실패 응답입니다"),

FILE_LOAD_FILE(1008, "파일 읽기에 실패했습니다");

private final int code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.time.LocalDateTime;

import org.emulator.device.VehicleConstant;
import org.emulator.device.VehicleInfoConstant;
import org.emulator.sensor.dto.GpsTime;
import org.emulator.device.infrastructure.external.command.vo.Direction;
import org.emulator.device.infrastructure.external.command.vo.Geo;
Expand Down Expand Up @@ -37,7 +37,7 @@ public static CycleInfo create(
.direction(new Direction(direction))
.speed(new Speed(speed))
.totalDistance(new TotalDistance(totalDistance))
.battery(VehicleConstant.BATTERY)
.battery(VehicleInfoConstant.BATTERY)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@

import lombok.Getter;

import org.emulator.device.VehicleConstant;
import org.emulator.device.VehicleInfoConstant;
import org.emulator.device.VehicleInfoDynamic;
import org.emulator.device.common.exception.BusinessException;
import org.emulator.device.common.response.ErrorCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
* 차량의 기본 데이터를 담는 VO
*
* @field mdn 차량 번호 - 차량을 식별하는 고유 번호
* @field num 차량 번호 - 번호판 번호
* @field tid 터미널 아이디 - 터미널 장치의 고유 식별자
* @field mid 제조사 아이디 - 제조사를 구분하는 식별자
* @field pv 패킷 버전 - 데이터 패킷의 버전 정보
* @field did 디바이스 아이디 - 설치된 디바이스의 고유 식별자
*/
@Component
@Getter
public class FixedVehicleInfo {
private static final FixedVehicleInfo INSTANCE = new FixedVehicleInfo();
private static FixedVehicleInfo INSTANCE;

private final long mdn;
private final String num;
Expand All @@ -25,16 +21,21 @@ public class FixedVehicleInfo {
private final int pv;
private final long did;

private FixedVehicleInfo() {
this.mdn = VehicleConstant.VEHICLE_PRIMARY_KEY;
this.num = VehicleConstant.VEHICLE_NUMBER;
this.tid = VehicleConstant.TERMINAL_ID;
this.mid = VehicleConstant.MANUFACTURER_ID;
this.pv = VehicleConstant.PACKET_VERSION;
this.did = VehicleConstant.DEVICE_ID;
@Autowired
public FixedVehicleInfo(VehicleInfoDynamic vehicleInfoDynamic) {
this.mdn = vehicleInfoDynamic.vehicleMdn();
this.num = vehicleInfoDynamic.vehicleNumber();
this.tid = VehicleInfoConstant.TERMINAL_ID;
this.mid = VehicleInfoConstant.MANUFACTURER_ID;
this.pv = VehicleInfoConstant.PACKET_VERSION;
this.did = VehicleInfoConstant.DEVICE_ID;
INSTANCE = this;
}

public static FixedVehicleInfo getInstance() {
if (INSTANCE == null) {
throw new BusinessException(ErrorCode.UTILITY_CLASS_NOT_INITIALIZED_YET);
}
return INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Getter;

import org.emulator.device.VehicleConstant;
import org.emulator.device.VehicleInfoConstant;

@Getter
public class Geo {
Expand All @@ -20,7 +20,7 @@ public Geo() {
}

public Geo(double latitude, double longitude) {
this.latitude = Math.clamp((long)(latitude * VehicleConstant.MIL), LATITUDE_MIN, LATITUDE_MAX);
this.longitude = Math.clamp((long)(longitude * VehicleConstant.MIL), LONGITUDE_MIN, LONGITUDE_MAX);
this.latitude = Math.clamp((long)(latitude * VehicleInfoConstant.MIL), LATITUDE_MIN, LATITUDE_MAX);
this.longitude = Math.clamp((long)(longitude * VehicleInfoConstant.MIL), LONGITUDE_MIN, LONGITUDE_MAX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import lombok.extern.slf4j.Slf4j;

import org.emulator.device.common.exception.BusinessException;
import org.emulator.device.common.response.ErrorCode;
import org.emulator.sensor.dto.Gps;
Expand All @@ -22,6 +24,7 @@

@RequiredArgsConstructor
@Component
@Slf4j
public class GpxFileParser {
@Value("${file-name}")
private String fileName;
Expand Down Expand Up @@ -58,6 +61,8 @@ public Queue<Gps> parse() {
gpsList.offer(new Gps(lat, lng));
}

log.info("➡️ GPS 파일 이름: {}", fileName);
log.info("➡️ GPS 개수: {}", gpsList.size());
return gpsList;
}
}
63 changes: 61 additions & 2 deletions monicar-emulator/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ server:
port: 8090

spring:
profiles:
active: default
application:
name: monicar-emulator

Expand All @@ -11,7 +13,64 @@ logging:
path: ${user.dir}/logs

api:
base-url: http://localhost:8082/api/v1/event-hub/
transmission-time: 60
base-url: http://localhost:8082/api/v1/event-hub/
# 에뮬레이터를 컨테이너로 만든 상태에서 로컬 event-hub 서버에 요청 보낼 때
# base-url: http://host.docker.internal:8082/api/v1/event-hub/

file-name: suwon-daejon-gumi-optimized.gpx

fixed:
vehicle-mdn: 1234567890
vehicle-number: 123나1234

---
server:
port: 8091

spring:
config:
activate:
on-profile: tomato
application:
name: monicar-emulator-tomato

file-name: yangyang-to-daegu_formatted.gpx

fixed:
vehicle-mdn: 1234567891
vehicle-number: 657가5202

---
server:
port: 8092

spring:
config:
activate:
on-profile: banana
application:
name: monicar-emulator-banana

file-name: yeosu-to-cheonan_formatted.gpx

fixed:
vehicle-mdn: 1234567892
vehicle-number: 309가9777

---
server:
port: 8093

spring:
config:
activate:
on-profile: apple
application:
name: monicar-emulator-apple

file-name: gwangju-to-muju_formatted.gpx

file-name: suwon-daejon-gumi-optimized.gpx
fixed:
vehicle-mdn: 1234567893
vehicle-number: 530가4820
Loading