Skip to content

Commit

Permalink
feat: get vcard content
Browse files Browse the repository at this point in the history
  • Loading branch information
DeimosHall committed Aug 24, 2023
1 parent d847e63 commit bd86a95
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
14 changes: 7 additions & 7 deletions examples/NDEFRead/NDEFRead.ino
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,20 @@ void displayDeviceInfo() {

void displayRecordInfo(NdefRecord record) {
if (record.isEmpty()) {
Serial.println("No more records, exiting...");
return;
}

uint8_t *payload = record.getPayload();
Serial.println("--- NDEF record received:");

switch (record.getType()) {
// case MEDIA_VCARD: {
// save = record.recordPayload[record.recordPayloadSize];
// record.recordPayload[record.recordPayloadSize] = '\0';
// Serial.print("vCard:");
// Serial.println(reinterpret_cast<const char *>(record.recordPayload));
// record.recordPayload[record.recordPayloadSize] = save;
// } break;
case MEDIA_VCARD: {
unsigned char save = record.getPayload()[record.getPayloadSize()];
record.getPayload()[record.getPayloadSize()] = '\0';
Serial.println("vCard:");
Serial.println(record.getVCardContent());
} break;

case WELL_KNOWN_SIMPLE_TEXT: {
Serial.println("\tWell known simple text");
Expand Down
31 changes: 20 additions & 11 deletions src/NdefRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ NdefRecord::NdefRecord() {
type = UNSUPPORTED_NDEF_RECORD;
payload = NULL;
payloadSize = 0;
newString = "null";
}

void NdefRecord::create(NdefRecord_t record) {
Expand Down Expand Up @@ -53,25 +54,21 @@ unsigned short NdefRecord::getPayloadSize() {
}

String NdefRecord::getText() {
Serial.println("here1");
Serial.println(payloadSize);
Serial.println(sizeof(payload));
unsigned char save = payload[payloadSize];
payload[payloadSize] = '\0';
String text = "";
String text = newString;

if (getType() == WELL_KNOWN_SIMPLE_TEXT) {
text = reinterpret_cast<const char *>(&payload[payload[0] + 1]);
}

payload[payloadSize] = save;
Serial.println("here2");

return text;
}

String NdefRecord::getBluetoothName() {
String bluetoothName = "";
String bluetoothName = newString;

if (getType() != MEDIA_HANDOVER_BT) {
return bluetoothName;
Expand All @@ -88,7 +85,7 @@ String NdefRecord::getBluetoothName() {
}

String NdefRecord::getBluetoothAddress() {
String bluetoothAddress = "";
String bluetoothAddress = newString;

if (getType() != MEDIA_HANDOVER_BT) {
return bluetoothAddress;
Expand All @@ -105,7 +102,7 @@ String NdefRecord::getBluetoothAddress() {
}

String NdefRecord::getWiFiSSID() {
String ssid = "";
String ssid = newString;

if (getType() != MEDIA_HANDOVER_WIFI) {
return ssid;
Expand All @@ -122,7 +119,7 @@ String NdefRecord::getWiFiSSID() {
}

String NdefRecord::getWiFiAuthenticationType() {
String authenticationType = "";
String authenticationType = newString;
unsigned char index = 0, i;

if (getType() != MEDIA_HANDOVER_WIFI) {
Expand All @@ -146,7 +143,7 @@ String NdefRecord::getWiFiAuthenticationType() {
}

String NdefRecord::getWiFiEncryptionType() {
String encryptionType = "";
String encryptionType = newString;
unsigned char index = 0, i;

if (getType() != MEDIA_HANDOVER_WIFI) {
Expand All @@ -170,7 +167,7 @@ String NdefRecord::getWiFiEncryptionType() {
}

String NdefRecord::getWiFiNetworkKey() {
String networkKey = "";
String networkKey = newString;
unsigned char index = 0, i;

if (getType() != MEDIA_HANDOVER_WIFI) {
Expand All @@ -192,3 +189,15 @@ String NdefRecord::getWiFiNetworkKey() {

return networkKey;
}

String NdefRecord::getVCardContent() {
String content = newString;

if (getType() != MEDIA_VCARD) {
return content;
}

content = reinterpret_cast<const char *>(getPayload());

return content;
}
2 changes: 2 additions & 0 deletions src/NdefRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class NdefRecord {
unsigned char *payload;
unsigned short payloadSize;
String getHexRepresentation(const byte *data, const uint32_t dataSize);
String newString;

public:
NdefRecord();
Expand All @@ -28,6 +29,7 @@ class NdefRecord {
String getWiFiAuthenticationType();
String getWiFiEncryptionType();
String getWiFiNetworkKey();
String getVCardContent();
};

#endif

0 comments on commit bd86a95

Please sign in to comment.