//================================================================================= // pkl_fdopen //================================================================================= PKLExport PKLImage pkl_fdopen(FILE *in) { PKLImage pkl; int result; pkl = malloc( sizeof(struct _PKLImage) ); if(!pkl) return(NULL); memset(pkl, 0, sizeof(struct _PKLImage)); pkl->compress = -1; format_type(pkl, in); switch(pkl->format){ case PKL_FORMAT_JPEG: result = load_jpeg(pkl, in); break; case PKL_FORMAT_PNG: result = load_png(pkl, in); break; case PKL_FORMAT_BITMAP: result = load_bitmap(pkl, in); break; default: result = 1; } if(result){ free(pkl); pkl=NULL; } return(pkl); }
void Format::frame_description (const Frame& frame) { const std::string native_description = "description_" + format_type (); if (frame.check (native_description)) { soft_linebreak (); raw (format_type (), frame.name (native_description)); soft_linebreak (); return; } const symbol d = frame.description (); if (d != Attribute::None ()) { soft_linebreak (); text (d); soft_linebreak (); } }
/// Raises an assertion error. /// /// This function prints information about the assertion failure and terminates /// execution immediately by calling std::abort(). This ensures a coredump so /// that the failure can be analyzed later. /// /// \param type The assertion type; this influences the printed message. /// \param file The file in which the assertion failed. /// \param line The line in which the assertion failed. /// \param message The failure message associated to the condition. void utils::sanity_failure(const assert_type type, const char* file, const size_t line, const std::string& message) { std::cerr << "*** " << file << ":" << line << ": " << format_type(type); if (!message.empty()) std::cerr << ": " << message << "\n"; else std::cerr << "\n"; std::abort(); }
int main(void) { /* enable interrupts (on the CPU) */ init_interrupts(); /* Initialize peripherals */ display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE ); console_init(); controller_init(); console_set_render_mode(RENDER_MANUAL); int testv = 0; int press = 0; uint8_t data[32]; memset( data, 0, 32 ); /* Main loop test */ while(1) { console_clear(); /* To do initialize routines */ controller_scan(); struct controller_data keys = get_keys_down(); for( int i = 0; i < 4; i++ ) { if( keys.c[i].A ) { rumble_start( i ); } if( keys.c[i].B ) { rumble_stop( i ); } if( keys.c[i].Z ) { press = read_mempak_address( i, 0x0000, data ); } } int controllers = get_controllers_present(); printf( "Controller 1 %spresent\n", (controllers & CONTROLLER_1_INSERTED) ? "" : "not " ); printf( "Controller 2 %spresent\n", (controllers & CONTROLLER_2_INSERTED) ? "" : "not " ); printf( "Controller 3 %spresent\n", (controllers & CONTROLLER_3_INSERTED) ? "" : "not " ); printf( "Controller 4 %spresent\n", (controllers & CONTROLLER_4_INSERTED) ? "" : "not " ); int accessories = get_accessories_present(); printf( "Accessory 1 %spresent %s\n", (accessories & CONTROLLER_1_INSERTED) ? "" : "not ", (accessories & CONTROLLER_1_INSERTED) ? format_type( identify_accessory( 0 ) ) : "" ); printf( "Accessory 2 %spresent %s\n", (accessories & CONTROLLER_2_INSERTED) ? "" : "not ", (accessories & CONTROLLER_2_INSERTED) ? format_type( identify_accessory( 1 ) ) : "" ); printf( "Accessory 3 %spresent %s\n", (accessories & CONTROLLER_3_INSERTED) ? "" : "not ", (accessories & CONTROLLER_3_INSERTED) ? format_type( identify_accessory( 2 ) ) : "" ); printf( "Accessory 4 %spresent %s\n", (accessories & CONTROLLER_4_INSERTED) ? "" : "not ", (accessories & CONTROLLER_4_INSERTED) ? format_type( identify_accessory( 3 ) ) : "" ); printf("\n%d\n\n", testv++ ); for( int i = 0; i < 32; i++ ) { printf( "%02X", data[i] ); } printf( "\n\n" ); printf( "Operation returned: %d\n", press ); console_render(); } }
int main(int argc, char** argv) { int target = TARGET_UDP_SOCKET; int input = INPUT_FILE; int output_mode = OUTPUT_MODE_CLICK; filter_code = 0xFF; filter_rate = 0xFFFF; filter_Nrx = 0xFF; char *csi_node = "0.0.0.0"; char *tx_node = "0.0.0.1"; int debug_level = 0; if ( (argc < 5) || ((argc > 1) && (strcmp(argv[1], "help") == 0)) ) { print_help(); exit(0); } target = io_type(argv[1][2],TARGET); input = io_type(argv[1][0],INPUT); output_mode = format_type(argv[4][0]); printf("Config: %s (%s -> %s) %s %s %s\n", argv[1], input_types[input], output_types[target], argv[2], argv[3], format_types[output_mode]); if ( argc > 5 ) { csi_node = argv[5]; tx_node = argv[6]; } if ( argc > 7 ) { debug_level = atoi(argv[7]); } struct cn_msg *cmsg; unsigned char cmsg_input_buf[BUF_SIZE]; char sendline[3000]; unsigned char buf[BUF_SIZE]; int ret; int count = 0; char hostname[1024]; gethostname(hostname, 1024); uint32_t csi_node_addr = (uint32_t)inet_addr(csi_node); uint32_t tx_node_addr = (uint32_t)inet_addr(tx_node); unsigned short l, l2; /* Make sure usage is correct */ check_usage(argc, argv); /* Set up the "caught_signal" function as this program's sig handler */ signal(SIGINT, caught_signal); /* Prepare Input */ switch ( input ) { case INPUT_SOCKET: netlink_sock_fd = open_iwl_netlink_socket(); break; case INPUT_FILE: netlink_sock_fd = open_file(argv[3], "r"); break; } /* Prepare Output */ switch ( target ) { case TARGET_TCP_SOCKET: out_fd = open_tcp_socket(argv[2], 32000); break; case TARGET_UDP_SOCKET: out_fd = open_udp_socket(argv[2], 32000); break; case TARGET_FILE: out_fd = open_file(argv[2], "w"); break; case TARGET_STDOUT: out_fd = 1; break; } /* Poll socket forever waiting for a message */ u_char *buf_p; int len_p, len_sendline; while (1) { /* Receive from socket with infinite timeout */ //ret = recv(sock_fd, buf, sizeof(buf), 0); /* Read the next entry size */ if (DEBUG_LEVEL_DEV) { printf("\n----- Next Data -----\n\n"); } switch (input) { case INPUT_FILE: /* Read the next entry size */ ret = read(netlink_sock_fd, &l2, 1 * sizeof(unsigned short)); if ( ret != 0 ) { l = ntohs(l2); /* Sanity-check the entry size */ if (l == 0) { fprintf(stderr, "Error: got entry size=0\n"); exit_program(-1); } else if (l > BUF_SIZE) { fprintf(stderr, "Error: got entry size %u > BUF_SIZE=%u\n", l, BUF_SIZE); exit_program(-2); } /* Read in the entry */ read(netlink_sock_fd, buf, l * sizeof(*buf)); cmsg = (struct cn_msg*)&cmsg_input_buf[0]; cmsg->id.idx = 0; cmsg->id.val = 0; cmsg->seq = 0; cmsg->ack = 0; cmsg->len = l; cmsg->flags = 0; memcpy(cmsg->data,buf,l); } if ( ret == 0 ) ret = -1; break; case INPUT_SOCKET: ret = iwl_netlink_recv(netlink_sock_fd, &buf_p, &len_p, &cmsg); break; } if (ret == -1) exit_program_err(-1, "recv"); if (cmsg == NULL) { printf("cmsg == NULL\n"); continue; } struct iwl5000_bfee_notif *bfee = NULL; bfee = (struct iwl5000_bfee_notif *)&(cmsg->data[1]); /* Filter */ if ( (filter_code != 0xFF) && (cmsg->data[0] != filter_code) ) continue; if ( (filter_rate != 0xFFFF) && (bfee->fake_rate_n_flags != filter_rate) ) continue; if ( (filter_Nrx != 0xFF) && (bfee->Nrx != filter_Nrx) ) continue; if (DEBUG_LEVEL_DEV) printf("Entry size=%d, code=0x%X\n", cmsg->len, cmsg->data[0]); /* Evaluation */ double eff_snrs[MAX_NUM_RATES][4]; if ( cmsg->data[0] == IWL_CONN_BFEE_NOTIF /*0xBB*/) { /* Beamforming packet */ calc_eff_snrs(bfee, eff_snrs); struct timeval timeVal; gettimeofday (&timeVal, NULL); if (DEBUG_LEVEL_INFO) printf("Rcvd pkt at <%ld.%06ld>\n", (long int)(timeVal.tv_sec), (long int)(timeVal.tv_usec)); if (DEBUG_LEVEL_DEV) { /* Beamforming packet */ printf("\nBeamforming: rate=0x%x\n", bfee->fake_rate_n_flags); /* Pull out the message portion and print some stats */ if (count % SLOW_MSG_CNT == 0) printf("Received %d bytes: id: %d val: %d seq: %d clen: %d\n", cmsg->len, cmsg->id.idx, cmsg->id.val, cmsg->seq, cmsg->len); printf("\n--- Effektive SNR ---\n\n"); int i; for ( i = 0; i < MAX_NUM_RATES; i++) { printf("%d: %f %f %f %f\n", i, db(eff_snrs[i][0]), db(eff_snrs[i][1]), db(eff_snrs[i][2]), db(eff_snrs[i][3])); } printf("\n---------------------\n\n"); } } /* Log the data remote */ /* Puffer mit Text füllen */ switch (output_mode) { case OUTPUT_MODE_FORMAT: sprintf(sendline, "%s, Received %d bytes: id: %d val: %d seq: %d clen: %d\n", hostname, cmsg->len, cmsg->id.idx, cmsg->id.val, cmsg->seq, cmsg->len); len_sendline = strlen(sendline); break; case OUTPUT_MODE_BFEE: if ( bfee != NULL) { calc_eff_snrs_tostr(bfee, eff_snrs, sendline, hostname); } else { sprintf(sendline, "bfee == NULL\n"); } if (DEBUG_LEVEL_DEV) printf("To tx:\n%s\n", sendline); break; case OUTPUT_MODE_CLICK: len_sendline = click_output(sendline, bfee, cmsg, eff_snrs, csi_node_addr, tx_node_addr); break; default: /* Log the data to file */ l = (unsigned short) cmsg->len; l2 = htons(l); memcpy(sendline, &l2, 1 * sizeof(unsigned short)); len_sendline = 1 * sizeof(unsigned short); memcpy(&(sendline[len_sendline]), cmsg->data, 1 * l); len_sendline += 1 * l; if ((count % 100 == 0) && (DEBUG_LEVEL_DEV)) printf("wrote %d bytes [msgcnt=%u]\n", len_sendline, count); } switch ( target ) { case TARGET_FILE: case TARGET_TCP_SOCKET: ret = write(out_fd, sendline, len_sendline); break; case TARGET_UDP_SOCKET: sendto(out_fd, sendline, len_sendline, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); break; case TARGET_STDOUT: dprintf(out_fd,"%s",sendline); break; } ++count; } exit_program(0); return 0; }