181 lines
6.7 KiB
C
181 lines
6.7 KiB
C
#ifndef _MY_FUNC_H_
|
|
#define _MY_FUNC_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#define FUNC_TIME_TYPE_SYS 1
|
|
#define FUNC_TIME_TYPE_CAL 2
|
|
|
|
|
|
typedef struct
|
|
{
|
|
uint32_t ms: 16; /* millisecond */
|
|
uint32_t min: 6; /* minute */
|
|
uint32_t :2; /* reserved */
|
|
uint32_t hour: 5; /* hour */
|
|
uint32_t :3; /* reserved */
|
|
uint32_t day: 5; /* day */
|
|
uint32_t week: 3; /* week */
|
|
uint32_t month: 4; /* month */
|
|
uint32_t :4; /* reserved */
|
|
uint32_t year: 7; /* year */
|
|
uint32_t :1; /* reserved */
|
|
}stru_func_time_sys;
|
|
|
|
typedef struct
|
|
{
|
|
time_t sec; /* second */
|
|
time_t usec; /* microsecond */
|
|
}stru_func_time_cal;
|
|
|
|
|
|
typedef struct
|
|
{
|
|
int resp_msg_queue_id;
|
|
int resp_type;
|
|
int len;
|
|
char text[4096];
|
|
}stru_func_ipc_msg_text;
|
|
|
|
enum FUNC_IPC_MSG_TYPE
|
|
{
|
|
FUNC_IPC_RESP_NONE = 1,
|
|
FUNC_IPC_RESP_ONCE,
|
|
FUNC_IPC_RESP_ALWAYS,
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
long id;
|
|
stru_func_ipc_msg_text text;
|
|
}stru_func_ipc_msg;
|
|
|
|
|
|
#pragma pack (1)
|
|
typedef struct
|
|
{
|
|
uint64_t flag; // 0xA55AA55AA55AA55A
|
|
char ver[16]; // version
|
|
char author[16]; // author
|
|
char modify_date[32]; // YYYY-MM-DD HH-MM-SS
|
|
uint16_t crc;
|
|
char desc[128]; // additional information
|
|
char bak[54]; // align 256 bytes
|
|
}stru_func_file_tip_info;
|
|
#pragma pack ()
|
|
|
|
|
|
/*------------------------------------------------------------------------
|
|
function define
|
|
------------------------------------------------------------------------*/
|
|
|
|
/*************************************************************************/
|
|
// 校验计算函数
|
|
/*************************************************************************/
|
|
uint8_t func_cal_sum_byte(const uint8_t *data, const uint32_t len);
|
|
uint16_t func_cal_sum_word(const uint8_t *data, const uint32_t len);
|
|
uint16_t func_cal_crc16(const uint8_t *data, const uint32_t len);
|
|
uint32_t func_cal_crc32(const uint8_t *data, const uint32_t len);
|
|
uint16_t func_cal_file_crc16(const char *file_path);
|
|
uint32_t func_cal_file_crc32(const char *file_path);
|
|
|
|
|
|
/*************************************************************************/
|
|
// 数据转换函数
|
|
/*************************************************************************/
|
|
uint8_t func_get_hex_from_ASCLL(const char ch);
|
|
uint8_t func_get_dec_from_ASCLL(const char ch);
|
|
int func_string_hex_to_dec(char *src);
|
|
int func_string_dec_to_dec(char *src);
|
|
int func_string_hex_to_buf(const char *src, char *dst, int *dst_size);
|
|
char *func_dec_to_string(char *src, int src_size, int dec, int width);
|
|
char *func_hex_to_string(char *src, int src_size, int hex, int width);
|
|
char *func_float_to_string(char *src, int src_size, float f, int width);
|
|
char *func_buf_to_string(char *src, int src_size, const char *buf, int buf_size);
|
|
int func_string_to_argv(char *p_rx, uint8_t *argc, char *argv[], uint8_t argv_size);
|
|
|
|
/*************************************************************************/
|
|
// 时间函数
|
|
/*************************************************************************/
|
|
char *func_sys_time_to_string(char *src, int src_size, stru_func_time_sys *p_tm_sys);
|
|
int func_string_to_sys_time(const char *src, stru_func_time_sys *p_tm_sys);
|
|
int func_get_time(void *p_tm, int time_type);
|
|
int func_set_time(void *p_tm, int time_type);
|
|
void func_time_sys_to_cal(stru_func_time_sys *p_tm_sys, stru_func_time_cal *p_tm_cal);
|
|
void func_time_cal_to_sys(stru_func_time_cal *p_tm_cal, stru_func_time_sys *p_tm_sys);
|
|
|
|
|
|
/*************************************************************************/
|
|
// 文件函数
|
|
/*************************************************************************/
|
|
int func_dir_exist(const char *p_dir);
|
|
int func_make_dirs(const char *p_dir);
|
|
int func_del_dirs(const char *p_path);
|
|
int func_del_dirs_by_cmd(const char *p_path);
|
|
int func_file_exist(const char *p_file);
|
|
uint32_t func_get_file_size(const char *p_file);
|
|
int func_read_file_to_buf(const char *p_file, char *p_buf, uint32_t buf_size, uint32_t *p_ret_len);
|
|
uint8_t *func_read_file_alloc_buf(const char *p_file, uint32_t *p_ret_len);
|
|
int func_write_buf_to_file(const char *p_file, const char *p_buf, uint32_t buf_size);
|
|
|
|
int func_read_file_tip_info(const char *p_file, stru_func_file_tip_info *p_tip_info, int check);
|
|
|
|
|
|
/*************************************************************************/
|
|
// 进程相关信息获取函数
|
|
/*************************************************************************/
|
|
int func_get_process_self_name(char *proc_name, uint32_t name_size);
|
|
int func_get_process_name_by_pid(int pid, char *proc_name, uint32_t name_size);
|
|
int func_get_process_pid();
|
|
int func_get_process_pid_by_name(const char *proc_name);
|
|
int func_process_exist_by_pid(int pid);
|
|
int func_get_process_path_by_pid(int pid, char *path, uint32_t len);
|
|
int func_get_process_self_path(char *path, uint32_t len);
|
|
|
|
|
|
/*************************************************************************/
|
|
// 环境变量操作函数
|
|
/*************************************************************************/
|
|
int func_get_work_path(char *path, uint32_t len);
|
|
int func_get_sys_cfg_path(char *path, uint32_t len);
|
|
int func_get_app_root_path(char *path, uint32_t len);
|
|
int func_get_his_root_path(char *path, uint32_t len);
|
|
int func_get_log_root_path(char *path, uint32_t len);
|
|
int func_get_dbc_root_path(char *path, uint32_t len);
|
|
int func_get_shell_path(char *path, uint32_t len);
|
|
int func_get_update_path(char *path, uint32_t len);
|
|
|
|
int func_get_app_path(const char *app_name, char *path, uint32_t len);
|
|
int func_get_app_cfg_path(const char *app_name, const char *postfix, char *path, uint32_t len);
|
|
int func_get_app_his_path(const char *app_name, char *path, uint32_t len);
|
|
int func_get_app_log_path(const char *app_name, char *path, uint32_t len);
|
|
|
|
/*************************************************************************/
|
|
// ipc消息队列操作函数
|
|
/*************************************************************************/
|
|
int func_create_ipc_msg_queue_by_name(char *proc_name, int *p_msg_queue_id);
|
|
int func_create_ipc_msg_queue_by_pid(int pid, int *p_msg_queue_id);
|
|
int func_get_ipc_msg_queue_by_name(const char *proc_name, int *p_msg_queue_id);
|
|
int func_get_ipc_msg_queue_by_pid(int pid, int *p_msg_queue_id);
|
|
|
|
int func_ipc_msg_send_buf(int msg_queue_id, uint8_t *p_tx, uint32_t len);
|
|
int func_ipc_msg_recv_buf(int msg_queue_id, uint8_t *p_rx, uint32_t len);
|
|
int func_ipc_msg_send_struct(int msg_queue_id, stru_func_ipc_msg *p_msg);
|
|
int func_ipc_msg_recv_struct(int msg_queue_id, stru_func_ipc_msg *p_msg);
|
|
int func_delete_ipc_msg_queue(int msg_queue_id);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif |