2019-07-04 16:18:38 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import { decode_payload } from './DecodePayload.mjs';
|
|
|
|
|
|
|
|
class MessageHandler {
|
2019-07-09 16:31:08 +00:00
|
|
|
constructor({ ReadingRepo, RSSIRepo, GatewayRepo }) {
|
|
|
|
this.repo_reading = ReadingRepo;
|
|
|
|
this.repo_rssi = RSSIRepo;
|
|
|
|
this.repo_gateway = GatewayRepo;
|
2019-07-04 16:18:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-09 12:14:25 +00:00
|
|
|
async handle(message) {
|
|
|
|
console.log(message);
|
|
|
|
|
|
|
|
let decoded_payload = decode_payload(message.payload_raw);
|
|
|
|
console.log(decoded_payload);
|
2019-07-09 16:31:08 +00:00
|
|
|
|
|
|
|
this.repo_reading.add({
|
|
|
|
id: decoded_payload.id,
|
|
|
|
latitude: decoded_payload.latitude,
|
|
|
|
longitude: decoded_payload.longitude,
|
|
|
|
|
|
|
|
data_rate: message.metadata.data_rate,
|
|
|
|
code_rate: message.metadata.coding_rate
|
|
|
|
});
|
2019-07-04 16:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MessageHandler;
|