update proc.h and utils.h
10 files modified
1 files added
2 files renamed
| File was renamed from project/booster/util_proc.c |
| | |
| | | * 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> |
| | |
| | | #include <sys/types.h> |
| | | #include <sys/stat.h> |
| | | |
| | | #include "util_proc.h" |
| | | #include "proc.h" |
| | | #include "logger.h" |
| | | |
| | | proc_signal_t g_signal={0}; |
| | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | /* install default signal process functions */ |
| | | void install_default_signal(void) |
| | |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | |
| | | /* **************************************************************************** |
| | | * FunctionName: record_daemon_pid |
| | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | |
| | | /* **************************************************************************** |
| | | * FunctionName: set_daemon_running |
| | | * Description : Set the programe running as daemon if it's not running and record |
| | |
| | | goto CleanUp; |
| | | |
| | | CleanUp: |
| | | |
| | | |
| | | if( thread_id ) |
| | | { |
| | | if( rv ) |
| | |
| | | pthread_attr_destroy(&thread_attr); |
| | | return rv; |
| | | } |
| | | |
| | | |
| | | /* excute a linux command by system() */ |
| | | void exec_system_cmd(const char *format, ...) |
| | |
| | | |
| | | system(cmd); |
| | | } |
| | | |
| | | |
| File was renamed from project/booster/util_proc.h |
| | |
| | | * 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~) |
| | |
| | | #define __UTIL_PROC_H_ |
| | | |
| | | #include <signal.h> |
| | | #include <time.h> |
| | | |
| | | #define PID_ASCII_SIZE 11 |
| | | |
| | |
| | | |
| | | /* 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 |
| New file |
| | |
| | | /******************************************************************************** |
| | | * 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 |
| | |
| | | |
| | | #include "logger.h" |
| | | #include "comport.h" |
| | | #include "util_proc.h" |
| | | #include "proc.h" |
| | | |
| | | typedef struct gps_fix_s |
| | | { |
| | |
| | | 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); |
| | | |
| | |
| | | #define __CONF_H_ |
| | | |
| | | #include <stddef.h> |
| | | #include "utils.h" |
| | | #include "gpio.h" |
| | | |
| | | enum |
| | |
| | | } 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); |
| | |
| | | #include <errno.h> |
| | | |
| | | #include "logger.h" |
| | | #include "util_proc.h" |
| | | #include "utils.h" |
| | | #include "gpio.h" |
| | | |
| | | #define RPI_GPIONAME "gpiochip0" |
| | |
| | | #include <sys/types.h> |
| | | #include <sys/stat.h> |
| | | |
| | | #include "util_proc.h" |
| | | #include "logger.h" |
| | | #include "utils.h" |
| | | #include "tsl2561.h" |
| | | |
| | | |
| | |
| | | #include <cjson/cJSON.h> |
| | | |
| | | #include "logger.h" |
| | | #include "util_proc.h" |
| | | #include "proc.h" |
| | | #include "config.h" |
| | | #include "tsl2561.h" |
| | | #include "ds18b20.h" |
| | |
| | | #include <libgen.h> |
| | | |
| | | #include "logger.h" |
| | | #include "util_proc.h" |
| | | #include "utils.h" |
| | | #include "pwm.h" |
| | | |
| | | /* check PWM $channel export or not */ |
| | |
| | | #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); |
| | |
| | | #include <sys/types.h> |
| | | #include <sys/stat.h> |
| | | |
| | | #include "util_proc.h" |
| | | #include "utils.h" |
| | | #include "logger.h" |
| | | #include "tsl2561.h" |
| | | |
| | |
| | | #ifndef __CONF_H_ |
| | | #define __CONF_H_ |
| | | |
| | | #include <stddef.h> |
| | | #include "utils.h" |
| | | |
| | | enum |
| | | { |
| | |
| | | } 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); |
| | |
| | | #include <cjson/cJSON.h> |
| | | |
| | | #include "logger.h" |
| | | #include "util_proc.h" |
| | | #include "proc.h" |
| | | #include "config.h" |
| | | #include "sht20.h" |
| | | #include "leds.h" |