Skip to content

Commit

Permalink
Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephendade committed Nov 11, 2024
1 parent 62b3ad0 commit d57e356
Show file tree
Hide file tree
Showing 33 changed files with 200 additions and 204 deletions.
13 changes: 7 additions & 6 deletions mavlink/mavManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,19 @@ class mavManager {
let buf = Buffer.from(gpmessage)
const msgset = []
const maxBytes = 180
while (true) {
if (buf.length > maxBytes) {
while (buf.length > maxBytes) {
//if (buf.length > maxBytes) {
// slice
msgset.push(buf.slice(0, maxBytes))
buf = buf.slice(maxBytes)
} else {
//} else {
// need to pad to 180 chars? No, message packing
// will do this for us
msgset.push(buf)
break
}
// msgset.push(buf)
// break
//}
}
msgset.push(buf)

for (let i = 0, len = msgset.length; i < len; i++) {
const msg = new common.GpsRtcmData()
Expand Down
23 changes: 11 additions & 12 deletions mavlink/mavManager.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const assert = require('assert')
const should = require('should')
const mavManager = require('./mavManager')
const udp = require('dgram')

Expand All @@ -15,7 +14,7 @@ describe('MAVLink Functions', function () {
const m = new mavManager(2, '127.0.0.1', 15000)
const packets = []

m.eventEmitter.on('gotMessage', (packet, data) => {
m.eventEmitter.on('gotMessage', (packet,) => {
packets.push(packet.buffer)
})

Expand Down Expand Up @@ -50,11 +49,11 @@ describe('MAVLink Functions', function () {

assert.equal(m.statusBytesPerSec.avgBytesSec, 0)

m.eventEmitter.on('linkready', (info) => {
m.eventEmitter.on('linkready', () => {
m.sendVersionRequest()
})

udpStream.on('message', (msg, rinfo) => {
udpStream.on('message', (msg) => {
msg.should.eql(Buffer.from([0xfd, 0x21, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x14, 0x43, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x01, 0xbf, 0x5b]))
Expand All @@ -75,11 +74,11 @@ describe('MAVLink Functions', function () {
const m = new mavManager(2, '127.0.0.1', 15000)
const udpStream = udp.createSocket('udp4')

m.eventEmitter.on('linkready', (info) => {
m.eventEmitter.on('linkready', () => {
m.sendDSRequest()
})

udpStream.on('message', (msg, rinfo) => {
udpStream.on('message', (msg) => {
msg.should.eql(Buffer.from([253, 6, 0, 0, 0, 0, 191, 66, 0, 0, 4, 0, 0, 0, 0, 1, 171, 220]))
m.close()
udpStream.close()
Expand All @@ -97,11 +96,11 @@ describe('MAVLink Functions', function () {
const m = new mavManager(2, '127.0.0.1', 15000)
const udpStream = udp.createSocket('udp4')

m.eventEmitter.on('linkready', (info) => {
m.eventEmitter.on('linkready', () => {
m.sendReboot()
})

udpStream.on('message', (msg, rinfo) => {
udpStream.on('message', (msg) => {
msg.should.eql(Buffer.from([253, 33, 0, 0, 0, 0, 191, 76, 0, 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 246, 0, 0, 0, 1, 187, 227]))
m.close()
udpStream.close()
Expand All @@ -119,11 +118,11 @@ describe('MAVLink Functions', function () {
const m = new mavManager(2, '127.0.0.1', 15000)
const udpStream = udp.createSocket('udp4')

m.eventEmitter.on('linkready', (info) => {
m.eventEmitter.on('linkready', () => {
m.sendHeartbeat()
})

udpStream.on('message', (msg, rinfo) => {
udpStream.on('message', (msg) => {
msg.should.eql(Buffer.from([253, 9, 0, 0, 0, 0, 191, 0, 0, 0, 0, 0, 0, 0, 18, 8, 0, 0, 2, 61, 244 ]))
m.close()
udpStream.close()
Expand All @@ -141,11 +140,11 @@ describe('MAVLink Functions', function () {
const m = new mavManager(2, '127.0.0.1', 15000)
const udpStream = udp.createSocket('udp4')

m.eventEmitter.on('linkready', (info) => {
m.eventEmitter.on('linkready', () => {
m.sendCommandAck()
})

udpStream.on('message', (msg, rinfo) => {
udpStream.on('message', (msg) => {
msg.should.eql(Buffer.from([253, 9, 0, 0, 0, 0, 191, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 197, 27]))
m.close()
udpStream.close()
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"npm": "^10.5.2",
"ntrip-client": "^1.1.1",
"nyc": "^17.1.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-bootstrap": "^2.8.0",
"react-dom": "^18.2.0",
Expand Down
8 changes: 4 additions & 4 deletions server/aboutInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getDiskInfo (callback) {
})
}

function rebootCC () {
/*function rebootCC () {
// reboot the companion computer
console.log('Reboot now')
winston.info('Reboot now')
Expand All @@ -35,13 +35,13 @@ function rebootCC () {
console.log(stdout)
winston.info(stdout)
})
}
}*/

function shutdownCC () {
// shutdown the companion computer
console.log('Shutting down')
winston.info('Shutting down')
exec('sudo shutdown now', function (error, stdout, stderr) {
exec('sudo shutdown now', function (error, stdout) {
if (error) {
console.log(error)
winston.info(error)
Expand Down Expand Up @@ -103,7 +103,7 @@ function getHardwareInfo (callback) {
sysData = execSync('cat /proc/cpuinfo | awk \'/Model/ {print substr($0, index($0,$3))}\'').toString()
}
// get Pi HAT data, if it exists
exec('cat /proc/device-tree/hat/product && printf "\n" && cat /proc/device-tree/hat/vendor && printf "\n" && cat /proc/device-tree/hat/product_ver', (error, stdout, stderr) => {
exec('cat /proc/device-tree/hat/product && printf "\n" && cat /proc/device-tree/hat/vendor && printf "\n" && cat /proc/device-tree/hat/product_ver', (error, stdout) => {
if (!error && stdout.split('\n').length === 3) {
const items = stdout.split('\n')
hatData.product = items[0]
Expand Down
2 changes: 1 addition & 1 deletion server/adhocManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class adhocManager {
// if Ahoc mode is supposed to be active, then activate it. As OS won't save settings between reboots
if (this.device !== null) {
// this.setAdapter(true, this.device, this.devicesettings, null)
this.setAdapter(true, this.device, this.devicesettings, (err, netDeviceList, netDeviceSelected, settings) => {
this.setAdapter(true, this.device, this.devicesettings, (err) => {
if (!err) {
console.log('Adhoc Init ' + this.device.toString())
this.winston.info('Adhoc Init ' + this.device.toString())
Expand Down
26 changes: 16 additions & 10 deletions server/flightController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const SerialPort = require('serialport')
const { autoDetect } = require('@serialport/bindings-cpp')
const fs = require('fs')
const events = require('events')
const path = require('path')
const appRoot = require('app-root-path')
const { spawn, spawnSync, exec } = require('child_process')
const { spawn, spawnSync } = require('child_process')
const si = require('systeminformation')

const mavManager = require('../mavlink/mavManager.js')
Expand Down Expand Up @@ -104,11 +103,11 @@ class FCDetails {
if (this.activeDevice !== null) {
// restart link if saved serial device is found
let found = false
this.getSerialDevices((err, devices, bauds, seldevice, selbaud, mavers, selmav, active, enableHeartbeat, enableTCP) => {
this.getSerialDevices((err, devices) => {
for (let i = 0, len = devices.length; i < len; i++) {
if (this.activeDevice.serial.value === devices[i].value) {
found = true
this.startLink((err, active) => {
this.startLink((err) => {
if (err) {
console.log("Can't open found FC " + this.activeDevice.serial.value + ', resetting link')
this.winston.info("Can't open found FC " + this.activeDevice.serial.value + ', resetting link')
Expand Down Expand Up @@ -180,9 +179,10 @@ class FCDetails {

// restart mavlink-router, if link active
if (this.m) {
this.closeLink((err) => {
this.closeLink(() => {
this.startLink((err) => {
if (err) {
console.log(err)
}
})
})
Expand All @@ -192,6 +192,7 @@ class FCDetails {
try {
this.saveSerialSettings()
} catch (e) {
console.log(e)
}

return this.getUDPOutputs()
Expand All @@ -215,9 +216,10 @@ class FCDetails {

// restart mavlink-router, if link active
if (this.m) {
this.closeLink((err) => {
this.closeLink(() => {
this.startLink((err) => {
if (err) {
console.log(err)
}
})
})
Expand All @@ -227,6 +229,7 @@ class FCDetails {
try {
this.saveSerialSettings()
} catch (e) {
console.log(e)
}

return this.getUDPOutputs()
Expand Down Expand Up @@ -340,7 +343,9 @@ class FCDetails {
fs.unlinkSync(this.binlog)
}
}
} catch (err) {}
} catch (err) {
console.log(err)
}
const res = data.toString().split(' ')
const curLog = (res[res.length - 1]).trim()
this.binlog = path.join(appRoot.toString(), 'flightlogs', 'binlogs', curLog)
Expand Down Expand Up @@ -493,9 +498,10 @@ class FCDetails {
if (this.m && this.m.conStatusInt() === -1) {
console.log('Trying to reconnect FC...')
this.winston.info('Trying to reconnect FC...')
this.closeLink((err) => {
this.closeLink(() => {
this.startLink((err) => {
if (err) {
console.log(err)
} else {
// DS request is in this.m.restart()
this.m.restart()
Expand Down Expand Up @@ -564,7 +570,7 @@ class FCDetails {
} else {
// close link
this.activeDevice = null
this.closeLink((err) => {
this.closeLink(() => {
this.saveSerialSettings()
clearInterval(this.intervalObj)
this.previousConnection = false
Expand All @@ -589,7 +595,7 @@ class FCDetails {
console.log('Saved FC settings')
this.winston.info('Saved FC settings')
} catch (e) {

console.log(e)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/flightController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Flight Controller Functions', function () {
assert.equal(FC.previousConnection, false)
})

it('#fcGetSerialDevices()', async () => {
it('#fcGetSerialDevices()', async function () {
settings.clear()
const FC = new FCManagerClass(settings, winston)

Expand Down
4 changes: 2 additions & 2 deletions server/flightLogger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Logging Functions', function () {
// Recursively delete folder and files
const deleteFolderRecursive = function (path, ext) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach((file, index) => {
fs.readdirSync(path).forEach((file) => {
const curPath = Path.join(path, file)
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath)
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('Logging Functions', function () {
// create a fake log
fs.writeFileSync(Path.join(appRoot.toString(), 'flightlogs', 'flight.tlog'), Buffer.from('tést'))

Lgr.getLogs(function (err, tlogs, binlogs, kmzlogs, activeLogging) {
Lgr.getLogs(function (err, tlogs, binlogs, kmzlogs) {
assert.equal(tlogs.length, 1)
assert.equal(binlogs.length, 0)
assert.equal(kmzlogs.length, 0)
Expand Down
10 changes: 5 additions & 5 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ app.use(limiter)
app.use(fileUpload({ limits: { fileSize: 500 }, abortOnLimit: true, useTempFiles: true, tempFileDir: '/tmp/', safeFileNames: true, preserveExtension: 4 }))

const io = require('socket.io')(http, { cookie: false })
const { check, validationResult, oneOf } = require('express-validator')
const { check, validationResult } = require('express-validator')

// Init settings before running the other classes
settings.init({
Expand Down Expand Up @@ -536,12 +536,12 @@ app.get('/api/FCDetails', (req, res) => {
})
})

app.post('/api/shutdowncc', function (req, res) {
app.post('/api/shutdowncc', function () {
// User wants to shutdown the computer
aboutPage.shutdownCC()
})

app.post('/api/updatemaster', function (req, res) {
app.post('/api/updatemaster', function () {
// User wants to update Rpanion to latest master
aboutPage.updateRS(io)
})
Expand All @@ -567,7 +567,7 @@ app.post('/api/FCModify', [check('device').isJSON(), check('baud').isJSON(), che
})
})

app.post('/api/FCReboot', function (req, res) {
app.post('/api/FCReboot', function () {
fcManager.rebootFC()
})

Expand Down Expand Up @@ -597,7 +597,7 @@ app.post('/api/removeudpoutput', [check('removeoutputIP').isIP(), check('removeo
res.send(JSON.stringify({ UDPoutputs: newOutput }))
})

io.on('connection', function (socket) {
io.on('connection', function () {
// only set interval if not already set
if (FCStatusLoop !== null) {
return
Expand Down
2 changes: 1 addition & 1 deletion server/networkClients.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const networkClients = require('./networkClients')
describe('Network Client Functions', function () {
it('#networkclientgetClients()', function (done) {
// Getting a list of clients
networkClients.getClients((err, apnamev, apclientsv) => {
networkClients.getClients((err) => {
assert.equal(err, null)
done()
})
Expand Down
4 changes: 2 additions & 2 deletions server/networkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ function addConnection (conNameStr, conType, conAdapter, conSettings, callback)
if (conType === 'wifi') {
exec('nmcli connection add type ' + conType + ' ifname ' + conAdapter +
' con-name ' + conNameStr + ' ssid \'' + conSettings.ssid.value + '\' 802-11-wireless.mode ' +
conSettings.mode.value + (conSettings.band === {} ? (' 802-11-wireless.band ' + conSettings.band.value) : '') +
(conSettings.channel === {} ? (' 802-11-wireless.channel ' + (conSettings.channel.value === '0' ? '\'\'' : conSettings.channel.value)) : '') +
conSettings.mode.value + (Object.keys(conSettings.band).length ? (' 802-11-wireless.band ' + conSettings.band.value) : '') +
(Object.keys(conSettings.channel).length ? (' 802-11-wireless.channel ' + (conSettings.channel.value === '0' ? '\'\'' : conSettings.channel.value)) : '') +
' ipv4.method ' + conSettings.ipaddresstype.value + ' connection.autoconnect no ' + ' && ' +
'nmcli -g connection.uuid con show ' + conNameStr, (error, stdout, stderr) => {
if (stderr) {
Expand Down
4 changes: 2 additions & 2 deletions server/networkManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const networkManager = require('./networkManager')
describe('Network Functions', function () {
it('#networkmanagergetAdapters()', function (done) {
// Getting a list of adapters
networkManager.getAdapters(function (err, netDeviceList) {
networkManager.getAdapters(function (err) {
assert.equal(err, null)
done()
})
})

it('#networkmanagergetConnections()', function (done) {
// Getting a list of adapters
networkManager.getConnections(function (err, netConnectionList) {
networkManager.getConnections(function (err) {
assert.equal(err, null)
done()
})
Expand Down
1 change: 1 addition & 0 deletions server/ntrip.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ntrip {
this.eventEmitter.emit('rtcmpacket', data, this.seq)
this.seq = this.seq + 1
} catch (e) {
console.log('Bad ntrip data')
}
}
})
Expand Down
Loading

0 comments on commit d57e356

Please sign in to comment.