blob: 21876895703032a71771202c4b6dd887ce4bd5a1 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/**
2 *
3 * @file cp_log.c
4 * @brief
5 * This file is part of ZCAT.
6 * zcatÓ¦Óòãlog_agent´¦ÀícplogÉ豸
7 *
8 * @details
9 * @author Tools Team.
10 * @email
11 * @copyright Copyright (C) 2013 Sanechips Technology Co., Ltd.
12 * @warning
13 * @date 2019/02/02
14 * @version 1.2
15 * @pre
16 * @post
17 *
18 * @par
19 * Change History :
20 * ---------------------------------------------------------------------------
21 * date version author description
22 * ---------------------------------------------------------------------------
23 * 2017/07/17 1.0 hou.bing Create file
24 * 2019/01/24 1.1 jiang.fenglin 1.Ìí¼Óusblog¶ÁÐ´Ëø
25 * 2.Ìí¼ÓÏß³ÌÃû³Æ
26 * 2019/02/02 1.2 jiang.fenglin ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen
27 * ---------------------------------------------------------------------------
28 *
29 *
30 */
31
32#include <string.h>
33#include <time.h>
34#include <pthread.h>
35#include <sys/prctl.h>
36#include "log_agent.h"
37
38#define MAX_PACKET_LEN (0x10000)
39#define MAX_CP_PACKET_LEN (MAX_PACKET_LEN * 2)
40
41const char* cplog_dev = "/dev/cplog"; // É豸·¾¶
42static unsigned char g_cp_read_buffer[MAX_CP_PACKET_LEN] = {0}; // Êý¾Ý»º´æ
43pthread_t read_cplog_thread = 0;
44int cplog_fd = -1;
45
46extern void send_log_out(unsigned char* buf, int len);
47
48/**
49 * @brief ¶ÁÈ¡cplogÏ̺߳¯Êý£¬\n
50 * ´¦Àí´ÓcplogÉ豸ÖеÄlogÊý¾Ý£¬²¢×ª·¢³öÈ¥.
51 * @param[in] args Ï̺߳¯Êý²ÎÊý
52 * @return void
53 * @note
54 * @see
55 */
56void *read_cplog(void* args)
57{
58 const struct timespec notimer_interval = {0, 20000000};//20ms
59 int read_Len = -1;
60 int nosleep_ret = -1;
61
62 prctl(PR_SET_NAME, "read_cplog");
63
64 while(1)
65 {
66 read_Len = read(cplog_fd, g_cp_read_buffer, MAX_CP_PACKET_LEN);
67
68 if(read_Len > 0)
69 {
70 //printf("zcat: read_cplog read_Len %d\n", read_Len);
71 send_log_out(g_cp_read_buffer, read_Len);
72 memset(g_cp_read_buffer, 0, MAX_CP_PACKET_LEN);
73 }
74 else if(read_Len == 0)
75 {
76 nosleep_ret = nanosleep(&notimer_interval, NULL);
77 if(nosleep_ret < 0)
78 {
79 sleep(1);
80 }
81 }
82 else
83 {
84 sleep(1);
85 }
86
87 }
88}
89