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] = {0x06, 0x00, 0x52, 0x00,};//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=0; sizeof(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;
}
#define CRC_POLYNOM 0x8408
#define CRC_PRESET 0xFFFF
unsigned short CRC16(void *p, unsigned int cnt);
int main()
{
unsigned char ucCrc[6] = {0x06, 0x00, 0x52, 0x00,};//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=0; sizeof(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] = {0x05, 0x00, 0x63,};
unsigned int i;
printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));
*((unsigned short *)(ucCrc+3)) = CRC16(ucCrc, sizeof(ucCrc)-2);
for(i=0; sizeof(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;
}
#define CRC_POLYNOM 0x8408
#define CRC_PRESET 0xFFFF
unsigned short CRC16(void *p, unsigned int cnt);
int main()
{
unsigned char ucCrc[5] = {0x05, 0x00, 0x63,};
unsigned int i;
printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));
*((unsigned short *)(ucCrc+3)) = CRC16(ucCrc, sizeof(ucCrc)-2);
for(i=0; sizeof(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] = {0x05, 0x00, 0x65,};
unsigned int i;
printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));
*((unsigned short *)(ucCrc+3)) = CRC16(ucCrc, sizeof(ucCrc)-2);
for(i=0; sizeof(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;
}
#define CRC_POLYNOM 0x8408
#define CRC_PRESET 0xFFFF
unsigned short CRC16(void *p, unsigned int cnt);
int main()
{
unsigned char ucCrc[5] = {0x05, 0x00, 0x65,};
unsigned int i;
printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));
*((unsigned short *)(ucCrc+3)) = CRC16(ucCrc, sizeof(ucCrc)-2);
for(i=0; sizeof(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] = {0x05, 0x00, 0x66,};
unsigned int i;
printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));
*((unsigned short *)(ucCrc+3)) = CRC16(ucCrc, sizeof(ucCrc)-2);
for(i=0; sizeof(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;
}
#define CRC_POLYNOM 0x8408
#define CRC_PRESET 0xFFFF
unsigned short CRC16(void *p, unsigned int cnt);
int main()
{
unsigned char ucCrc[5] = {0x05, 0x00, 0x66,};
unsigned int i;
printf("%04X\n", CRC16(ucCrc, sizeof(ucCrc)-2));
*((unsigned short *)(ucCrc+3)) = CRC16(ucCrc, sizeof(ucCrc)-2);
for(i=0; sizeof(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
'코스웨어 > 11년 내장형하드웨어' 카테고리의 다른 글
[내장형]이동현_11월4일_일일보고서 (7) | 2011.11.07 |
---|---|
[내장형]김정우-2011.11.03 (8) | 2011.11.03 |
[내장형]황세선_2011.11.02 (14) | 2011.11.03 |
[내장형] 2011년 11월 1일 일일보고서 - 정선주 (6) | 2011.11.01 |
[내장형]심재원_2011.10.31_일일보고서 (3) | 2011.10.31 |
[내장형]이수란_2011.10.28 (8) | 2011.10.28 |
[내장형]김동화_2011년 10월 27일 일일보고서 (6) | 2011.10.27 |
[내장형]최남식-2011년10월26일일일보고서 (9) | 2011.10.26 |