add free memory command
add read and write nfc commands fix function sending
This commit is contained in:
110
nfcbord.cpp
110
nfcbord.cpp
@ -111,13 +111,13 @@ uint8_t NfcBoard::csToIrq(uint8_t cs)
|
||||
switch(cs)
|
||||
{
|
||||
case 0:
|
||||
return 3;
|
||||
return 4;
|
||||
case 1:
|
||||
return 2;
|
||||
case 2:
|
||||
return 1;
|
||||
case 3:
|
||||
return 7;
|
||||
return 0;
|
||||
case 4:
|
||||
return 7;
|
||||
case 5:
|
||||
@ -160,9 +160,11 @@ void NfcBoard::printNfcDevices()
|
||||
serial->write_p(PSTR("NFC DEVICES:\n"));
|
||||
for(uint8_t i = 0; i < readers.count(); ++i)
|
||||
{
|
||||
snprintf_P(buffer, SNPRINTF_BUFFER_SIZE, PSTR("NFC NUMBER: %u IRQ: %x TYPE: %d\n"),
|
||||
readers[i].type == TYPE_MFRC522 ? i+0x80 : readers[i].device.proxy.getId(),
|
||||
irqPins[i], readers[i].type);
|
||||
uint8_t id = readers[i].type == TYPE_MFRC522 ? i+0x80 : readers[i].device.proxy.getId();
|
||||
uint8_t cs = readers[i].type == TYPE_MFRC522 ?
|
||||
readers[i].device.mfrc522.getCs() : readers[i].device.proxy.getCs();
|
||||
snprintf_P(buffer, SNPRINTF_BUFFER_SIZE, PSTR("NFC NUMBER: %u CS: %x IRQ: %x TYPE: %d\n"),
|
||||
id, cs, irqPins[i], readers[i].type);
|
||||
serial->write(buffer, SNPRINTF_BUFFER_SIZE);
|
||||
}
|
||||
}
|
||||
@ -189,8 +191,6 @@ int NfcBoard::dispatch(char* inBuffer)
|
||||
}
|
||||
else if(strcmp(inBuffer, "irqs") == 0 )
|
||||
{
|
||||
PCMSK1 &= ~(1 << PCINT11);
|
||||
PCICR &= ~(1 << PCIE1);
|
||||
serial->write_p(PSTR("Irq pin detection test\n"));
|
||||
while(!serial->dataIsWaiting())
|
||||
{
|
||||
@ -206,8 +206,6 @@ int NfcBoard::dispatch(char* inBuffer)
|
||||
}
|
||||
}
|
||||
serial->write_p(PSTR("Finished\n"));
|
||||
PCMSK1 |= 1 << PCINT11;
|
||||
PCICR |= 1 << PCIE1;
|
||||
return 0;
|
||||
}
|
||||
else if(strcmp(inBuffer, "select") == 0 )
|
||||
@ -317,9 +315,66 @@ int NfcBoard::dispatch(char* inBuffer)
|
||||
}
|
||||
else if(strcmp(inBuffer, "read") == 0 )
|
||||
{
|
||||
char* token = strtok(NULL, " ");
|
||||
int16_t addr = -1;
|
||||
int16_t csPin = -1;
|
||||
|
||||
char* token = strtok(NULL, " ");
|
||||
if(token)
|
||||
csPin = strtol(token, nullptr, 16);
|
||||
if(csPin < 0 || csPin > 7)
|
||||
{
|
||||
serial->write_p(PSTR("A valid cs pin must be specified\n"));
|
||||
return -1;
|
||||
}
|
||||
token = strtok(NULL, " ");
|
||||
if(token)
|
||||
addr = strtol(token, nullptr, 16);
|
||||
if(addr < 0 || addr > 0xFF)
|
||||
{
|
||||
serial->write_p(PSTR("A address must be specified\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t result = 0;
|
||||
for(uint8_t i = 0; i < readers.count(); ++i)
|
||||
{
|
||||
if(readers[i].type == TYPE_MFRC522)
|
||||
{
|
||||
if(readers[i].device.mfrc522.getCs() == csPin)
|
||||
{
|
||||
result = readers[i].device.mfrc522.read(addr);
|
||||
serial->write_p(PSTR("read sucessfull\n"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(readers[i].device.proxy.getCs() == csPin)
|
||||
{
|
||||
result = readers[i].device.proxy.read(addr);
|
||||
serial->write_p(PSTR("read sucessfull\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
snprintf_P(buffer, SNPRINTF_BUFFER_SIZE, PSTR("Got: 0x%02x in return\n"), result);
|
||||
serial->write(buffer, SNPRINTF_BUFFER_SIZE);
|
||||
return 0;
|
||||
}
|
||||
else if(strcmp(inBuffer, "write") == 0 )
|
||||
{
|
||||
int16_t addr = -1;
|
||||
int16_t csPin = -1;
|
||||
int16_t data = -1;
|
||||
|
||||
char* token = strtok(NULL, " ");
|
||||
if(token)
|
||||
csPin = strtol(token, nullptr, 16);
|
||||
if(csPin < 0 || csPin > 7)
|
||||
{
|
||||
serial->write_p(PSTR("A valid cs pin must be specified\n"));
|
||||
return -1;
|
||||
}
|
||||
token = strtok(NULL, " ");
|
||||
if(token)
|
||||
addr = strtol(token, nullptr, 16);
|
||||
if(addr < 0 || addr > 0xFF)
|
||||
@ -329,21 +384,32 @@ int NfcBoard::dispatch(char* inBuffer)
|
||||
}
|
||||
token = strtok(NULL, " ");
|
||||
if(token)
|
||||
csPin = strtol(token, nullptr, 16);
|
||||
if(csPin < 0 || csPin > 7)
|
||||
data = strtol(token, nullptr, 16);
|
||||
if(data < 0 || data > 0xFF)
|
||||
{
|
||||
serial->write_p(PSTR("A valid cs pin must be specified\n"));
|
||||
serial->write_p(PSTR("Data must be specified\n"));
|
||||
return -1;
|
||||
}
|
||||
csReg.setBit(csPin, false);
|
||||
_delay_us(5);
|
||||
spim.readWrite(addr);
|
||||
_delay_us(5);
|
||||
uint8_t result = spim.readWrite();
|
||||
csReg.setBit(csPin, true);
|
||||
serial->write_p(PSTR("Got: "));
|
||||
serial->write((int)result);
|
||||
serial->write_p(PSTR(" in return\n"));
|
||||
|
||||
for(uint8_t i = 0; i < readers.count(); ++i)
|
||||
{
|
||||
if(readers[i].type == TYPE_MFRC522)
|
||||
{
|
||||
if(readers[i].device.mfrc522.getCs() == csPin)
|
||||
{
|
||||
readers[i].device.mfrc522.write(addr, data);
|
||||
serial->write_p(PSTR("Write sucessfull\n"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(readers[i].device.proxy.getCs() == csPin)
|
||||
{
|
||||
serial->write_p(PSTR("Mfrc522 proxies are not writable\n"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -3;
|
||||
|
Reference in New Issue
Block a user