Ejemplo n.º 1
0
static int emwin_sync_wx14_raw(int fd){
  /*
   * The strategy here is the same as in the function
   *
   * emwin_sync_serial()
   *
   * above
   */
  struct emwin_packet ep;
  int status = 0;
  int i = 0;

  wx14_init(&g.wx14msg);
  status = emwin_sync_device(fd);

  /*
   * Reuse "g.readtimeout_retry" here
   */
  while((i <= g.readtimeout_retry) && (status == 0)){
    status = get_emwin_packet_wx14_raw(fd, &ep);
    if(status < 2)
      break;
    else
      status = emwin_sync_device(fd);
    
    ++i;
  }

  return(status);
}
Ejemplo n.º 2
0
static int process_packets(struct emwin_server *emserver){

  int status;
  int skip = 0;
  struct emwin_packet ep;
  int server_fd = emserver->fd;

  if(server_type_wx14_msg_device(emserver))
    status = get_emwin_packet_wx14_msg(server_fd, &ep);
  else if(server_type_wx14_raw_device(emserver))
    status = get_emwin_packet_wx14_raw(server_fd, &ep);
  else if(server_type_serial_device(emserver))
    status = get_emwin_packet_serial(server_fd, &ep);
  else
    status = get_emwin_packet_bb(server_fd, &ep);

  update_emwin_server_stats(status);
  if(write_emwin_server_stats(g.emwinstatusfile) != 0)
    log_err2("Error writing status file", g.emwinstatusfile);

  if(server_type_wx14_msg_device(emserver)){
    if(status == -1)
      log_err2("Error reading packet from WX14 msg device:", emserver->ip);
    else if(status != 0)
      log_errx("Error [%d] reading packet from WX14 msg device:",
	       status, emserver->ip);
    else {
      if(wx14_signalstatus_write(g.wx14_signal_statusfile, &g.wx14msg) != 0)
	log_err2("Error writing wx14 file", g.wx14_signal_statusfile);

      if(wx14_signalstatus_log(g.wx14_signal_logfile, &g.wx14msg) != 0)
	log_err2("Error writing wx14 file", g.wx14_signal_logfile);
    }
  } else {
    /*
     * This applies to both the wx14 raw device and a serial device
     *
     *    server_type_wx14_raw_device(emserver)
     *    server_type_serial_device(emserver)
     */
    if(status == -1)
      log_err2("Error reading packet from", emserver->ip);
    else if(status == -2)
      log_errx("Timedout trying to get packet from %s.", emserver->ip);
    else if(status == -3)
      log_info("Connection closed by %s.", emserver->ip);
    else if(status == 1)
      log_errx("Short read from %s.", emserver->ip);
    else if(status == 2)
      log_errx("Error in header format or unrecognized packet type.");
    else if(status == 3)
      log_errx("Checksum error.");
    else if(status == 4)
      log_errx("Check file name error: %s", ep.header.filename);
    else if(status != 0)
      log_errx("Cannot process packet: unknown error from get_emwin_packet()");
  }

  if(status != 0)    
    return(status);

  /*
   * Sends the packet to the queues for retransmission to the clients.
   */
  if(g.f_server_enabled == 1)
    (void)server_send_client_queues(&ep);

  if(ep.bbtype == BB_PACKET_TYPE_SRVLIST){
    status = save_server_list(&ep);
    if(status != 0)
      log_err("Error saving the server list.");
    else
      log_info("Received the server list.");

    return(0);
  }

  /*
   * Handle and save the data packet.
   */
  if(ep.header.blockno == 1){
    /*
     * Only the first block needs to be checked because, if the file
     * is rejected, it is not inserted in the queue and subsequent blocks
     * will be discarded.
     * "filename" is the product name and the extension; e.g.,
     * cfwsjupr.txt
     */
    skip = exec_filter(ep.header.filename);
    if(skip == 1){
      log_verbose(1, "Prefilter is rejecting %s.", ep.header.filename);
      return(0);
    }
  }

  log_verbose(1, "Received: %s (%d of %d)", 
	      ep.header.filename, ep.header.blockno, ep.header.numblocks);

  status = save_emwin_packet(&ep);

  if(status == -1)
    log_err2("Error saving", ep.header.filename);
  else
    log_verbose(1, "Saved: %s (%d of %d)", 
		ep.header.filename, ep.header.blockno, ep.header.numblocks);
  
  if(status == 0)
    ++g.packet_count;

  return(status);
}