From 4aada81527b55a62cd4e9b6d5bfbabf114dbc434 Mon Sep 17 00:00:00 2001 From: vinaxue Date: Sun, 24 Feb 2019 16:28:08 -0600 Subject: [PATCH 1/5] We wrote the debug message for telemetry when a message catched is not in the message handler --- services/telemetry/src/mavlink-socket.js | 2 +- services/telemetry/src/plane.js | 30 +++++++++++++++++------- services/telemetry/test/plane.test.js | 25 ++++++++++++++++++++ services/telemetry/test/service.test.js | 0 4 files changed, 48 insertions(+), 9 deletions(-) mode change 100644 => 100755 services/telemetry/src/mavlink-socket.js mode change 100644 => 100755 services/telemetry/src/plane.js create mode 100755 services/telemetry/test/plane.test.js mode change 100644 => 100755 services/telemetry/test/service.test.js diff --git a/services/telemetry/src/mavlink-socket.js b/services/telemetry/src/mavlink-socket.js old mode 100644 new mode 100755 index 0389e8c5..2f33de8f --- a/services/telemetry/src/mavlink-socket.js +++ b/services/telemetry/src/mavlink-socket.js @@ -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. diff --git a/services/telemetry/src/plane.js b/services/telemetry/src/plane.js old mode 100644 new mode 100755 index 0094b4ef..22e7be5b --- a/services/telemetry/src/plane.js +++ b/services/telemetry/src/plane.js @@ -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'; @@ -239,13 +239,27 @@ 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('message', (type) => { + if (!(type in messageHandler)) { + logger.debug(`Ignoring message ${type}`); + } + }); } async _onAttitude(fields) { diff --git a/services/telemetry/test/plane.test.js b/services/telemetry/test/plane.test.js new file mode 100755 index 00000000..ca87b1f0 --- /dev/null +++ b/services/telemetry/test/plane.test.js @@ -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 onUnknownMessage = jest.fn().mockImplementation(() => {}); + const spy = jest.spyOn(logger, 'debug').mockImplementation((msg) => { + if (msg.includes(msgName)) + onUnknownMessage(); + originalLoggerDebug(msg); + }); + + plane._mav.emit('message', { type: msgName }); + await new Promise((resolve) => setTimeout(resolve, 50)); + expect(onUnknownMessage).toHaveBeenCalled(); + + spy.mockRestore(); +}); diff --git a/services/telemetry/test/service.test.js b/services/telemetry/test/service.test.js old mode 100644 new mode 100755 From 54c9a6a3b66ca7cad4bec900d2270ce097468a6e Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Sun, 24 Feb 2019 19:46:03 -0600 Subject: [PATCH 2/5] Fix file permissions from previous commit --- services/telemetry/src/mavlink-socket.js | 0 services/telemetry/src/plane.js | 0 services/telemetry/test/plane.test.js | 0 services/telemetry/test/service.test.js | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 services/telemetry/src/mavlink-socket.js mode change 100755 => 100644 services/telemetry/src/plane.js mode change 100755 => 100644 services/telemetry/test/plane.test.js mode change 100755 => 100644 services/telemetry/test/service.test.js diff --git a/services/telemetry/src/mavlink-socket.js b/services/telemetry/src/mavlink-socket.js old mode 100755 new mode 100644 diff --git a/services/telemetry/src/plane.js b/services/telemetry/src/plane.js old mode 100755 new mode 100644 diff --git a/services/telemetry/test/plane.test.js b/services/telemetry/test/plane.test.js old mode 100755 new mode 100644 diff --git a/services/telemetry/test/service.test.js b/services/telemetry/test/service.test.js old mode 100755 new mode 100644 From 918f6457efec137ff995ee56a8c1fba48f19dfa7 Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Tue, 26 Feb 2019 10:37:20 -0600 Subject: [PATCH 3/5] Fix race condition in unknown message test --- services/telemetry/test/plane.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/services/telemetry/test/plane.test.js b/services/telemetry/test/plane.test.js index ca87b1f0..28523376 100644 --- a/services/telemetry/test/plane.test.js +++ b/services/telemetry/test/plane.test.js @@ -10,16 +10,16 @@ beforeAll(() => { test('log unknown message', async () => { const msgName = 'HIGH_LATENCY'; const originalLoggerDebug = logger.debug; - let onUnknownMessage = jest.fn().mockImplementation(() => {}); - const spy = jest.spyOn(logger, 'debug').mockImplementation((msg) => { - if (msg.includes(msgName)) - onUnknownMessage(); - originalLoggerDebug(msg); - }); - plane._mav.emit('message', { type: msgName }); - await new Promise((resolve) => setTimeout(resolve, 50)); - expect(onUnknownMessage).toHaveBeenCalled(); + let spy; + await new Promise((resolve) => { + spy = jest.spyOn(logger, 'debug').mockImplementation((msg) => { + if (msg.includes(msgName)) + resolve(); + originalLoggerDebug(msg); + }); + plane._mav.emit('message', msgName); + }); spy.mockRestore(); }); From ed557f19b080d3667870659f8aa9a1028565fe20 Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Tue, 26 Feb 2019 10:37:47 -0600 Subject: [PATCH 4/5] plane.test.js: CRLF -> LF --- services/telemetry/test/plane.test.js | 50 +++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/services/telemetry/test/plane.test.js b/services/telemetry/test/plane.test.js index 28523376..b7a794a6 100644 --- a/services/telemetry/test/plane.test.js +++ b/services/telemetry/test/plane.test.js @@ -1,25 +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('message', msgName); - }); - - spy.mockRestore(); -}); +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('message', msgName); + }); + + spy.mockRestore(); +}); From 06b848255dfc06b61c020fb8a7448de10a82be5b Mon Sep 17 00:00:00 2001 From: zhangirisz Date: Thu, 28 Feb 2019 19:38:55 -0600 Subject: [PATCH 5/5] changed event to 'ignored' --- services/telemetry/src/plane.js | 6 ++---- services/telemetry/test/plane.test.js | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/services/telemetry/src/plane.js b/services/telemetry/src/plane.js index 22e7be5b..817ffba8 100644 --- a/services/telemetry/src/plane.js +++ b/services/telemetry/src/plane.js @@ -255,10 +255,8 @@ export default class Plane { // If the message type is not part // of the message handler, print debug message - this._mav.on('message', (type) => { - if (!(type in messageHandler)) { - logger.debug(`Ignoring message ${type}`); - } + this._mav.on('ignored', (type) => { + logger.debug(`Ignoring message ${type}`); }); } diff --git a/services/telemetry/test/plane.test.js b/services/telemetry/test/plane.test.js index b7a794a6..d45b67a7 100644 --- a/services/telemetry/test/plane.test.js +++ b/services/telemetry/test/plane.test.js @@ -18,7 +18,7 @@ test('log unknown message', async () => { resolve(); originalLoggerDebug(msg); }); - plane._mav.emit('message', msgName); + plane._mav.emit('ignored', msgName); }); spy.mockRestore();