Пример #1
0
Файл: main.c Проект: qstemper/42
static void		read_option(t_env *e, int ac, char **av)
{
	if (ac != 2)
		error_arg();
	if (open_file(e, av[1]) == 0)
		error_map();
}
Пример #2
0
/*  init_method2(): file method but check existing devices(s)  */
static int init_method2(int dev_no)
{
  FHANDLE dev_handle;           /* device handle */
  int gen_status;  /* generic error codes returned to the application */  
  int other_dev;   

  gen_status = NORMAL;          /* assume normal status */
  other_dev = dev_no;  
  
  if (pos_setup[dev_no].init_flag)
      gen_status = DEV_EXIST;

  if (gen_status == DEV_EXIST)  /* already initialized */
  {
    /* update the POS Device table */ 
    update_table(1, dev_no, pos_setup[other_dev].file_num, -1, -1, -1, -1);  
    gen_status = NORMAL;    
  }
  else  /* not yet initialized */
  {
    dev_handle = _fsOpen(pos_setup[dev_no].dev_type, OPEN_FLAGS );

    gen_status = error_map(_fsError());  /* get the generic error status */

    if (gen_status == NORMAL)
      update_table(1, dev_no, dev_handle, -1, -1, -1, -1);  /* update the POS Device table */        
  }

  return gen_status;  
}
Пример #3
0
/*  int close_method1(): file method  */
static int close_method1(int dev_no)
{
  int gen_status;  /* generic error codes returned to the application */

  _fsClose(pos_setup[dev_no].file_num);

  gen_status = error_map(_fsError());  /* get the generic error status */

  if (gen_status == NORMAL)
    update_table(0, dev_no, -1, -1, -1, -1, -1);  /* update the POS Device table */

  return gen_status;
}
Пример #4
0
/*  init_method1(): file method  */
static int init_method1(int dev_no)
{
  FHANDLE dev_handle;           /* device handle */
  int gen_status;               /* generic error codes returned to the application */  

  dev_handle = _fsOpen(pos_setup[dev_no].dev_type, OPEN_FLAGS );

  gen_status = error_map(_fsError());  /* get the generic error status */

  if (gen_status == NORMAL)
    update_table(1, dev_no, dev_handle, -1, -1, -1, -1);  /* update the POS Device table */    

  return gen_status;    
}
Пример #5
0
/*  close_method2(): file method but check existing devices(s)  */
static int close_method2(int dev_no)
{
  int gen_status;  /* generic error codes returned to the application */
  int other_dev;

  other_dev = 0;
  gen_status = NORMAL;  /* assume normal status */

   
  switch (dev_no)
  {
     case POS_KEYBOARD: 
     case POS_CARD_READ:
     case POS_CKEYLOCK: /* check existing devices */
                        if (chk_init_flag(POS_CARD_READ))  /* card reader */
                          ++other_dev;  

                        if (chk_init_flag(POS_CKEYLOCK))  /* keylock */
                          ++other_dev;

                        if (chk_init_flag(POS_KEYBOARD))  /* POS keyboard */
                          ++other_dev;

                        break;
                    
  }  

  if (other_dev > 1)  /* link to other devices */
    update_table(0, dev_no, -1, -1, -1, -1, -1);  /* update the POS Device table */ 
  else  
  {
    _fsClose(pos_setup[dev_no].file_num);

    gen_status = error_map(_fsError());  /* get the generic error status */

    if (gen_status == NORMAL)
      update_table(0, dev_no, -1, -1, -1, -1, -1);  /* update the POS Device table */
  }

  return gen_status;
}
Пример #6
0
/*  pos_device_chk: performs additional hardware checking or initialization  */
static int pos_device_chk(int dev_no)
{
  int gen_status;  /* generic error codes returned to the application */  
  unsigned char esc_cmd[12]; /* holds the escape sequence command */
  int port_status;

  gen_status = NORMAL;  /* assume normal */
  switch (dev_no)
  {
#if 1
    case POS_CASH_DISP:  /* cashier or operator display */
      /* clear the screen */
      esc_cmd[0] = ESC_CODE;
      esc_cmd[1] = 'C';
      
      /* cursor off and no blink */
      esc_cmd[2] = ESC_CODE;
      esc_cmd[3] = 'A';
      esc_cmd[4] = 0x01;

      /* set cursor to the leftmost column */
      esc_cmd[5] = ESC_CODE;
      esc_cmd[6] = 'D';
      esc_cmd[7] = 0x00;
      
      /* select overwrite mode 
      esc_cmd[8] = ESC_CODE;
      esc_cmd[9] = 'S';
      esc_cmd[10] = 0x02;      */

      _fsWrite(pos_setup[dev_no].file_num, esc_cmd, 8);
      
      gen_status = error_map(_fsError());

      if (gen_status == NORMAL)
      {
        /* select overwrite mode */
        esc_cmd[0] = ESC_CODE;
        esc_cmd[1] = 'S';
        esc_cmd[2] = 0x02;      

        _fsWrite(pos_setup[dev_no].file_num, esc_cmd, 3);
        gen_status = error_map(_fsError());      
      } 
      
      break;
      
    case POS_CUST_DISP1: /* 1 X 9 integrated customer display */
      /* initialize display */
      esc_cmd[0] = 0x00;
      
      /* clear the screen and set the cursor to the leftmost column */
      esc_cmd[1] = '\n';

      _fsWrite(pos_setup[dev_no].file_num, esc_cmd, 2);
      gen_status = error_map(_fsError());
      break;
#endif
    case POS_CUST_DISP2: /* 2 X 20 customer display (additional) */
      port_status = pfl_com_init(pos_setup[dev_no].port, pos_setup[dev_no].setup,
                                (unsigned char) pos_setup[dev_no].protocol);
             
      if ((port_status & 0x0030) != 0x0030)  /* data set ready & clear to send */
        gen_status = DEV_NOT_READY;

      if (gen_status == NORMAL)
      {
        /* initialize display */ 
        esc_cmd[0] = ESC_CODE;
        esc_cmd[1] = '@';
        
        /* set character set to U.S.A. */
        esc_cmd[2] = ESC_CODE;
        esc_cmd[3] = 'f';
        esc_cmd[4] = 'A';

        /* select font: comply with ASCII code */
        esc_cmd[5] = ESC_CODE;
        esc_cmd[6] = 'c';
        esc_cmd[7] = 'A';

        if (pfl_com_nsend(esc_cmd, 8))
          gen_status = DEV_NOT_READY;

        delay(50);  /* put some delay */
        
        /* specify overwrite mode */
        esc_cmd[0] = ESC_CODE;
        esc_cmd[1] = 0x11;

        /* move the cursor to the leftmost position on the upper line 
        esc_cmd[2] = ESC_CODE;
        esc_cmd[3] = '[';
        esc_cmd[4] = 'H'; */

        if (pfl_com_nsend(esc_cmd, 2))
          gen_status = DEV_NOT_READY;

        delay(500);  /* put some delay */

        /* clear display screen */
        esc_cmd[0] = 0x0c;        

        if (pfl_com_send(esc_cmd[0]))
          gen_status = DEV_NOT_READY;          

        delay(500);
      }
      break;

    case OPT_SLIP_PRNTR: /* optional slip printer */
      port_status = pfl_com_init(pos_setup[dev_no].port, pos_setup[dev_no].setup,
                                (unsigned char) pos_setup[dev_no].protocol);
      /* check printer status: see corresponding printer manual for verifying the printer status */
      esc_cmd[0] = ESC_CODE;
      esc_cmd[1] = 0x76;
      pfl_com_nsend(esc_cmd, 2);
      
      if (pfl_com_drecv() == -1)  /* cannot retrieve the status */
        gen_status = DEV_NOT_READY;
      
      break;

    case POS_SCAN:  /* scanner or optical reader */
      port_status = pfl_com_init(pos_setup[dev_no].port, pos_setup[dev_no].setup,
                                (unsigned char) pos_setup[dev_no].protocol);
      /*if (!(port_status & 0x0020))   */  /* data set ready ? */
      /*   gen_status = DEV_NOT_READY; */   /* scanner not ready */
       gen_status = NORMAL;
      break;

    case POS_CASH_DRAW: /* cash drawer */            
      port_status = pfl_com_init(pos_setup[dev_no].port, pos_setup[dev_no].setup,
                                (unsigned char) pos_setup[dev_no].protocol);
        
      if (!(port_status & 0x0010))  /* not clear to send */
          gen_status = DEV_NOT_READY;
          
      break;  
    case POS_PRINTER: /* POS RJS printer */
      /* set paper end signal to journal printer */

      esc_cmd[0] = ESC_CODE;
      esc_cmd[1] = 'c';
      esc_cmd[2] = '3';
      esc_cmd[3] = 1;        

      pfl_lpt_nsend(pos_setup[dev_no].lpt_port, esc_cmd, 4);          
      
      delay(50);  /* put some delay */
      
      port_status = pfl_lpt_sts(pos_setup[dev_no].lpt_port);
      
      /* timeout, I/O error, out of paper, busy, and not selected status */
      if ((port_status & 0x29) || !(port_status & 0x80) || !(port_status & 0x10))
        gen_status = DEV_NOT_READY;

      break;

    case POS_KEYBOARD:
      pfl_key_clear(); /* clear POS keyboard buffer */

      break;

    case POS_CKEYLOCK:
      if (!check_pfl_klck())  /* PFL_KLCK.COM not installed */
        gen_status = NO_DRIVER;
      
      break;
  }

  if (gen_status != NORMAL)  /* update the POS Device table */
  {
    if (pos_setup[dev_no].open_method == 1)  /* device opened as a file */
      _fsClose(pos_setup[dev_no].file_num);            
    else if (pos_setup[dev_no].open_method == 2)  /* file method but linked to
                                                     other devices */
      close_link_dev(dev_no);                                                     
      
    update_table(0, dev_no, -1, -1, -1, -1, -1);  /* update the POS Device table */          
  }
    
  return gen_status;
}