From 4c2677100744cfa66d55d5f551523231799a781b Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Thu, 14 Apr 2022 10:08:52 +0800
Subject: [PATCH] Merge branch 'master' of ssh://master.iot-yun.club:2280/framwork

---
 booster/comport.c |  101 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 61 insertions(+), 40 deletions(-)

diff --git a/booster/comport.c b/booster/comport.c
index 30e814d..8f45e45 100644
--- a/booster/comport.c
+++ b/booster/comport.c
@@ -1,5 +1,5 @@
 /*********************************************************************************
- *      Copyright:  (C) 2018 LingYun IoT System Studio
+ *      Copyright:  (C) 2018 Guo Wenxue <guowenxue@gmail.com>
  *                  All rights reserved.
  *
  *       Filename:  cp_comport.c
@@ -171,12 +171,53 @@
     /* Set baudrate */
     switch (comport->baudrate)
     {
+		/*  Upper is not POSIX(bits/termios-baud.h) */
+		case 4000000:
+			tmp = B4000000;
+			break;
+		case 3500000:
+			tmp = B3500000;
+			break;
+		case 3000000:
+			tmp = B3000000;
+			break;
+		case 2500000:
+			tmp = B2500000;
+			break;
+		case 2000000:
+			tmp = B2000000;
+			break;
+		case 1500000:
+			tmp = B1500000;
+			break;
+		case 1152000:
+			tmp = B1152000;
+			break;
+		case 1000000:
+			tmp = B1000000;
+			break;
+		case 921600:
+			tmp = B921600;
+			break;
+		case 576000:
+			tmp = B576000;
+			break;
+		case 500000:
+			tmp = B500000;
+			break;
+		case 460800:
+			tmp = B460800;
+			break;
+		case 230400:
+			tmp = B230400;
+			break;
         case 115200:
             tmp = B115200;
             break;
         case 57600:
             tmp = B57600;
             break;
+		/* Below is POSIX(bits/termios.h) */
         case 38400:
             tmp = B38400;
             break;
@@ -281,7 +322,7 @@
 int comport_send(comport_t *comport, char *buf, int send_bytes)
 {
     int                         rv = 0;
-    char                       *ptr, *end;
+    char                       *ptr, left_bytes;
     int                         send = 0;
 
     if ( !comport || !buf || send_bytes<=0 )
@@ -300,48 +341,28 @@
 
     //printf("Send %s with %d bytes.\n", buf, send_bytes);
 
-    // Large data, then slice them and send
-    if (comport->frag_size < send_bytes)
-    {
-        ptr = buf;
-        end = buf + send_bytes;
 
-        do
-        {
-            // Large than frag_size
-            if (comport->frag_size < (end - ptr))
-            {
-                send = write(comport->fd, ptr, comport->frag_size);
-                if (0 >= send || comport->frag_size != send)
-                {
-                    rv = -4;
-                    goto CleanUp;
-                }
-                ptr += comport->frag_size;
-            }
-            else   // Less than frag_size, maybe last fragmention.
-            {
-                send = write(comport->fd, ptr, (end - ptr));
-                if (0 >= send || (end - ptr) != send)
-                {
-                    rv = -4;
-                    goto CleanUp;
-                }
-                ptr += (end - ptr);
-            }
-        }
-        while (ptr < end);
-    }
-    else                        // The send data is not large than a fragmention.
+    left_bytes = send_bytes;
+    ptr = buf;
+
+    while( left_bytes > 0 )
     {
-        send = write(comport->fd, buf, send_bytes);
-        if (0 >= send || send_bytes != send)
-        {
-            rv = -5;
-            goto CleanUp;
-        }
+        /* Large data, then slice them to frag and send */
+	send = left_bytes>comport->frag_size ? comport->frag_size : left_bytes;
+	
+	rv = write(comport->fd, ptr, send);
+       	if( rv<0 )
+       	{
+	       	rv = -4;
+	       	goto CleanUp;
+       	} 
+	
+	left_bytes -= rv; 
+	ptr += rv; 
     }
 
+    rv = 0;
+
 CleanUp:
     return rv;
 }

--
Gitblit v1.9.1