// this is the fn parameter passed into file_list() int file_list_callback(const char *path, bool dir, long mod, void *fl_context) { // -> / path = remove_substring(path, "//"); //printf("file_list_callback %s\n", path); size_t size = file_size(path); path = remove_substring(path, hal_doc_path(NULL)); struct file_list_context *flc = (struct file_list_context*)fl_context; struct variable *path3 = variable_new_str_chars(flc->context, path); struct variable *key2 = variable_new_str_chars(flc->context, RESERVED_DIR); struct variable *value = variable_new_bool(flc->context, dir); struct variable *metadata = variable_new_list(flc->context, NULL); variable_map_insert(flc->context, metadata, key2, value); key2 = variable_new_str_chars(flc->context, RESERVED_MODIFIED); value = variable_new_int(flc->context, (int32_t)mod); variable_map_insert(flc->context, metadata, key2, value); variable_map_insert(flc->context, flc->result, path3, metadata); key2 = variable_new_str_chars(flc->context, RESERVED_SIZE); value = variable_new_int(flc->context, (int32_t)size); variable_map_insert(flc->context, metadata, key2, value); variable_map_insert(flc->context, flc->result, path3, metadata); return 0; }
static int check_for_bc( char *timestr) { char *text_loc; remove_substring( timestr, "ad"); /* Just grab the 'ad' or 'a.d.'; */ remove_substring( timestr, "a.d."); /* they have no actual effect */ text_loc = remove_substring( timestr, "bc"); if( !text_loc) text_loc = remove_substring( timestr, "b.c."); remove_leading_and_trailing_spaces( timestr); return( text_loc ? 1 : 0); }
int dash_eval(char *line, char *std_input, char *origin) { if (line == NULL) return 1; int num_tokens; char **tokens = str_split(line, " ", &num_tokens); char *token; int i; int remote_pipe_pos = -1; for (i = 0; i < num_tokens; i++) { if (strcmp(tokens[i], REMOTE_PIPE) == 0) { remote_pipe_pos = i; break; } } if (remote_pipe_pos == -1) // No remote pipes { char *msg_data = dash_exec_scmd(tokens, remote_pipe_pos + 1, num_tokens, std_input); if (std_input == NULL) { printf("%s", msg_data); return 1; } else { // Send to origin char *fio_msg = dashp_fio(msg_data); send_to_host(fio_msg, origin); return 1; } } else // Remote pipe at remote_pipe_pos { char *subcommand = join_strings(tokens, " ", remote_pipe_pos+1, num_tokens); char *remotehost = extract_host(subcommand); char *maincommand = join_strings(tokens, " ", 0, remote_pipe_pos); char *msg_data = dash_exec_scmd(tokens, 0, remote_pipe_pos, std_input); char *send_msg; if (std_input == NULL) { // TODO: MAKE IP ADDRESS FUNCTION WORK! char *fin_remote_host = (char *) malloc (strlen(remotehost) + 1); strcat(fin_remote_host, remotehost); strcat(fin_remote_host, ":"); remove_substring(subcommand, fin_remote_host); free (fin_remote_host); subcommand[strlen(subcommand)-1] = '\0'; send_msg = dashp_pip(msg_data, "127.0.0.1", subcommand); } else { send_msg = dashp_pip(msg_data, origin, subcommand); } send_to_host(send_msg, remotehost); printf("Sent"); return 2; } }
int rf_zmq_open_multi(char* args, void** h, uint32_t nof_channels) { int ret = SRSLTE_ERROR; if (h) { *h = NULL; if (nof_channels != 1) { printf("rf_zmq only supports single port at the moment.\n"); return SRSLTE_ERROR; } rf_zmq_handler_t* handler = (rf_zmq_handler_t*)malloc(sizeof(rf_zmq_handler_t)); if (!handler) { perror("malloc"); return SRSLTE_ERROR; } bzero(handler, sizeof(rf_zmq_handler_t)); *h = handler; handler->base_srate = 23.04e6; // Sample rate for 100 PRB cell handler->rx_gain = 0.0; handler->info.max_rx_gain = +INFINITY; handler->info.min_rx_gain = -INFINITY; handler->info.max_tx_gain = +INFINITY; handler->info.min_tx_gain = -INFINITY; strcpy(handler->id, "zmq\0"); pthread_mutex_init(&handler->mutex, NULL); pthread_mutex_init(&handler->mutex_tx, NULL); // parse args if (args) { // base_srate { const char config_arg[] = "base_srate="; char config_str[PARAM_LEN] = {0}; char* config_ptr = strstr(args, config_arg); if (config_ptr) { copy_subdev_string(config_str, config_ptr + strlen(config_arg)); printf("Using base rate=%s\n", config_str); handler->base_srate = strtod(config_str, NULL); remove_substring(args, config_arg); remove_substring(args, config_str); } } // rxport { const char config_arg[] = "rx_port="; char config_str[PARAM_LEN] = {0}; char* config_ptr = strstr(args, config_arg); if (config_ptr) { copy_subdev_string(config_str, config_ptr + strlen(config_arg)); printf("Using rx_port=%s\n", config_str); strncpy(handler->rx_port, config_str, PARAM_LEN); handler->rx_port[PARAM_LEN - 1] = 0; remove_substring(args, config_arg); remove_substring(args, config_str); } } // txport { const char config_arg[] = "tx_port="; char config_str[PARAM_LEN] = {0}; char* config_ptr = strstr(args, config_arg); if (config_ptr) { copy_subdev_string(config_str, config_ptr + strlen(config_arg)); printf("Using tx_port=%s\n", config_str); strncpy(handler->tx_port, config_str, PARAM_LEN); handler->tx_port[PARAM_LEN - 1] = 0; remove_substring(args, config_arg); remove_substring(args, config_str); } } // id { const char config_arg[] = "id="; char config_str[PARAM_LEN_SHORT] = {0}; char* config_ptr = strstr(args, config_arg); if (config_ptr) { copy_subdev_string(config_str, config_ptr + strlen(config_arg)); printf("Using ID=%s\n", config_str); strncpy(handler->id, config_str, PARAM_LEN_SHORT); handler->id[PARAM_LEN_SHORT - 1] = 0; remove_substring(args, config_arg); remove_substring(args, config_str); } } } update_rates(handler, 1.92e6); // Create ZMQ context handler->context = zmq_ctx_new(); if (!handler->context) { fprintf(stderr, "[zmq] Error: creating new context\n"); goto clean_exit; } if (strlen(handler->tx_port) != 0) { // Initialise transmitter handler->transmitter = zmq_socket(handler->context, ZMQ_REP); if (!handler->transmitter) { fprintf(stderr, "[zmq] Error: creating transmitter socket\n"); goto clean_exit; } rf_zmq_info(handler, "Binding transmitter: %s\n", handler->tx_port); ret = zmq_bind(handler->transmitter, handler->tx_port); if (ret) { fprintf(stderr, "Error: connecting transmitter socket: %s\n", zmq_strerror(zmq_errno())); goto clean_exit; } #if ZMQ_TIMEOUT_MS // set recv timeout for transmitter int timeout = ZMQ_TIMEOUT_MS; if (zmq_setsockopt(handler->transmitter, ZMQ_RCVTIMEO, &timeout, sizeof(timeout)) == -1) { fprintf(stderr, "Error: setting receive timeout on tx socket\n"); goto clean_exit; } if (zmq_setsockopt(handler->transmitter, ZMQ_SNDTIMEO, &timeout, sizeof(timeout)) == -1) { fprintf(stderr, "Error: setting receive timeout on tx socket\n"); goto clean_exit; } // set linger timeout for transmitter timeout = 0; if (zmq_setsockopt(handler->transmitter, ZMQ_LINGER, &timeout, sizeof(timeout)) == -1) { fprintf(stderr, "Error: setting linger timeout on tx socket\n"); } #endif } else { fprintf(stdout, "[zmq] %s Tx port not specified. Disabling transmitter.\n", handler->id); } // initialize receiver if (strlen(handler->rx_port) != 0) { handler->receiver = zmq_socket(handler->context, ZMQ_REQ); if (!handler->receiver) { fprintf(stderr, "[zmq] Error: creating receiver socket\n"); goto clean_exit; } rf_zmq_info(handler, "Connecting receiver: %s\n", handler->rx_port); ret = zmq_connect(handler->receiver, handler->rx_port); if (ret) { fprintf(stderr, "Error: binding receiver socket: %s\n", zmq_strerror(zmq_errno())); goto clean_exit; } #if ZMQ_TIMEOUT_MS // set recv timeout for receiver int timeout = ZMQ_TIMEOUT_MS; if (zmq_setsockopt(handler->receiver, ZMQ_RCVTIMEO, &timeout, sizeof(timeout)) == -1) { fprintf(stderr, "Error: setting receive timeout on tx socket\n"); goto clean_exit; } if (zmq_setsockopt(handler->receiver, ZMQ_SNDTIMEO, &timeout, sizeof(timeout)) == -1) { fprintf(stderr, "Error: setting receive timeout on tx socket\n"); goto clean_exit; } timeout = 0; // set linger timeout for receiver if (zmq_setsockopt(handler->receiver, ZMQ_LINGER, &timeout, sizeof(timeout)) == -1) { fprintf(stderr, "Error: setting linger timeout on rx socket\n"); } #endif // init rx ringbuffer if (srslte_ringbuffer_init(&handler->rx_ringbuffer, BUFFER_SIZE)) { fprintf(stderr, "Error, initiating rx ringbuffer\n"); goto clean_exit; } } else { fprintf(stdout, "[zmq] %s Rx port not specified. Disabling receiver.\n", handler->id); } if (handler->transmitter == NULL && handler->receiver == NULL) { fprintf(stderr, "[zmq] Error: Neither Tx port nor Rx port specified.\n"); goto clean_exit; } // Create decimation and overflow buffer handler->buffer_decimation = srslte_vec_malloc(ZMQ_MAX_RX_BYTES); if (!handler->buffer_decimation) { fprintf(stderr, "Error: allocating decimation buffer\n"); goto clean_exit; } handler->buffer_tx = srslte_vec_malloc(ZMQ_MAX_RX_BYTES); if (!handler->buffer_tx) { fprintf(stderr, "Error: allocating tx buffer\n"); goto clean_exit; } handler->buffer_rx = srslte_vec_malloc(ZMQ_MAX_RX_BYTES); if (!handler->buffer_rx) { fprintf(stderr, "Error: allocating rx buffer\n"); goto clean_exit; } handler->running = true; if (handler->receiver) { pthread_create(&handler->thread, NULL, rf_zmq_async_rx_thread, handler); } ret = SRSLTE_SUCCESS; clean_exit: if (ret) { rf_zmq_close(handler); } } return ret; }