exsilium / xmodem.js

XMODEM implementation in JavaScript
BSD 2-Clause "Simplified" License
13 stars 6 forks source link

CRC failure on ZIP File #6

Closed brandonmpetty closed 2 years ago

brandonmpetty commented 2 years ago

Hey @exsilium, first off... thank you for the library.

I am using this library to serve up a ZIP file for download from SyncTERM. When I do that, I get a CRC failure. A standard TXT files seems to work fine however. Am I missing something? The first chuck seems to be getting sent over perfectly, just a failing CRC.

Code:

xmodem.send(socket, fs.readFileSync('zines/LOD-4.ZIP'));

image

exsilium commented 2 years ago

Hi @brandonmpetty , thank you for the kind words. It certainly has been a while and I don't have an immediate answer to you why the CRC error occurs.

It seems that first few blocks are sent succesfully. Is it Block 4 that fails? Are you working on virtual serialport or over real serial lines? Could hardware/baud-rates etc. bring in real transmission issues? Try another binary/zip file to see if you have better success?

From xmodem library point of view you could try with the xmodem normal mode (8-bit checksum), prior to sending set:

SyncTerm should fail couple of times and fallback to the normal xmodem checksum operating mode. See if that changes anything.

brandonmpetty commented 2 years ago

I appreciate the quick reply @exsilium. The code to reproduce is simple:

const Net = require('net');

const xmodem = require('xmodem.js');
const fs = require('fs');
const server = new Net.Server();

server.listen(8080);

server.on('connection', function(socket) {

    console.log(`Connection: ${socket.remoteAddress}`);

    socket.write('Sending file through XModem - test.txt');
    xmodem.send(socket, fs.readFileSync('test.txt'));

    socket.on('end', function() {
        console.log('Closing connection with the client');
    });

    socket.on('error', function(err) {
        console.log(`Error: ${err}`);
    });
});

I got it to break with non-binary data. You'll have to pardon the content of the .txt file (lol), but when I changed the content I could not reproduce so I left it as is. This file is failing the CRC check on block 51: test.txt

Some content works, other content does not. Could this be an issue with SyncTERM?

exsilium commented 2 years ago

I love you too ;) I tried to repro this with SyncTerm 1.1 on MacOS but was unable to. The transfer is successful, however, I do got some extra bytes to the end of the file: ^Z. Can we compare the default connection settings you are using?

Screenshot 2022-08-16 at 21 40 24

I ran this on NodeJS v16.14.2 I did a 20MB Binary file transfer using your code, only the EOF differed when checking with cmp tool, I have to check what that is about but it does seem to indicate a way or issue how SyncTerm handles file writing.

brandonmpetty commented 2 years ago

Ha! I am using SyncTerm 1.1 on Windows 10.

I really wish their logs would tell me what the CRC was so I could compare it. I feel like I'm going to have to get medieval on this thing. It sounds like the issue could be on the SyncTerm side.

Here is a dump of what it provides: Xfer Debug: Requesting data block 51 Xfer Warning: Block 51: CRC ERROR Xfer Error: Too many errors (10) Xfer Debug: file_bytes=2147483647 Xfer Debug: file_bytes_left=2147477247 Xfer Debug: filelength=6400 Xfer Error: File Transfer Cancelled

My SyncTerm settings are identical to yours. I am also running the exact same version of Node as you. As for the EOF being different, I could see that but block 51 seems to be right in the middle.

Thanks for looking into it to it. I'll split this thing up, grab the 51st block and manually calculate the crc and make sure it seems right. If it is, that means the issue must be with SyncTerm. Thanks again!

brandonmpetty commented 2 years ago

Block 6 - Looks good: image

Block 51 - Also looks good: image

The issue appears to be with SyncTerm on Windows. I'll file a report. Thanks again for your help. I will reference this issue.