본문 바로가기
코스웨어/11년 내장형하드웨어

[내장형]윤수영-2011.10.31 일일보고서

by 알 수 없는 사용자 2011. 10. 31.
728x90
반응형

PROTOCOL FOR READER CONTROL
 
● checksum
  1) iRet(결과값) =  read가 6byte가 와야 일치(즉, 속도가 맞아야 응답이 된다)
  2) CRC수행(4) - 수신값과 확인
  3) 명령에 따라 분류처리, 52이면 6byte return(4+2(CRC))

1. Baud Rate Detection[0x52]
 - 리더의 비동기 인터페이스의 실제 전송속도를 감지하는데 사용



#include <stdio.h>

#define CRC_POLYNOM    0x8408
#define CRC_PRESET     0xFFFF

unsigned short CRC16(void *p, unsigned int cnt);

int main()
{
  unsigned char ucCrc[6= {0x060x000x520x00,};//checksum을 구하기 위해서 앞에 4바이트 초기값설정
  unsigned int i;

  printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));  //CRC16의 인자로 ucCrc의 주소와 4을 넘겨줌
  *((unsigned short *)(ucCrc+4)) = CRC16(ucCrc, sizeof(ucCrc)-2);
  //0x06 ucCrc, 0x00 ucCrc+1, 0x52 ucCrc+2, 0x00 ucCrc+3, ...+4에 함수호출    
  for(i=0sizeof(ucCrc)>i; ++i)
  {
    printf("%02X ", *((unsigned char*)ucCrc + i));
  }
  printf("\n");
  
  return 0;
}

unsigned short CRC16(void *p, unsigned int cnt)
{
  unsigned char *DATA = p;
  unsigned int crc = CRC_PRESET;
  unsigned int i;
  unsigned int j;

  for(i=0; i<cnt; i++)
  {
    crc ^= DATA[i];
    for(j=0; j<8; j++)
    {
      if(crc & 0x0001)
      {
        crc = (crc >> 1)^CRC_POLYNOM;
      }
      else
      {
        crc = (crc >> 1);
      }
    }
  }
  return crc;
}


[실행결과]



2. CPU Reset[0x63]

 - CPU를 재설정



#include <stdio.h>

#define CRC_POLYNOM    0x8408
#define CRC_PRESET     0xFFFF

unsigned short CRC16(void *p, unsigned int cnt);

int main()
{
  unsigned char ucCrc[5= {0x050x000x63,};
  unsigned int i;

  printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));  
  *((unsigned short *)(ucCrc+3)) = CRC16(ucCrc, sizeof(ucCrc)-2);
  
  for(i=0sizeof(ucCrc)>i; ++i)
  {
    printf("%02X ", *((unsigned char*)ucCrc + i));
  }
  printf("\n");
  
  return 0;
}

unsigned short CRC16(void *p, unsigned int cnt)
{
  unsigned char *DATA = p;
  unsigned int crc = CRC_PRESET;
  unsigned int i;
  unsigned int j;

  for(i=0; i<cnt; i++)
  {
    crc ^= DATA[i];
    for(j=0; j<8; j++)
    {
      if(crc & 0x0001)
      {
        crc = (crc >> 1)^CRC_POLYNOM;
      }
      else
      {
        crc = (crc >> 1);
      }
    }
  }
  return crc;
}


[실행결과]



3. Get Software Version[0x65]
 - 소프트웨어 버전의 형식을 확인



SW-REV : 일반용 펌웨어 버전
D-REV : 개발용 펌웨어 버전
HW-TYPE : 하드웨어 타입
SW-TYPE : 소프트웨어 타입(pdf p.118 참조)
TR-TYPE : Transponders. RFID 태그 (해당 비트에 1이 들어가면 지원, 모두 1이 들어가면 모두 지원한다.)



#include <stdio.h>

#define CRC_POLYNOM    0x8408
#define CRC_PRESET     0xFFFF

unsigned short CRC16(void *p, unsigned int cnt);

int main()
{
  unsigned char ucCrc[5= {0x050x000x65,};
  unsigned int i;

  printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));
  *((unsigned short *)(ucCrc+3)) = CRC16(ucCrc, sizeof(ucCrc)-2);
      
  for(i=0sizeof(ucCrc)>i; ++i)
  {
    printf("%02X ", *((unsigned char*)ucCrc + i));
  }
  printf("\n");
  
  return 0;
}

unsigned short CRC16(void *p, unsigned int cnt)
{
  unsigned char *DATA = p;
  unsigned int crc = CRC_PRESET;
  unsigned int i;
  unsigned int j;

  for(i=0; i<cnt; i++)
  {
    crc ^= DATA[i];
    for(j=0; j<8; j++)
    {
      if(crc & 0x0001)
      {
        crc = (crc >> 1)^CRC_POLYNOM;
      }
      else
      {
        crc = (crc >> 1);
      }
    }
  }
  return crc;
}


[실행결과]



4. Get Reader Info[0x66]
 - 펌웨어버전, 종류 확인...


16/17 : 16 또는 17
RX-BUF : 호스트 프로토콜 초과하면 최대 리더 버퍼 크기가 나타남.
TX-BUF : 리더의 최대 송신 버퍼 크기.

#include <stdio.h>

#define CRC_POLYNOM    0x8408
#define CRC_PRESET     0xFFFF

unsigned short CRC16(void *p, unsigned int cnt);

int main()
{
  unsigned char ucCrc[5= {0x050x000x66,};
  unsigned int i;

  printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));  
  *((unsigned short *)(ucCrc+3)) = CRC16(ucCrc, sizeof(ucCrc)-2);

  for(i=0sizeof(ucCrc)>i; ++i)
  {
    printf("%02X ", *((unsigned char*)ucCrc + i));
  }
  printf("\n");
  
  return 0;
}

unsigned short CRC16(void *p, unsigned int cnt)
{
  unsigned char *DATA = p;
  unsigned int crc = CRC_PRESET;
  unsigned int i;
  unsigned int j;

  for(i=0; i<cnt; i++)
  {
    crc ^= DATA[i];
    for(j=0; j<8; j++)
    {
      if(crc & 0x0001)
      {
        crc = (crc >> 1)^CRC_POLYNOM;
      }
      else
      {
        crc = (crc >> 1);
      }
    }
  }
  return crc;
}


[실행결과]


 


 

728x90