/* C entry. * * \param argc the number of arguments. * \param argv the arguments. * * DO NOT CHANGES THE NAME OF PARAMETERS, otherwise your program will get * a compile error if you are using INIT_CMD_PIPE macro. */ int main(int argc, char *argv[]) { char binary[16]; /* init cmd pipe after local variable declaration */ INIT_CMD_PIPE(); strcpy(binary, argv[0]); db_msg("%s: here is an example.\n", binary); /* send OK to core if test OK, otherwise send FAIL * by using SEND_CMD_PIPE_FAIL(). */ SEND_CMD_PIPE_OK(); return 0; }
/* C entry. * * \param argc the number of arguments. * \param argv the arguments. * * DO NOT CHANGES THE NAME OF PARAMETERS, otherwise your program will get * a compile error if you are using INIT_CMD_PIPE macro. */ int main(int argc, char *argv[]) { char buf[128]; char device_node_path[256]; char call_number[128]; int single_level; int setup_delay; int call_time; /* init cmd pipe after local variable declaration */ INIT_CMD_PIPE(); init_script(atoi(argv[2])); db_msg("2g tester\n"); if(script_fetch("2g","device_node",(int*)device_node_path,sizeof(device_node_path)/4)){ db_warn("2gtester:can't fetch device_node,set to /dev/ttyUSB0\n"); strcpy(device_node_path,"/dev/ttyUSB0"); } db_msg("device_node=%s\n",device_node_path); if(script_fetch("2g","call_number",(int*)call_number,sizeof(call_number)/4)){ db_warn("2gtester:can't fetch call_number,set to 10086\n"); strcpy(call_number,"10086"); } if(script_fetch("2g","setup_delay",&setup_delay,1)){ db_warn("2gtester:can't fetch setup_delay,set to 5s\n"); setup_delay=5; } if(script_fetch("2g","call_time",&call_time,1)){ db_warn("2gtester:can't fetch call_time,set to 30s\n"); call_time=30; } single_level=setup_2g_device(device_node_path,setup_delay); if(single_level==0) { SEND_CMD_PIPE_FAIL_EX("can't get single level"); return -1; } db_msg("single level=%d\n",single_level); sprintf(buf,"single level=%d dB\n",single_level); SEND_CMD_PIPE_OK_EX(buf); //make a telephone call with the specified number //return: 0 means ok; -1 means fail; if(call_number_2g_device(call_number)) { SEND_CMD_PIPE_FAIL_EX("can't make a call!"); return -1; } //call time delay,you can speak th each other in this time sleep(call_time); // hangup_2g_device(); /* send OK to core if test OK, otherwise send FAIL * by using SEND_CMD_PIPE_FAIL(). */ SEND_CMD_PIPE_OK_EX("test done"); return 0; }
int main(int argc, char *argv[]) { unsigned int args[4]; int status = 0; int retry = 0; int flags = 0; int ret; pthread_t tid; __disp_output_type_t disp_output_type; int mic_activated; INIT_CMD_PIPE(); init_script(atoi(argv[2])); disp = open("/dev/disp", O_RDWR); if (disp == -1) { db_error("hdmitester: open /dev/disp failed(%s)\n", strerror(errno)); goto err; } args[0] = 0; disp_output_type = (__disp_output_type_t)ioctl(disp, DISP_CMD_GET_OUTPUT_TYPE,(void*)args); if(script_fetch("mic", "activated", &mic_activated,1)){ mic_activated=0; } /* test main loop */ while (1) { if(disp_output_type==DISP_OUTPUT_TYPE_LCD) args[0] = 1; else args[0] = 0; ret = ioctl(disp, DISP_CMD_HDMI_GET_HPD_STATUS, args); if (ret == 1) { flags = 0; if (status == 1) { sleep(1); continue; } /* try three times before go on... * it will take 3 second. */ if (retry < 3) { retry++; sleep(1); continue; } if(disp_output_type==DISP_OUTPUT_TYPE_LCD){ /* detect and set output mode */ ret = detect_output_mode(); if (ret < 0) { goto err; } args[0] = 1; args[1] = output_mode; ret = ioctl(disp, DISP_CMD_HDMI_SET_MODE, args); if (ret < 0) { db_error("hdmitester: set hdmi output mode failed(%d)\n", ret); goto err; } /* init layer */ ret = init_layer(); if (ret < 0) { db_error("hdmitester: init layer failed\n"); goto err; } /* set hdmi on */ args[0] = 1; ret = ioctl(disp, DISP_CMD_HDMI_ON, args); if (ret < 0) { db_error("hdmitester: set hdmi on failed(%d)\n", ret); exit_layer(); goto err; } /* create sound play thread */ sound_play_stop = 0; //ret = pthread_create(&tid, NULL, sound_play, NULL); ret=0; if (ret != 0) { db_error("hdmitester: create sound play thread failed\n"); exit_layer(); args[0] = 1; ioctl(disp, DISP_CMD_HDMI_OFF, args); goto err; } }else if((disp_output_type==DISP_OUTPUT_TYPE_HDMI)&&(!mic_activated)){ /* create sound play thread */ sound_play_stop = 0; ret = pthread_create(&tid, NULL, sound_play, NULL); if (ret != 0) { db_error("hdmitester: create sound play thread failed\n"); exit_layer(); args[0] = 1; ioctl(disp, DISP_CMD_HDMI_OFF, args); goto err; } } status = 1; SEND_CMD_PIPE_OK(); } else { void *retval; /* reset retry to 0 */ retry = 0; if (status == 0) { sleep(1); continue; } if (flags < 3) { flags++; sleep(1); continue; } status = 0; if(disp_output_type==DISP_OUTPUT_TYPE_LCD){ /* end sound play thread */ sound_play_stop = 1; db_msg("hdmitester: waiting for sound play thread finish...\n"); if (pthread_join(tid, &retval)) { db_error("hdmitester: can't join with sound play thread\n"); } db_msg("hdmitester: sound play thread exit code #%d\n", (int)retval); exit_layer(); args[0] = 1; ioctl(disp, DISP_CMD_HDMI_OFF, args); } else if((disp_output_type==DISP_OUTPUT_TYPE_HDMI)&&(!mic_activated)){ /* end sound play thread */ sound_play_stop = 1; db_msg("hdmitester: waiting for sound play thread finish...\n"); if (pthread_join(tid, &retval)) { db_error("hdmitester: can't join with sound play thread\n"); } db_msg("hdmitester: sound play thread exit code #%d\n", (int)retval); } } /* sleep 1 second */ sleep(1); } err: SEND_CMD_PIPE_FAIL(); close(disp); deinit_script(); return -1; }
/* C entry. * * \param argc the number of arguments. * \param argv the arguments. * * DO NOT CHANGES THE NAME OF PARAMETERS, otherwise your program will get * a compile error if you are using INIT_CMD_PIPE macro. */ int main(int argc, char *argv[]) { char device_node_path[256]; int setup_delay; int call_time; int loop_ctl_pipe_fd; int loop_mode_flag = 1; int ret = -1; /* init cmd pipe after local variable declaration */ INIT_CMD_PIPE(); init_script(atoi(argv[2])); db_msg("2glooptester\n"); if(script_fetch("loop","device_node",(int*)device_node_path,sizeof(device_node_path)/4)){ db_warn("2glooptester:can't fetch device_node,set to /dev/ttyUSB0\n"); strcpy(device_node_path,"/dev/ttyUSB0"); } db_msg("device_node=%s\n",device_node_path); if(script_fetch("loop","setup_delay",&setup_delay,1)){ db_warn("2glooptester:can't fetch setup_delay,set to 5s\n"); setup_delay=5; } if(script_fetch("loop","call_time",&call_time,1)){ db_warn("2glooptester:can't fetch call_time,set to 30s\n"); call_time=30; } /* single_level=setup_device(device_node_path,setup_delay); if(single_level==0) { SEND_CMD_PIPE_FAIL_EX("can't get single level"); return -1; }*/ loop_ctl_pipe_fd = open(LOOP_CTL_PIPE_NAME,O_RDONLY ,0); if(loop_ctl_pipe_fd==NULL){ printf("2glooptester:fail to open loop_ctl_pipe\n"); } setup_device(device_node_path,setup_delay); LOOP_TEST: if(enter_loop_mode()){ SEND_CMD_PIPE_FAIL_EX("failed:loop\n"); return 0; } if(loop_test()){ SEND_CMD_PIPE_FAIL_EX("failed:sound_loop\n"); return 0; } SEND_CMD_PIPE_OK(); //call time delay,you can speak th each other in this time // sleep(call_time); // exit_loop_mode(); /* send OK to core if test OK, otherwise send FAIL * by using SEND_CMD_PIPE_FAIL(). */ SEND_CMD_PIPE_OK_EX("test done"); while(1){ db_msg("get loop_ctl_pipe\n"); ret = read(loop_ctl_pipe_fd,&loop_mode_flag,sizeof(loop_mode_flag)); if(ret == -1){ db_msg("no data avlaible\n"); } db_msg("loop mode ON \n"); if(!loop_mode_flag){ db_msg("exit_loop_mode\n"); exit_loop_mode(); break; } sleep(1); } while(1){ ret = read(loop_ctl_pipe_fd,&loop_mode_flag,sizeof(loop_mode_flag)); if(ret == -1){ db_msg("no data avlaible\n"); } db_msg("loop mode OFF \n"); sleep(2); if(loop_mode_flag) goto LOOP_TEST; } close(loop_ctl_pipe_fd); return 0; }
int main(int argc, char *argv[]) { unsigned int args[4] = {0}; int test_status = 0; // 1: sucessed int dev_status = 0; // 1: opended int retry = 0; int flags = 0; int ret; pthread_t tid; disp_output_type output_type; int hdmi_status; int mic_activated; INIT_CMD_PIPE(); init_script(atoi(argv[2])); disp = open("/dev/disp", O_RDWR); if (disp == -1) { db_error("tvtester: open /dev/disp failed(%s)\n", strerror(errno)); goto err; } if(script_fetch("mic", "activated", &mic_activated,1)) { mic_activated = 0; } /* test main loop */ while (1) { args[0] = 1; output_type = getCurrentOutputType(); hdmi_status = isHdmiPluged(); if (hdmi_status != 1) { if (retry < 3) { retry++; sleep(1); continue; } if (test_status == 1) { sleep(1); db_warn("TV: HPD!\n"); continue; } if(DISP_OUTPUT_TYPE_NONE == output_type) { db_warn("then open tv\n"); args[0] = 0; args[1] = output_type; //ret = ioctl(disp, DISP_CMD_TV_SET_MODE, args); ret = 0; if (ret < 0) { db_error("tvtester: set tv output mode failed(%d)\n", ret); goto err; } //init_layer(tv_format); if(dev_status == 0) { //ret = ioctl(disp, DISP_CMD_TV_ON, args); ret = 0; if (ret < 0) { db_error("tvtester: open tv failed(%d)\n", ret); goto err; } dev_status = 1; } } else if(DISP_OUTPUT_TYPE_TV == output_type) { dev_status = 1; } else { db_error("other display device runing! ,output_type[%d]\n", output_type); sleep(3); continue; } db_warn("tvtester: mic_activated[%d]\n", mic_activated); if(!mic_activated) { // create sound play thread sound_play_stop = 0; ret = pthread_create(&tid, NULL, sound_play, NULL); if (ret != 0) { db_error("tvtester: create sound play thread failed\n"); //ioctl(disp, DISP_CMD_TV_OFF, args); goto err; } mic_activated = 1; } test_status = 1; SEND_CMD_PIPE_OK(); } else { void *retval; //db_warn("tvtester: output_type[%d] is not tv!\n", output_type); // reset retry to 0 retry = 0; if (flags < 3) { flags++; sleep(1); continue; } test_status = 0; if((dev_status == 1) || (output_type == DISP_OUTPUT_TYPE_TV)) { args[0] = 0; //ret = ioctl(disp, DISP_CMD_TV_OFF, args); ret = 0; if (ret < 0) { db_error("tvtester: close tv failed(%d)\n", ret); } dev_status = 0; } if(mic_activated) { // end sound play thread sound_play_stop = 1; db_msg("tvtester: waiting for sound play thread finish...\n"); if (pthread_join(tid, &retval)) { db_error("tvtester: can't join with sound play thread\n"); } db_msg("tvtester: sound play thread exit code #%d\n", (int)retval); mic_activated = 0; } } // sleep 1 second sleep(1); } err: SEND_CMD_PIPE_FAIL(); //exit_layer(); close(disp); deinit_script(); return -1; }
int main(int argc, char *argv[]) { char dev_path[64]; int fd; int x=0; int y=0; int z=0; struct input_event event; char buf[64]; char class_path[256]; int ret; INIT_CMD_PIPE(); if(sensor_get_class_path(class_path,argv[4]) < 0) { db_error("can't get the sensor class path\n"); goto err; } ret=sprintf(buf,"%d",1); if(0!=set_sysfs_input_attr(class_path,"enable",buf,ret)){ db_warn("can't set sensor enable!!! (%s)\n", strerror(errno)); } fd=open_input_device(argv[4]); if (fd== -1) { db_error("can't open %s(%s)\n",argv[4], strerror(errno)); goto err; } /* strncpy(dev_path, "/dev/input/event2", 64); fd= open(dev_path, O_RDONLY); if (fd== -1) { db_error("can't open %s(%s)\n", dev_path, strerror(errno)); goto err; } */ while(1){ ret = read(fd, &event, sizeof(event)); if(ret==-1){ db_error("can't read %s(%s)\n", dev_path, strerror(errno)); goto err; } if (event.type == EV_ABS) { switch (event.code) { case ABS_X: x =event.value; //db_msg("senser data is: x=%d\n",x); break; case ABS_Y: y =event.value; // db_msg("senser date is: y=%d\n",y); break; case ABS_Z: z =event.value; // db_msg("senser date is:z=%d\n",z); break; } sprintf(buf,"(%d,%d,%d)",x,y,z); //db_msg("senser data is:x=%d,y=%d,z=%d\n",x,y,z); SEND_CMD_PIPE_OK_EX(buf); } sleep(1); } close(fd); err: SEND_CMD_PIPE_FAIL(); EXIT_CMD_PIPE(); return 0; }
int main(int argc, char *argv[]) { char dev_path[64]; FILE *fp; char evt_path[32]; int fd; int version; unsigned short id[4]; char name[32]; unsigned long bit[EV_MAX][NBITS(KEY_MAX)]; int i, j, k; int abs[5]; struct input_event evt[64]; int rd; char buf[64]; char pre_key[64]; INIT_CMD_PIPE(); strncpy(dev_path, "/sys/class/input/event0/device/name", 64); for (i = 0; i < 5; i++) { dev_path[22] = '0' + i; if (access(dev_path, F_OK)) { db_error("can't access %s(%s)\n", dev_path, strerror(errno)); goto err; } fp = fopen(dev_path, "r"); if (fp == NULL) { db_error("can't open %s(%s)\n", dev_path, strerror(errno)); goto err; } if (fgets(evt_path, 32, fp) == NULL) { db_error("can't read %s(%s)\n", dev_path, strerror(errno)); goto err; } if (match_ir(evt_path) == 0) { fclose(fp); break; } fclose(fp); } if (i == 5) { db_error("NO!!! ir input found\n"); goto err; } strncpy(evt_path, "/dev/input/event0", 32); evt_path[16] = '0' + i; if ((fd = open(evt_path, O_RDONLY)) < 0) { db_error("can't open %s(%s)\n", evt_path, strerror(errno)); goto err; } if (ioctl(fd, EVIOCGVERSION, &version)) { db_error("can't get version\n"); goto err; } db_debug("Input driver version is %d.%d.%d\n", version >> 16, (version >> 8) & 0xff, version & 0xff); ioctl(fd, EVIOCGID, id); db_debug("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n", id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]); ioctl(fd, EVIOCGNAME(sizeof(name)), name); db_debug("Input device name: \"%s\"\n", name); memset(bit, 0, sizeof(bit)); ioctl(fd, EVIOCGBIT(0, sizeof(bit[0])), bit[0]); db_dump("Supported events:\n"); for (i = 0; i < EV_MAX; i++) { if (test_bit(i, bit[0])) { db_dump(" Event type %d (%s)\n", i, events[i] ? events[i] : "?"); if (!i) continue; ioctl(fd, EVIOCGBIT(i, sizeof(bit[0])), bit[i]); for (j = 0; j < KEY_MAX; j++) { if (test_bit(j, bit[i])) { db_dump(" Event code %d (%s)\n", j, names[i] ? (names[i][j] ? names[i][j] : "?") : "?"); if (i == EV_ABS) { ioctl(fd, EVIOCGABS(j), abs); for (k = 0; k < 5; k++) { if ((k < 3) || abs[k]) printf("%s %6d\n", absval[k], abs[k]); } } } } } } memset(pre_key, 0, sizeof(pre_key)); while (1) { rd = read(fd, evt, sizeof(struct input_event) * 64); if (rd < (int)sizeof(struct input_event)) { db_error("error in reading\n"); goto err; } for (i = 0; i < rd / sizeof(struct input_event); i++) { if (evt[i].type == EV_SYN) { ; } else if (evt[i].type == EV_MSC && (evt[i].code == MSC_RAW || evt[i].code == MSC_SCAN)) { db_debug("%s, %s(%d, %02x)\n", events[evt[i].type] ? events[evt[i].type] : "?", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", evt[i].code, evt[i].value); if (evt[i].value) continue; if (pre_key[0]) { snprintf(buf, sizeof(buf), "%s, %s", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", pre_key); } else { snprintf(buf, sizeof(buf), "%s", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?"); } snprintf(pre_key, sizeof(pre_key), "%s", buf); SEND_CMD_PIPE_OK_EX(buf); } else { db_debug("%s, %s(%d, %02x)\n", events[evt[i].type] ? events[evt[i].type] : "?", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", evt[i].code, evt[i].value); if (evt[i].value) continue; if (pre_key[0]) { snprintf(buf, sizeof(buf), "%s, %s", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?", pre_key); } else { snprintf(buf, sizeof(buf), "%s", names[evt[i].type] ? (names[evt[i].type][evt[i].code] ? names[evt[i].type][evt[i].code] : "?") : "?"); } snprintf(pre_key, sizeof(pre_key), "%s", buf); SEND_CMD_PIPE_OK_EX(buf); } } } err: SEND_CMD_PIPE_FAIL(); EXIT_CMD_PIPE(); return 0; }