Replaced concat() with spread operator (...).

js-code-approach
neiviv-ui 1 year ago
parent b74b61a396
commit f32643c13a
  1. 44
      internal.js

@ -14,9 +14,6 @@ var p7 = {
(function() {
/* ---------------------Global variables--------------------- */
var checksumTries = 0;
/* ---------------------Utilitaries--------------------- */
/* Sum individual bytes
@ -56,36 +53,36 @@ var p7 = {
/* Create a basic (Non-Extended) packet */
/* Return the packet */
p7.make.basicPacket = (type, subtype) => p7.make.checksum([type] //Type (T)
.concat(subtype.hexToAscii(2)) //Subtype (ST)
.concat([0x30])); //Extended (EX)
p7.make.basicPacket = (type, subtype) => p7.make.checksum([type, //Type (T)
...subtype.hexToAscii(2), //Subtype (ST)
0x30]); //Extended (EX)
/* Create an extended command packet */
/* Return the packet */
p7.make.extendedCommandPacket = (subtype, datatype, fileSize, commandArguments) => {
let data = [0x30, 0x30] //Overwrite (OW)
.concat([0x30, 0x30]) //Data type (DT) ??
.concat(fileSize.hexToAscii(8)) //File size (FS)
.concat(commandArguments.flatMap((element) => element.length.hexToAscii(2))) //Size of Data {1..6} (SD{1..6})
.concat(commandArguments.join('').toAscii()); //Data {1..6} (D{1..6})
let data = [0x30, 0x30, //Overwrite (OW)
...[0x30, 0x30], //Data type (DT) ??
...fileSize.hexToAscii(8), //File size (FS)
...commandArguments.flatMap((element) => element.length.hexToAscii(2)), //Size of Data {1..6} (SD{1..6})
...commandArguments.join('').toAscii()]; //Data {1..6} (D{1..6})
return p7.make.checksum([0x01] //Type (T)
.concat(subtype.hexToAscii(2)) //Subtype (ST)
.concat([0x31]) //Extended (EX)
.concat(data.length.hexToAscii(4)) //Data size (DS)
.concat(data)); //Data (D)
return p7.make.checksum([0x01, //Type (T)
...subtype.hexToAscii(2), //Subtype (ST)
0x31, //Extended (EX)
...data.length.hexToAscii(4), //Data size (DS)
...data]); //Data (D)
}
/* Create a data packet */
/* Return the packet */
p7.make.dataPacket = (subtype, totalNumber, currentNumber, data) =>
p7.make.checksum([0x02] //Type field
.concat(subtype.hexToAscii(2)) //Subtype (ST) field
.concat([0x31]) //Extended (EX) field
.concat((data.length + 8 /* Total number (TN) and Current number (CN) subfields */ ).hexToAscii(4)) //Data size (DS) field
.concat(totalNumber.hexToAscii(4)) //Total number (TN) subfield
.concat(currentNumber.hexToAscii(4)) //Current number (CN) subfield
.concat(data)); //Data (DD) subfield
p7.make.checksum([0x02, //Type field
...subtype.hexToAscii(2), //Subtype (ST) field
0x31, //Extended (EX) field
...(data.length + 8).hexToAscii(4), //Data size (DS) field
...totalNumber.hexToAscii(4), //Total number (TN) subfield
...currentNumber.hexToAscii(4), //Current number (CN) subfield
...data]); //Data (DD) subfield
/* ---------------------Packet decoding--------------------- */
@ -201,7 +198,6 @@ var p7 = {
});
}
/* ---------------------Packet sending--------------------- */
p7.send.packet = async function (buffer) {

Loading…
Cancel
Save