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

Function native_srixRead

src/modules/bjs_interpreter/rfid_js.cpp:242–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240// ============================================================================
241
242JSValue native_srixRead(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) {
243 // usage: srixRead(timeout_in_seconds : number = 10);
244 // returns: { uid: string, blocks: number, size: number, data: string } or null
245
246 int timeout = 10;
247 if (argc > 0 && JS_IsNumber(ctx, argv[0])) { JS_ToInt32(ctx, &timeout, argv[0]); }
248
249 SRIXTool *srixReader = getSRIXReader();
250
251 // Use existing headless functionality
252 String jsonResult = srixReader->read_tag_headless(timeout);
253
254 if (jsonResult.isEmpty()) { return JS_NULL; }
255
256 // Create a JS object from the fields
257 JSValue obj = JS_NewObject(ctx);
258
259 // Get UID using getUID() method
260 String uid_str = "";
261 uint8_t *uid = srixReader->getUID();
262 for (uint8_t i = 0; i < 8; i++) {
263 if (uid[i] < 0x10) uid_str += "0";
264 uid_str += String(uid[i], HEX);
265 if (i < 7) uid_str += " ";
266 }
267 uid_str.toUpperCase();
268 JS_SetPropertyStr(ctx, obj, "uid", JS_NewString(ctx, uid_str.c_str()));
269
270 // Blocks count
271 JS_SetPropertyStr(ctx, obj, "blocks", JS_NewInt32(ctx, 128));
272
273 // Size in bytes
274 JS_SetPropertyStr(ctx, obj, "size", JS_NewInt32(ctx, 512));
275
276 // Data as hex string using getDump() method
277 String dump_str = "";
278 uint8_t *dump = srixReader->getDump();
279 for (uint16_t i = 0; i < 512; i++) {
280 if (dump[i] < 0x10) dump_str += "0";
281 dump_str += String(dump[i], HEX);
282 }
283 dump_str.toUpperCase();
284 JS_SetPropertyStr(ctx, obj, "data", JS_NewString(ctx, dump_str.c_str()));
285
286 return obj;
287}
288
289JSValue native_srixWrite(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) {
290 // usage: srixWrite(timeout_in_seconds : number = 10);

Callers

nothing calls this directly

Calls 4

getSRIXReaderFunction · 0.85
getUIDMethod · 0.80
getDumpMethod · 0.80
read_tag_headlessMethod · 0.45

Tested by

no test coverage detected