more crc check improvements

This commit is contained in:
DJ2LS 2022-12-27 23:30:15 +01:00
parent c6d99f8866
commit 58342b975f
3 changed files with 40 additions and 12 deletions

View file

@ -323,8 +323,8 @@ db.post({
}
var timestamp = Math.floor(Date.now() / 1000);
var checksum = crc32(file).toString(16).toUpperCase();
console.log(checksum)
var file_checksum = crc32(file).toString(16).toUpperCase();
console.log(file_checksum)
var data_with_attachment = chatmessage + split_char + filename + split_char + filetype + split_char + file + split_char + timestamp;
document.getElementById('selectFilesButton').innerHTML = ``;
@ -336,7 +336,7 @@ db.post({
mode: 255,
frames: 1,
data: data_with_attachment,
checksum: checksum,
checksum: file_checksum,
uuid: uuid
};
ipcRenderer.send('run-tnc-command', Data);
@ -346,7 +346,7 @@ db.post({
dxcallsign: dxcallsign,
dxgrid: 'null',
msg: chatmessage,
checksum: 'null',
checksum: file_checksum,
type: "transmit",
status: 'transmit',
uuid: uuid,
@ -997,8 +997,35 @@ function scrollMessagesToBottom() {
messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight;
}
// CRC CHECKSUMS
// https://stackoverflow.com/a/50579690
// crc32 calculation
//console.log(crc32('abc'));
//var crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t<r.length;t++)n=n>>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};
//console.log(crc32('abc').toString(16).toUpperCase()); // hex
var crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t<r.length;t++)n=n>>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};
var makeCRCTable = function(){
var c;
var crcTable = [];
for(var n =0; n < 256; n++){
c = n;
for(var k =0; k < 8; k++){
c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
}
crcTable[n] = c;
}
return crcTable;
}
var crc32 = function(str) {
var crcTable = window.crcTable || (window.crcTable = makeCRCTable());
var crc = 0 ^ (-1);
for (var i = 0; i < str.length; i++ ) {
crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
}
return (crc ^ (-1)) >>> 0;
};

View file

@ -517,7 +517,7 @@ exports.sendFile = function(dxcallsign, mode, frames, filename, filetype, data,
// Send Message
exports.sendMessage = function(dxcallsign, mode, frames, data, checksum, uuid, command) {
socketLog.info(data)
//socketLog.info(data)
// Disabled this here
// convert message to plain utf8 because of unicode emojis
@ -528,13 +528,14 @@ exports.sendMessage = function(dxcallsign, mode, frames, data, checksum, uuid, c
var datatype = "m"
data = datatype + split_char + command + split_char + checksum + split_char + uuid + split_char + data
socketLog.info(data)
socketLog.info(btoa(data))
//socketLog.info(data)
console.log(data)
console.log("CHECKSUM" + checksum)
//socketLog.info(btoa(data))
data = btoa(data)
//command = '{"type" : "arq", "command" : "send_message", "parameter" : [{ "dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '" , "checksum" : "' + checksum + '"}]}'
command = '{"type" : "arq", "command" : "send_raw", "uuid" : "'+ uuid +'", "parameter" : [{"dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '", "attempts": "15"}]}'
socketLog.info(command)

View file

@ -3106,7 +3106,7 @@ class DATA:
decoded_data = data_frame.split(split_char)
if decoded_data[0] in [b'm']:
checksum_delivered = decoded_data[2].lower()
checksum_delivered = str(decoded_data[2], "utf-8").lower()
# transmission_uuid = decoded_data[3]
message = decoded_data[4]
filename = decoded_data[5]