aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Vymetálek <pavel@vym.cz>2024-01-13 10:42:40 +0100
committerPavel Vymetálek <pavel@vym.cz>2024-01-13 10:42:40 +0100
commitf43be8bee9140a477cf83ced0e1caf877a009008 (patch)
tree3ae391b70d28288ad5a739a5055cb6d6032c7d73
parent9951618476f25d92907510eddd83ab51bbbd58d3 (diff)
downloadsercp-pc-f43be8bee9140a477cf83ced0e1caf877a009008.tar.gz
Fixed receiving ACK on Windowsv0.4.0
-rw-r--r--sercp.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/sercp.c b/sercp.c
index fdc9fb8..683ec00 100644
--- a/sercp.c
+++ b/sercp.c
@@ -73,7 +73,7 @@ const char* _version = "v0.4.0";
FILE *tapout_fd = NULL;
int is_outfile = 0;
int baud_rate = 0;
-int wait_ms = 800
+int wait_ms = 800;
char *path;
char sercp_file[FILENAME_MAX];
unsigned char buff[32768];
@@ -402,7 +402,7 @@ uint8_t fi_ack_buffer[] = {'A','c','k',0, 0x49, 0x0F};
unsigned long ulNumBytes;
WriteFile(serial_fd, (void*)fi_ack_buffer, sizeof(fi_ack_buffer), &ulNumBytes, NULL);
#else
- size_t odeslano;
+ size_t odeslano;
odeslano = write (serial_fd, (void*)fi_ack_buffer, sizeof(fi_ack_buffer));
if (tcdrain(serial_fd) == -1) {
perror("tcdrain err1: ");
@@ -443,15 +443,18 @@ void sendBlockAck(uint8_t block_num) {
uint8_t buf_ack[8];
uint8_t* WaitReadAck(void) {
-int result;
-int x;
-size_t len = 0;
-
-#ifdef _WIN32
- unsigned long ulNumBytes;
- sleep_ms(10);
- ReadFile(serial_fd, buf_ack, 6, &ulNumBytes, NULL);
+ size_t len = 0;
+ #ifdef _WIN32
+ unsigned long ulNumBytes =0;
+ while (1) {
+ sleep_ms(10);
+ ReadFile(serial_fd, &buf_ack[len], 6, &ulNumBytes, NULL);
+ len += (size_t) ulNumBytes;
+ if (len == 6) break;
+ }
#else
+ // int x;
+ int result;
memset(buf_ack, 0, 8);
while (1) {
result = poll (spolfd_serial, 1, 300); // 200ms timeout
@@ -525,7 +528,7 @@ void sercpRecv(void) {
#ifdef _WIN32
sleep_ms(10);
ReadFile(serial_fd, p_buff, sizeof(fileinfo), &ulNumBytes, NULL);
- len = (uint16_t) ulNumBytes;
+ len = (size_t) ulNumBytes;
#else
sleep_ms(10);
len = read (serial_fd, p_buff, sizeof(fileinfo)-length);
@@ -580,7 +583,7 @@ void sercpRecv(void) {
// receive of data block - max. length 16kiB
#ifdef _WIN32
ReadFile(serial_fd, p_buff, expected_len, &ulNumBytes, NULL);
- len = (uint16_t)ulNumBytes;
+ len = (size_t)ulNumBytes;
#else
len = read (serial_fd, p_buff, expected_len);
#endif