Skip to content
Open
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
Binary file modified .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation("org.assertj:assertj-core:3.23.1")
implementation 'org.apache.commons:commons-math3:3.6.1'
// https://mvnrepository.com/artifact/org.json/json
implementation("org.json:json:20240303")

}

tasks.named('test') {
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
Binary file modified src/.DS_Store
Binary file not shown.
Binary file modified src/main/.DS_Store
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class LanternOfDuskBeApplication {

public static void main(String[] args) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
package IOT_Platform.Lantern_Of_Dusk_BE.controller;

import IOT_Platform.Lantern_Of_Dusk_BE.entity.Connection;
import IOT_Platform.Lantern_Of_Dusk_BE.entity.Marker;
import IOT_Platform.Lantern_Of_Dusk_BE.entity.Position;
import IOT_Platform.Lantern_Of_Dusk_BE.service.ApiService;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.*;

@RestController
@AllArgsConstructor
@CrossOrigin
@RequestMapping("/api")
public class ApiController {

private final ApiService apiService;

// GET /api/connection/list ⇒ 모든 연결 정보 / X
@GetMapping("/connection/list")
public List<Connection> getConnectionAll() {
return apiService.findAll();
public List<Connection> readConnectionList() {
return apiService.getConnectionList();
}

// GET /api/connection/:id ⇒ 특정 아이디의 연결 정보 / (int id)
@GetMapping("/connection/{id}")
public ResponseEntity<Connection> getConnection(@PathVariable int id) {
public ResponseEntity<Connection> readConnection(@PathVariable int id) {
try {
Connection connection = apiService.findById(id);
Connection connection = apiService.getConnection(id);
if (connection != null) {
return new ResponseEntity<>(connection, HttpStatus.OK);
} else {
Expand All @@ -39,13 +40,13 @@ public ResponseEntity<Connection> getConnection(@PathVariable int id) {
}
}

// POST /api/connection ⇒ 연결 정보 생성 / json {id, name, applicationEntity}
// POST /api/connection ⇒ 연결 정보 생성 / json {name, applicationEntity}
@PostMapping("/connection")
public ResponseEntity<Connection> postConnection(@RequestBody Connection connectionContext) {
public ResponseEntity<Connection> createConnection(@RequestBody Connection connection) {
try {
if (apiService.findByAe(connectionContext.getApplicationEntity()) == null) {
apiService.save(connectionContext);
return new ResponseEntity<>(apiService.findByAe(connectionContext.getApplicationEntity()), HttpStatus.CREATED);
if (apiService.getConnection(connection.getAe()) == null) {
apiService.saveConnection(connection);
return new ResponseEntity<>(HttpStatus.CREATED);
} else return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
Expand All @@ -55,15 +56,14 @@ public ResponseEntity<Connection> postConnection(@RequestBody Connection connect
// PUT /api/connection/{id} ⇒ 연결 정보 업데이트 / (int id), json {id, name, applicationEntity}
@PutMapping("/connection/{id}")
public ResponseEntity<Connection> updateConnection(@PathVariable int id, @RequestBody Connection updatedConnection) {

try {
if (apiService.findById(id) != null) {
Connection pastConnection = apiService.findById(id);
if (apiService.getConnection(id) != null) {
Connection pastConnection = apiService.getConnection(id);
pastConnection.setId(updatedConnection.getId());
pastConnection.setName(updatedConnection.getName());
pastConnection.setApplicationEntity(updatedConnection.getApplicationEntity());
apiService.save(pastConnection);
return new ResponseEntity<>(apiService.findById(id), HttpStatus.OK);
pastConnection.setAe(updatedConnection.getAe());
apiService.saveConnection(pastConnection);
return new ResponseEntity<>(apiService.getConnection(id), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
Expand All @@ -75,10 +75,9 @@ public ResponseEntity<Connection> updateConnection(@PathVariable int id, @Reques
// DELETE /api/connection/:id ⇒ 연결 정보 삭제 / (int id)
@DeleteMapping("/connection/{id}")
public ResponseEntity<String> deleteConnection(@PathVariable int id) {

try {
if (apiService.findById(id) != null) {
apiService.deleteById(id);
if (apiService.getConnection(id) != null) {
apiService.deleteDevice(id);
return new ResponseEntity<>("ID의 ae가 삭제되었습니다", HttpStatus.OK);
} else {
return new ResponseEntity<>("요청에 문제가 있습니다.", HttpStatus.BAD_REQUEST);
Expand All @@ -88,25 +87,49 @@ public ResponseEntity<String> deleteConnection(@PathVariable int id) {
}
}

// DELETE /api/connection ⇒ 연결 정보 삭제
@DeleteMapping("/connection")
public ResponseEntity<String> deleteAllConnection() {

apiService.deleteAll();
return new ResponseEntity<>("전체 connection-ae가 삭제되었습니다.", HttpStatus.OK);
}

// GET /api/position/:deviceId ⇒ deviceId 위치정보 / (int deviceId)
@GetMapping("/position/{deviceId}")
public ResponseEntity<Position> getPositionByDeviceId(@PathVariable int deviceId) {

public ResponseEntity<Position> readPosition(@PathVariable int deviceId) {
try {
if (apiService.findById(deviceId) != null && apiService.getApplicationEntityByDeviceId(deviceId) != null) {
Position position = apiService.getApplicationEntityByDeviceId(deviceId);
if (apiService.getConnection(deviceId) != null && apiService.getPosition(deviceId) != null) {
Position position = apiService.getPosition(deviceId);
return new ResponseEntity<>(position, HttpStatus.OK);
} else return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

// GET /api/marker/list ⇒ 마커 정보 / x
@GetMapping("/marker/list")
public List<Marker> readMarkerList() {
return apiService.getMarkerList();
}

// POST /api/marker ⇒ 마커 정보 / json {x, y, z}
@PostMapping("/marker")
public ResponseEntity<Marker> createMarker(@RequestBody Marker marker) {
try {
apiService.saveMarker(marker);
return new ResponseEntity<>(HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

// DELETE /api/marker/:id ⇒ 마커 삭제 / (int id)
@DeleteMapping("/marker/{id}")
public ResponseEntity<String> deleteMarker(@PathVariable int id) {
try {
if (apiService.getMarker(id) != null) {
apiService.deleteMarker(id);
return new ResponseEntity<>("Marker가 삭제되었습니다.", HttpStatus.OK);
} else {
return new ResponseEntity<>("요청에 문제가 있습니다.", HttpStatus.BAD_REQUEST);
}
} catch (Exception e) {
return new ResponseEntity<>("서버에 오류 발생했습니다.", HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package IOT_Platform.Lantern_Of_Dusk_BE.controller;

import IOT_Platform.Lantern_Of_Dusk_BE.service.ProcessService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@CrossOrigin
@RequestMapping("/process")
public class DeviceController {

private final ProcessService processService;

@GetMapping("/start")
public void startProcess() {
processService.startProcess();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package IOT_Platform.Lantern_Of_Dusk_BE.core;

import org.apache.commons.math3.complex.Complex;

public class Butterworth {
public static double[][] designHighPassFilter(int order, double cutoffFreq, double sampleRate) {
double[] a = new double[order + 1];
double[] b = new double[order + 1];

// Normalize cutoff frequency
double wc = Math.tan(Math.PI * cutoffFreq / sampleRate);

// Poles and zeros
Complex[] poles = new Complex[order];
for (int k = 0; k < order; k++) {
double theta = (2 * k + 1) * Math.PI / (2 * order);
poles[k] = new Complex(-Math.sin(theta), Math.cos(theta));
}

// Gain calculation
double gain = 1;
for (Complex pole : poles) {
gain *= -pole.getReal();
}
gain = Math.pow(wc, order) / gain;

// Coefficients calculation
for (int i = 0; i <= order; i++) {
a[i] = 0;
b[i] = 0;
}
b[0] = gain;
for (int k = 0; k < order; k++) {
Complex pole = poles[k];
for (int j = order; j > 0; j--) {
a[j] += a[j - 1] * 2 * pole.getReal();
b[j] += b[j - 1] * 2 * pole.getReal();
}
for (int j = order; j > 1; j--) {
a[j] += a[j - 2];
b[j] += b[j - 2];
}
a[1] += 1;
b[1] += 1;
}

// Denominator coefficients adjustment
for (int i = 0; i <= order; i++) {
a[i] = (i % 2 == 0) ? a[i] : -a[i];
}

return new double[][]{b, a};
}
}
Loading