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

Method load_file_headless

src/modules/rfid/srix_tool.cpp:1116–1196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1114}
1115
1116int SRIXTool::load_file_headless(String filename) {
1117 if (!nfc) return -1;
1118
1119 FS *fs;
1120 if (!getFsStorage(fs)) return -1;
1121
1122 // Build filepath
1123 String filepath = "/BruceRFID/SRIX/" + filename;
1124 if (!filename.endsWith(".srix")) filepath += ".srix";
1125
1126 if (!(*fs).exists(filepath)) return -2; // File not found
1127
1128 // Open file
1129 File file = (*fs).open(filepath, FILE_READ);
1130 if (!file) return -1;
1131
1132 // Reset buffers
1133 memset(_dump, 0, sizeof(_dump));
1134 memset(_uid, 0, sizeof(_uid));
1135
1136 bool header_passed = false;
1137 int blocks_loaded = 0;
1138
1139 // Parse file line by line
1140 while (file.available()) {
1141 String line = file.readStringUntil('\n');
1142 line.trim();
1143 if (line.isEmpty()) continue;
1144
1145 // Parse UID from header
1146 if (line.startsWith("UID:")) {
1147 String uid_str = line.substring(5);
1148 uid_str.trim();
1149 uid_str.replace(" ", "");
1150
1151 for (uint8_t i = 0; i < 8 && i * 2 < uid_str.length(); i++) {
1152 String byteStr = uid_str.substring(i * 2, i * 2 + 2);
1153 _uid[i] = strtoul(byteStr.c_str(), NULL, 16);
1154 }
1155 continue;
1156 }
1157
1158 // Skip header until "# Data:"
1159 if (!header_passed) {
1160 if (line.startsWith("# Data:")) header_passed = true;
1161 continue;
1162 }
1163
1164 // Parse blocks in format: [XX] YYYYYYYY
1165 if (line.startsWith("[") && line.indexOf("]") > 0) {
1166 int bracket_end = line.indexOf("]");
1167 String block_num_str = line.substring(1, bracket_end);
1168 String data_str = line.substring(bracket_end + 1);
1169 data_str.trim();
1170 data_str.replace(" ", "");
1171
1172 uint8_t block_num = strtoul(block_num_str.c_str(), NULL, 16);
1173 if (block_num >= 128) continue; // Skip invalid blocks

Callers 2

native_rfidLoadFunction · 0.45
native_srixLoadFunction · 0.45

Calls 4

getFsStorageFunction · 0.85
closeMethod · 0.80
availableMethod · 0.45
readStringUntilMethod · 0.45

Tested by

no test coverage detected