Browse Source

드론관제 날씨 기능

ctrlDraw
sanguu(박상현) 2 years ago
parent
commit
80816006f5
  1. 7
      src/modules/control/gp/models/controlGpModel.ts
  2. 1
      src/modules/control/gp/reducers/controlGpReducer.ts
  3. 19
      src/modules/control/gp/sagas/controlGpSaga.ts
  4. 161
      src/views/control/report/ControlReportDetail.js
  5. 106
      test/pav-warning.js

7
src/modules/control/gp/models/controlGpModel.ts

@ -54,6 +54,7 @@ export interface ControlDetailData {
ownerNm: string;
hpno: string;
telno: string;
items: [];
}
export interface ControlGpDtlData {
@ -100,12 +101,6 @@ export interface ControlGpData {
controlWarnNotyCd: boolean;
}
export interface ControlweatherData {
serviceKey: string;
numOfRows: string;
pageNo: string;
dataType: string;
base_date: string;
base_time: string;
nx: string;
ny: string;
}

1
src/modules/control/gp/reducers/controlGpReducer.ts

@ -113,7 +113,6 @@ export const controlGpDtlReducer = createReducer<
.handleAction(controlGpDtlAction.success, (state, action) =>
produce(state, draft => {
const data: ControlDetailData = action.payload;
draft.controlDetail = data;
})
);

19
src/modules/control/gp/sagas/controlGpSaga.ts

@ -119,9 +119,26 @@ function* controlDtlSaga(
) {
try {
const controlId = action.payload;
const state = yield select();
const { controlGpList } = state.controlGpState;
const a = controlGpList.filter(i => i.controlId === controlId);
const lat = a[0].lat;
const lng = a[0].lng;
const rq = {
nx: lat,
ny: lng
};
//날씨 api 호출
const res = yield call(controlGpApi.apiweather, rq);
const { data } = yield call(controlGpApi.getDetail, controlId);
yield put(Actions.controlGpDtlAction.success(data));
yield put(
Actions.controlGpDtlAction.success({
...data,
items: res.response.body.items
})
);
} catch (error) {
yield put(Actions.controlGpDtlAction.failure(error));
}

161
src/views/control/report/ControlReportDetail.js

@ -1,5 +1,5 @@
import moment from 'moment';
import React from 'react';
import React, { useMemo } from 'react';
import { useState, useEffect } from 'react';
import { X } from 'react-feather';
import { useDispatch, useSelector } from 'react-redux';
@ -33,77 +33,94 @@ const ControlReportDetail = props => {
const { controlGpDetail, controlDetail } = useSelector(
state => state.controlGpDtlState
);
const { controlWheather } = useSelector(state => state.ControlGpWeatherState);
//const { controlWheather } = useSelector(state => state.ControlGpWeatherState);
const { controlGpWarnLog } = useSelector(state => state.controlGpLogState);
useEffect(() => {
if (controlGpDetail) {
const rs = dfsxyconv("toXY", controlGpDetail?.lat, controlGpDetail?.lng);
let now = new Date();
let year = now.getFullYear(); // 년도
let month = now.getMonth() + 1; // 월
let day = ('0' + now.getDate()).slice(-2); // 날짜
const today = `${year}${month}${day}`;
let hours = now.getHours();
let minutes = now.getMinutes();
let basetime = "2300";
if ((hours >= 2 && minutes > 9) && hours <= 5) {
basetime = "0200";
}
else if ((hours >= 5 && minutes > 9) && hours < 8) {
basetime = "0500";
}
else if (hours >= 8 && minutes < 10) {
basetime = "0500";
}
else if ((hours >= 8 && minutes > 9) && hours < 11) {
basetime = "0800";
}
else if (hours >= 11 && minutes < 10) {
basetime = "0800";
}
else if (hours >= 11 && hours < 14) {
basetime = "1100";
}
else if (hours >= 14 && minutes < 10) {
basetime = "1100";
}
else if ((hours >= 14 && minutes > 9) && hours < 17) {
basetime = "1400";
}
else if (hours >= 17 && minutes < 10) {
basetime = "1400";
}
else if ((hours >= 17 && minutes > 9) && hours < 20) {
basetime = "1700";
}
else if (hours >= 20 && minutes < 10) {
basetime = "2000";
}
else if ((hours >= 20 && minutes > 9) && hours < 23) {
basetime = "2000";
}
else if (hours >= 23 && minutes < 10) {
basetime = "2300";
}
else if (hours >= 23 && minutes > 9) {
basetime = "2300";
}
const apidata = {
serviceKey: "r6RMUsk3Vtama7D6uq7MiWV9dTC9MwfIIr4%2F45y0uVNw6BaYbgpKmL%2BLUDFVTfIYUmEe4K%2FaniEjdV9mg5t82Q%3D%3D",
numOfRows: 14,
pageNo: 1,
dataType: "JSON",
base_date: today,
base_time: basetime,
nx: rs.x,
ny: rs.y,
}
dispatch(controlweatherAction.request(apidata));
function a() {
if (controlDetail) {
let wheatherDetail = controlDetail.items.item;
let skyDetail = wheatherDetail[6].fcstValue;
if (skyDetail == 1 || skyDetail == 2 || skyDetail == 4) {
return <CloudRain />;
} else if (skyDetail == 4) {
return <CloudSnow />;
} else if (skyDetail == 0 || wheatherDetail[5].fcstValue == 1) {
return <Sun />;
} else
return <Cloud />;
}
}
// console.log("time", time);
// useEffect(() => {
// if (controlGpDetail) {
// const rs = dfsxyconv("toXY", controlGpDetail?.lat, controlGpDetail?.lng);
// let now = new Date();
// let year = now.getFullYear(); // 년도
// let month = now.getMonth() + 1; // 월
// let day = ('0' + now.getDate()).slice(-2); // 날짜
// const today = `${year}${month}${day}`;
// let hours = now.getHours();
// let minutes = now.getMinutes();
// let basetime = "2300";
// if ((hours >= 2 && minutes > 9) && hours <= 5) {
// basetime = "0200";
// }
// else if ((hours >= 5 && minutes > 9) && hours < 8) {
// basetime = "0500";
// }
// else if (hours >= 8 && minutes < 10) {
// basetime = "0500";
// }
// else if ((hours >= 8 && minutes > 9) && hours < 11) {
// basetime = "0800";
// }
// else if (hours >= 11 && minutes < 10) {
// basetime = "0800";
// }
// else if (hours >= 11 && hours < 14) {
// basetime = "1100";
// }
// else if (hours >= 14 && minutes < 10) {
// basetime = "1100";
// }
// else if ((hours >= 14 && minutes > 9) && hours < 17) {
// basetime = "1400";
// }
// else if (hours >= 17 && minutes < 10) {
// basetime = "1400";
// }
// else if ((hours >= 17 && minutes > 9) && hours < 20) {
// basetime = "1700";
// }
// else if (hours >= 20 && minutes < 10) {
// basetime = "2000";
// }
// else if ((hours >= 20 && minutes > 9) && hours < 23) {
// basetime = "2000";
// }
// else if (hours >= 23 && minutes < 10) {
// basetime = "2300";
// }
// else if (hours >= 23 && minutes > 9) {
// basetime = "2300";
// }
// const apidata = {
// serviceKey: "r6RMUsk3Vtama7D6uq7MiWV9dTC9MwfIIr4%2F45y0uVNw6BaYbgpKmL%2BLUDFVTfIYUmEe4K%2FaniEjdV9mg5t82Q%3D%3D",
// numOfRows: 14,
// pageNo: 1,
// dataType: "JSON",
// base_date: today,
// base_time: basetime,
// nx: rs.x,
// ny: rs.y,
// }
// dispatch(controlweatherAction.request(apidata));
// }
}, [controlGpDetail])
// }, [controlGpDetail])
useEffect(() => {
if (historyModal) {
@ -335,11 +352,11 @@ const ControlReportDetail = props => {
</thead>
<tbody>
<tr>
<td>15</td>
<td><Sun /></td>
<td>27</td>
<td><Navigation2 className="rotate-45" /></td>
<td>2m/s</td>
<td>{controlDetail?.items.item[12].fcstTime.substring(0, 2)}</td>
<td>{a()}</td>
<td>{controlDetail?.items.item[12].fcstValue}</td>
<td><Navigation2 style={{ transform: `rotate(${controlDetail?.items.item[3].fcstValue}deg)` }} /></td>
<td>{controlDetail?.items.item[4].fcstValue}m/s</td>
</tr>
</tbody>
</Table>

106
test/pav-warning.js

@ -2,82 +2,82 @@ const { getConnection, writeData } = require('./pav-client');
const { getCoordsFormBetweenCoord, dumyData } = require('./pav-utils');
// const host = "192.168.0.24"
// const host = "localhost"
const host = '192.168.0.34';
const host = "localhost"
// const host = '192.168.0.34';
const port = 8082;
// 기본정보
const prefix = 'PA';
const prefix = 'PASANGUU';
const pathSampleCoord = [
[37.5215, 126.605],
[37.5215, 126.61],
// [37.5215, 126.6082],
[37.521, 126.6082],
[37.521, 126.6057],
[37.5205, 126.6057],
[37.5205, 126.6082],
[37.52, 126.6082],
[37.52, 126.6057],
[37.5195, 126.6057],
[37.5195, 126.6082],
[37.519, 126.6082],
[37.519, 126.605]
[37.5215, 126.605],
[37.5215, 126.61],
// [37.5215, 126.6082],
[37.521, 126.6082],
[37.521, 126.6057],
[37.5205, 126.6057],
[37.5205, 126.6082],
[37.52, 126.6082],
[37.52, 126.6057],
[37.5195, 126.6057],
[37.5195, 126.6082],
[37.519, 126.6082],
[37.519, 126.605]
];
const divDist = 10; // [m]
// 특정거리에 따른 좌표 추출
const getCoords = coords => {
if (!coords || coords.length < 1) return;
const totalCoords = [];
for (let i = 1; i < coords.length; i++) {
const divCoords = getCoordsFormBetweenCoord(
coords[i - 1],
coords[i],
divDist
);
totalCoords.push(...divCoords);
}
return totalCoords;
if (!coords || coords.length < 1) return;
const totalCoords = [];
for (let i = 1; i < coords.length; i++) {
const divCoords = getCoordsFormBetweenCoord(
coords[i - 1],
coords[i],
divDist
);
totalCoords.push(...divCoords);
}
return totalCoords;
};
const getClient = () => {
const dronName = prefix + '003';
// const dronName = prefix + '0000001A';
const dronName = prefix;
// const dronName = prefix + '0000001A';
const client = {};
client.dronName = dronName;
client.socket = getConnection(dronName, host, port);
client.data = getCoords(pathSampleCoord);
return client;
const client = {};
client.dronName = dronName;
client.socket = getConnection(dronName, host, port);
client.data = getCoords(pathSampleCoord);
return client;
};
const sendData = (client, cnt) => {
const data = {
...dumyData,
terminalId: client.dronName,
body: [
{
...dumyData.body[0],
objectId: client.dronName,
lat: client.data[cnt][0],
lon: client.data[cnt][1]
}
]
};
writeData(client.socket, JSON.stringify(data));
iteratorSendData(++cnt);
const data = {
...dumyData,
terminalId: client.dronName,
body: [
{
...dumyData.body[0],
objectId: client.dronName,
lat: client.data[cnt][0],
lon: client.data[cnt][1]
}
]
};
writeData(client.socket, JSON.stringify(data));
iteratorSendData(++cnt);
};
const client = getClient();
const iteratorSendData = (cnt = 0) => {
if (cnt >= client.data.length) {
client.socket.destroy();
return;
}
setTimeout(() => sendData(client, cnt), 1000);
if (cnt >= client.data.length) {
client.socket.destroy();
return;
}
setTimeout(() => sendData(client, cnt), 1000);
};
iteratorSendData();

Loading…
Cancel
Save