From 24345339421493cdacdbaae0248c3928ea9404c2 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Tue, 18 Nov 2025 12:41:40 +0800
Subject: [PATCH] update proc.h and utils.h
---
project/modules/sht20.c | 2
project/lightd/lightd.c | 2
project/thingsboard/config.h | 3
project/lightd/hal/gpio.c | 2
project/gpsd/gpsd.c | 3
project/thingsboard/thingsboard.c | 2
project/lightd/config.h | 2
project/modules/pwm.c | 2
project/modules/tsl2561.c | 2
project/booster/proc.h | 42 -------------
project/booster/utils.h | 61 ++++++++++++++++++++
project/booster/proc.c | 16 +----
project/lightd/hal/tsl2561.c | 2
13 files changed, 75 insertions(+), 66 deletions(-)
diff --git a/project/booster/util_proc.c b/project/booster/proc.c
similarity index 98%
rename from project/booster/util_proc.c
rename to project/booster/proc.c
index 1a3d127..6cb2109 100644
--- a/project/booster/util_proc.c
+++ b/project/booster/proc.c
@@ -2,8 +2,8 @@
* Copyright: (C) 2020 LingYun IoT System Studio
* All rights reserved.
*
- * Filename: util_proc.c
- * Description: This file is the process API
+ * Filename: proc.c
+ * Description: This file is the process/thread API
*
* Version: 1.0.0(7/06/2020)
* Author: Guo Wenxue <guowenxue@gmail.com>
@@ -22,7 +22,7 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include "util_proc.h"
+#include "proc.h"
#include "logger.h"
proc_signal_t g_signal={0};
@@ -59,7 +59,6 @@
break;
}
}
-
/* install default signal process functions */
void install_default_signal(void)
@@ -184,8 +183,6 @@
return 0;
}
-
-
/* ****************************************************************************
* FunctionName: record_daemon_pid
@@ -345,8 +342,6 @@
return 0;
}
-
-
/* ****************************************************************************
* FunctionName: set_daemon_running
* Description : Set the programe running as daemon if it's not running and record
@@ -398,8 +393,6 @@
goto CleanUp;
CleanUp:
-
-
if( thread_id )
{
if( rv )
@@ -412,7 +405,6 @@
pthread_attr_destroy(&thread_attr);
return rv;
}
-
/* excute a linux command by system() */
void exec_system_cmd(const char *format, ...)
@@ -428,5 +420,3 @@
system(cmd);
}
-
-
diff --git a/project/booster/util_proc.h b/project/booster/proc.h
similarity index 73%
rename from project/booster/util_proc.h
rename to project/booster/proc.h
index 22a5fd7..7ee5113 100644
--- a/project/booster/util_proc.h
+++ b/project/booster/proc.h
@@ -2,7 +2,7 @@
* Copyright: (C) 2020 LingYun IoT System Studio
* All rights reserved.
*
- * Filename: util_proc.h
+ * Filename: proc.h
* Description: This head file is for Linux process/thread API
*
* Version: 1.0.0(7/06/2012~)
@@ -15,7 +15,6 @@
#define __UTIL_PROC_H_
#include <signal.h>
-#include <time.h>
#define PID_ASCII_SIZE 11
@@ -62,44 +61,5 @@
/* get daemon process ID from $pid_file */
extern pid_t get_daemon_pid(const char *pid_file);
-
-/* +------------------------+
- * | inline functions API |
- * +------------------------+*/
-static inline void msleep(unsigned long ms)
-{
- struct timespec cSleep;
- unsigned long ulTmp;
-
- cSleep.tv_sec = ms / 1000;
- if (cSleep.tv_sec == 0)
- {
- ulTmp = ms * 10000;
- cSleep.tv_nsec = ulTmp * 100;
- }
- else
- {
- cSleep.tv_nsec = 0;
- }
-
- nanosleep(&cSleep, 0);
- return ;
-}
-
-static inline int check_timeout(time_t *last_time, int interval)
-{
- int timeout = 0;
- time_t now;
-
- time(&now);
-
- if( difftime(now, *last_time)>interval )
- {
- timeout = 1;
- *last_time = now;
- }
-
- return timeout;
-}
#endif
diff --git a/project/booster/utils.h b/project/booster/utils.h
new file mode 100644
index 0000000..65bbc07
--- /dev/null
+++ b/project/booster/utils.h
@@ -0,0 +1,61 @@
+/********************************************************************************
+ * Copyright: (C) 2020 LingYun IoT System Studio
+ * All rights reserved.
+ *
+ * Filename: util.h
+ * Description: This file is common utility functions
+ *
+ * Version: 1.0.0(7/06/2012~)
+ * Author: Guo Wenxue <guowenxue@gmail.com>
+ * ChangeLog: 1, Release initial version on "7/06/2012 09:21:33 PM"
+ *
+ ********************************************************************************/
+
+#ifndef __UTIL_H_
+#define __UTIL_H_
+
+#include <time.h>
+#include <stddef.h>
+
+#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member)))
+
+/* +------------------------+
+ * | time functions API |
+ * +------------------------+*/
+static inline void msleep(unsigned long ms)
+{
+ struct timespec cSleep;
+ unsigned long ulTmp;
+
+ cSleep.tv_sec = ms / 1000;
+ if (cSleep.tv_sec == 0)
+ {
+ ulTmp = ms * 10000;
+ cSleep.tv_nsec = ulTmp * 100;
+ }
+ else
+ {
+ cSleep.tv_nsec = 0;
+ }
+
+ nanosleep(&cSleep, 0);
+ return ;
+}
+
+static inline int check_timeout(time_t *last_time, int interval)
+{
+ int timeout = 0;
+ time_t now;
+
+ time(&now);
+
+ if( difftime(now, *last_time)>interval )
+ {
+ timeout = 1;
+ *last_time = now;
+ }
+
+ return timeout;
+}
+
+#endif
diff --git a/project/gpsd/gpsd.c b/project/gpsd/gpsd.c
index 61356f1..9593a97 100644
--- a/project/gpsd/gpsd.c
+++ b/project/gpsd/gpsd.c
@@ -17,7 +17,7 @@
#include "logger.h"
#include "comport.h"
-#include "util_proc.h"
+#include "proc.h"
typedef struct gps_fix_s
{
@@ -30,7 +30,6 @@
float speed; /* Speed over ground, meters/sec */
float track; /* Course made good (relative to true north) */
} gps_fix_t;
-
int proc_gprmc(char *buf, int size, gps_fix_t *info);
diff --git a/project/lightd/config.h b/project/lightd/config.h
index 0e9e131..5c0bc98 100644
--- a/project/lightd/config.h
+++ b/project/lightd/config.h
@@ -14,6 +14,7 @@
#define __CONF_H_
#include <stddef.h>
+#include "utils.h"
#include "gpio.h"
enum
@@ -75,7 +76,6 @@
} iotd_ctx_t;
/* get iotd_ctx address by mqtt_ctx address */
-#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member)))
#define to_iotd(ctx) container_of(ctx, iotd_ctx_t, mqtt);
extern int parser_conf(const char *conf_file, iotd_ctx_t *ctx, int debug);
diff --git a/project/lightd/hal/gpio.c b/project/lightd/hal/gpio.c
index fb89c33..fdbdd11 100644
--- a/project/lightd/hal/gpio.c
+++ b/project/lightd/hal/gpio.c
@@ -17,7 +17,7 @@
#include <errno.h>
#include "logger.h"
-#include "util_proc.h"
+#include "utils.h"
#include "gpio.h"
#define RPI_GPIONAME "gpiochip0"
diff --git a/project/lightd/hal/tsl2561.c b/project/lightd/hal/tsl2561.c
index b912433..63af892 100644
--- a/project/lightd/hal/tsl2561.c
+++ b/project/lightd/hal/tsl2561.c
@@ -37,8 +37,8 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include "util_proc.h"
#include "logger.h"
+#include "utils.h"
#include "tsl2561.h"
diff --git a/project/lightd/lightd.c b/project/lightd/lightd.c
index 22ce0cb..e3df1ec 100644
--- a/project/lightd/lightd.c
+++ b/project/lightd/lightd.c
@@ -23,7 +23,7 @@
#include <cjson/cJSON.h>
#include "logger.h"
-#include "util_proc.h"
+#include "proc.h"
#include "config.h"
#include "tsl2561.h"
#include "ds18b20.h"
diff --git a/project/modules/pwm.c b/project/modules/pwm.c
index 922ccbf..ffaa7be 100644
--- a/project/modules/pwm.c
+++ b/project/modules/pwm.c
@@ -32,7 +32,7 @@
#include <libgen.h>
#include "logger.h"
-#include "util_proc.h"
+#include "utils.h"
#include "pwm.h"
/* check PWM $channel export or not */
diff --git a/project/modules/sht20.c b/project/modules/sht20.c
index 8250d03..a96d0c6 100644
--- a/project/modules/sht20.c
+++ b/project/modules/sht20.c
@@ -40,7 +40,7 @@
#include <linux/i2c-dev.h>
#include "logger.h"
-#include "util_proc.h"
+#include "utils.h"
#include "sht20.h"
int i2c_write(int fd, uint8_t slave_addr, uint8_t *data, int len);
diff --git a/project/modules/tsl2561.c b/project/modules/tsl2561.c
index b912433..7bb19d7 100644
--- a/project/modules/tsl2561.c
+++ b/project/modules/tsl2561.c
@@ -37,7 +37,7 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include "util_proc.h"
+#include "utils.h"
#include "logger.h"
#include "tsl2561.h"
diff --git a/project/thingsboard/config.h b/project/thingsboard/config.h
index acb008b..6a57b08 100644
--- a/project/thingsboard/config.h
+++ b/project/thingsboard/config.h
@@ -13,7 +13,7 @@
#ifndef __CONF_H_
#define __CONF_H_
-#include <stddef.h>
+#include "utils.h"
enum
{
@@ -75,7 +75,6 @@
} iotd_ctx_t;
/* get iotd_ctx address by mqtt_ctx address */
-#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member)))
#define to_iotd(ctx) container_of(ctx, iotd_ctx_t, mqtt);
extern int parser_conf(const char *conf_file, iotd_ctx_t *ctx, int debug);
diff --git a/project/thingsboard/thingsboard.c b/project/thingsboard/thingsboard.c
index 6611f22..d1b4f41 100644
--- a/project/thingsboard/thingsboard.c
+++ b/project/thingsboard/thingsboard.c
@@ -23,7 +23,7 @@
#include <cjson/cJSON.h>
#include "logger.h"
-#include "util_proc.h"
+#include "proc.h"
#include "config.h"
#include "sht20.h"
#include "leds.h"
--
Gitblit v1.9.1