void tcpcli_init() { fd_data_c2s = connect_fd(PORT_C2S); fd_data_s2c = connect_fd(PORT_S2C); //test //uint16_t x; //x = 65432; //write(fd_c2s, &x, sizeof(x)); }
/* * From the SANE spec: * This function is used to establish a connection to a particular * device. The name of the device to be opened is passed in argument * name. If the call completes successfully, a handle for the device * is returned in *h. As a special case, specifying a zero-length * string as the device requests opening the first available device * (if there is such a device). */ SANE_Status sane_open (SANE_String_Const name, SANE_Handle * handle) { struct scanner *dev = NULL; struct scanner *s = NULL; SANE_Status ret; DBG (10, "sane_open: start\n"); if(name[0] == 0){ if(scanner_devList){ DBG (15, "sane_open: no device requested, using first\n"); s = scanner_devList; } else{ DBG (15, "sane_open: no device requested, none found\n"); } } else{ DBG (15, "sane_open: device %s requested, attaching\n", name); ret = attach_one(name); if(ret){ DBG (5, "sane_open: attach error %d\n",ret); return ret; } for (dev = scanner_devList; dev; dev = dev->next) { if (strcmp (dev->sane.name, name) == 0) { s = dev; break; } } } if (!s) { DBG (5, "sane_open: no device found\n"); return SANE_STATUS_INVAL; } DBG (15, "sane_open: device %s found\n", s->sane.name); *handle = s; /* connect the fd so we can talk to scanner */ ret = connect_fd(s); if(ret != SANE_STATUS_GOOD){ return ret; } DBG (10, "sane_open: finish\n"); return SANE_STATUS_GOOD; }
/** * sickldmrs_init - Initialize the sick LD-MRS device * * addr is a string containing its IPv4 address like "192.168.1.1" * port is a string containing the port number, like "12000" */ struct sickldmrs_device * sickldmrs_init(const char *addr, const char *port, bool readTask) { struct sickldmrs_device *dev; struct sickldmrs_private *priv; dev = malloc(sizeof(struct sickldmrs_device)); if (dev == NULL) return NULL; memset(dev, 0, sizeof(struct sickldmrs_device)); priv = (struct sickldmrs_private *) malloc(sizeof(struct sickldmrs_private)); if (priv == NULL) { free(dev); return NULL; } dev->priv = priv; if (pthread_mutex_init(&priv->lock, NULL) != 0) { free(priv); free(dev); return NULL; } if (pthread_cond_init(&priv->cond, NULL) != 0) { pthread_mutex_destroy(&priv->lock); free(priv); free(dev); return NULL; } dev->priv->fd = connect_fd(addr, port); if (dev->priv->fd == -1) { pthread_mutex_destroy(&priv->lock); free(priv); free(dev); return NULL; } if (readTask) { if (pthread_create(&dev->priv->tid, NULL, sickldmrsReadTask, dev) != 0) { close(dev->priv->fd); free(priv); free(dev); return NULL; } } else priv->tid = -1; priv->pending = -1; return dev; }
/* callback used by sane_get_devices * build the scanner struct and link to global list * unless struct is already loaded, then pretend */ static SANE_Status attach_one (const char *device_name) { struct scanner *s; int ret, i; SANE_Word vid, pid; DBG (10, "attach_one: start '%s'\n", device_name); for (s = scanner_devList; s; s = s->next) { if (strcmp (s->sane.name, device_name) == 0) { DBG (10, "attach_one: already attached!\n"); return SANE_STATUS_GOOD; } } /* build a scanner struct to hold it */ DBG (15, "attach_one: init struct\n"); if ((s = calloc (sizeof (*s), 1)) == NULL) return SANE_STATUS_NO_MEM; /* copy the device name */ s->device_name = strdup (device_name); if (!s->device_name){ free (s); return SANE_STATUS_NO_MEM; } /* connect the fd */ DBG (15, "attach_one: connect fd\n"); s->fd = -1; ret = connect_fd(s); if(ret != SANE_STATUS_GOOD){ free (s->device_name); free (s); return ret; } /* clean up the scanner struct based on model */ /* this is the only piece of model specific code */ sanei_usb_get_vendor_product(s->fd,&vid,&pid); if(vid == 0x08f0){ s->vendor_name = "CardScan"; if(pid == 0x0005){ s->product_name = "800c"; } else if(pid == 0x0002){ s->product_name = "600c"; } else{ DBG (5, "Unknown product, using default settings\n"); s->product_name = "Unknown"; } } else if(vid == 0x0451){ s->vendor_name = "Sanford"; if(pid == 0x6250){ s->product_name = "800c"; } else{ DBG (5, "Unknown product, using default settings\n"); s->product_name = "Unknown"; } } else{ DBG (5, "Unknown vendor/product, using default settings\n"); s->vendor_name = "Unknown"; s->product_name = "Unknown"; } DBG (15, "attach_one: Found %s scanner %s at %s\n", s->vendor_name, s->product_name, s->device_name); /*copy config file settings*/ s->has_cal_buffer = global_has_cal_buffer; s->lines_per_block = global_lines_per_block; s->color_block_size = s->lines_per_block * PIXELS_PER_LINE * 3; s->gray_block_size = s->lines_per_block * PIXELS_PER_LINE; /* try to get calibration */ if(s->has_cal_buffer){ DBG (15, "attach_one: scanner calibration\n"); ret = load_calibration(s); if (ret != SANE_STATUS_GOOD) { DBG (5, "sane_start: ERROR: cannot calibrate, incompatible?\n"); free (s->device_name); free (s); return ret; } } else{ DBG (15, "attach_one: skipping calibration\n"); } /* set SANE option 'values' to good defaults */ DBG (15, "attach_one: init options\n"); /* go ahead and setup the first opt, because * frontend may call control_option on it * before calling get_option_descriptor */ memset (s->opt, 0, sizeof (s->opt)); for (i = 0; i < NUM_OPTIONS; ++i) { s->opt[i].name = "filler"; s->opt[i].size = sizeof (SANE_Word); s->opt[i].cap = SANE_CAP_INACTIVE; } s->opt[OPT_NUM_OPTS].name = SANE_NAME_NUM_OPTIONS; s->opt[OPT_NUM_OPTS].title = SANE_TITLE_NUM_OPTIONS; s->opt[OPT_NUM_OPTS].desc = SANE_DESC_NUM_OPTIONS; s->opt[OPT_NUM_OPTS].type = SANE_TYPE_INT; s->opt[OPT_NUM_OPTS].cap = SANE_CAP_SOFT_DETECT; DBG (15, "attach_one: init settings\n"); /* we close the connection, so that another backend can talk to scanner */ disconnect_fd(s); /* load info into sane_device struct */ s->sane.name = s->device_name; s->sane.vendor = s->vendor_name; s->sane.model = s->product_name; s->sane.type = "scanner"; s->next = scanner_devList; scanner_devList = s; DBG (10, "attach_one: finish\n"); return SANE_STATUS_GOOD; }
void method_datagram_t::do_init() { source->init(name); loggers->init(name); datagram_fd = connect_fd(); }