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

Function native_rfidSave

src/modules/bjs_interpreter/rfid_js.cpp:133–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133JSValue native_rfidSave(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) {
134 // usage: rfidSave(filename : string);
135 // returns: { success: boolean, message: string, filepath: string }
136
137 if (argc < 1 || !JS_IsString(ctx, argv[0])) { return JS_NULL; }
138
139 JSCStringBuf buf;
140 const char *filename = JS_ToCString(ctx, argv[0], &buf);
141 if (!filename) { return JS_NULL; }
142
143 TagOMatic *tagReader = getTagReader();
144
145 // Save file
146 String result = tagReader->save_file_headless(String(filename));
147
148 // Create return object
149 JSValue obj = JS_NewObject(ctx);
150
151 if (!result.isEmpty()) {
152 JS_SetPropertyStr(ctx, obj, "success", JS_NewBool(true));
153 JS_SetPropertyStr(ctx, obj, "message", JS_NewString(ctx, "File saved successfully"));
154 JS_SetPropertyStr(ctx, obj, "filepath", JS_NewString(ctx, result.c_str()));
155 } else {
156 JS_SetPropertyStr(ctx, obj, "success", JS_NewBool(false));
157 JS_SetPropertyStr(ctx, obj, "message", JS_NewString(ctx, "Error saving file"));
158 JS_SetPropertyStr(ctx, obj, "filepath", JS_NewString(ctx, ""));
159 }
160
161 return obj;
162}
163
164JSValue native_rfidLoad(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) {
165 // usage: rfidLoad(filename : string);

Callers

nothing calls this directly

Calls 2

getTagReaderFunction · 0.85
save_file_headlessMethod · 0.45

Tested by

no test coverage detected