hc
2024-08-12 0517ab8c70e05fc5877c0c6dae1a5f42a16dcf88
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 *  sdcard_test.c  --  sdcardtest application
 *
 *  Copyright (c) 2017 Rockchip Electronics Co. Ltd.
 *  Author:
 *  Author:
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/input.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
 
#include <unistd.h>
 
 
#define LOG_TAG "camera_test"
#include "common.h"
 
/*Ö÷º¯ÊýÈë¿Ú*/
int main(int argc, char *argv[])
{
    int test_flag = 0,err_code = 0;
    char buf[COMMAND_VALUESIZE] = "camera_test";
    char result[COMMAND_VALUESIZE] = RESULT_FAIL;
    int ret;
    int exit_status;
 
 
   log_info("=============== camera test start...============\n");
 
    pid_t fpid;
 
    fpid = fork();
    if (fpid < 0) {
        printf("error in fork!\n");
        return fpid;
    } else if (fpid == 0) {
        pid_t child_pid;
 
        child_pid = fork();
        if (child_pid < 0) {
            printf("error in fork,fork error in child pid!\n");
            return child_pid;
        } else if (child_pid == 0) {
            //child process, capture one frame camera data,save to /tmp/camera_data.
            char *argv0[]={"./v4l2_test", NULL};
            char *envp0[]={"/data",NULL}; //´«µÝ¸øÖ´ÐÐÎļþÐµĻ·¾³±äÁ¿Êý×é
            ret = execve("/data/v4l2_test", argv0, envp0);
            if(ret == -1) {
                printf("######## v4l2_test run error : %s ###### \n", strerror(errno));
            } else {
                printf("######## v4l2_test run... ######\n");
            }
        } else {
            //father process
            int status;
 
            ret = wait(&status);
            if (ret < 0) {
                log_err("ERR: wait child failed: (%d)\n", ret);
                return ret;
            }
 
            log_info("process(%d) wait child(%d) status: %d\n",
                   getpid(), ret, status);
 
            if (WIFEXITED(status)) {
                exit_status = WEXITSTATUS(status);
                log_info(" v412_test run success and exit. exit_status = %d \n",exit_status);
            } else {
                log_info(" v412_test run seem no good....\n");
                return -1;
            }
 
            /* nv12 transform to bmp */
            char *argv1[]={"./nv12_to_bmp_main", "/tmp/camera_data", "720", "576", NULL};
            char *envp1[]={"/data",NULL}; //´«µÝ¸øÖ´ÐÐÎļþÐµĻ·¾³±äÁ¿Êý×é
            ret = execve("/data/nv12_to_bmp_main", argv1, envp1);
            if (ret == -1) {
                printf("######## nv12_to_bmp_main run error : %s ###### \n", strerror(errno));
            } else {
                printf("######## nv12_to_bmp_main run... ######\n");
            }
        }
    } else {
        //father process
        int status;
 
        ret = wait(&status);
        if (ret < 0) {
            log_err("ERR: wait child failed: (%d)\n", ret);
            return ret;
        }
 
        log_info("process(%d) wait child(%d) status: %d\n",
               getpid(), ret, status);
 
        if (WIFEXITED(status)) {
            exit_status = WEXITSTATUS(status);
            log_info(" All run success and exit. exit_status = %d \n",exit_status);
        } else {
            log_info(" Somethings run seem no good....\n");
            err_code = CAMERA_PROC_ERR;
        }
 
        if (err_code)
           strcpy(result, RESULT_FAIL);
        else
            strcpy(result, RESULT_PASS);
 
        printf("######## send msg to server... ######\n");
        send_msg_to_server(buf, result, err_code);
    }
 
    return 0;
}