Esempio n. 1
0
// calcuate CRC & send command - response in binarray
BOOL hitag1_send_command(BYTE *response, BYTE *command, BOOL reset, BOOL sync, BYTE response_length)
{
    BYTE crc= HITAG1_CRC_PRESET, tmp[HITAG1_MAX_COMMAND_LEN], length; // supplied command is 4 bits + 8 bit address. we add 8 bit CRC
    
    // calculate crc
    length= binstringtobinarray(tmp, command);
    hitag1_binarray_crc(&crc, tmp, length);

    // add 8 bit crc to command
    inttobinarray(tmp + length, (unsigned int) crc, 8);
    length += 8;

    // send command - first gap is GAP, not SLEEP
    if(!rwd_send(tmp, length, reset, BLOCK, RWD_STATE_START_SEND, RFIDlerConfig.FrameClock, RFIDlerConfig.RWD_Gap_Period, RFIDlerConfig.RWD_Wake_Period, RFIDlerConfig.RWD_Zero_Period, RFIDlerConfig.RWD_One_Period, RFIDlerConfig.RWD_Gap_Period, RFIDlerConfig.RWD_Wait_Switch_TX_RX))
        return FALSE;

    if(!response_length)
        return TRUE;

    // read response as binary data
    //Manchester_Auto_Correct= TRUE;
    if(read_ask_data(RFIDlerConfig.FrameClock, RFIDlerConfig.DataRate, response, response_length, RFIDlerConfig.Sync, sync ? RFIDlerConfig.SyncBits : 0, RFIDlerConfig.Timeout, ONESHOT_READ, BINARY) == response_length)
    {
        // delay for RX->TX time
        Delay_us((RFIDlerConfig.FrameClock * RFIDlerConfig.RWD_Wait_Switch_RX_TX) / 100);
        return TRUE;
    }

    return FALSE;
}
Esempio n. 2
0
// this routine accepts either binary arrays or binary strings
BOOL rwd_send(unsigned char *command, unsigned int length, BOOL reset, BOOL block, BYTE initial_state, unsigned int fc, unsigned int sleep, unsigned int wake, unsigned int pw0, unsigned int pw1, unsigned int gap, unsigned int post_wait)
{
    unsigned int i;

    RWD_Fc= fc;

    // convert FCs to OCM ticks
    RWD_Sleep_Period= sleep * 2;
    RWD_Wake_Period= wake * 2;
    RWD_Zero_Period= pw0 * 2;
    RWD_One_Period= pw1 * 2;
    RWD_Gap_Period= gap * 2;
    RWD_Post_Wait= post_wait * 2;
    
    if(!RWD_Zero_Period || !RWD_One_Period || !RWD_Gap_Period)
        return FALSE;

    // convert ascii string to bin if required
    if(command[0] == '0' || command[0] == '1')
    {
        if(!binstringtobinarray(RWD_Command_Buff, command))
            return FALSE;
    }
    else
        memcpy(RWD_Command_Buff, command, length);
    
    RWD_Command_Buff[length]= '*';
    RWD_Command_ThisBit= RWD_Command_Buff;

    // start clock and wait for TAG to wake if not already running
    // this is needed in case a non-resetting RWD command is issued before any other action has woken tag
    if(mGetLED_Clock() == mLED_OFF)
    {
        RWD_State= RWD_STATE_INACTIVE;
        InitHWReaderClock(OC_TOGGLE_PULSE, RWD_Fc / 2L, RWD_Fc, RWD_State);
        if(!reset)
            Delay_us((RFIDlerConfig.FrameClock * RFIDlerConfig.RWD_Wake_Period) / 100);
    }

    if(reset)
        RWD_State= RWD_STATE_GO_TO_SLEEP;
    else
        RWD_State= initial_state;

    // see if ISR has flagged RWD command finished
   if(block)
       while(RWD_State != RWD_STATE_ACTIVE)
           ;

    return TRUE;
}