MCPcopy Create free account
hub / github.com/BruceDevices/firmware / save_file_headless

Method save_file_headless

src/modules/rfid/srix_tool.cpp:1055–1114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1053}
1054
1055String SRIXTool::save_file_headless(String filename) {
1056 if (!_dump_valid_from_read && !_dump_valid_from_load) return ""; // No data
1057
1058 FS *fs;
1059 if (!getFsStorage(fs)) return "";
1060
1061 // Create directories if needed
1062 if (!(*fs).exists("/BruceRFID")) (*fs).mkdir("/BruceRFID");
1063 if (!(*fs).exists("/BruceRFID/SRIX")) (*fs).mkdir("/BruceRFID/SRIX");
1064
1065 // Build filepath
1066 String filepath = "/BruceRFID/SRIX/" + filename;
1067 if (!filename.endsWith(".srix")) filepath += ".srix";
1068
1069 // Handle existing file
1070 if ((*fs).exists(filepath)) {
1071 int i = 1;
1072 String base = filepath.substring(0, filepath.length() - 5); // Remove .srix
1073 while ((*fs).exists(base + "_" + String(i) + ".srix")) i++;
1074 filepath = base + "_" + String(i) + ".srix";
1075 }
1076
1077 // Open file for writing
1078 File file = (*fs).open(filepath, FILE_WRITE);
1079 if (!file) return "";
1080
1081 // Build UID string
1082 String uid_str = "";
1083 for (uint8_t i = 0; i < 8; i++) {
1084 if (_uid[i] < 0x10) uid_str += "0";
1085 uid_str += String(_uid[i], HEX);
1086 }
1087 uid_str.toUpperCase();
1088
1089 // Write header
1090 file.println("Filetype: Bruce SRIX Dump");
1091 file.println("UID: " + uid_str);
1092 file.println("Blocks: 128");
1093 file.println("Data size: 512");
1094 file.println("# Data:");
1095
1096 // Write blocks in format: [XX] YYYYYYYY
1097 for (uint8_t block = 0; block < 128; block++) {
1098 uint16_t offset = block * 4;
1099 String line = "[";
1100 if (block < 0x10) line += "0";
1101 line += String(block, HEX);
1102 line += "] ";
1103
1104 for (uint8_t i = 0; i < 4; i++) {
1105 if (_dump[offset + i] < 0x10) line += "0";
1106 line += String(_dump[offset + i], HEX);
1107 }
1108 line.toUpperCase();
1109 file.println(line);
1110 }
1111
1112 file.close();

Callers 2

native_rfidSaveFunction · 0.45
native_srixSaveFunction · 0.45

Calls 3

getFsStorageFunction · 0.85
closeMethod · 0.80
printlnMethod · 0.45

Tested by

no test coverage detected