김장현
2 years ago
4 changed files with 80 additions and 79 deletions
@ -1,77 +1,83 @@
|
||||
const {getConnection, writeData} = require("./pav-client") |
||||
const {getCoordsFormBetweenCoord, dumyData} = require("./pav-utils") |
||||
const { getConnection, writeData } = require('./pav-client'); |
||||
const { getCoordsFormBetweenCoord, dumyData } = require('./pav-utils'); |
||||
|
||||
// const host = "192.168.0.24"
|
||||
// const host = "localhost"
|
||||
const host = "211.253.38.218" |
||||
const port = 8082 |
||||
const host = '192.168.0.34'; |
||||
const port = 8082; |
||||
|
||||
// 기본정보
|
||||
const prefix = 'TEST-DRON-W-' |
||||
const prefix = 'PA'; |
||||
|
||||
const pathSampleCoord = [ |
||||
[37.5215, 126.6050], |
||||
[37.5215, 126.6082], |
||||
[37.5210, 126.6082], |
||||
[37.5210, 126.6057], |
||||
[37.5205, 126.6057], |
||||
[37.5205, 126.6082], |
||||
[37.5200, 126.6082], |
||||
[37.5200, 126.6057], |
||||
[37.5195, 126.6057], |
||||
[37.5195, 126.6082], |
||||
[37.5190, 126.6082], |
||||
[37.5190, 126.6050] |
||||
] |
||||
[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 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; |
||||
} |
||||
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; |
||||
}; |
||||
|
||||
const getClient = () => { |
||||
const dronName = prefix + '001'; |
||||
const dronName = prefix + '003'; |
||||
// 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() |
||||
iteratorSendData(); |
||||
|
Loading…
Reference in new issue