Bladeren bron

Send checksum after last line

Send checksum also after the end of the transmission.
Mateusz Bugdalski 13 jaren geleden
bovenliggende
commit
6ac0e8079a
2 gewijzigde bestanden met toevoegingen van 10 en 4 verwijderingen
  1. 6 3
      lpc.c
  2. 4 1
      uucode.c

+ 6 - 3
lpc.c

@@ -109,6 +109,7 @@ void lpc_write_ram(struct lpc_device *dev, const struct sprog_data *d, unsigned
   int checksum;
   char buf[64];
   int i;
+  int j;
   
   if(d->size & 3)
     sprog_error("Invalid data size - should be aligned to 4\n");
@@ -122,9 +123,9 @@ void lpc_write_ram(struct lpc_device *dev, const struct sprog_data *d, unsigned
   sprog_progress((offset*100)/d->size);
   checksum = 0;
   
-  for(i=0; uuencode_line(d, buf, &offset, &checksum); i++) {
-    lpc_printf("%s\r\n", buf);
-    if((i % 20)==19) {
+  for(i=0; (j = uuencode_line(d, buf, &offset, &checksum)); i++) {
+    if(j==1) lpc_printf("%s\r\n", buf);
+    if(j==2 || (i % 20)==19) {
       lpc_printf("%u\r\n", checksum);
       checksum = 0;
       
@@ -132,6 +133,8 @@ void lpc_write_ram(struct lpc_device *dev, const struct sprog_data *d, unsigned
 	if(strcmp(reply_buf, "OK\r\n")==0) {
 	  last_offset = offset;
 	  last_i = i;
+	  if(j==2)
+	    offset = -1;
 	} else {
 	  sprog_error("Received '%s'\n", reply_buf);
 	  offset = last_offset;

+ 4 - 1
uucode.c

@@ -10,6 +10,9 @@ int uuencode_line(const struct sprog_data *d, char *dst, int *offset, int *check
   int n;
   int i;
   
+  if(*offset==-1)
+    return 0;
+  
   b = d->size - *offset;
   if(b>45) b = 45;
 
@@ -46,7 +49,7 @@ int uuencode_line(const struct sprog_data *d, char *dst, int *offset, int *check
   dstd[0] = 0;
   
   if(*offset >= d->size)
-    return 0;
+    return 2;
   
   *offset += b;
   return 1;