int read_multi_t(unsigned char device_var,unsigned short *put_data_into_here,unsigned short start_address,int length,int slot)
{
	int retVal = -100;
	int executeMBFunc = 0;
	static int readCount = 0;

	if (MbPollOpen == 1)
	{
		executeMBFunc = 1;
	}
	else
	{
		executeMBFunc = 0;
	}

	if (executeMBFunc == 1)
	{
		if ((trafficSlotNo == slot) && (trafficSlotNo != -1))
		{
			retVal =  read_multi_log(device_var, put_data_into_here, start_address, length, &sendData[0], &recvData[0], &sendDataLen, &recvDataLen);
			insertDataString = 1;
		}
		else
		{
			retVal =  read_multi(device_var, put_data_into_here, start_address, length);
		}

		if (!(retVal < 0))
		{
			LoadReadMultiData(device_var, put_data_into_here, start_address, length);
		}
		mbpollTotalCount[slot]++;
		if (retVal < 0)
		{
			mbpollErrCount[slot]++;
		}
		/*CString temp;
		readCount++;
		temp.Format(_T("addr = %d count = %d ret = %d"), start_address, readCount, retVal); 
		MessageBox(NULL, temp, L"read_multi", MB_OK);*/
	}
	return retVal;
}
示例#2
0
static void
tfm_get_n (FILEPTR tfm_fp, unsigned nwords, unsigned char **outbuf)
{
  unsigned n = nwords * 4;
  void *buf = (void *) malloc (n);

  if (buf == NULL) {BCLOSE(tfm_fp); Fatal("(tfm): out of memory error!\n");}
  read_multi (buf, 1, n, tfm_fp);
  if (FEOF(tfm_fp)) {
    BCLOSE(tfm_fp); Fatal("dvilj(tfm): Could not read %u bytes from TFM file.\n", n);
    exit (1);
  }

  /* If OUTBUF is null, free what we just read, else return it. */
  if (outbuf) {
    *outbuf = buf;
  } else {
    free (buf);
  }
}
示例#3
0
文件: read_db.c 项目: rc0/cstum
/*}}}*/
void read_db(const char *dbname, struct node *top, struct prune_data *prunings) /*{{{*/
{
  FILE *in;
  char buffer[256];
  int lineno;
  struct data *cursor = NULL;
  int count_pos;
  int count_meas;

  if (dbname[0] == '+') {
    read_multi(dbname+1, top, prunings);
    return;
  }

  /* ordinary case, read a single file */

  in = fopen(dbname, "r");
  if (!in) {
    fprintf(stderr, "Could not open %s\n", dbname);
    exit(2);
  }

  lineno = 0;
  count_pos = 0;
  count_meas = 0;
  while (fgets(buffer, sizeof(buffer), in)) {
    ++lineno;
    if (buffer[0] == ':') {
      int xi, yi;
      if (sscanf(buffer+1, "%d %d", &xi, &yi) != 2) {
        fprintf(stderr, "Line %d corrupt\n", lineno);
        exit(2);
      }
      cursor = lookup_spatial(top, xi, yi);
      count_pos++;
    } else if (!is_blank(buffer)) {
      int n, gen, lac, cid, timeframe;
      char *p;
      int i;
      int total;
      int asus[32];

      if (!cursor) {
        fprintf(stderr, "Data line with no earlier location, bailing at line %d\n", lineno);
        exit (2);
      }
      if (sscanf(buffer, "%d%d%d%d%n", &gen, &timeframe, &lac, &cid, &n) != 4) {
        fprintf(stderr, "Parse error at line %d\n", lineno);
        exit(2);
      }
      if ((gen < 2) || (gen > 3)) {
        fprintf(stderr, "gen (%d) can only be 2 or 3 at line %d\n", gen, lineno);
        exit(2);
      }
      p = buffer + n;
      while (isspace(*p)) p++;
      memset(asus, 0, sizeof(asus));
      i = 0;
      total = 0;
#define FREEZE do { asus[i++] = total; count_meas += total; total = 0; } while (0)
#define FREEZE2 do { if (total > 0) { asus[i++] = total; count_meas += total; } total = 0; } while (0)
      while (*p) {
        switch (*p) {
          case 'a': FREEZE2; i +=  0; break;
          case 'b': FREEZE2; i +=  1; break;
          case 'c': FREEZE2; i +=  2; break;
          case 'd': FREEZE2; i +=  3; break;
          case 'e': FREEZE2; i +=  4; break;
          case 'f': FREEZE2; i +=  5; break;
          case 'g': FREEZE2; i +=  6; break;
          case 'h': FREEZE2; i +=  7; break;
          case 'i': FREEZE2; i +=  8; break;
          case 'j': FREEZE2; i +=  9; break;
          case 'k': FREEZE2; i += 10; break;
          case 'l': FREEZE2; i += 11; break;
          case 'm': FREEZE2; i += 12; break;
          case 'n': FREEZE2; i += 13; break;
          case 'o': FREEZE2; i += 14; break;
          case 'p': FREEZE2; i += 15; break;
          case 'q': FREEZE2; i += 16; break;
          case 'r': FREEZE2; i += 17; break;
          case 's': FREEZE2; i += 18; break;
          case 't': FREEZE2; i += 19; break;
          case 'u': FREEZE2; i += 20; break;
          case 'v': FREEZE2; i += 21; break;
          case 'w': FREEZE2; i += 22; break;
          case 'x': FREEZE2; i += 23; break;
          case 'y': FREEZE2; i += 24; break;
          case 'z': FREEZE2; i += 25; break;
          case 'A': FREEZE2; i += 26; break;
          case 'B': FREEZE2; i += 27; break;
          case 'C': FREEZE2; i += 28; break;
          case 'D': FREEZE2; i += 29; break;
          case 'E': FREEZE2; i += 30; break;
          case 'F': FREEZE2; i += 31; break;

          case ',':
          case '\n':
            FREEZE;
            break;
          case '0':
          case '1':
          case '2':
          case '3':
          case '4':
          case '5':
          case '6':
          case '7':
          case '8':
          case '9':
            total = (10*total) + (*p - '0');
            break;
          default:
            fprintf(stderr, "Parse error at line %d, char code is 0x%02x\n", lineno, (int) *p);
        }
        p++;
      }
      if (!prunings || !prune_this(prunings, lac, cid, timeframe)) {
        insert_asus(cursor, gen, lac, cid, timeframe, asus);
      }
    }

  }

  fclose(in);
  fprintf(stderr, "Read in data for %d positions, %d measurements\n",
      count_pos, count_meas);
}