Пример #1
0
SKYETEK_STATUS 
SkyeTekReader_GetSystemParameter(
    LPSKYETEK_READER             lpReader, 
    SKYETEK_SYSTEM_PARAMETER     parameter,
    LPSKYETEK_DATA               *lpData
    )
{
  LPPROTOCOLIMPL lppi;
  SKYETEK_ADDRESS addr;
  SKYETEK_STATUS st;
  if( lpReader == NULL || lpReader->lpProtocol == NULL || 
      lpReader->lpDevice == NULL || lpData == NULL )
    return SKYETEK_INVALID_PARAMETER;
  
  lppi = (LPPROTOCOLIMPL)lpReader->lpProtocol->internal;
  if( (st = STR_GetSystemAddrForParm(parameter,&addr,lpReader->lpProtocol->version)) != SKYETEK_SUCCESS )
    return st;
  if( parameter == SYS_OPTIMAL_POWER_C1G1 || parameter == SYS_OPTIMAL_POWER_C1G2 || 
    parameter == SYS_OPTIMAL_POWER_180006B || parameter == SYS_RSSI_VALUES )
    return lppi->GetSystemParameter(lpReader,&addr,lpData,10000);
  else
    return lppi->GetSystemParameter(lpReader,&addr,lpData,SKYETEK_TIMEOUT);
}
LPSKYETEK_READER 
GetReader(
  LPSKYETEK_DEVICE    lpDevice, 
  LPPROTOCOLIMPL      lpPI,
  unsigned int        ver
  )
{
  LPSKYETEK_READER lpReader = NULL;
  SKYETEK_READER tmpReader;
  SKYETEK_STATUS status;
  SKYETEK_ADDRESS addr;
  LPSKYETEK_DATA lpData = NULL;
  TCHAR *str = NULL;
  int i = 0;
  unsigned int ix = 0;

  if( lpDevice == NULL )
    return NULL;

  /* Fill temp reader for system calls */
  if( ver == 2 )
  {
    tmpReader.id = SkyeTek_AllocateID(1);
    if( tmpReader.id != NULL )
      tmpReader.id->id[0] = 0xFF;
  }
  else
  {
    tmpReader.id = SkyeTek_AllocateID(4);
    if( tmpReader.id != NULL )
      for( i = 0; i < 4; i++ )
        tmpReader.id->id[i] = 0xFF;
  }
  tmpReader.sendRID = 1;
  tmpReader.lpDevice = lpDevice;
  tmpReader.internal = &SkyetekReaderImpl;

  status = STR_GetSystemAddrForParm(SYS_FIRMWARE,&addr,ver);
  if( status != SKYETEK_SUCCESS )
    goto failure;
  status = lpPI->GetSystemParameter(&tmpReader, &addr, &lpData,100);
  if( status != SKYETEK_SUCCESS || lpData == NULL )
    goto failure;

  lpReader = (LPSKYETEK_READER)malloc(sizeof(SKYETEK_READER));
  if( lpReader == NULL )
  {
    SkyeTek_FreeData(lpData);
    goto failure;
  }
  memset(lpReader, 0, sizeof(SKYETEK_READER));

  str = SkyeTek_GetStringFromData(lpData);
  if( str != NULL )
  {
    _tcscpy(lpReader->firmware,str);
    SkyeTek_FreeString(str);
  }

  if( ver == 2 && lpData != NULL && lpData->data != NULL && lpData->size > 0 )
  {
    switch(lpData->data[0])
    {
      case 0x00:
      case 0x01:
      case 0x50:
      case 0x60:
      case 0xA0:
      case 0xC0:
      case 0xD0:
        _tcscpy(lpReader->model, _T("M1")); 
        break;
      case 0xE0:
        _tcscpy(lpReader->model, _T("M8")); 
        break;
		  case 0x20:
        _tcscpy(lpReader->model, _T("M2")); 
        break;
		  default:
        _tcscpy(lpReader->model, _T("??")); 
    }
  }
  SkyeTek_FreeData(lpData);

  if( ver == 3 )
  {
    SKYETEK_Sleep(100);
    status = STR_GetSystemAddrForParm(SYS_PRODUCT,&addr,ver);
    if( status != SKYETEK_SUCCESS )
      goto failure;
    status = lpPI->GetSystemParameter(&tmpReader, &addr, &lpData,100);
    if( status == SKYETEK_SUCCESS && lpData->data != NULL && lpData->size >= 2 )
    {
      switch(lpData->data[1])
      {
      case 0x02:
        _tcscpy(lpReader->model, _T("M2"));
        break;
      case 0x04:
        _tcscpy(lpReader->model, _T("M4"));
        break;
      case 0x2A:
        _tcscpy(lpReader->model, _T("M2A"));
        break;
      case 0x07:
        _tcscpy(lpReader->model, _T("M7"));
        break;
      case 0x09:
        _tcscpy(lpReader->model, _T("M9"));
        break;
	  case 0x0A:
		_tcscpy(lpReader->model, _T("M10"));
		break;
      default:
        _tcscpy(lpReader->model, _T("??"));
        break;
      }
      SkyeTek_FreeData(lpData);
    }
    else
      _tcscpy(lpReader->model, _T("??"));
  }

  SKYETEK_Sleep(100);
  status = STR_GetSystemAddrForParm(SYS_READER_NAME,&addr,ver);
  if( status != SKYETEK_SUCCESS )
    goto failure;
  status = lpPI->GetSystemParameter(&tmpReader, &addr, &lpData,100);
  if( status != SKYETEK_SUCCESS )
  {
    free(lpReader);
    goto failure;
  }
  if( lpData != NULL && lpData->size > 0 && lpData->data != NULL )
  {
    /* make sure we have a null pointer */
    i = 0;
    for( ix = 0; ix < lpData->size; ix++ )
    {
      if( lpData->data[ix] == '\0' )
      {
        i = 1;
        break;
      }
    }
    if( i == 1 )
	{
		//Reader name is stored in standard ascii
		for(ix = 0; ix < lpData->size; ix++)
			lpReader->readerName[ix] = (TCHAR)lpData->data[ix];
	}
  }
  SkyeTek_FreeData(lpData);

  SKYETEK_Sleep(100);
  status = STR_GetSystemAddrForParm(SYS_SERIALNUMBER,&addr,ver);
  if( status != SKYETEK_SUCCESS )
    goto failure;
  status = lpPI->GetSystemParameter(&tmpReader, &addr, &lpData,100);
  if( status != SKYETEK_SUCCESS )
  {
    free(lpReader);
    goto failure;
  }
  str = SkyeTek_GetStringFromData(lpData);
  if( str != NULL )
  {
    _tcscpy(lpReader->serialNumber, str);
    SkyeTek_FreeString(str);
  }
  SkyeTek_FreeData(lpData);

  SKYETEK_Sleep(100);
  status = STR_GetSystemAddrForParm(SYS_RID,&addr,ver);
  if( status != SKYETEK_SUCCESS )
    goto failure;
  status = lpPI->GetSystemParameter(&tmpReader, &addr, &lpData,100);
  if( status != SKYETEK_SUCCESS )
	{
	  free(lpReader);
	  goto failure;
	}
	lpReader->id = (LPSKYETEK_ID)lpData;
  lpReader->internal = &SkyetekReaderImpl;
  lpReader->lpDevice = lpDevice;
  lpReader->lpProtocol = (LPSKYETEK_PROTOCOL)malloc(sizeof(SKYETEK_PROTOCOL));
  if( lpReader->lpProtocol == NULL )
  {
    free(lpReader);
    goto failure;
  }
  lpReader->lpProtocol->version = ver;
  lpReader->lpProtocol->internal = lpPI;
  _tcscpy(lpReader->manufacturer, _T("SkyeTek"));
  str = SkyeTek_GetStringFromID(lpReader->id);
  if( str == NULL )
  {
    free(lpReader);
    goto failure;
  }
  _tcscpy(lpReader->rid,str);

  /* TODO: See if Reader Name can be used */
  _stprintf(lpReader->friendly, _T("%s-%s-%s"), lpReader->manufacturer, lpReader->model, str);
  SkyeTek_FreeString(str);

  return lpReader;
failure:
  SkyeTek_FreeID(tmpReader.id);
  return NULL;
}