/* * Capture an image */ static int camera_capture (Camera* camera, CameraCaptureType type, CameraFilePath* path, GPContext *context) { unsigned char cmd[3], buf[256], ack; int ret, nbr_images,images_taken,i; GP_DEBUG ("*** ENTER: camera_capture ***"); /* Just check if there is space available yet */ cmd[0] = ESC; cmd[1] = GETCAMINFO; ret = gp_port_write (camera->port, (char*)cmd, 2); if (ret<GP_OK) return ret; ret = gp_port_read (camera->port, (char*)buf, INFO_BUFFER); nbr_images = (buf[FREE_IMAGE_PTR] << 8) | (buf[FREE_IMAGE_PTR+1]); images_taken = (buf[TAKEN_IMAGE_PTR] << 8) | (buf[TAKEN_IMAGE_PTR+1]); /* Capture the image */ cmd[0] = ESC; cmd[1] = CAPTUREIMAGE_CMD1; cmd[2] = CAPTUREIMAGE_CMD2; ret = gp_port_write (camera->port, (char*)cmd, sizeof(cmd)); if (ret<GP_OK) return ret; ret = gp_port_read (camera->port, (char*)&ack, ACK_LEN); if (ret<GP_OK) return ret; if (ack == NACK) { if (buf[CAMERA_MODE_PTR] != REC_MODE) gp_context_error(context, _("You must be in record " "mode to capture images.")); else if (!nbr_images) gp_context_error(context, _("No space available " "to capture new images. You must delete some " "images.")); else gp_context_error(context, _("Can't capture new images. " "Unknown error")); return (GP_ERROR); } /* Wait image writting in camera's memory */ for (i=0; i<=15; i++) { sleep(1); if ((ret = k_ping(camera->port)) == GP_OK) break; } if (ret < GP_OK) { gp_context_error(context, _("No answer from the camera.")); return (GP_ERROR); } /* Now register new image */ images_taken++; sprintf (path->name, FILENAME, (unsigned int) images_taken); return (GP_OK); }
int digi_init (GPPort *port, CameraPrivateLibrary *priv) { char c[0x14]; int i,j=0; unsigned char *catalog = calloc(0x4010,1); unsigned char *catalog_tmp; if (!catalog) return GP_ERROR_NO_MEMORY; SQWRITE (port, 0x0c, 0x14f4, 0x0, NULL, 0); SQREAD (port, 0x0c, 0xf5, 0x00, c, 0x14); SQWRITE (port, 0x0c, 0x1440, 0x110f, NULL, 0); digi_reset (port); SQWRITE (port, 0x0c, 0x14f0, 0x0, NULL, 0); gp_port_read (port, c, 0x14); digi_reset(port); SQWRITE (port, 0x0c, 0x20, 0x40, NULL, 0); gp_port_read(port, (char *)catalog, 0x4000); /* We need 16 bytes for each photo. */ digi_reset (port); /* The first occurence of a zero denotes end of files entries */ for (i=0; i<0x4000 && catalog[i]; i+=16); priv->nb_entries = i>>4; catalog_tmp = realloc(catalog, i+16); memset (catalog_tmp+i, 0, 16); if (i) { /* * 0x913c cameras allow individual photo deletion. This causes * the relevant catalog line to start with 0x64. So the related * lines of config data must be removed, and the deleted * images need to be cast out from the count. */ for (j=0; j<i; j+=16) { if ((!catalog[j])||(catalog_tmp[j] == 0x64)) { memcpy(catalog_tmp+j, catalog_tmp+j+16, i+16-j); priv->nb_entries -- ; } } if (catalog_tmp) priv->catalog = catalog_tmp; else priv->catalog = catalog; } else { free (catalog); priv->catalog = NULL; /* We just have freed catalog_tmp */ } digi_reset (port); priv->last_fetched_entry = -1; priv->init_done=1; return GP_OK; }
/* * Delete all images */ static int delete_all_func (CameraFilesystem *fs, const char *folder, void *data, GPContext *context) { unsigned char cmd[7], ack; int ret; Camera *camera = data; GP_DEBUG ("*** ENTER: delete_all_func ***"); cmd[0] = ESC; cmd[1] = ERASEIMAGE_CMD1; cmd[2] = IMAGE_CMD2; cmd[3] = 0x30; cmd[4] = 0x30; cmd[5] = 0x30; cmd[6] = 0x30; ret = gp_port_write (camera->port, (char*)cmd, sizeof(cmd)); if (ret<GP_OK) return ret; ret = gp_port_read (camera->port, (char*)&ack, ACK_LEN); if (ret<GP_OK) return ret; if (ack != ACK) { gp_context_error(context, _("Can't delete all images.")); return (GP_ERROR); } return (GP_OK); }
int digita_usb_open(CameraPrivateLibrary *dev, Camera *camera) { GPPortSettings settings; unsigned char buffer[128]; int ret; ret = gp_port_get_settings(camera->port, &settings); if (ret < 0) return ret; /* We'll take the defaults. The core should have the done what's */ /* necessary to find the config, interface, altsetting and endpoints */ ret = gp_port_set_settings(dev->gpdev, settings); if (ret < 0) return ret; dev->send = digita_usb_send; dev->read = digita_usb_read; gp_port_set_timeout(camera->port, 100); /* Mop up anything still pending */ while (gp_port_read(dev->gpdev, buffer, sizeof(buffer)) > 0) ; gp_port_set_timeout(camera->port, 10000); return GP_OK; }
static int m_read (GPPort *port, char *data, int size) { gp_port_write(port, "\x21", 1); gp_port_read(port, data, 16); return GP_OK; }
/* Read exactly this number of bytes from the port within the given timeouts */ int mesa_read( GPPort *port, uint8_t *b, int s, int timeout2, int timeout1 ) { int n = 0; int r, t; struct timeval start, now; t = timeout1 ? timeout1 : timeout2; /* set first byte timeout */ gettimeofday( &start, NULL ); do { /* limit reads to 1k segment */ r = gp_port_read( port, &b[n], s>1024?1024:s ); if ( r > 0 ) { n += r; s -= r; gettimeofday( &start, NULL ); t = timeout2; } gettimeofday( &now, NULL ); } while ( s > 0 && t > timediff( &now, &start ) ); return n; }
int digi_read_picture_data (GPPort *port, unsigned char *data, int size, int n ) { int remainder = size % 0x8000; int offset = 0; if (!n) { SQWRITE (port, 0x0c, 0x30, 0x00, NULL, 0); } while ((offset + 0x8000 < size)) { gp_port_read (port, (char *)data + offset, 0x8000); offset = offset + 0x8000; } gp_port_read (port, (char *)data + offset, remainder); return GP_OK; }
int camera_init (Camera *camera, GPContext *context) { GPPortSettings settings; int speeds[] = { 115200, 9600, 19200, 38400, 57600, 115200 }; int ret, i; char cmd[3], buf[1]; /* First, set up all the function pointers. */ camera->functions->capture = camera_capture; camera->functions->about = camera_about; camera->functions->get_config = camera_get_config; camera->functions->set_config = camera_set_config; camera->functions->summary = camera_summary; camera->functions->manual = camera_manual; /* Now, tell the filesystem where to get lists, files and info */ gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera); /* * The port is already provided with camera->port (and * already open). You just have to use functions like * gp_port_timeout_set, gp_port_settings_get, gp_port_settings_set. */ gp_port_get_settings (camera->port, &settings); settings.serial.speed = 115200; settings.serial.bits = 8; settings.serial.stopbits= 1; settings.serial.parity = 0; gp_port_set_settings (camera->port, settings); /* * Once you have configured the port, you should check if a * connection to the camera can be established. */ for (i=0;i<sizeof(speeds)/sizeof(speeds[0]);i++) { gp_port_get_settings (camera->port, &settings); settings.serial.speed = speeds[i]; gp_port_set_settings (camera->port, settings); if (GP_OK<=k_ping (camera->port)) break; } if (i == sizeof(speeds)/sizeof(speeds[0])) return GP_ERROR; cmd[0] = ESC; cmd[1] = SETSPEED; cmd[2] = 0x30 + 4; /* speed nr 4:(9600, 19200, 38400, 57600, 115200) */ ret = gp_port_write (camera->port, cmd, 3); if (ret<GP_OK) return ret; ret = gp_port_read (camera->port, buf, 1); if (ret<GP_OK) return ret; if (buf[0] != ACK) return GP_ERROR; gp_port_get_settings (camera->port, &settings); settings.serial.speed = 115200; gp_port_set_settings (camera->port, settings); return GP_OK; }
int jl2005c_read_data (GPPort *port, char *data, int size) { /* These cameras tend to be slow. */ usleep (10000); gp_port_read (port, data, size); usleep (10000); return GP_OK; }
static int mars_routine (Info *info, GPPort *port, char param, int n) { char c[16]; char start[2] = {0x19, 0x51}; char do_something[2]; char address1[2]; char address2[2]; char address3[2]; char address4[2]; char address5[2]; char address6[2]; do_something[0]= 0x19; do_something[1]=param; /* See protocol.txt for my theories about what these mean. */ address1[0] = 0x19; address1[1] = info[8*n+1]; address2[0] = 0x19; address2[1] = info[8*n+2]; address3[0] = 0x19; address3[1] = info[8*n+3]; address4[0] = 0x19; address4[1] = info[8*n+4]; address5[0] = 0x19; address5[1] = info[8*n+5]; address6[0] = 0x19; address6[1] = info[8*n+6]; memset(c,0,sizeof(c)); /*Routine used in initialization, photo download, and reset. */ m_read(port, c, 16); m_command(port, start, 2, c); m_command(port, do_something, 2, c); m_command(port, address1, 2, c); c[0] = 0; gp_port_write(port, address2, 2); /* Moving the memory cursor to the given address? */ while (( c[0] != 0xa) ) { m_read(port, c, 16); } m_command(port, address3, 2, c); m_command(port, address4, 2, c); m_command(port, address5, 2, c); m_command(port, address6, 2, c); gp_port_write(port, "\x19", 1); gp_port_read(port, c , 16); /* Next thing is to switch the inep. Some cameras need a pause here */ usleep (MARS_SLEEP); return(c[0]); }
/* * Read block described by req */ static int sx330z_read_block(Camera *camera, GPContext *context, struct traveler_req *req, uint8_t *buf) { int ret; uint8_t trxbuf[0x20]; /* 1. send request */ sx330z_fill_req(trxbuf, req); ret = gp_port_usb_msg_write(camera->port, USB_REQ_RESERVED, req->requesttype, 0, (char *)trxbuf, 0x20); if (ret != 0x20) return(GP_ERROR_IO_WRITE); /* 2. read data */ ret = gp_port_read(camera->port, (char *)buf, req->size); if (ret != req->size)return(GP_ERROR_IO_READ); /* 3. read Ack */ ret = gp_port_read(camera->port, (char *)trxbuf, 0x10); if (ret != 0x10) return(GP_ERROR); /* FIXME : Security check ???*/ return(GP_OK); } /* read block */
static int ultrapocket_command(GPPort *port, int iswrite, unsigned char *data, int datasize) { int ret; if (iswrite) ret = gp_port_write(port, (char *)data, datasize); else ret = gp_port_read(port, (char *)data, datasize); return ret; }
/* * Read image informations */ static int k_info_img (unsigned int image_no, void *data, CameraFileInfo* info, int *data_number) { unsigned char cmd[6], buf[INFO_BUFFER]; Camera *camera = data; int ret; /* Read file information */ cmd[0] = ESC; cmd[1] = GETIMAGEINFO; cmd[2] = 0x30 + ((image_no/1000)%10); cmd[3] = 0x30 + ((image_no/100 )%10); cmd[4] = 0x30 + ((image_no/10 )%10); cmd[5] = 0x30 + ( image_no %10); ret = gp_port_write (camera->port, (char*)cmd, sizeof(cmd)); if (ret<GP_OK) return ret; ret = gp_port_read (camera->port, (char*)buf, INFO_BUFFER); if (ret<GP_OK) return ret; /* Search the image data number into the memory */ if (data_number != NULL) *data_number = (buf[IMAGE_NUMBER] << 8) | (buf[IMAGE_NUMBER+1]); /* Get the file info here and write it into <info> */ /* There is no audio support with this camera */ info->audio.fields = GP_FILE_INFO_NONE; /* Preview informations */ info->preview.fields = GP_FILE_INFO_TYPE | GP_FILE_INFO_SIZE | GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT; strcpy (info->preview.type, GP_MIME_JPEG); info->preview.size = ((buf[PREVIEW_SIZE_PTR] << 24) | (buf[PREVIEW_SIZE_PTR+1] << 16) | (buf[PREVIEW_SIZE_PTR+2] << 8) | buf[PREVIEW_SIZE_PTR+3]); info->preview.width = PREVIEW_WIDTH; info->preview.height = PREVIEW_HEIGHT; /* Image information */ info->file.fields = GP_FILE_INFO_TYPE | GP_FILE_INFO_SIZE | GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT | GP_FILE_INFO_PERMISSIONS; strcpy (info->file.type, GP_MIME_JPEG); info->file.size = ((buf[IMAGE_SIZE_PTR] << 24) | (buf[IMAGE_SIZE_PTR+1] << 16) | (buf[IMAGE_SIZE_PTR+2] << 8) | buf[IMAGE_SIZE_PTR+3]); info->file.width = IMAGE_WIDTH; info->file.height = IMAGE_HEIGHT; if (buf[IMAGE_PROTECTION_FLAG] == IMAGE_PROTECTED) info->file.permissions = GP_FILE_PERM_READ; else info->file.permissions = GP_FILE_PERM_ALL; return (GP_OK); }
static int aox_read_data (GPPort *port, char *data, int size) { int MAX_BULK = 0x1000; while(size > 0) { int len = (size>MAX_BULK)?MAX_BULK:size; gp_port_read (port, data, len); /* 0x84 = EP IN NEEDED HERE.*/ data += len; size -= len; } return 1; }
static int ultrapocket_skip(GPPort *port, int npackets) { int old_timeout = 200; unsigned char retbuf[0x1000]; gp_port_get_timeout(port, &old_timeout); gp_port_set_timeout(port, 100); for (; (npackets > 0) && gp_port_read(port, (char *)retbuf, 0x1000); npackets--); gp_port_set_timeout(port, old_timeout); return GP_OK; }
int digi_delete_all (GPPort *port, CameraPrivateLibrary *priv) { int size; int num_pics; unsigned char get_size[0x50]; unsigned char *junk=NULL; num_pics = priv->nb_entries; GP_DEBUG("number of entries is %i\n", num_pics); digi_reset (port); digi_reset (port); if(!num_pics) { GP_DEBUG("Camera is already empty!\n"); return GP_OK; } SQWRITE (port, 0x0c, 0x1440, 0x110f, NULL, 0); if ((gp_port_read(port, (char *)get_size, 0x50)!=0x50)) { GP_DEBUG("Error in reading data\n"); return GP_ERROR; } GP_DEBUG("get_size[0x40] = 0x%x\n", get_size[0x40]); size = get_size[0x40]|(get_size[0x41]<<8)|(get_size[0x42]<<16)| (get_size[0x43]<<24); GP_DEBUG("size = 0x%x\n", size); if(size <= 0xff) { GP_DEBUG("No size to read. This will not work.\n"); digi_reset(port); return GP_OK; } junk = malloc(size); if(! junk) { GP_DEBUG("allocation of junk space failed\n"); return GP_ERROR_NO_MEMORY; } gp_port_read(port, (char *)junk, size); free(junk); digi_reset (port); return GP_OK; }
/* * receive Bytes from camera */ int mdc800_rs232_receive (GPPort *port,unsigned char* buffer, int b) { int ret; gp_port_set_timeout (port,MDC800_DEFAULT_TIMEOUT ); ret=gp_port_read(port,(char*)buffer,b); if (ret!=b) { printCError ("(mdc800_rs232_receive) can't read %i Bytes !\n",b); return GP_ERROR_IO; } return GP_OK; }
static int ez200_read_data (GPPort *port, char *data, int size) { int MAX_BULK = 0x1000; /* Read Data by blocks */ while(size > 0) { int len = (size>MAX_BULK)?MAX_BULK:size; gp_port_read (port, data, len); data += len; size -= len; } return 1; }
/* * l859_disconnect - reset camera, free buffers and close files */ static int l859_disconnect(Camera *camera) { GP_DEBUG ("Disconnecting the camera."); if (l859_sendcmd(camera, L859_CMD_RESET) != GP_OK) return GP_ERROR; if (gp_port_read(camera->port, camera->pl->buf, 1) == GP_ERROR) return GP_ERROR; GP_DEBUG ("Camera disconnected."); return GP_OK; }
static uint16_t ptp_usb_getpacket(PTPParams *params, PTPUSBBulkContainer *packet, unsigned long *rlen) { int tries = 0, result; Camera *camera = ((PTPData *)params->data)->camera; gp_log (GP_LOG_DEBUG, "ptp2/ptp_usb_getpacket", "getting next ptp packet"); /* read the header and potentially the first data */ if (params->response_packet_size > 0) { gp_log (GP_LOG_DEBUG, "ptp2/ptp_usb_getpacket", "queuing buffered response packet"); /* If there is a buffered packet, just use it. */ memcpy(packet, params->response_packet, params->response_packet_size); *rlen = params->response_packet_size; free(params->response_packet); params->response_packet = NULL; params->response_packet_size = 0; /* Here this signifies a "virtual read" */ return PTP_RC_OK; } retry: /* A packet should come in a single read always. */ result = gp_port_read (camera->port, (char*)packet, sizeof(*packet)); /* This might be a left over zero-write of the device at the end of the previous transmission */ if (result == 0) result = gp_port_read (camera->port, (char*)packet, sizeof(*packet)); if (result > 0) { *rlen = result; return PTP_RC_OK; } if (result == GP_ERROR_IO_READ) { gp_log (GP_LOG_DEBUG, "ptp2/usbread", "Clearing halt on IN EP and retrying once."); gp_port_usb_clear_halt (camera->port, GP_PORT_USB_ENDPOINT_IN); /* retrying only makes sense if we did not read anything yet */ if (tries++ < 1) goto retry; } return PTP_ERROR_IO; }
/* * Get the table of contents (directory) from the cam * * Verified: Yes */ static int enigma13_get_toc(Camera *camera, int *filecount, char** toc) { char* flash_toc=NULL; int toc_size = 0; char buf[10]; uint16_t response = 0; int ret=1; CHECK(enigma13_wait_for_ready(camera)); CHECK (gp_port_usb_msg_read (camera->port, 0x54, 0x0000, 0x0000, (char*)&response, 0x02)); LE16TOH (response); *filecount = response; /* Calc toc size */ toc_size = (response) * 0x20; if (toc_size % 0x200 != 0) toc_size = ((toc_size / 0x200) + 1) * 0x200; CHECK(enigma13_wait_for_ready(camera)); CHECK (gp_port_usb_msg_write (camera->port, 0x54, response, 0x0001, NULL, 0x0000)); /* Wait until cam is ready to send the T.O.C */ usleep(ENIGMA13_WAIT_TOC_DELAY_MS * 1000); CHECK (gp_port_usb_msg_read (camera->port, 0x21, 0x0000, 0x0000, buf, 0x01)); if (buf[0]!=0x41) return GP_ERROR; CHECK (gp_port_usb_msg_read (camera->port, 0x21, 0x0000, 0x0002, buf, 0x01)); if (buf[0]!=0x01) return GP_ERROR; flash_toc = (char*)malloc(toc_size); if (!flash_toc) return GP_ERROR_NO_MEMORY; ret=gp_port_read (camera->port, flash_toc, toc_size); *toc= flash_toc; gp_log(GP_LOG_DEBUG, "enigma13","Byte transferred :%d ", ret); return ret; }
static int dread(GPPort *port, caddr_t buf, int xsize) { int i; int ret = gp_port_read(port,buf,xsize); if (ret == -1) { perror("dread"); return -1; } fprintf(stderr,"dread[%d]:",ret); for (i=0;i<ret;i++) fprintf(stderr,"%02x,",buf[i]); fprintf(stderr,"\n"); return ret; }
/* * Check the connection and the camera */ static int k_ping (GPPort *port) { char cmd[2], buf[1]; int ret; cmd[0] = ESC; cmd[1] = PING; ret = gp_port_write (port, cmd, 2); if (ret<GP_OK) return ret; ret = gp_port_read (port, buf, 1); if (ret<GP_OK) return ret; if (buf[0] != ACK) return GP_ERROR; return GP_OK; }
static int digita_serial_read(CameraPrivateLibrary *dev, void *_buffer, int len) { char *buffer = _buffer; unsigned short s; int received = 0, size, eob; while (received < len) { if (poll_and_reply(dev->gpdev, &size, &eob, 0) < 0) return -1; if (gp_port_read(dev->gpdev, buffer + received, size) < 0) return -1; received += size; if (eob) break; } if (gp_port_read(dev->gpdev, (void *)&s, sizeof(s)) < 0) return -1; return received; }
static int mars_read_data (GPPort *port, char *data, int size) { int MAX_BULK = 0x2000; int len = 0; while(size > 0) { len = (size>MAX_BULK)?MAX_BULK:size; gp_port_read (port, data, len); data += len; size -= len; } return 1; }
static int SDSC_receive (GPPort *port, unsigned char *buf, int length) { char tmp[3]; int i, result = GP_OK; for (i = 0; i < SDSC_RETRIES; i++) { /* Read the header (3 bytes) and check for EOF */ CHECK_RESULT (gp_port_read (port, tmp, 1)); if (tmp[0] == 0x04) return (SDSC_ERROR_EOF); result = gp_port_read (port, tmp, 2); if (result < 0) { CHECK_RESULT (SDSC_send (port, SDSC_RETRANSMIT)); continue; } /* Read data */ result = gp_port_read (port, buf, length); if (result < 0) { CHECK_RESULT (SDSC_send (port, SDSC_RETRANSMIT)); continue; } /* Read footer (2 bytes) */ result = gp_port_read (port, tmp, 2); if (result < 0) { CHECK_RESULT (SDSC_send (port, SDSC_RETRANSMIT)); continue; } break; } return (result); }
/* * l859_retrcmd - Packet received from camera */ static int l859_retrcmd(Camera *camera) { int s; if ((s = gp_port_read(camera->port, camera->pl->buf, 116)) == GP_ERROR) return GP_ERROR; if (s != 116) return GP_ERROR; camera->pl->size = 116; GP_DEBUG ("Retrieved Data"); return GP_OK; }
/* * Delete one image * The image mustn't be protected */ static int delete_file_func (CameraFilesystem *fs, const char *folder, const char *filename, void *data, GPContext *context) { Camera *camera = data; CameraFileInfo file_info; unsigned char cmd[7], ack; int image_no; int ret; GP_DEBUG ("*** ENTER: delete_file_func ***"); image_no = gp_filesystem_number(fs, folder, filename, context); if (image_no < 0) return image_no; image_no++; ret = k_info_img (image_no, data, (CameraFileInfo *)&file_info, &image_no); if (ret < GP_OK) return ret; /* Now, check if the image isn't protected */ if (file_info.file.permissions == GP_FILE_PERM_READ) { gp_context_error(context, _("Image %s is delete protected."), filename); return (GP_ERROR); } /* Erase the image */ cmd[0] = ESC; cmd[1] = ERASEIMAGE_CMD1; cmd[2] = IMAGE_CMD2; cmd[3] = 0x30 + ((image_no/1000)%10); cmd[4] = 0x30 + ((image_no/100 )%10); cmd[5] = 0x30 + ((image_no/10 )%10); cmd[6] = 0x30 + ( image_no %10); ret = gp_port_write (camera->port, (char*)cmd, sizeof(cmd)); if (ret<GP_OK) return ret; ret = gp_port_read (camera->port, (char*)&ack, ACK_LEN); if (ret<GP_OK) return ret; if (ack != ACK) { gp_context_error(context, _("Can't delete image %s."),filename); return (GP_ERROR); } return (GP_OK); }
static int poll_and_wait(gp_port *dev, int length, int bob, int eob) { unsigned short s, poll, poll_reply; poll = POLL_POLL | POLL_CMD | (length & POLL_LENGTH_MASK) | (bob ? POLL_BOB : 0) | (eob ? POLL_EOB : 0); do { s = htobe16(poll); if (gp_port_write(dev, (void *)&s, sizeof(s)) < 0) return -1; if (gp_port_read(dev, (void *)&s, sizeof(s)) < 0) return -1; poll_reply = be16toh(s); } while (poll_reply & POLL_NAK); return 0; }
static int poll_and_reply(gp_port *dev, int *length, int *eob, int nak) { unsigned short s, poll; if (gp_port_read(dev, (void *)&s, sizeof(s)) < 0) return -1; poll = be16toh(s); if (length) *length = poll & POLL_LENGTH_MASK; if (eob) *eob = poll & POLL_EOB; s = htobe16(nak ? POLL_NAK : POLL_ACK); if (gp_port_write(dev, (void *)&s, sizeof(s)) < 0) return -1; return 0; }