RaspberrPi project source code
guowenxue
11 hours ago 24345339421493cdacdbaae0248c3928ea9404c2
update proc.h and utils.h
10 files modified
1 files added
2 files renamed
141 ■■■■ changed files
project/booster/proc.c 16 ●●●● patch | view | raw | blame | history
project/booster/proc.h 42 ●●●●● patch | view | raw | blame | history
project/booster/utils.h 61 ●●●●● patch | view | raw | blame | history
project/gpsd/gpsd.c 3 ●●●● patch | view | raw | blame | history
project/lightd/config.h 2 ●●● patch | view | raw | blame | history
project/lightd/hal/gpio.c 2 ●●● patch | view | raw | blame | history
project/lightd/hal/tsl2561.c 2 ●●● patch | view | raw | blame | history
project/lightd/lightd.c 2 ●●● patch | view | raw | blame | history
project/modules/pwm.c 2 ●●● patch | view | raw | blame | history
project/modules/sht20.c 2 ●●● patch | view | raw | blame | history
project/modules/tsl2561.c 2 ●●● patch | view | raw | blame | history
project/thingsboard/config.h 3 ●●●● patch | view | raw | blame | history
project/thingsboard/thingsboard.c 2 ●●● patch | view | raw | blame | history
project/booster/proc.c
File was renamed from project/booster/util_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);
}
project/booster/proc.h
File was renamed from project/booster/util_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
project/booster/utils.h
New file
@@ -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
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);
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);
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"
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"
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"
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 */
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);
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"
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);
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"