您的位置:首页 > 其它

嵌入式 嵌入式开发常用头文件以及宏、枚举和结构体定义示例

2013-12-15 14:04 387 查看
#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

#include <string.h>

#include <sys/types.h>

#include <netinet/in.h>

#include <sys/socket.h>

#include <sys/wait.h>

#include <unistd.h>

#include <arpa/inet.h>

//#include <openssl/ssl.h>

//#include <openssl/err.h>

#include <pthread.h>

#include <sys/time.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <errno.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <sys/ioctl.h>

#include <net/if.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <net/route.h>

#include <unistd.h>

#include <signal.h>

 #include <net/if_arp.h>

#include <sys/time.h>

#include <string.h>

#include <stdio.h>

#include <fcntl.h>

#include <dirent.h>

#include <sys/vfs.h>

#include "joseph_config.h"

 

#if 1

//*alter by kj

#define JOSEPH_IPNC_AVSERVER "/opt/joseph/av_server/"

#define JOSEPH_IPNC_AVSERVER_TMP "/opt/joseph/av_server_tmp/"

#if 1

#define IPNC_CONF  "/opt/joseph/av_server/config/ipnc.conf"

#else

#define IPNC_CONF  "./config/ipnc.conf"

#endif

#define JOSEPH_IPNC_SYS_NAME  "av_server"

#define SOCK_UNIX_VIDEO_STREAM_FILE "/tmp/video1_sock"

#define SOCK_UNIX_AUDIO_STREAM_FILE "/tmp/audio1_sock"

#define SOCK_UNIX_VIDEO_STREAM_PROCESS_NAME "/opt/joseph/av_server/ipnc_send"

#define JOSEPH_CHAR_MAX_ROWLENGTH 64

#define JOSEPH_PRERECORD_FILE_NAME_FRONT "joseph_prerecord_front.h264"

#define JOSEPH_PRERECORD_FILE_NAME_LATER "joseph_prerecord_later.h264"

#define JOSEPH_IPNC_VERSION "Version V1.0.0 build time :"__DATE__"  "__TIME__

#define LED_DEV "/dev/joseph_led"

#define JOSEPH_WATCHDOG "/dev/watchdog"

#define JOSEPH_WATCHDOG_PROGRESS_NAME "joseph_sys_defend"

#define JOSEPH_SYS_UPDATE_PROGRESS_NAME "joseph_wget"

#define JOSEPH_SYS_UPDATE_LOG_NAME "joseph_load.log"

#define JOSEPH_WATCHDOG_SIGNAL_TYPE 10

#define JOSEPH_FEED_WATCHDOG_TIME_INTERVAL 20

#define TIME_DATA_MAX_SIZE 8

#define MSLEEP_TIME 1000

#define JOSEPH_IPNC_NICKNAME_MAX 64

#define JOSEPH_IPNC_SERVER_IP_MAX 16

#define JOSEPH_IPNC_SERVER_PORT_MAX 8

#define JOSEPH_IPNC_ID_MAX_SIZE 16

#define JOSEPH_IPNC_PASSWD_MAX_SIZE 32

#define JOSEPH_IPNC_TIME_STRING_MAX_SIZE 32

#define JOSEPH_IPNC_ALARM_BUF_MAX_SIZE 128

#define MAX_VALUE_LEN 32

/*

 /opt/joseph/qy_zoneinfo

 Midway    GMT-11:00

 Honolulu    GMT-10:00

 Anchorage   GMT-9:00

 Los_Angeles   GMT-8:00

 Phoenix    GMT-7:00

 Chicago    GMT-6:00

 New_York   GMT-5:00

 Barbados   GMT-4:00

 Sao_Paulo   GMT-3:00

 South_Georgia  GMT-2:00

 Azores    GMT-1:00

 London    GMT-00:00

 Brussels    GMT+1:00

 Athens    GMT+2:00

 Kuwait    GMT+3:00

 Moscow    GMT+4:00

 Karachi    GMT+5:00

 Almaty    GMT+6:00

 Bangkok    GMT+7:00

 Shanghai   GMT+8:00  

 Seoul    GMT+9:00

 Tokyo    GMT+9:00

 Sydney    GMT+10:00

 Vladivostok   GMT+11:00

 Auckland   GMT+12:00

 Tongatapu   GMT+13:00

*/

#define JOSEPH_ZONE_INFO_URL "/opt/joseph/qy_zoneinfo"

#define JOSEPH_ZONE_ETC_TIME "/etc/localtime"

#define WEAT_11_REGION  0

#define WEAT_10_REGION  1

#define WEAT_9_REGION  2

#define WEAT_8_REGION  3

#define WEAT_7_REGION  4

#define WEAT_6_REGION  5

#define WEAT_5_REGION  6

#define WEAT_4_REGION  7

#define WEAT_3_REGION  8

#define WEAT_2_REGION  9

#define WEAT_1_REGION  10

#define ZERO_0_REGION  11

#define EAST_1_REGION 12

#define EAST_2_REGION 13

#define EAST_3_REGION 14

#define EAST_4_REGION 15

#define EAST_5_REGION 16

#define EAST_6_REGION 17

#define EAST_7_REGION 18

#define EAST_8_REGION 19

#define EAST_9_REGION 20

#define EAST_10_REGION 21

#define EAST_11_REGION 22

#define ETWT_12_REGION 23

/*

 jipnc_socket status

*/

typedef struct {

 int joseph_ipnc_s_scoket_sta;

 int joseph_ipnc_s_scoket_fd;

} JOSEPH_JIPNC_S_SOCKET;

 

/*

 720P   1280*720--16

 D1    720*576--4

 VGA   640*480--7

 CIF    352*288--1

 QVGA   320*240--6 

 PIC_QCIF  176*144--0

*/

typedef struct {

 int joseph_ipnc_enSize_first;

 int joseph_ipnc_enSize_second;

 int joseph_ipnc_enSize_third;

} JOSEPH_JIPNC_ENSIZE;

/*

 level   0~10 step=2

 status   0-close;1-open

 sadth  1~4080

 objnum  1~128

*/

typedef struct {

 int joseph_ipnc_md_level;//0~10 default 6

 int joseph_ipnc_md_open_status;//open or not (sys restart)

 int joseph_ipnc_md_close_status;//close the runing vda or not(no sys restart)

 int joseph_ipnc_md_sadth;

 int joseph_ipnc_md_objnum;

} JOSEPH_JIPNC_VIDEO_VDA;

/*

 minqp  ( 0,51)

 maxqp  (minqp,51)

 level   0~100

 maxbitrate (1024*3*3)

*/

typedef struct {

 int joseph_ipnc_maxqp;

 int joseph_ipnc_minqp;

 int joseph_ipnc_qp_level;

 int joseph_ipnc_rc_maxbitrate;

} JOSEPH_JIPNC_QP;

/*

 luma   0~100

 contr  0~100

 satu   0~100

 hue   0~100

 mirror  0--clsoe;1--open;

*/

typedef struct {

 int joseph_ipnc_luma;

 int joseph_ipnc_contr;

 int joseph_ipnc_satu;

 int joseph_ipnc_hue;

 int joseph_ipnc_mirror;

} JOSEPH_JIPNC_PIC_ATTR;

/*

 jdas info

 jstor info

 jms info

 jss info

 jipnc info

 

*/

typedef struct {

 char joseph_ipnc_jds_ip[JOSEPH_IPNC_SERVER_IP_MAX];

 char joseph_ipnc_jds_port[JOSEPH_IPNC_SERVER_PORT_MAX];

 int joseph_ipnc_jds_status;

 int joseph_ipnc_jds_socketfd;

} JOSEPH_IPNC_JDS_ATTR;

typedef struct {

 char joseph_ipnc_jss_ip[JOSEPH_IPNC_SERVER_IP_MAX];

 char joseph_ipnc_jss_port[JOSEPH_IPNC_SERVER_PORT_MAX];

 int joseph_ipnc_jss_status;

 int joseph_ipnc_jss_socketfd;

} JOSEPH_IPNC_JSS_ATTR;

typedef struct {

 char joseph_ipnc_jms_ip[JOSEPH_IPNC_SERVER_IP_MAX];

 char joseph_ipnc_jms_port[JOSEPH_IPNC_SERVER_PORT_MAX];

 int joseph_ipnc_jms_status;

 int joseph_ipnc_jms_socketfd;

 int joseph_ipnc_jms_md_alarm;// 0 - no alarm;1 - alarm 

} JOSEPH_IPNC_JMS_ATTR;

typedef struct {

 char joseph_ipnc_jstor_ip[JOSEPH_IPNC_SERVER_IP_MAX];

 char joseph_ipnc_jstor_port[JOSEPH_IPNC_SERVER_PORT_MAX];

 int joseph_ipnc_stor_scoket_sta;

 int joseph_ipnc_stor_scoket_fd;

 int joseph_ipnc_stor_transfer_sta;// 0 - no;1 - transfer

 int joseph_ipnc_stor_video_duration;// mcoms

 int joseph_ipnc_stor_socketfd;

 int joseph_time_trigger_status;//0 - close ; 1 - open

 int joseph_time_trigger_begin;// unit seconds

 int joseph_time_trigger_end;// unit seconds

 int joseph_time_trigger_length;

} JOSEPH_JIPNC_STOR_SOCKET;

typedef struct {

 char joseph_ipnc_ip_info[JOSEPH_IPNC_SERVER_IP_MAX];

 char joseph_ipnc_nickname[JOSEPH_IPNC_NICKNAME_MAX];//storage the nickname of the ipnc

 char joseph_ipnc_id_attr[JOSEPH_IPNC_ID_MAX_SIZE];//16

 char joseph_ipnc_owner_id_attr[JOSEPH_IPNC_ID_MAX_SIZE];//16

 char joseph_ipnc_passwd_attr[JOSEPH_IPNC_PASSWD_MAX_SIZE];//32

 char joseph_ipnc_alarm_content[JOSEPH_IPNC_ALARM_BUF_MAX_SIZE];//128

 char josep_ipnc_update_schedule[JOSEPH_IPNC_PASSWD_MAX_SIZE];

 char *joseph_ipnc_thumdnail_buf_pointer;//global buf malloc need lock

 int joseph_ipnc_device_type;

 int joseph_ipnc_run_status;// 0 - offline ; 1 - online ; 2 - update ;3 - update succeed;4 - update failed

 int joseph_ipnc_time_zone;// default east eight time zone

 int joseph_ipnc_led_glitter_close;// 0 - close ; 1 - open;

 int joseph_ipnc_first_reg_jrm_status;//0 - no register ; 1 - have register

 int joseph_ipnc_thumbnail_to_jlcient_status;// 0 - no ; 1 - transform

 int joseph_ipnc_thumbnail_buf_size;

 int joseph_ipnc_sys_watchdog_progress_pid;

 uint32_t joseh_send_to_jss_frame_num;//send to jss coutner frame num

 

} JOSEPH_IPNC_NETWORK_ATTR;

typedef struct {

 JOSEPH_IPNC_JMS_ATTR joseph_ipnc_jms_attr;

 JOSEPH_IPNC_JSS_ATTR joseph_ipnc_jss_attr;

 JOSEPH_IPNC_NETWORK_ATTR joseph_ipnc_network_attr;

 JOSEPH_IPNC_JDS_ATTR joseph_ipnc_das_attr;

} JOSEPH_JIPNC_SERVER_ATTR;

/*

 the type of record video to jstor enum

 the sock type of server

*/

enum JOSEPH_RECORD_VIDEO_SEND_TO_JSTOR_TYPE{

 VIDEO_MD = 0,

 VIDEO_OD = 1,

 VIDEO_TIME = 2,

 AUDIO_TRIGGE = 3,

 AUDIO_TIME = 4

};

enum JOSEPH_IPNC_CONNECT_TO_SERVER_TYPE{

 JRM_SERVER_SOCKET = 0,

 JSS_SERVER_SOCKET = 1,

 JMS_SERVER_SOCKET = 2,

 JSTOR_SERVER_SOCKET = 3

};

/*

 target_framerate  5~10~15~20~25~30

 vi_standard  pal--0;ntsc--1;

 rc_type   cbr--0;vbr--1;

 i_interval   2~150

 stream_type  0~2

*/

typedef struct {

 int joseph_ipnc_target_framerate;

 int joseph_ipnc_vi_standard;

 int joseph_ipnc_rc_type;

 int joseph_ipnc_i_interval;

 int joseph_ipnc_stream_type;

 int joseph_ipnc_stream_stor_type;

 int joseph_ipnc_sys_status; //sys status(used to judge sys the live_time)

 int joseph_ipnc_sys_wakeup;

 int joseph_ipnc_sys_standby;//0 -clsoe ; 1 - open

 int joseph_ipnc_sys_poweroff;//0 -close ;1 - open

 int joseph_ipnc_sys_time_surplus;

 JOSEPH_JIPNC_ENSIZE joseph_ipnc_ensize;

 JOSEPH_JIPNC_QP joseph_ipnc_qp;

 JOSEPH_JIPNC_PIC_ATTR joseph_ipnc_pic_attr;

 JOSEPH_JIPNC_VIDEO_VDA joseph_ipnc_video_vda;

 JOSEPH_JIPNC_SERVER_ATTR joseph_ipnc_server_attr;

 JOSEPH_JIPNC_STOR_SOCKET joseph_ipnc_stor_socket;

 JOSEPH_IPNC_NETWORK_ATTR joseph_ipnc_network_attr;

 

} JOSEPH_JIPNC_PARAM;

/*

 the default config struct

*/

#if 1

typedef struct {

 int joseph_ipnc_enSize_first;

 int joseph_ipnc_enSize_second;

 int joseph_ipnc_enSize_third;

 int joseph_ipnc_rc_type;

 int joseph_ipnc_i_interval;

 int joseph_ipnc_target_framerate;

 int joseph_ipnc_vi_standard;

 int joseph_ipnc_maxqp;

 int joseph_ipnc_minqp;

 int joseph_ipnc_qp_level;

 int joseph_ipnc_luma;

 int joseph_ipnc_contr;

 int joseph_ipnc_satu;

 int joseph_ipnc_hue;

 int joseph_ipnc_mirror;

 int joseph_ipnc_rc_maxbitrate;

 int joseph_ipnc_stream_type;

 int joseph_ipnc_stream_stor_type;

 int joseph_ipnc_md_level;

 int joseph_ipnc_md_open_status;

 int joseph_ipnc_md_close_status;

 int joseph_ipnc_md_sadth;

 int joseph_ipnc_md_objnum;

 int joseph_ipnc_sys_wakeup;

 int joseph_ipnc_stor_video_duration;

#if 0

 uint32_t joseph_ipnc_jds_ip;

 uint16_t joseph_ipnc_jds_port;

#else

 int joseph_ipnc_jds_ip;

 int joseph_ipnc_jds_port;

#endif

 int joseph_ipnc_nickname;

 int joseph_ipnc_time_zone;

 int joseph_ipnc_sys_standby;//0 -clsoe ; 1 - open

 int joseph_ipnc_sys_poweroff;//0 -close ;1 - open

 int joseph_ipnc_sys_time_surplus;

 int joseph_ipnc_stor_transfer_sta;// 0 - no;1 - transfer

 int joseph_ipnc_led_glitter_close;// 0 - close ; 1 - open;

 int joseph_ipnc_first_reg_jrm_status;//0 - no register ; 1 - have register

 int joseph_ipnc_run_status;// 0 - offline ; 1 - online ; 2 - update ;3 - update_succeed ; 4 - update_failed

 int joseph_time_trigger_status;//0 - close ; 1 - open

 int joseph_time_trigger_begin;// unit seconds

 int joseph_time_trigger_end;// unit seconds

 int joseph_time_trigger_length;

 int joseph_ipnc_thumbnail_to_jlcient_status;// 0 - no ; 1 - transform

} DEFAULT_JIPNC_PARAM;

#endif

/*joseph prerecord*/

typedef struct joseph_prerecord 



 char *ipnc_frame_buf[25];

 int ipnc_frame_buf_size[25];

 

}JOSEPH_RECORD;

typedef struct joseph_prerecord_time 



 char begin_tm_seconds[JOSEPH_IPNC_TIME_STRING_MAX_SIZE];

 char end_tm_seconds[JOSEPH_IPNC_TIME_STRING_MAX_SIZE];

 

}JOSEPH_RECORD_TIME;

typedef struct joseph_time_trigger_buf 



 char *frame_buf_pointer_by_time_trigger;

 int frame_buf_size_by_time_trigger;

 int frame_buf_type; //0 - p; 1 - i

 

}JOSEPH_TIME_TRIGGER_BUF;

typedef struct node 



 JOSEPH_RECORD joseph_prerecord_ipnc;

 struct node *next; 

 struct node *pione;

}NODE;

/*end joseph prerecord*/

/*variable alter by kj */

JOSEPH_JIPNC_PARAM joseph_ipnc_param;

JOSEPH_JIPNC_S_SOCKET joseph_ipnc_s_socket;

JOSEPH_TIME_TRIGGER_BUF joseph_time_trigger_buf_temp;

/*function alter by kj */

int write_user_file(char *data,int length,int label);

int read_user_file(char *param_name);

void alter_ipnc_param(char *joseph_param_name, char *joseph_param_values);

int sample_venc(char which);

int ntp_adjtime_block(char *hostname,int block_time);

void ntp_adjtime_thread(char *hostname,unsigned int interval);

void create_menu(void);

int dyn_alter_pic_attr(char *pic_attr_name,char *pic_attr_value);

int dyn_alter_pic_mirror(char *mirror_value);

int static_alter_resolution(char *resolution,char *resolution_value);

int static_alter_pic_qp(char *pic_qp_value);

int static_alter_video_i_interval(char *i_interval,char *i_interval_value);

int static_alter_target_framerate(char *target_framerate,char *target_framerate_value);

int static_alter_pic_qp_maxbitrate(char *pic_qp_maxbitrate,char *pic_qp_maxbitrate_value);

int static_alter_reset(void);

int static_alter_restart(void);

int static_alter_mode_video(char *mode_video,char *mode_video_value);

int static_alter_rc_type(char *rc_type,char *rc_type_value);

int static_open_dyn_close_vda(char *vda_status_value);

int static_alter_vda_level(char *level_value);

int static_alter_prerecord_time(char *joseph_prerecord_video_value);

int dyn_ipnc_standby(char *standby_value);

int dyn_ipnc_wakeup(char *status_wakeup);

int ipnc_communication(void);

void * client_config_ipnc(JOSEPH_JMS_SERVER_T *jms_server_in );

void  *wifi_connect(void);

NODE * prerecord_node_create(void);

void init_joseph_prerecord_ipnc(JOSEPH_RECORD *in);

void prerecord_node_fill(NODE *head,JOSEPH_RECORD *in);

NODE * prerecord_node_insert(NODE *head,JOSEPH_RECORD *joseph_prerecord_in);

void ipnc_frame_print(NODE *head);

void ipnc_frame_free(NODE *head);

NODE * ipnc_frame_free_node(NODE *head);

void ipnc_frame_save(NODE * head, int transfer_time_in);

int tcp_connect_server(char *ip, char *port,int type);//typre :jstor  or jms

int get_status_led(char * led_status);

int set_led_status(char * led_status,int glitter_type);

int alter_ipnc_zoneinfo(char *zoneinfo_name);

int get_current_time(char *buf);

int dyn_ipnc_standby_cancle(void);

int dyn_ipnc_poweroff_cancle(void);

int dyn_ipnc_wakeup_cancle(void);

int get_ipnc_sys_time_surplus(void);

int dyn_ipnc_poweroff(char *poweroff_value);

int dyn_ipnc_standby_pthread(char * standby_value);

int dyn_ipnc_wakeup_pthread(char * wakeup_value);

int dyn_ipnc_poweroff_pthread(char * poweroff_value);

int joseph_set_awb_attr_s(int awb_type);

int joseph_set_ae_attr_s(int ae_type);

void ipnc_i_frame_save(char *i_buf_addr, int i_buf_size,int transfer_time_in);

int dyn_alter_prerecoed_transform_status(char *transform_status);

int set_blue_glitter_wifi(char *color_type);

int set_blue_glitter_wifi_pthread(char *status_value);

int pthread_count_second(int time_interval);

int dyn_close_opt_to_led(char *opt_status);

int get_current_time_to_jms(char *buf);

int joseph_live_jss_pressure_test_pthread(void);

void analyze_socket_data(char *dest,char *src);

int dyn_send_video_to_jstor_by_time_trigger(JOSEPH_RECORD_TIME *time_in);

int dyn_send_video_to_jstor_by_time_trigger_pthread(char *begin_value,char * end_value);

int dyn_send_frame_by_time_trigger_pthread(void);

int get_current_time_second(void);

int joseph_feed_pthread_by_signal(void);

int joseph_sys_update_pthread(char *ftp_addr);

int joseph_ipnc_sys_ntp_client_pthread(void);

void init_net_video_send_stream(void);

int joseph_create_conf(void);

//end alter

#endif

//****************************************************************

int GetfreememInfo( void );

void print_current_time(void);

void *debug_log(const char *format, ...) ;

void run_pthread(void *func,void *param);

void joseph_mutex_open(void);

void joseph_mutex_close(void);

void joseph_lock(void);

void joseph_unlock(void);

void joseph_net_lock(void);

void joseph_net_unlock(void);

void joseph_jstor_lock(void);// no used

void joseph_jstor_unlock(void);// no used

void joseph_thumbnail_to_jclient_lock(void);// no used

void joseph_thumbnail_to_jclient_unlock(void);//no used

//****************************************************************

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐