Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit 9037e0c

Browse files
committed
Fixed some issues in sz.
1 parent 466a66b commit 9037e0c

File tree

4 files changed

+51
-33
lines changed

4 files changed

+51
-33
lines changed

src/protocol/zmodem/constants.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ pub const ESC_0X93: u8 = 0x93 ^ 0x40;
5757
pub const ESC_0X0D: u8 = 0x0D ^ 0x40;
5858
pub const ESC_0X8D: u8 = 0x8D ^ 0x40;
5959

60-
pub const ABORT_SEQ: [u8; 21] = [
61-
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
62-
0x08, 0x08, 0x08, 0x08, 0x00,
60+
pub const ABORT_SEQ: [u8; 18] = [
61+
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, /* 8 CAN */
62+
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, /* 10 BS */
6363
];
6464

6565
pub mod zfile_flag {

src/protocol/zmodem/headers.rs

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,46 @@ pub enum HeaderType {
2121

2222
#[derive(PartialEq, Clone, Copy, Debug)]
2323
pub enum ZFrameType {
24-
RQInit = 0, // Request receive init
25-
RIinit = 1, // Receive init
26-
Sinit = 2, // Send init sequence (optional)
27-
Ack = 3, // ACK to above
28-
File = 4, // File name from sender
29-
Skip = 5, // To sender: skip this file
30-
Nak = 6, // Last packet was garbled
31-
Abort = 7, // Abort batch transfers
32-
Fin = 8, // Finish session
33-
RPos = 9, // Resume data trans at this position
34-
Data = 10, // Data packet(s) follow
35-
Eof = 11, // End of file
36-
FErr = 12, // Fatal Read or Write error Detected
37-
Crc = 13, // Request for file CRC and response
38-
Challenge = 14, // Receiver's Challenge
39-
Compl = 15, // Request is complete
40-
Can = 16, // Other end canned session with CAN*5
41-
FreeCnt = 17, // Request for free bytes on filesystem
42-
Command = 18, // Command from sending program
43-
StdErr = 19, // Output to standard error, data follows
24+
/// Request receive init (s->r)
25+
RQInit = 0,
26+
/// Receive init (r->s)
27+
RIinit = 1,
28+
// Send init sequence (optional) (s->r)
29+
Sinit = 2,
30+
// ACK to RQInit, RInit or SInit (s<->r)
31+
Ack = 3,
32+
/// File name from sender (s->r)
33+
File = 4,
34+
/// To sender: skip this file (r->s)
35+
Skip = 5,
36+
/// Last packet was garbled (???)
37+
Nak = 6,
38+
/// Abort batch transfers (???)
39+
Abort = 7,
40+
/// Finish session (s<->r)
41+
Fin = 8,
42+
/// Resume data trans at this position (r->s)
43+
RPos = 9,
44+
/// Data packet(s) follow (s->r)
45+
Data = 10,
46+
/// End of file (s->r)
47+
Eof = 11,
48+
/// Fatal Read or Write error Detected (?)
49+
FErr = 12,
50+
/// Request for file CRC and response (?)
51+
Crc = 13,
52+
/// Receiver's Challenge (r->s)
53+
Challenge = 14,
54+
/// Request is complete (?)
55+
Compl = 15,
56+
/// Other end canned session with CAN*5 (?)
57+
Can = 16,
58+
/// Request for free bytes on filesystem (s->r)
59+
FreeCnt = 17,
60+
/// Command from sending program (s->r)
61+
Command = 18,
62+
/// Output to standard error, data follows (?)
63+
StdErr = 19,
4464
}
4565

4666
#[derive(PartialEq, Clone, Debug)]
@@ -171,7 +191,7 @@ impl Header {
171191
header_type: HeaderType,
172192
escape_ctrl_chars: bool,
173193
) -> TerminalResult<usize> {
174-
println!("send header:{:?} - {:?}", header_type, self);
194+
// println!("send header:{:?} - {:?}", header_type, self);
175195
com.send(self.build(header_type, escape_ctrl_chars))?;
176196
Ok(12)
177197
}

src/protocol/zmodem/rz.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct Rz {
4444
can_break: bool,
4545
want_fcs_16: bool,
4646
escape_8th_bit: bool,
47+
attn_seq: Vec<u8>,
4748
}
4849

4950
impl Rz {
@@ -63,6 +64,7 @@ impl Rz {
6364
no_streaming: false,
6465
want_fcs_16: true,
6566
escape_8th_bit: false,
67+
attn_seq: vec![0],
6668
}
6769
}
6870

@@ -201,8 +203,8 @@ impl Rz {
201203
self.can_esc_control,
202204
);
203205
match pck {
204-
Ok(_) => {
205-
// TODO: Atn sequence
206+
Ok(attn_seq) => {
207+
self.attn_seq = attn_seq.0;
206208
self.sender_flags = res.f0();
207209
Header::empty(ZFrameType::Ack).write(
208210
com,
@@ -265,13 +267,9 @@ impl Rz {
265267
Err(err) => {
266268
log::error!("{err}");
267269
self.errors += 1;
268-
Header::empty(ZFrameType::Nak).write(
269-
com,
270-
HeaderType::Hex,
271-
self.can_esc_control,
272-
)?;
270+
com.send(self.attn_seq.clone())?;
273271
Header::from_number(
274-
ZFrameType::FErr,
272+
ZFrameType::RPos,
275273
storage_handler.current_file_length() as u32,
276274
)
277275
.write(

src/protocol/zmodem/sz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl Sz {
408408
Zmodem::cancel(com)?;
409409
return Ok(());
410410
}
411-
self.send_zfile(com, tries + 1); /* resend */
411+
// self.send_zfile(com, tries + 1); /* resend */
412412
}
413413
_ => {
414414
log::error!("unexpected header {header:?}");

0 commit comments

Comments
 (0)