* Fix FTN packet created date/time & moment stuff

This commit is contained in:
Bryan Ashby 2016-02-23 23:38:05 -07:00
parent 1417b7efdd
commit ae20dc1f7c
2 changed files with 34 additions and 26 deletions

View File

@ -39,7 +39,7 @@ const FTN_MESSAGE_SAUCE_HEADER = new Buffer('SAUCE00');
const FTN_MESSAGE_KLUDGE_PREFIX = '\x01';
class PacketHeader {
constructor(origAddr, destAddr, version, created) {
constructor(origAddr, destAddr, version, createdMoment) {
const EMPTY_ADDRESS = {
node : 0,
net : 0,
@ -51,7 +51,7 @@ class PacketHeader {
this.origAddress = origAddr || EMPTY_ADDRESS;
this.destAddress = destAddr || EMPTY_ADDRESS;
this.created = created || moment();
this.created = createdMoment || moment();
// uncommon to set the following explicitly
this.prodCodeLo = 0xfe; // http://ftsc.org/docs/fta-1005.003
@ -63,6 +63,9 @@ class PacketHeader {
this.capWord = 0x0001;
this.capWordValidate = ((this.capWord & 0xff) << 8) | ((this.capWord >> 8) & 0xff);
this.prodCodeHi = 0xfe; // see above
this.prodRevHi = 0;
}
get origAddress() {
@ -129,16 +132,23 @@ class PacketHeader {
}
get created() {
return moment(this); // use year, month, etc. properties
return moment({
year : this.year,
month : this.month - 1, // moment uses 0 indexed months
date : this.day,
hour : this.hour,
minute : this.minute,
second : this.second
});
}
set created(momentCreated) {
if(!moment.isMoment(momentCreated)) {
created = moment(momentCreated);
momentCreated = moment(momentCreated);
}
this.year = momentCreated.year();
this.month = momentCreated.month();
this.month = momentCreated.month() + 1; // moment uses 0 indexed months
this.day = momentCreated.date(); // day of month
this.hour = momentCreated.hour();
this.minute = momentCreated.minute();
@ -257,7 +267,7 @@ function Packet() {
packetHeader.created = moment({
year : packetHeader.year,
month : packetHeader.month,
month : packetHeader.month - 1, // moment uses 0 indexed months
date : packetHeader.day,
hour : packetHeader.hour,
minute : packetHeader.minute,
@ -267,7 +277,6 @@ function Packet() {
let ph = new PacketHeader();
_.assign(ph, packetHeader);
cb(null, ph);
});
};
@ -277,12 +286,13 @@ function Packet() {
buffer.writeUInt16LE(packetHeader.origNode, 0);
buffer.writeUInt16LE(packetHeader.destNode, 2);
buffer.writeUInt16LE(packetHeader.created.year(), 4);
buffer.writeUInt16LE(packetHeader.created.month(), 6);
buffer.writeUInt16LE(packetHeader.created.date(), 8); // day of month
buffer.writeUInt16LE(packetHeader.created.hour(), 10);
buffer.writeUInt16LE(packetHeader.created.minute(), 12);
buffer.writeUInt16LE(packetHeader.created.second(), 14);
buffer.writeUInt16LE(packetHeader.year, 4);
buffer.writeUInt16LE(packetHeader.month, 6);
buffer.writeUInt16LE(packetHeader.day, 8);
buffer.writeUInt16LE(packetHeader.hour, 10);
buffer.writeUInt16LE(packetHeader.minute, 12);
buffer.writeUInt16LE(packetHeader.second, 14);
buffer.writeUInt16LE(packetHeader.baud, 16);
buffer.writeUInt16LE(FTN_PACKET_HEADER_TYPE, 18);
buffer.writeUInt16LE(packetHeader.origNet, 20);

View File

@ -212,11 +212,9 @@ function FTNMessageScanTossModule() {
// When exporting messages, we should create/update SEEN-BY
// with remote address(s) we are exporting to.
//
const seenByAdditions = [ options.network.localAddress ].concat(Config.messageNetworks.ftn.areas[message.areaTag].uplinks);
message.meta.FtnProperty.ftn_seen_by =
ftnUtil.getUpdatedSeenByEntries(
message.meta.FtnProperty.ftn_seen_by,
Config.messageNetworks.ftn.areas[message.areaTag].uplinks
);
ftnUtil.getUpdatedSeenByEntries(message.meta.FtnProperty.ftn_seen_by, seenByAdditions);
//
// And create/update PATH for ourself