Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry: Log unknown messages #73

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion services/telemetry/src/mavlink-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class MavlinkSocket extends EventEmitter {
// Wait for specific message event to get the all the fields.
this._mav.once(type, (_, fields) => {
// Emit both events.
this.emit('receive', type, fields);
this.emit('message', type, fields);
let listened = this.emit(type, fields);

// Emit another event if the message was not listened for.
Expand Down
28 changes: 20 additions & 8 deletions services/telemetry/src/plane.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import queue from 'async/queue';

import { interop, telemetry } from './messages';

import logger from './common/logger';
import MavlinkSocket from './mavlink-socket';
import { receiveMission, sendMission, sendMissionCurrent } from './mission';
import { degrees, modDegrees360, modDegrees180 } from './util';
Expand Down Expand Up @@ -239,13 +239,25 @@ export default class Plane {
// Attach listeners below to update the state on incomming
// messages.
_bindMessages() {
this._mav
.on('ATTITUDE', this._onAttitude.bind(this))
.on('GLOBAL_POSITION_INT', this._onGlobalPositionInt.bind(this))
.on('MISSION_CURRENT', this._onMissionCurrent.bind(this))
.on('MISSION_ITEM', this._onMissionItem.bind(this))
.on('VFR_HUD', this._onVfrHud.bind(this))
.on('SYS_STATUS', this._onSysStatus.bind(this));
let messageHandler = {
'ATTITUDE' : this._onAttitude.bind(this),
'GLOBAL_POSITION_INT' : this._onGlobalPositionInt.bind(this),
'MISSION_CURRENT': this._onMissionCurrent.bind(this),
'MISSION_ITEM': this._onMissionItem.bind(this),
'VFR_HUD': this._onVfrHud.bind(this),
'SYS_STATUS': this._onSysStatus.bind(this)
};

// Make every message definition .on
for (let message in messageHandler) {
this._mav.on(message, messageHandler[message]);
}

// If the message type is not part
// of the message handler, print debug message
this._mav.on('ignored', (type) => {
logger.debug(`Ignoring message ${type}`);
});
}

async _onAttitude(fields) {
Expand Down
25 changes: 25 additions & 0 deletions services/telemetry/test/plane.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Plane from '../src/plane';
import logger from '../src/common/logger';

let plane;

beforeAll(() => {
plane = new Plane({ host: 'localhost', port: 9999 });
});

test('log unknown message', async () => {
const msgName = 'HIGH_LATENCY';
const originalLoggerDebug = logger.debug;

let spy;
await new Promise((resolve) => {
spy = jest.spyOn(logger, 'debug').mockImplementation((msg) => {
if (msg.includes(msgName))
resolve();
originalLoggerDebug(msg);
});
plane._mav.emit('ignored', msgName);
});

spy.mockRestore();
});