aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO6
-rw-r--r--sercp.c23
2 files changed, 19 insertions, 10 deletions
diff --git a/TODO b/TODO
index bc4625c..91596cc 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,9 @@
+2024-02-05
+ + add -o switch to use old "protocol" wihout ack messages
+ - fix buffer overflow when receiving fileinfo @115200Bd and other computer send it @38400Bd
+
2024-01-11
- - check Ack messages properly
+ + check Ack messages properly
2023-07-29
+ add support for ack of messages
diff --git a/sercp.c b/sercp.c
index f01fe2e..9c8cf51 100644
--- a/sercp.c
+++ b/sercp.c
@@ -89,6 +89,7 @@ int scp = 0;
int is_scp_read = 0;
int is_continue = 1;
int is_flow_control_hw = 0; // 1 - set flow control to NONE
+int is_old_protocol = 0; // 1 - set old protocol without AKC messages
// prototypes
@@ -153,6 +154,7 @@ void usage(void) {
printf ("\t-b, --baud\tSet the communication baud rate. Default 38400Bd\n");
printf ("\t-t, --turbo\tSet the baud rate 115200Bd\n");
printf ("\t-l, --hwflow\tSet the flow control to CTS/RTS. Default is NONE.\n\t\t\tThis is useful for old .sercp with HW flow control\n");
+ printf ("\t-o, --oldprot\tUse the old protocol without AKC messages.\n\t\t\tThis is useful for old .sercp with missing HW flow control\n");
printf ("\t-w, --wait\tWaiting in milliseconds between transmitted blocks.\n\t\t\tIn case of improperly functioning hw flow control\n");
printf ("\t-r, --read\tRead file from serial port\n");
}
@@ -169,13 +171,14 @@ void TestArgs (int argc, char *argv[])
{"baud", required_argument, NULL, 'b'},
{"wait", required_argument, NULL, 'w'},
{"hwflow", no_argument, NULL, 'l'},
+ {"oldprot", no_argument, NULL, 'o'},
{"read", no_argument, NULL, 'r'},
{"turbo", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
- c = getopt_long (argc, argv, "d:b:w:lrtvh", long_options, &option_index);
+ c = getopt_long (argc, argv, "d:b:w:lortvh", long_options, &option_index);
if (c == -1) {
// end of arguments
break;
@@ -203,6 +206,9 @@ void TestArgs (int argc, char *argv[])
case 'l':
is_flow_control_hw = 1;
break;
+ case 'o':
+ is_old_protocol = 1;
+ break;
case 'v':
printf ("%s\n", _version);
exit(1);
@@ -398,6 +404,7 @@ uint32_t GetOverallLen(FILEINFO *p_fi) {
void sendAckFileinfo(void) {
uint8_t fi_ack_buffer[] = {'A','c','k',0, 0x49, 0x0F};
+ if (is_old_protocol) return;
#ifdef _WIN32
unsigned long ulNumBytes;
WriteFile(serial_fd, (void*)fi_ack_buffer, sizeof(fi_ack_buffer), &ulNumBytes, NULL);
@@ -415,6 +422,8 @@ void sendAckBlock(uint8_t block_num) {
int x;
uint8_t s_xor = 0;
uint8_t s_sum = 0;
+ if (is_old_protocol) return;
+
fi_ack_buffer[3] = block_num;
// printf("\n Ack sent: ");
for (x=0; x<(sizeof(fi_ack_buffer)-2);x++) {
@@ -466,11 +475,6 @@ uint8_t WaitReadAck(void) {
} else if (result) {
len += read (serial_fd, &buf_ack[len], 6);
if (len == 6) {
- // printf("\nAck ok: ");
- // for (x = 0; x < 6; x++) {
- // printf("%2X ", buf_ack[x]);
- // }
- // printf("\n");
break;
}
}
@@ -495,6 +499,7 @@ int CheckAckSum() {
}
void RecvAckFileinfo(void) {
+ if (is_old_protocol) return;
if (WaitReadAck() == 6) {
if (CheckAckSum()) {
printf("\nErr Ack fileinfo\n");
@@ -505,6 +510,7 @@ void RecvAckFileinfo(void) {
}
void RecvAckBlock(uint8_t block_number) {
+ if (is_old_protocol) return;
if (WaitReadAck() == 6) {
if (CheckAckSum() || (buf_ack[3] != block_number)) {
printf("\nErr ACK block\n");
@@ -567,7 +573,6 @@ void sercpRecv(void) {
p_buff = buff; // initialize buffer pointer
length = 0;
expected_len = p_fileinfo->fi_blocks[block_index].block_len;
- // TODO Send FileinfoAck
sleep_ms(100);
sendAckFileinfo();
tapout_fd = fopen ((char*)p_fileinfo->fi_name, "wb");
@@ -746,7 +751,7 @@ void sercpSend(void) {
}
#endif
printf("Fileinfo sent with filename: %s\n", p_bname);
- if (!is_flow_control_hw) {
+ if (!is_flow_control_hw && !is_old_protocol) {
RecvAckFileinfo();
} else {
sleep_ms(wait_ms);
@@ -783,7 +788,7 @@ void sercpSend(void) {
DoProgress(overall_sent, st.st_size, PROGRESS_PERCENT);
}
file_len -= len;
- if (!is_flow_control_hw) {
+ if (!is_flow_control_hw && !is_old_protocol) {
RecvAckBlock(blck_num);
} else {
if (file_len > 0) {