| 162 | } |
| 163 | |
| 164 | JSValue 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 | |
| 199 | JSValue native_rfidClear(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) { |
| 200 | // usage: rfidClear(); |
nothing calls this directly
no test coverage detected