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

Function native_rfidLoad

src/modules/bjs_interpreter/rfid_js.cpp:164–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164JSValue native_rfidLoad(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) {
165 // usage: rfidLoad(filename : string);
166 // returns: object with tag data or null on error
167
168 if (argc < 1 || !JS_IsString(ctx, argv[0])) { return JS_NULL; }
169
170 JSCStringBuf buf;
171 const char *filename = JS_ToCString(ctx, argv[0], &buf);
172 if (!filename) { return JS_NULL; }
173
174 TagOMatic *tagReader = getTagReader();
175
176 // Load file
177 bool success = tagReader->load_file_headless(String(filename));
178
179 if (!success) { return JS_NULL; }
180
181 // Create a JS object from the loaded data
182 JSValue obj = JS_NewObject(ctx);
183
184 // Extract fields from the interface
185 RFIDInterface *rfid = tagReader->getRFIDInterface();
186 if (rfid) {
187 JS_SetPropertyStr(ctx, obj, "uid", JS_NewString(ctx, rfid->printableUID.uid.c_str()));
188 JS_SetPropertyStr(ctx, obj, "type", JS_NewString(ctx, rfid->printableUID.picc_type.c_str()));
189 JS_SetPropertyStr(ctx, obj, "sak", JS_NewString(ctx, rfid->printableUID.sak.c_str()));
190 JS_SetPropertyStr(ctx, obj, "atqa", JS_NewString(ctx, rfid->printableUID.atqa.c_str()));
191 JS_SetPropertyStr(ctx, obj, "bcc", JS_NewString(ctx, rfid->printableUID.bcc.c_str()));
192 JS_SetPropertyStr(ctx, obj, "pages", JS_NewString(ctx, rfid->strAllPages.c_str()));
193 JS_SetPropertyStr(ctx, obj, "totalPages", JS_NewInt32(ctx, rfid->totalPages));
194 }
195
196 return obj;
197}
198
199JSValue native_rfidClear(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) {
200 // usage: rfidClear();

Callers

nothing calls this directly

Calls 3

getTagReaderFunction · 0.85
getRFIDInterfaceMethod · 0.80
load_file_headlessMethod · 0.45

Tested by

no test coverage detected