Skip to content

Commit

Permalink
added support "Gwiot 7941E" sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
Pako2 committed Nov 18, 2018
1 parent 81d2ad8 commit 0ea0e2e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/rfid.esp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void ICACHE_FLASH_ATTR rfidloop()
if (RFIDr.Available())
{
uid = RFIDr.GetHexID();
type = "EM4100";
type = RFIDr.GetTagType();
cooldown = millis() + 2000;
#ifdef DEBUG
Serial.print(F("[ INFO ] PICC's UID: "));
Expand Down
64 changes: 51 additions & 13 deletions src/rfid125kHz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
==================================================================
Hardware: RDM6300 or RF125-PS
Hardware: RDM6300 or RF125-PS or Gwiot 7941E
Uses 125KHz RFID tags.
*/

Expand Down Expand Up @@ -88,13 +88,27 @@ String RFID_Reader::GetHexID()
uint8_t b[5];
memcpy(b, &new_ID, 5);
char buf[11];
sprintf(buf,"%02x%02x%02x%02x%02x\0",b[4],b[3],b[2],b[1],b[0]);
sprintf(buf,"%02x%02x%02x%02x%02x%c",b[4],b[3],b[2],b[1],b[0],'\0');
lasttagtype = tagtype;
data_available = false;
return String(buf);
}
return "None";
}

/*
Returns Tag type.
*/
String RFID_Reader::GetTagType()
{
for (uint8_t x = 0; x < 12; x++) {
if (typeDict[x].itype == lasttagtype) return String(typeDict[x].stype);
}
return "Unknown";
}



/*
Returns the ID decimal representation, and resets the Available flag.
*/
Expand All @@ -104,6 +118,7 @@ String RFID_Reader::GetDecID()
{
char ptr[128];
ulltostr(new_ID, ptr, 10);
lasttagtype = tagtype;
data_available = false;
return String(ptr);
}
Expand All @@ -113,7 +128,8 @@ String RFID_Reader::GetDecID()

void RFID_Reader::rfidSerial(char x)
{
if (x == StartByte)
//if (x == StartByte && (ix==0 || ix > 1))
if (x == StartByte && ix != 1)
{
ix = 0;
} else if (x == EndByte)
Expand Down Expand Up @@ -151,20 +167,42 @@ the module spits out HEX values, we need to convert them to an unsigned long.
*/
void RFID_Reader::parse()
{
uint8_t lshift = 0;
uint8_t lshift = 40;
unsigned long long val = 0;
unsigned long long tagIdValue = 0;
uint8_t i;
for (i = 0; i < 10; i++) {
val = char2int(msg[i]);
lshift = 4 * (9 - i);
tagIdValue |= val << lshift;
}
uint8_t checksum = get_checksum(tagIdValue);
uint8_t checksum = 0;
uint8_t recChecksum = 0;
new_ID = 0ULL;
if (msgLen == 12) {recChecksum = char2int(msg[i+1]) | char2int(msg[i]) << 4;}//RDM6300
else if (msgLen == 11) {recChecksum = (uint8_t)msg[i];} //RF125-PS
if ((msgLen + 2) == msg[0])//Gwiot 7941E
{
for (i = 0; i < msgLen - 1; i++)
{
val = msg[i];
checksum = checksum ^ val;
if (i > 1)
{
//lshift = 8 * (msgLen - 2 - i);
lshift = (msgLen - 2 - i) << 3;
tagIdValue |= val << lshift;
}
}
recChecksum = (uint8_t)msg[i];
tagtype = (uint8_t)msg[1];
}
else
{
for (i = 0; i < 10; i++) {
val = char2int(msg[i]);
//lshift = 4 * (9 - i);
lshift -= 4;
tagIdValue |= val << lshift;
}
checksum = get_checksum(tagIdValue);
new_ID = 0ULL;
if (msgLen == 12) {recChecksum = char2int(msg[i+1]) | char2int(msg[i]) << 4;}//RDM6300
else if (msgLen == 11) {recChecksum = (uint8_t)msg[i];} //RF125-PS
tagtype = 2;
}
if (checksum != recChecksum) return;
unsigned long _now = millis();
if ((_now-LastRFID > 3000)||(tagIdValue != last_ID))
Expand Down
24 changes: 23 additions & 1 deletion src/rfid125kHz.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
==================================================================
Hardware: RDM6300 or RF125-PS
Hardware: RDM6300 or RF125-PS or Gwiot 7941E
Uses 125KHz RFID tags.
*/

Expand All @@ -43,6 +43,7 @@ class RFID_Reader
bool Available();
String GetHexID();
String GetDecID();
String GetTagType();
private:
char *ulltostr(unsigned long long value, char *ptr, int base);
void parse();
Expand All @@ -53,11 +54,32 @@ class RFID_Reader
bool data_available = false;
unsigned long long new_ID = 0ULL;
unsigned long long last_ID = 0ULL;
uint8_t tagtype;
uint8_t lasttagtype;
unsigned long LastRFID = 0UL;
char msg[15];
uint8_t msgLen;
byte ix = 0;
byte StartByte = 0x02;
byte EndByte = 0x03;
typedef struct {
uint8_t itype;
char* stype;
} typeDictionary;

const typeDictionary typeDict[12] {
{0x01, (char*)"MIFARE 1K"},
{0x02, (char*)"EM4100"},
{0x03, (char*)"MIFARE 4K"},
{0x10, (char*)"HID card"},
{0x11, (char*)"T5567"},
{0x20, (char*)"2G certificate"},
{0x21, (char*)"IS014443B"},
{0x22, (char*)"FELICA"},
{0x30, (char*)"15693 tag"},
{0x50, (char*)"CPU card"},
{0x51, (char*)"sector information"},
{0xFF, (char*)"keyboard data"}
};
};
#endif

0 comments on commit 0ea0e2e

Please sign in to comment.