int src_alloc(struct ausrc_st **stp, const struct ausrc *as, struct media_ctx **ctx, struct ausrc_prm *prm, const char *device, ausrc_read_h *rh, ausrc_error_h *errh, void *arg) { struct ausrc_st *st; int err = 0; (void)ctx; (void)errh; if (!stp || !as || !prm) return EINVAL; st = mem_zalloc(sizeof(*st), ausrc_destructor); if (!st) return ENOMEM; st->as = as; st->prm = *prm; st->rh = rh; st->arg = arg; err = device_connect(&st->dev, device, NULL, st); if (err) goto out; out: if (err) mem_deref(st); else *stp = st; return err; }
int play_alloc(struct auplay_st **stp, struct auplay *ap, struct auplay_prm *prm, const char *device, auplay_write_h *wh, void *arg) { struct auplay_st *st; int err; if (!stp || !ap || !prm) return EINVAL; st = mem_zalloc(sizeof(*st), auplay_destructor); if (!st) return ENOMEM; st->ap = mem_ref(ap); st->prm = *prm; st->wh = wh; st->arg = arg; err = device_connect(&st->dev, device, st, NULL); if (err) goto out; out: if (err) mem_deref(st); else *stp = st; return err; }
static gpointer directtcp_listen_thread( gpointer data) { XferSourceRecovery *self = XFER_SOURCE_RECOVERY(data); XferElement *elt = XFER_ELEMENT(self); int result; DBG(1, "(this is directtcp_listen_thread)"); /* we need to make an outgoing connection to downstream; we do this while * holding the start_part_mutex, so that a part doesn't get started until * we're finished with the device */ g_mutex_lock(self->start_part_mutex); if (elt->cancelled) { g_mutex_unlock(self->start_part_mutex); goto send_done; } g_assert(self->device != NULL); /* have a device */ g_assert(elt->downstream->input_listen_addrs != NULL); /* downstream listening */ DBG(2, "making DirectTCP connection on device %s", self->device->device_name); result = device_connect(self->device, FALSE, elt->downstream->input_listen_addrs, &self->conn, &elt->cancelled, self->start_part_mutex, self->abort_cond); if (result == 1 && !elt->cancelled) { xfer_cancel_with_error(elt, _("error making DirectTCP connection: %s"), device_error_or_status(self->device)); g_mutex_unlock(self->start_part_mutex); wait_until_xfer_cancelled(elt->xfer); goto send_done; } else if (result == 2 || elt->cancelled) { g_mutex_unlock(self->start_part_mutex); wait_until_xfer_cancelled(elt->xfer); goto send_done; } DBG(2, "DirectTCP connect succeeded"); return directtcp_common_thread(self); send_done: xfer_queue_message(elt->xfer, xmsg_new(elt, XMSG_DONE, 0)); return NULL; }
/* Link all the known devices together */ void connect_devices() { struct le *le, *lep; for (le = devicel.head; le; le = le->next) { struct device *dev = (struct device *)le->data; for (lep = devicel.head; lep; lep = lep->next) { struct device *devp; devp = (struct device *)lep->data; if (dev == devp) continue; if (device_find_peer(dev, devp)) continue; device_connect(dev, devp); } } }
/* Make OS device a ZIP device. */ void zip_mount_os(void) { uint8 buffer[256]; uint8* szZipArchiveName; DEVICEPARAM p_readonly = { STRING_AND_LENGTH("ReadOnly"), ParamBoolean, NULL }; DEVICEPARAM p_crc32 = { STRING_AND_LENGTH("CheckCRC32"), ParamBoolean, NULL }; DEVICEPARAM p_filename = { STRING_AND_LENGTH("Filename"), ParamString, NULL }; /* Mount new swzipread device so we can read the zipped SW folder */ swzipreaddevice = device_alloc(STRING_AND_LENGTH(SWZIP_READ_DEV_NAME)) ; if ( !device_connect(swzipreaddevice, SWZIPREAD_DEVICE_TYPE, SWZIP_READ_DEV_NAME, DEVICEUNDISMOUNTABLE|DEVICEENABLED, TRUE)) { device_free(swzipreaddevice) ; swzipreaddevice = NULL ; } else { /* Add ZIP read device. */ device_add(swzipreaddevice); } /* If we have managed to mount an SW ZIP read device, assume that we MUST have a zipped SW folder to use. */ if (swzipreaddevice != NULL) { /* Rename %os% to something else */ theIDevName(osdevice) = (uint8*)SWZIP_WRITE_DEV_NAME; /* Mount new os device as ZIP device */ if ( ! device_connect(osdevice, ZIP_DEVICE_TYPE, "os", DEVICEUNDISMOUNTABLE|DEVICEENABLED, TRUE)) { device_free(swzipreaddevice) ; swzipreaddevice = NULL ; (void)dispatch_SwExit(swexit_error_zipsw_init, "Cannot initialise ZIP os device"); return; } /* Make ZIP OS device first device */ device_add_first(osdevice); /* NOTE: can't do this here since ZIP device calls SwOftenUnsafe which * depends on SystemParams, but that has not been set up yet! * Originally done in doBootup() which was last thing before interpreter * kicks off, so ideally need hook from there! */ /* ZIP device is already mounted enabled - need to turn on checksum checking * and modifiable */ theDevParamBoolean(p_crc32) = TRUE; if ( ((theISetParam(osdevice))(osdevice, &p_crc32) != ParamAccepted)) { (void)dispatch_SwExit(swexit_error_zipsw_config_01, "Failed to configure OS device(1)"); return; } theDevParamBoolean(p_readonly) = FALSE; if ( ((theISetParam(osdevice))(osdevice, &p_readonly) != ParamAccepted )) { (void)dispatch_SwExit(swexit_error_zipsw_config_02, "Failed to configure OS device(2)"); return; } szZipArchiveName = getZipReadArchiveName (buffer, sizeof (buffer)); theDevParamString(p_filename) = szZipArchiveName; theDevParamStringLen(p_filename) = strlen_int32 ((char*) szZipArchiveName); if ( ((theISetParam(osdevice))(osdevice, &p_filename) != ParamAccepted ) ) { (void)dispatch_SwExit(swexit_error_zipsw_config_03, "Failed to configure OS device(3)"); return; } } else { /* We did not manage to mount a SW ZIP read device, so just assume a normal SW folder. Do nothing. */ } } /* zip_mount_os */
int main (int argc, char **argv) { int error; device_t *device; iqoffset = calc_offset_iq(); signal(SIGINT, sighandler); if (0 != (error = memlock_setup())) LOG_ERROR_AND_RETURN(EXIT_FAILURE, "failed to memlock_init(), %d", error); if (0 != (error = core_init())) LOG_ERROR_AND_RETURN(EXIT_FAILURE, "failed to core_init(), %d", error); sleep(1); if (NULL == (gDevice = device = core_device_get(0))) LOG_ERROR_AND_RETURN(EXIT_FAILURE, "failed to core_device_get(0)"); if (0 != (error = device_connect(device))) LOG_ERROR_AND_RETURN(EXIT_FAILURE, "failed to device_connect(), %d", error); device->span = 190; device->gain = -10; device->frequency = 1040000; // // planar graph // { graphplanar_t *graphplanar = NULL; dspchain_t *dspchain = NULL; hamming_t *hamming = NULL; ooura4_t *ooura4 = NULL; average_t *average = NULL; cpx2pwr_t *cpx2pwr = NULL; smooth_t *smooth = NULL; invert_t *invert = NULL; datastream_t *datastream = NULL; if (0 != (error = core_graph_planar(&graphplanar, "Planar") || graphplanar == NULL)) LOG_ERROR_AND_RETURN(EXIT_FAILURE, "failed to core_graph_planar(), %d", error); graph_set_axis(graphplanar_graph(graphplanar), GRAPH_AXIS_X, "Frequency", GRAPH_SCALE_LIN, 0., 0., 1024); graph_set_axis(graphplanar_graph(graphplanar), GRAPH_AXIS_Y, "Amplitude", GRAPH_SCALE_LIN, 100., 0., 250); graph_ready(graphplanar_graph(graphplanar)); graph_datastream(graphplanar_graph(graphplanar), &datastream); graph_dspchain(graphplanar_graph(graphplanar), &dspchain); device_datastream_add(device, datastream); core_dsp_window_hamming(&hamming, ASCP_IQ_COUNT, iqoffset); core_dsp_fft_ooura4(&ooura4, ASCP_IQ_COUNT, FFT_DIR_FORWARD); core_dsp_other_cpx2pwr(&cpx2pwr, 0., -100.); core_dsp_other_average(&average, ASCP_IQ_COUNT/4, 100); core_dsp_other_invert(&invert, INVERT_REAL); core_dsp_other_smooth(&smooth, 3); dspchain_add(dspchain, (dsp_t*)hamming, -1); dspchain_add(dspchain, (dsp_t*)ooura4, -1); dspchain_add(dspchain, (dsp_t*)cpx2pwr, -1); dspchain_add(dspchain, (dsp_t*)average, -1); dspchain_add(dspchain, (dsp_t*)invert, -1); dspchain_add(dspchain, (dsp_t*)smooth, -1); graph_set_redraw_fp(graphplanar_graph(graphplanar), (graph_redraw_fp_func)graph_redraw, graphplanar); graph_set_draw_path_fp(graphplanar_graph(graphplanar), (graph_draw_path_fp_func)graph_draw_path); graph_set_draw_line_fp(graphplanar_graph(graphplanar), (graph_draw_line_fp_func)graph_draw_line); } // // history graph // { graphhistory_t *graphhistory = NULL; dspchain_t *dspchain = NULL; hamming_t *hamming = NULL; ooura4_t *ooura4 = NULL; average_t *average = NULL; cpx2pwr_t *cpx2pwr = NULL; invert_t *invert = NULL; datastream_t *datastream = NULL; if (0 != (error = core_graph_history(&graphhistory, "History") || graphhistory == NULL)) LOG_ERROR_AND_RETURN(EXIT_FAILURE, "failed to core_graph_history(), %d", error); graph_set_axis(graphhistory_graph(graphhistory), GRAPH_AXIS_X, "Frequency", GRAPH_SCALE_LIN, 0., 0., 1024); graph_set_axis(graphhistory_graph(graphhistory), GRAPH_AXIS_Y, "Time", GRAPH_SCALE_LIN, 15., 0., 250); graph_ready(graphhistory_graph(graphhistory)); graph_datastream(graphhistory_graph(graphhistory), &datastream); graph_dspchain(graphhistory_graph(graphhistory), &dspchain); device_datastream_add(device, datastream); core_dsp_window_hamming(&hamming, ASCP_IQ_COUNT, iqoffset); core_dsp_fft_ooura4(&ooura4, ASCP_IQ_COUNT, FFT_DIR_FORWARD); core_dsp_other_cpx2pwr(&cpx2pwr, 0., -100.); core_dsp_other_invert(&invert, INVERT_REAL); core_dsp_other_average(&average, ASCP_IQ_COUNT/4, 100); dspchain_add(dspchain, (dsp_t*)hamming, -1); dspchain_add(dspchain, (dsp_t*)ooura4, -1); dspchain_add(dspchain, (dsp_t*)cpx2pwr, -1); dspchain_add(dspchain, (dsp_t*)invert, -1); dspchain_add(dspchain, (dsp_t*)average, -1); graph_set_redraw_fp(graphhistory_graph(graphhistory), (graph_redraw_fp_func)graph_redraw, graphhistory); graph_set_draw_hist_fp(graphhistory_graph(graphhistory), (graph_draw_hist_fp_func)graph_draw_hist); graph_set_draw_path_fp(graphhistory_graph(graphhistory), (graph_draw_path_fp_func)graph_draw_path); graph_set_draw_line_fp(graphhistory_graph(graphhistory), (graph_draw_line_fp_func)graph_draw_line); } sleep(1); if (0 != (error = device_span_set(device, device->span))) LOG_ERROR_AND_RETURN(EXIT_FAILURE, "failed to device_span_set(), %d", error); sleep(1); if (0 != (error = device_data_start(device))) LOG_ERROR_AND_RETURN(EXIT_FAILURE, "failed to device_data_start(), %d", error); while (1) sleep(1); return EXIT_SUCCESS; }
void prog_init() { libusb_init(NULL); device_connect(); }