void init() { fb = malloc(sizeof(Tframebuffer)); fb = init_frame_buffer(fb, FB_PATH); img_list = malloc(sizeof(Com_box)); img_list = img_search(JPG_PATH, img_list); mp3_list = malloc(sizeof(Mp3_box)); mp3_list = mp3_search(MP3_PATH, mp3_list); init_font(); weather_getinfo(weather_info, 10); }
// application entry point int main(int argc, char* argv[]) { uint8_t packet[ (8 * MAX_PIXELS) + 32]; // 8 bytes per pixel is the maximum size ssize_t packet_size; uint16_t x, y; uint8_t r, g, b, a; uint8_t pixellength = 0, protocol, version; uint16_t i; uint8_t offset = 2; int sock_fd = get_udp_socket(UDP_PORT); // Init screen buffer if (!init_frame_buffer()) { die("Failed to init screen buffer.\n"); } // draw each udp packet while( (packet_size = get_udp_packet(sock_fd, (char*)&packet, sizeof(packet))) >= 0 ) { // Get protocol from the packet version = packet[1]; // the version protocol = packet[0]; // protocol switch //printf("V:%d, P:%d\n", version, protocol); switch (protocol) { // Protocol 0: xyrgb 16:16:8:8:8 specified for each pixel case 0: pixellength = 7; packet_size = MIN(offset + (pixellength * MAX_PIXELS), packet_size); for (i=offset; i<packet_size; i+=pixellength) { x = packet[i ] | packet[i+1]<<8; y = packet[i+2] | packet[i+3]<<8; r = packet[i+4]; g = packet[i+5]; b = packet[i+6]; a = 0xFF; write_pixel_to_screen(x, y, r, g, b, a); } break; // Protocol 1: xyrgba 16:16:8:8:8:8 specified for each pixel case 1: pixellength = 8; packet_size = MIN(offset + (pixellength * MAX_PIXELS), packet_size); for (i=offset; i<packet_size; i+=pixellength) { x = packet[i ] | packet[i+1]<<8; y = packet[i+2] | packet[i+3]<<8; r = packet[i+4]; g = packet[i+5]; b = packet[i+6]; a = packet[i+7]; write_pixel_to_screen(x, y, r, g, b, a); } break; // Protocol 2: xyrgb 12:12:8:8:8 specified for each pixel case 2: pixellength = 6; packet_size = MIN(offset + (pixellength * MAX_PIXELS), packet_size); for (i=offset; i<packet_size; i+=pixellength) { x = packet[i ] | (packet[i+1]&0xF0)<<4; y = (packet[i+1]&0x0F) | packet[i+2]<<4; r = packet[i+3]; g = packet[i+4]; b = packet[i+5]; a = 0xFF; write_pixel_to_screen(x, y, r, g, b, a); } break; // Protocol 3: xyrgba 12:12:8:8:8:8 specified for each pixel case 3: pixellength = 7; packet_size = MIN(offset + (pixellength * MAX_PIXELS), packet_size); for (i=offset; i<packet_size; i+=pixellength) { x = packet[i ] | (packet[i+1]&0xF0)<<4; y = (packet[i+1]&0x0F) | packet[i+2]<<4; r = packet[i+3]; g = packet[i+4]; b = packet[i+5]; a = packet[i+6]; write_pixel_to_screen(x, y, r, g, b, a); } break; // Protocol 4: xyrgb 12:12:3:3:2 specified for each pixel case 4: pixellength = 4; packet_size = MIN(offset + (pixellength * MAX_PIXELS), packet_size); for (i=offset; i<packet_size; i+=pixellength) { x = packet[i ] | (packet[i+1]&0xF0)<<4; y = (packet[i+1]&0x0F) | packet[i+2]<<4; r = packet[i+3] & 0xE0; g = packet[i+3]<<3 & 0xE0; b = packet[i+3]<<6 & 0xC0; a = 0xFF; write_pixel_to_screen(x, y, r, g, b, a); } break; // Protocol 5: xyrgba 12:12:2:2:2:2 specified for each pixel case 5: pixellength = 4; packet_size = MIN(offset + (pixellength * MAX_PIXELS), packet_size); for (i=offset; i<packet_size; i+=pixellength) { x = packet[i ] | (packet[i+1]&0xF0)<<4; y = (packet[i+1]&0x0F) | packet[i+2]<<4; r = packet[i+3] & 0xC0; g = packet[i+3]<<2 & 0xC0; b = packet[i+3]<<4 & 0xC0; a = packet[i+3]<<6 & 0xC0; write_pixel_to_screen(x, y, r, g, b, a); } break; // Error no recognied protocol defined default: break; } } // Deinitialize screen buffer deinit_frame_buffer(); return 0; }
int main(int argc, char *argv[]) { struct core *core; int option; bool enable_memory_dump = false; uint32_t mem_dump_base = 0; uint32_t mem_dump_length = 0; char *mem_dump_filename = NULL; size_t mem_dump_filename_len = 0; bool verbose = false; uint32_t fb_width = 640; uint32_t fb_height = 480; bool block_device_open = false; bool enable_fb_window = false; uint32_t total_threads = 4; char *separator; uint32_t memory_size = 0x1000000; const char *shared_memory_file = NULL; struct stat st; enum { MODE_NORMAL, MODE_COSIMULATION, MODE_GDB_REMOTE_DEBUG } mode = MODE_NORMAL; while ((option = getopt(argc, argv, "f:d:vm:b:t:c:r:s:i:o:")) != -1) { switch (option) { case 'v': verbose = true; break; case 'r': screen_refresh_rate = parse_num_arg(optarg); break; case 'f': enable_fb_window = true; separator = strchr(optarg, 'x'); if (!separator) { fprintf(stderr, "Invalid frame buffer size %s\n", optarg); return 1; } fb_width = parse_num_arg(optarg); fb_height = parse_num_arg(separator + 1); break; case 'm': if (strcmp(optarg, "normal") == 0) mode = MODE_NORMAL; else if (strcmp(optarg, "cosim") == 0) mode = MODE_COSIMULATION; else if (strcmp(optarg, "gdb") == 0) mode = MODE_GDB_REMOTE_DEBUG; else { fprintf(stderr, "Unkown execution mode %s\n", optarg); return 1; } break; case 'd': // Memory dump, of the form: filename,start,length separator = strchr(optarg, ','); if (separator == NULL) { fprintf(stderr, "bad format for memory dump\n"); usage(); return 1; } mem_dump_filename_len = (size_t)(separator - optarg); mem_dump_filename = (char*) malloc(mem_dump_filename_len + 1); strncpy(mem_dump_filename, optarg, mem_dump_filename_len); mem_dump_filename[mem_dump_filename_len] = '\0'; mem_dump_base = parse_num_arg(separator + 1); separator = strchr(separator + 1, ','); if (separator == NULL) { fprintf(stderr, "bad format for memory dump\n"); usage(); return 1; } mem_dump_length = parse_num_arg(separator + 1); enable_memory_dump = true; break; case 'b': if (open_block_device(optarg) < 0) return 1; block_device_open = true; break; case 'c': memory_size = parse_num_arg(optarg); break; case 't': total_threads = parse_num_arg(optarg); if (total_threads < 1 || total_threads > 32) { fprintf(stderr, "Total threads must be between 1 and 32\n"); return 1; } break; case 's': shared_memory_file = optarg; break; case 'i': recv_interrupt_fd = open(optarg, O_RDWR); if (recv_interrupt_fd < 0) { perror("main: failed to open receive interrupt pipe"); return 1; } if (fstat(recv_interrupt_fd, &st) < 0) { perror("main: stat failed on receive interrupt pipe"); return 1; } if ((st.st_mode & S_IFMT) != S_IFIFO) { fprintf(stderr, "%s is not a pipe\n", optarg); return 1; } break; case 'o': send_interrupt_fd = open(optarg, O_RDWR); if (send_interrupt_fd < 0) { perror("main: failed to open send interrupt pipe"); return 1; } if (fstat(send_interrupt_fd, &st) < 0) { perror("main: stat failed on send interrupt pipe"); return 1; } if ((st.st_mode & S_IFMT) != S_IFIFO) { fprintf(stderr, "%s is not a pipe\n", optarg); return 1; } break; case '?': usage(); return 1; } } if (optind == argc) { fprintf(stderr, "No image filename specified\n"); usage(); return 1; } // Don't randomize memory for cosimulation mode, because // memory is checked against the hardware model to ensure a match core = init_core(memory_size, total_threads, mode != MODE_COSIMULATION, shared_memory_file); if (core == NULL) return 1; if (load_hex_file(core, argv[optind]) < 0) { fprintf(stderr, "Error reading image %s\n", argv[optind]); return 1; } if (enable_fb_window) { if (init_frame_buffer(fb_width, fb_height) < 0) return 1; } switch (mode) { case MODE_NORMAL: if (verbose) enable_tracing(core); set_stop_on_fault(core, false); if (enable_fb_window) { while (execute_instructions(core, ALL_THREADS, screen_refresh_rate)) { update_frame_buffer(core); poll_fb_window_event(); check_interrupt_pipe(core); } } else { while (execute_instructions(core, ALL_THREADS, 1000000)) check_interrupt_pipe(core); } break; case MODE_COSIMULATION: set_stop_on_fault(core, false); if (run_cosimulation(core, verbose) < 0) return 1; // Failed break; case MODE_GDB_REMOTE_DEBUG: set_stop_on_fault(core, true); remote_gdb_main_loop(core, enable_fb_window); break; } if (enable_memory_dump) write_memory_to_file(core, mem_dump_filename, mem_dump_base, mem_dump_length); dump_instruction_stats(core); if (block_device_open) close_block_device(); if (stopped_on_fault(core)) return 1; return 0; }
int main(int argc, char *argv[]){ HANDLE acq_image_thread, save_thread, acq_imu_thread; DWORD acq_image_thread_id, save_thread_id, acq_imu_thread_id; char line_buffer[128] ; FILE *imuFile; int frame_index = 0 ; if(argc == 1){ printf("Usage : capture_sequence <nb_frames> <capture folder> \n"); exit(0); } if(argc > 1) nb_frames = atoi(argv[1]); if(argc > 2){ sprintf(path_base, "%s", argv[2]); }else{ sprintf(path_base, "./"); } if(init_frame_buffer(&my_frame_buffer,nb_frames, IMAGE_BYTES) < 0){ printf("Cannot allocate %d bytes \n", IMAGE_BYTES*nb_frames); exit(-1); } max_imu_data = (nb_frames > 0)?(((nb_frames/30)+1024)*250):((3600)*250); nb_imu_data = 0 ; //buffer for enough imu data at 250Hz imu_buffer = malloc(max_imu_data*IMU_LINE_BYTES); if(imu_buffer == NULL){ printf("Cannot allocate buffer for IMU data \n"); return 0 ; } sprintf(line_buffer, "%s/IMU.log", path_base); imuFile = fopen(line_buffer, "w"); if (imuFile == NULL) { perror("cannot open IMU file for write \n"); return ; } export_imu_calib(imuFile, 4.0, 500.0); // AG and 500dps int opt; int i = 0, j = 0 ; int init = 0 ; signal(SIGINT, killHandler); signal(SIGKILL, killHandler); signal(SIGTERM, killHandler); signal(SIGTSTP, killHandler); thread_alive = 1 ; init_time(); if(nb_frames > 0){ acq_image_thread_id = pthread_create(&acq_image_thread, NULL, &acq_image_thread_func, NULL); save_thread_id = pthread_create(&save_thread, NULL, &save_thread_func, NULL); } acq_imu_thread_id = pthread_create(&acq_imu_thread, NULL, &acq_imu_thread_func, NULL); if(nb_frames > 0){ pthread_join(acq_image_thread, NULL ); thread_alive = 0 ; pthread_join(save_thread, NULL ); } pthread_join(acq_imu_thread, NULL ); printf("Saving IMU data to disk %u \n", nb_imu_data); for(i = 0; i < nb_imu_data ; i ++){ unsigned long timestamp ; short raw_imu [6]; memcpy(×tamp, &(imu_buffer[i*IMU_LINE_BYTES]), sizeof(unsigned long)); memcpy(raw_imu, &(imu_buffer[(i*IMU_LINE_BYTES)+sizeof(unsigned long)]), 6*sizeof(short)); export_imu_raw(imuFile, raw_imu, timestamp); usleep(1); } printf("save done \n"); fclose(imuFile); free(imu_buffer); free_frame_buffer(&my_frame_buffer); return 0; }