| 240 | // ============================================================================ |
| 241 | |
| 242 | JSValue 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 | |
| 289 | JSValue native_srixWrite(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) { |
| 290 | // usage: srixWrite(timeout_in_seconds : number = 10); |
nothing calls this directly
no test coverage detected