From 47579e3790b1ee5a1ad2ce35ea6028cd9ddf6ea0 Mon Sep 17 00:00:00 2001
From: GuoWenxue <“guowenxue@gmail.com”>
Date: Fri, 29 Apr 2022 09:23:27 +0800
Subject: [PATCH] update client_main.c to use packet_segmented_pack

---
 mqttd/hal/sht20.c |   47 ++++++++++++++++++++++++-----------------------
 1 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/mqttd/hal/sht20.c b/mqttd/hal/sht20.c
index 66af731..b9b4e6b 100644
--- a/mqttd/hal/sht20.c
+++ b/mqttd/hal/sht20.c
@@ -29,6 +29,7 @@
 #include <string.h>
 
 #include "sht20.h"
+#include "lylib/logger.h"
 
 static int s_sht2x_fd = -1;
 
@@ -36,7 +37,7 @@
 {
     close(s_sht2x_fd);
     s_sht2x_fd = -1;
-    printf("Terminate SHT2X\n");
+    log_warn("Terminate SHT2X\n");
 }
 
 #ifdef I2C_API_RDWR  /* Use I2C userspace driver read/write API */
@@ -47,7 +48,7 @@
 
 	if( fd<0 )
 	{
-		printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ );
+		log_err("Invalid input arguments\n");
 		return -1;
 	}
 
@@ -67,7 +68,7 @@
 	
 	if( (s_sht2x_fd=open("/dev/i2c-1", O_RDWR)) < 0)
 	{
-		printf("i2c device open failed: %s\n", strerror(errno));
+		log_fatal("i2c device open failed: %s\n", strerror(errno));
         return -1;
 	}
 	
@@ -77,7 +78,7 @@
 
 	if( sht2x_softreset(s_sht2x_fd) < 0 )
 	{
-		printf("SHT2x softreset failure\n");
+		log_err("SHT2x softreset failure\n");
         sht2x_term();
 		return -2;
 	}
@@ -91,7 +92,7 @@
 
 	if( !temp || !rh )
 	{
-		printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ );
+		log_err("Invalid input arguments\n");
 		return -1;
 	}
 
@@ -99,7 +100,7 @@
     {
         if( sht2x_init() < 0)
         {
-            printf("SHT2x initialise failure\n");
+            log_err("SHT2x initialise failure\n");
             return -2;
         }
     }
@@ -137,7 +138,7 @@
 
 	if( !serialnumber || size!=8 )
 	{
-		printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ );
+		log_err("Invalid input arguments\n");
 		return -1;
 	}
 
@@ -145,7 +146,7 @@
     {
         if( sht2x_init() < 0)
         {
-            printf("SHT2x initialise failure\n");
+            log_err("SHT2x initialise failure\n");
             return -2;
         }
     }
@@ -193,7 +194,7 @@
 
 	if( fd<0 )
 	{
-		printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ );
+		log_err("Invalid input arguments\n");
 		return -1;
 	}
 
@@ -208,7 +209,7 @@
 
 	if( ioctl(fd, I2C_RDWR, &sht2x_data) < 0 )
 	{
-		printf("%s() ioctl failure: %s\n", __func__, strerror(errno));
+		log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno));
         sht2x_term();
 		return -2;
 	}
@@ -223,13 +224,13 @@
 {
 	if( (s_sht2x_fd=open("/dev/i2c-1", O_RDWR)) < 0)
 	{
-		printf("i2c device open failed: %s\n", strerror(errno));
-	       	return -1;
+        log_err("i2c device open failed: %s\n", strerror(errno));
+        return -1;
 	}
 
 	if( sht2x_softreset(s_sht2x_fd) < 0 )
 	{
-		printf("SHT2x softreset failure\n");
+		log_err("SHT2x softreset failure\n");
         sht2x_term();
 		return -2;
 	}
@@ -246,7 +247,7 @@
 
 	if( !serialnumber || size!=8 )
 	{
-		printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ );
+		log_err("Invalid input arguments\n");
 		return -1;
 	}
 
@@ -254,7 +255,7 @@
     {
         if( sht2x_init() < 0)
         {
-            printf("SHT2x initialise failure\n");
+            log_err("SHT2x initialise failure\n");
             return -2;
         }
     }
@@ -280,7 +281,7 @@
 
 	if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 )
 	{
-		printf("%s() ioctl failure: %s\n", __func__, strerror(errno));
+		log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno));
         sht2x_term();
 		return -2;
 	}
@@ -312,7 +313,7 @@
 
 	if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 )
 	{
-		printf("%s() ioctl failure: %s\n", __func__, strerror(errno));
+		log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno));
         sht2x_term();
 		return -2;
 	}
@@ -336,7 +337,7 @@
 
 	if( !temp || !rh )
 	{
-		printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ );
+		log_err("Invalid input arguments\n");
 		return -1;
 	}
 
@@ -344,7 +345,7 @@
     {
         if( sht2x_init() < 0)
         {
-            printf("SHT2x initialise failure\n");
+            log_err("SHT2x initialise failure\n");
             return -2;
         }
     }
@@ -364,7 +365,7 @@
 
 	if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 )
 	{
-		printf("%s() ioctl failure: %s\n", __func__, strerror(errno));
+		log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno));
         sht2x_term();
 		return -2;
 	}
@@ -382,7 +383,7 @@
 
 	if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 )
 	{
-		printf("%s() ioctl failure: %s\n", __func__, strerror(errno));
+		log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno));
         sht2x_term();
 		return -2;
 	}
@@ -406,7 +407,7 @@
 
 	if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 )
 	{
-		printf("%s() ioctl failure: %s\n", __func__, strerror(errno));
+		log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno));
         sht2x_term();
 		return -2;
 	}
@@ -424,7 +425,7 @@
 
 	if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 )
 	{
-		printf("%s() ioctl failure: %s\n", __func__, strerror(errno));
+		log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno));
         sht2x_term();
 		return -2;
 	}

--
Gitblit v1.9.1