Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protocol/tagtinker_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ uint16_t tagtinker_crc16(const uint8_t* data, size_t len) {
return crc;
}

static size_t terminate(uint8_t* buf, size_t len) {
size_t terminate(uint8_t* buf, size_t len) {
uint16_t crc = tagtinker_crc16(buf, len);
buf[len] = crc & 0xFF;
buf[len + 1] = (crc >> 8) & 0xFF;
Expand Down
1 change: 1 addition & 0 deletions protocol/tagtinker_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef struct TagTinkerApp TagTinkerApp;

/* CRC used by the ESL wire format. */
uint16_t tagtinker_crc16(const uint8_t* data, size_t len);
size_t terminate(uint8_t* buf, size_t len);

typedef enum {
TagTinkerTagKindUnknown = 0,
Expand Down
65 changes: 65 additions & 0 deletions tagtinker_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,60 @@

#include "tagtinker_app.h"

#include <furi.h>
#include <cli/cli.h>
#include <cli/cli_registry.h>
#include <toolbox/args.h>

#define TAGTINKER_WEB_JOB_PATH APP_DATA_PATH("web_job.txt")

typedef enum {
TagTinkerCustomEventCliJob = 200,
} TagTinkerCustomEvent;

static bool tagtinker_try_consume_web_job(TagTinkerApp* app);

static void tag_cli(PipeSide* pipe, FuriString* args, void* context) {
UNUSED(pipe);
TagTinkerApp* app = context;

FuriString* arg = furi_string_alloc();

if(!args_read_string_and_trim(args, arg)) {
printf("Usage: tag rawsend <hex bytes...>\r\n");
furi_string_free(arg);
return;
}

bool is_rawsend = furi_string_equal(arg, "rawsend");
furi_string_free(arg);

if(!is_rawsend) {
printf("Usage: tag rawsend <hex bytes...>\r\n");
return;
}

/* Compute length by counting hex chars, cap at 128 */
const char* str = furi_string_get_cstr(args);
size_t pos = 0;
size_t buf_pos = 0;
size_t slen = strlen(str);
while(pos < slen && buf_pos < 128) {
while(pos < slen && str[pos] == ' ') pos++;
if(pos + 2 > slen) break;
if(!args_char_to_hex(str[pos], str[pos + 1], &app->cli_frame_buf[buf_pos++])) break;
pos += 2;
}
if (buf_pos == 0) {
printf("No hex bytes provided\r\n");
return;
}

app->cli_frame_len = buf_pos;
view_dispatcher_send_custom_event(app->view_dispatcher, TagTinkerCustomEventCliJob);
printf("Job queued.\r\n");
}

static bool navigation_cb(void* ctx) {
TagTinkerApp* app = ctx;
return scene_manager_handle_back_event(app->scene_manager);
Expand All @@ -26,6 +78,14 @@ static void tick_cb(void* ctx) {

static bool custom_event_cb(void* ctx, uint32_t event) {
TagTinkerApp* app = ctx;
if(event == TagTinkerCustomEventCliJob && app->cli_frame_len > 0) {
memcpy(app->frame_buf, app->cli_frame_buf, app->cli_frame_len);
app->frame_len = terminate(app->frame_buf, app->cli_frame_len);
app->frame_seq_count = 0;
app->cli_frame_len = 0;
scene_manager_next_scene(app->scene_manager, TagTinkerSceneTransmit);
return true;
}
return scene_manager_handle_custom_event(app->scene_manager, event);
}

Expand Down Expand Up @@ -862,6 +922,11 @@ static TagTinkerApp* app_alloc(void) {
bt_disconnect(app->bt);
bt_profile_restore_default(app->bt);

/* Register CLI command */
CliRegistry* cli = furi_record_open(RECORD_CLI);
cli_registry_add_command(cli, "tag", CliCommandFlagParallelSafe, tag_cli, app);
furi_record_close(RECORD_CLI);

app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&tagtinker_scene_handlers, app);

Expand Down
4 changes: 4 additions & 0 deletions tagtinker_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ struct TagTinkerApp {
uint8_t frame_buf[TAGTINKER_MAX_FRAME_SIZE];
size_t frame_len;

/* CLI raw frame input */
uint8_t cli_frame_buf[128];
size_t cli_frame_len;

/* Multi-frame sequence */
uint8_t** frame_sequence;
size_t* frame_lengths;
Expand Down