⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yepplib.c

📁 linux下驱动程序设计的文章
💻 C
📖 第 1 页 / 共 2 页
字号:
      yepp_phase4 ();      free (buf);      return 0;    }  i = buf[0];  yepp_phase3 ();  yepp_phase4 ();  do_progress (fname, writ, size, i, blocks, &start);  printf ("\n");  free (buf);  fprintf (stderr, "%s: file is now in index %d\n", fname, i);  return i;}//Op code 1intyepp_put (int where, int type, char *name, FILE * file){  return yepp_file_worker ("yepp_put", 0x1, where, type, name, file);}#ifdef HIFIintyepp_hifi_put (int where, int type, char *name, CFH h){  return yepp_hifi_worker ("yepp_hifi_put", 0x1, where, type, name, h);}#endif//Op code 2intyepp_get (int index, FILE * f){  unsigned char *buf, *ptr;  int size;  int blocks;  int i;  int red, togo;  struct timeval start;  if (!f)    {      MOAN ("yepp_get: passed null file pointer\n");      return 0;    }  buf = malloc (YEPP_RBBS);  if (!buf)    {      MOAN ("malloc failed\n");      return 0;    }  if (!yepp_phase1 ())    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (0x2))    {      yepp_phase4 ();      free (buf);      return 0;    }  if (!ieee1284_writebyte (index))    {      yepp_phase4 ();      free (buf);      return 0;    }  yepp_phase2 ();  if (yepp_read (buf, 4) != 4)    {      yepp_phase3 ();      yepp_phase4 ();      free (buf);      return 0;    }  gettimeofday (&start, NULL);  togo = size = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);  red = 0;  fprintf (stderr, "yepp_get: %d is %d bytes long\n", index, size);  bzero (buf, YEPP_RBBS);  i = yepp_read (buf, YEPP_RSBS);  if (i != YEPP_RSBS)    {      yepp_phase3 ();      yepp_phase4 ();      free (buf);      return 0;    }  fwrite (buf, 1, (togo > i) ? i : togo, f);  togo -= i;  red += i;  while (togo > 0)    {      yepp_phase3 ();      do_progress ("yepp_get", red, size, 0, 0, &start);      if (!ieee1284_writebyte (0x0))        {          yepp_phase4 ();          free (buf);          return 0;        }      yepp_phase2 ();      if (!ieee1284_readbyte (buf))        {          yepp_phase4 ();          free (buf);          return 0;        }      i = yepp_read (buf, YEPP_RBBS);      if (i != YEPP_RBBS)        {          yepp_phase3 ();          yepp_phase4 ();          free (buf);          return 0;        }      fwrite (buf, 1, (togo > i) ? i : togo, f);      red += i;      togo -= i;    }  printf ("\n");  yepp_phase3 ();  yepp_phase4 ();  free (buf);  fprintf (stderr, "yepp_put: done\n");  return size;}//Op code 3struct yepp_dirent *yepp_dir (void){  unsigned char buf[522];  struct yepp_dirent *ret = NULL, *next;  int i;  int merror = 0;  if (!yepp_phase1 ())    {      yepp_phase4 ();      return NULL;    }  if (!ieee1284_writebyte (0x3))    {      yepp_phase4 ();      return NULL;    }  if (!yepp_phase2 ())    {      yepp_phase3 ();      yepp_phase4 ();      return NULL;    }  while (1)    {      if (yepp_read (buf, 522) != 522)        {          yepp_dir_free (ret);          yepp_phase3 ();          yepp_phase4 ();          return NULL;        }      for (i = 0; i < 522; ++i)        {          if (buf[i])            break;        }      if (i == 522)        {          ieee1284_readbyte (buf); //0xff on end          yepp_phase3 ();          yepp_phase4 ();          if (merror)            {              yepp_dir_free (ret);              MOAN ("yepp_dir: malloc failed\n");              return NULL;            }          return ret;        }      next = (struct yepp_dirent *) malloc (sizeof (struct yepp_dirent));      if (next)        {          next->user = 0;          next->index = buf[0];          next->type = buf[1];          next->size =            buf[2] | (buf[3] << 8) | (buf[4] << 16) | (buf[5] << 24);          bcopy (buf + 6, next->name, 515);          bcopy (buf + 6, next->name, 515);          next->attr = buf[521];          next->next = ret;          ret = next;        }      else        {          merror++;        }    }}//Op code 4struct yepp_status *yepp_status (void){  unsigned char buf[8];  struct yepp_status *ret;  int i;  if (!yepp_phase1 ())    {      yepp_phase4 ();      return NULL;    }  if (!ieee1284_writebyte (0x4))    {      yepp_phase4 ();      return NULL;    }  if (!yepp_phase2 ())    return 0;  if (yepp_read (buf, 8) != 8)    {      yepp_phase3 ();      yepp_phase4 ();      return NULL;    }  yepp_phase3 ();  yepp_phase4 ();  ret = (struct yepp_status *) malloc (sizeof (struct yepp_status));  if (!ret)    {      MOAN ("yepp_status: malloc failed\n");      return NULL;    }  ret->main.size = ((buf[1] << 8) | buf[0]) * 16;  ret->main.free = ((buf[3] << 8) | buf[2]) * 16;  ret->card.size = ((buf[5] << 8) | buf[4]) * 16;  ret->card.free = ((buf[7] << 8) | buf[6]) * 16;  return ret;}//Op code 5intyepp_erase (int f){  unsigned char c;  int ret;  if (!yepp_phase1 ())    {      yepp_phase4 ();      return 0;    }  if (!ieee1284_writebyte (0x5))    {      yepp_phase4 ();      return 0;    }  if (!ieee1284_writebyte (f))    {      yepp_phase4 ();      return 0;    }  if (!yepp_phase2 ())    {      yepp_phase4 ();      return 0;    }  ret = ieee1284_readbyte (&c);  yepp_phase3 ();  yepp_phase4 ();  if (!ret)    return 0;  fprintf (stderr, "yepp_erase: status %d\n", c);  return (c == 0);}//Op code 6intyepp_format (int where){  unsigned char c;  int ret;  if (!yepp_phase1 ())    {      yepp_phase4 ();      return 0;    }  if (!ieee1284_writebyte (0x6))    {      yepp_phase4 ();      return 0;    }  if (!ieee1284_writebyte (where))    {      yepp_phase4 ();      return 0;    }  if (!yepp_phase2 ())    {      yepp_phase4 ();      return 0;    }  ret = ieee1284_readbyte (&c);  yepp_phase3 ();  yepp_phase4 ();  if (!ret)    return 0;  fprintf (stderr, "yepp_format: status %d\n", c);  return (c == 0xff);}//Op code 7intyepp_get_config (char *p1, unsigned char *order){  unsigned char gunk[] = { 0x3a, 0x68, 0xa0, 0x00, 0x00, 0x01, 0x03, 0x09 };  unsigned char buf[256];  char *ret;  if (!yepp_phase1 ())    {      yepp_phase4 ();      return 0;    }  if (!ieee1284_writebyte (0x7))    {      yepp_phase4 ();      return 0;    }  if (!yepp_phase2 ())    {      yepp_phase4 ();      return 0;    }  if (yepp_read (buf, 8) != 8)    {      yepp_phase3 ();      yepp_phase4 ();      return 0;    }  if (bcmp (buf, gunk, sizeof (gunk)))    fprintf (stderr,             "yepp_getconfig: gunk is different: %02x %02x %02x %02x %02x %02x %02x %02x\n",             buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);  if (p1)    bcopy (buf, p1, 8);  if (yepp_read (buf, 252) != 252)    {      yepp_phase3 ();      yepp_phase4 ();      return 0;    }  yepp_phase3 ();  yepp_phase4 ();  if (order)    {      bcopy (buf, order, 252);    }  return 1;}//Op code 10intyepp_ping (void){  unsigned char c;  int ret;  if (!yepp_phase1 ())    {      yepp_phase4 ();      return 0;    }  if (!ieee1284_writebyte (0xa))    {      yepp_phase4 ();      return 0;    }  if (!yepp_phase2 ())    {      yepp_phase4 ();      return 0;    }  ret = ieee1284_readbyte (&c);  yepp_phase3 ();  yepp_phase4 ();  if ((!ret) || (c != 1))    {      MOAN ("yepp_ping: failed\n");      return 0;    }  fprintf (stderr, "yepp_ping: ok\n");  return 1;}//Op code 11intyepp_put_config (int where, int type, char *name, char *buf, int len){  return yepp_memory_worker ("yepp_put_config", 0xb, where, type, name, buf,                             len);}//Op code 12intyepp_put_encode (int where, int type, char *name, FILE * file){  return yepp_file_worker ("yepp_put_encode", 0xc, where, type, name, file);}//Op code 13intyepp_put_decode (int where, int type, char *name, FILE * file){  return yepp_file_worker ("yepp_put_decode", 0xd, where, type, name, file);}//Op code 14intyepp_put_serial (int where, int type, char *name, FILE * file){  return yepp_file_worker ("yepp_put_serial", 0xe, where, type, name, file);}char *yepp_getorder (){  unsigned char buf[252], *ret;  if (!yepp_get_config (NULL, buf))    return NULL;  ret = (unsigned char *) malloc (YEPP_ORDER_LEN);  if (!ret)    return NULL;  bzero (ret, YEPP_ORDER_LEN);  bcopy (buf, ret, 250);  return ret;}char *yepp_getnamebyindex (int index){  struct yepp_dirent *yd, *ptr;  if (!yepp_ping ())    return NULL;  ptr = yd = yepp_dir ();  if (!yd)    return NULL;  while (ptr)    {      if (ptr->index == index)        {          char *ret = strdup (ptr->name);          yepp_dir_free (yd);          return (ret);        }      ptr = ptr->next;    }  yepp_dir_free (yd);  return NULL;}intyepp_putorder (unsigned char *order){  unsigned char buf[260];  unsigned char *name, *ptr;  int i = 0, j;  if (!order)    {      fprintf (stderr, "yepp_putorder: passed null order\n");      return 0;    }  j = YEPP_ORDER_LEN;  ptr = order;  while (j--)    {      if (!*ptr)        break;      if (*ptr > i)        i = *ptr;      ptr++;    }  name = yepp_getnamebyindex (YEPP_CONFIG_INDEX);  if (name)    {      if (strcmp (name, "config.dat"))        {          fprintf (stderr, "yepp_putorder: index %d is not config.dat\n",                   YEPP_CONFIG_INDEX);          return 0;        }      free (name);      yepp_erase (YEPP_CONFIG_INDEX);    }  bzero (buf, sizeof (buf));  bcopy (order, buf,         (sizeof (buf) > YEPP_ORDER_LEN) ? YEPP_ORDER_LEN : sizeof (buf));  buf[250] = i;  buf[251] = i;  buf[252] = 0x01;  buf[253] = 0x00;  buf[254] = 0xff;  buf[255] = 0xff;  buf[256] = 0x0;  buf[257] = 0x0;  buf[258] = 0x0;  buf[259] = 0x0;  if (!yepp_put_config (YEPP_WHERE_BASE, YEPP_TYPE_DATA, "config.dat",                        buf, sizeof (buf)))    {      fprintf (stderr, "yepp_putorder: put_config failed\n");      return 0;    }  return 1;}intyepp_init (int port){  return ieee1284_init (port);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -