From c4207b25c7e2c90a3cb25af524c17d961face86c Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Thu, 14 Apr 2022 11:24:28 +0800
Subject: [PATCH] remove space in the end of line

---
 booster/comport.c |   85 +++++++++++++++++++++++++++++++-----------
 1 files changed, 63 insertions(+), 22 deletions(-)

diff --git a/booster/comport.c b/booster/comport.c
index cdb21f5..f6d9d10 100644
--- a/booster/comport.c
+++ b/booster/comport.c
@@ -1,14 +1,14 @@
 /*********************************************************************************
- *      Copyright:  (C) 2018 LingYun IoT System Studio
+ *      Copyright:  (C) 2018 Guo Wenxue <guowenxue@gmail.com>
  *                  All rights reserved.
  *
  *       Filename:  cp_comport.c
  *    Description:  It's the comport operate library.
- *                  
+ *
  *        Version:  2.0.0(10/17/2018~)
  *         Author:  Guo Wenxue <guowenxue@gmail.com>
  *      ChangeLog:  1, Release initial version on "10/17/2018 03:33:25 PM"
- *                  
+ *
  ********************************************************************************/
 
 #include    "comport.h"
@@ -21,10 +21,10 @@
 
 
 
-/* 
+/*
  *  description: Open the serial port
  *
- *   input args: $comport:  corresponding comport point 
+ *   input args: $comport:  corresponding comport point
  *               $dev_name:  The comport device name path, such as '/dev/ttyS3'
  *               $baudrate:  The baudrate, such as 115200
  *               $settings:  The databit,parity,stopbit,flowctrl settings, such as '8N1N'
@@ -80,7 +80,7 @@
             goto CleanUp;
         }
     }
-    else   
+    else
     {
         rv = -5;
         goto CleanUp;
@@ -88,7 +88,7 @@
 
     if (0 != tcgetattr(comport->fd, &old_cfg))
     {
-        rv = -6;          // Failed to get Com settings  
+        rv = -6;          // Failed to get Com settings
         goto CleanUp;
     }
 
@@ -123,11 +123,11 @@
     /* Set the parity */
     switch (comport->parity)
     {
-        case 0x01:               // Odd  
+        case 0x01:               // Odd
             new_cfg.c_cflag |= (PARENB | PARODD);
             new_cfg.c_cflag |= (INPCK | ISTRIP);
             break;
-        case 0x02:               // Even 
+        case 0x02:               // Even
             new_cfg.c_cflag |= PARENB;
             new_cfg.c_cflag &= ~PARODD;;
             new_cfg.c_cflag |= (INPCK | ISTRIP);
@@ -153,7 +153,7 @@
     /* Set flow control */
     switch (comport->flowctrl)
     {
-        case 1:                  // Software control 
+        case 1:                  // Software control
         case 3:
             new_cfg.c_cflag &= ~(CRTSCTS);
             new_cfg.c_iflag |= (IXON | IXOFF);
@@ -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;
@@ -235,7 +276,7 @@
     tcflush(comport->fd, TCIFLUSH);
     if (0 != tcsetattr(comport->fd, TCSANOW, &new_cfg))
     {
-        rv = -7;          // Failed to set device com port settings   
+        rv = -7;          // Failed to set device com port settings
         goto CleanUp;
     }
 
@@ -251,8 +292,8 @@
 
 
 /*
- *  description: close comport 
- *   input args: $comport:  corresponding comport point 
+ *  description: close comport
+ *   input args: $comport:  corresponding comport point
  */
 
 void comport_close(comport_t *comport)
@@ -314,10 +355,10 @@
        	{
 	       	rv = -4;
 	       	goto CleanUp;
-       	} 
+       	}
 	
-	left_bytes -= rv; 
-	ptr += rv; 
+	left_bytes -= rv;
+	ptr += rv;
     }
 
     rv = 0;
@@ -366,21 +407,21 @@
         iRet = select(comport->fd + 1, &rdfds, 0, &exfds, &stTime);
         if (0 == iRet)
         {
-            rv = 0;         
+            rv = 0;
             goto CleanUp;
         }
         else if (0 < iRet)
         {
             if (0 != FD_ISSET(comport->fd, &exfds))
             {
-                rv = -6;  
+                rv = -6;
                 COM_PRINT("Error checking recv status.\n");
                 goto CleanUp;
             }
 
             if (0 == FD_ISSET(comport->fd, &rdfds))
             {
-                rv = 0;  
+                rv = 0;
                 COM_PRINT("No incoming data.\n");
                 goto CleanUp;
             }
@@ -390,12 +431,12 @@
             if (EINTR == errno)
             {
                 COM_PRINT("catch interrupt signal.\n");
-                rv = 0;  
+                rv = 0;
             }
             else
             {
                 COM_PRINT("Check recv status failure.\n");
-                rv = -7;  
+                rv = -7;
             }
 
             goto CleanUp;
@@ -439,7 +480,7 @@
 /**************************************************************************************
  *  Description: Set the comport databit,parity,stopbit,flowctrl into the comport structure
  *   Input Args: comport: the comport_t pointer
- *               settings: The databit/parity/stopbit/flowctrl settings as like "8N1N" 
+ *               settings: The databit/parity/stopbit/flowctrl settings as like "8N1N"
  *  Output Args: NONE
  * Return Value: NONE
  *************************************************************************************/

--
Gitblit v1.9.1