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

[내장형] 2011년 11월 1일 일일보고서 - 정선주

by 알 수 없는 사용자 2011. 11. 1.
728x90
반응형

 

 Capacitor SMD(Surface Mount Device)Type : 표면 실장 소자

 

 뒤면에 A 모 위에 칩이 들어 있다 잘 보이지는 않는다

 

 Host –> Reader

 1번 : 총 Byte 수(0x0D)

2번  : 장치 번호(0x00)

3번 :  명령어(0x71)

4, 5번 : OS(0x00, 0xFF)

6, 7번 : OSF(0x00, 0x00)

8, 9번 : OS-Time(0x00, 0xA)

10, 11번 : 0x00

12, 13번 : CRC16

 Host –> Reader

 1번 : 총 Byte 수(0x06)

2번 : 장치 번호(0x00)

3번 : 명령어(0x71)

4번 : 상태

5, 6번 :  CRC16

 

0, 1 Bit : LED grn mode

2, 3 Bit : LED red mode

4, 5 Bit : Beeper mode

 LED grn/ LEd red/ Beeper mode

b00 : 기본 상태

b01 : On 상태

b10 : Off 상태

b11 : FLASH

 RFID Test Source

   1:  #include <stdio.h>
   2:  #include <fcntl.h>
   3:  #include <unistd.h>
   4:  #include <termios.h>
   5:  #include <sys/stat.h>
   6:  #include <sys/signal.h>
   7:  #include <sys/time.h>
   8:  #include <sys/types.h>
   9:  //#include "CRC16.h"
  10:   
  11:  #define SPEED    B38400
  12:  #define COMPORT1    "/dev/ttyS0"    // 리눅스는 윈도우com10을 1로 보고있음!
  13:   
  14:  void Hanlde_Serial_sig(int);
  15:   
  16:  char cBuff[255];
  17:  char cFlag;                        // 종료 시그널 유무
  18:  int iCom1=0;
  19:  struct termios stOldSt1;    // Serial port (기존)
  20:  unsigned char ucBuff[13]={0x0d,0x00,0x71,0x00
  21:                          ,0x1f,0x00,0x00,0x00
  22:                          ,0xa0,0x00,0x00,};
  23:   
  24:  unsigned short CRC16(void * DATA, unsigned int cnt);
  25:  int main()
  26:  {
  27:      int iCnt;
  28:      int iRet;
  29:      int iMaxFD=0;                // maximum file descriptor used
  30:      struct termios stNewSt1;    // New prot (새로 설정한 포트)
  31:      struct sigaction stSigAct;    // 시그널 액션
  32:      fd_set stRFd;                // file descriptor set
  33:      *((unsigned short *)(ucBuff+11)) = CRC16(ucBuff, *ucBuff -2);
  34:      
  35:      
  36:      iCom1    =open(COMPORT1,O_RDWR|O_NOCTTY);    // 시리얼 포트 열기
  37:      if(0>iCom1)
  38:      {
  39:          perror(COMPORT1);
  40:          return -10;
  41:      }
  42:      
  43:      tcgetattr(iCom1,&stOldSt1);
  44:   
  45:      bzero(&stNewSt1,sizeof(stNewSt1));
  46:      stNewSt1.c_cflag=SPEED|CS8|CLOCAL|CREAD|PARENB;    //control flag 설정
  47:      stNewSt1.c_iflag=IGNPAR;                //input flag 
  48:      stNewSt1.c_cc[VMIN]=1;    
  49:      
  50:      tcflush(iCom1,TCIFLUSH);
  51:      tcsetattr(iCom1, TCSANOW, &stNewSt1);
  52:   
  53:      /*--------------------------------------------------*/
  54:      bzero(&stSigAct,sizeof(stSigAct));
  55:      stSigAct.sa_handler    =Hanlde_Serial_sig;
  56:      sigaction(SIGINT, &stSigAct, NULL);
  57:      
  58:      /*--------------------------------------------------*/
  59:      iMaxFD    =iCom1+1;
  60:      
  61:      while(1)
  62:      {
  63:          FD_ZERO(&stRFd);
  64:          FD_SET(iCom1, &stRFd);
  65:          FD_SET(0, &stRFd);
  66:              
  67:          select(iMaxFD, &stRFd, NULL,NULL,NULL);
  68:   
  69:          if(FD_ISSET(iCom1, &stRFd))    //수신시
  70:          {
  71:              iRet=read(iCom1, cBuff, 255);
  72:              //-----------------------------
  73:              iCnt=0;
  74:              while(iCnt<iRet)
  75:              {
  76:                  printf("%02X ",*(cBuff+iCnt));
  77:                  iCnt++;
  78:                  if(0 == (iCnt%16))
  79:                  {
  80:                      putchar('\n');                                
  81:                  }        
  82:              }
  83:              putchar('\n');                                    
  84:              putchar('\n');                                    
  85:              //-----------------------------
  86:              continue;
  87:          }
  88:          if(FD_ISSET(0,&stRFd));        //키보드 입력시
  89:          {
  90:              write(iCom1,ucBuff, *ucBuff);
  91:          }                
  92:      }
  93:      tcsetattr(iCom1,TCSANOW,&stOldSt1);
  94:      
  95:      close(iCom1);
  96:   
  97:      return 0;
  98:  }
  99:   
 100:  void Hanlde_Serial_sig(int Arg)
 101:  {
 102:      printf("...END\n");
 103:      tcsetattr(iCom1,TCSANOW,&stOldSt1);
 104:      close(iCom1);
 105:      
 106:      exit(0);
 107:  }
 108:  #define CRC_POLYNOM    0X8408
 109:  #define CRC_PRESET    0xFFFF
 110:   
 111:  unsigned short CRC16(void * DATA, unsigned int cnt)
 112:  {
 113:      unsigned short crc;
 114:      unsigned int i;
 115:      unsigned int j;
 116:   
 117:      crc    =CRC_PRESET;
 118:   
 119:      for(i=0; cnt>i; i++)
 120:      {
 121:          crc    =*((unsigned char *)DATA+i) ^ crc;
 122:          for(j=0; 8>j ; j++)
 123:          {
 124:              if(crc & 0x0001)
 125:              {
 126:                  crc    =(crc>>1)^CRC_POLYNOM;
 127:              }
 128:              else
 129:              {
 130:                  crc    =crc>>1;
 131:              }
 132:          }
 133:      }
 134:      
 135:      return crc;
 136:  }

 결과

 삐하는 소리가 아주 길게 나면서 빨강색 LED랑 녹색 LED가 깜박깜박 거린다

728x90