Skip to content

Commit

Permalink
convert more methods to use seader param instead of seader_uart
Browse files Browse the repository at this point in the history
  • Loading branch information
bettse committed Jul 25, 2024
1 parent 236332b commit 82300ad
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions sam_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ static int seader_print_struct_callback(const void* buffer, size_t size, void* a
}

void seader_send_payload(
SeaderUartBridge* seader_uart,
Seader* seader,
Payload_t* payload,
uint8_t to,
uint8_t from,
uint8_t replyTo) {
SeaderWorker* seader_worker = seader->worker;
SeaderUartBridge* seader_uart = seader_worker->uart;
uint8_t rBuffer[SEADER_UART_RX_BUF_SIZE] = {0};

asn_enc_rval_t er = der_encode_to_buffer(
Expand Down Expand Up @@ -215,7 +217,7 @@ void seader_send_payload(
}

void seader_send_response(
SeaderUartBridge* seader_uart,
Seader* seader,
Response_t* response,
uint8_t to,
uint8_t from,
Expand All @@ -227,15 +229,12 @@ void seader_send_response(
payload->present = Payload_PR_response;
payload->choice.response = *response;

seader_send_payload(seader_uart, payload, to, from, replyTo);
seader_send_payload(seader, payload, to, from, replyTo);

free(payload);
}

void seader_send_request_pacs(Seader* seader) {
SeaderWorker* seader_worker = seader->worker;
SeaderUartBridge* seader_uart = seader_worker->uart;

RequestPacs_t* requestPacs = 0;
requestPacs = calloc(1, sizeof *requestPacs);
assert(requestPacs);
Expand All @@ -258,17 +257,14 @@ void seader_send_request_pacs(Seader* seader) {
payload->present = Payload_PR_samCommand;
payload->choice.samCommand = *samCommand;

seader_send_payload(seader_uart, payload, 0x44, 0x0a, 0x44);
seader_send_payload(seader, payload, 0x44, 0x0a, 0x44);

free(requestPacs);
free(samCommand);
free(payload);
}

void seader_worker_send_serial_number(Seader* seader) {
SeaderWorker* seader_worker = seader->worker;
SeaderUartBridge* seader_uart = seader_worker->uart;

SamCommand_t* samCommand = 0;
samCommand = calloc(1, sizeof *samCommand);
assert(samCommand);
Expand All @@ -283,16 +279,13 @@ void seader_worker_send_serial_number(Seader* seader) {
payload->present = Payload_PR_samCommand;
payload->choice.samCommand = *samCommand;

seader_send_payload(seader_uart, payload, 0x44, 0x0a, 0x44);
seader_send_payload(seader, payload, 0x44, 0x0a, 0x44);

free(samCommand);
free(payload);
}

void seader_worker_send_version(Seader* seader) {
SeaderWorker* seader_worker = seader->worker;

SeaderUartBridge* seader_uart = seader_worker->uart;
SamCommand_t* samCommand = 0;
samCommand = calloc(1, sizeof *samCommand);
assert(samCommand);
Expand All @@ -307,15 +300,13 @@ void seader_worker_send_version(Seader* seader) {
payload->present = Payload_PR_samCommand;
payload->choice.samCommand = *samCommand;

seader_send_payload(seader_uart, payload, 0x44, 0x0a, 0x44);
seader_send_payload(seader, payload, 0x44, 0x0a, 0x44);

free(samCommand);
free(payload);
}

void seader_send_card_detected(Seader* seader, CardDetails_t* cardDetails) {
SeaderWorker* seader_worker = seader->worker;
SeaderUartBridge* seader_uart = seader_worker->uart;
CardDetected_t* cardDetected = 0;
cardDetected = calloc(1, sizeof *cardDetected);
assert(cardDetected);
Expand All @@ -337,7 +328,7 @@ void seader_send_card_detected(Seader* seader, CardDetails_t* cardDetails) {
payload->present = Payload_PR_samCommand;
payload->choice.samCommand = *samCommand;

seader_send_payload(seader_uart, payload, 0x44, 0x0a, 0x44);
seader_send_payload(seader, payload, 0x44, 0x0a, 0x44);

free(payload);
free(samCommand);
Expand Down Expand Up @@ -568,9 +559,6 @@ bool seader_parse_response(Seader* seader, Response_t* response) {
}

void seader_send_nfc_rx(Seader* seader, uint8_t* buffer, size_t len) {
SeaderWorker* seader_worker = seader->worker;
SeaderUartBridge* seader_uart = seader_worker->uart;

OCTET_STRING_t rxData = {.buf = buffer, .size = len};
uint8_t status[] = {0x00, 0x00};
RfStatus_t rfStatus = {.buf = status, .size = 2};
Expand All @@ -596,7 +584,7 @@ void seader_send_nfc_rx(Seader* seader, uint8_t* buffer, size_t len) {
response->present = Response_PR_nfcResponse;
response->choice.nfcResponse = *nfcResponse;

seader_send_response(seader_uart, response, 0x14, 0x0a, 0x0);
seader_send_response(seader, response, 0x14, 0x0a, 0x0);

free(nfcRx);
free(nfcResponse);
Expand Down Expand Up @@ -930,9 +918,6 @@ void seader_parse_nfc_command_transmit(

void seader_parse_nfc_off(Seader* seader) {
FURI_LOG_D(TAG, "Set Field Off");
SeaderWorker* seader_worker = seader->worker;
SeaderUartBridge* seader_uart = seader_worker->uart;

NFCResponse_t* nfcResponse = 0;
nfcResponse = calloc(1, sizeof *nfcResponse);
assert(nfcResponse);
Expand All @@ -946,7 +931,7 @@ void seader_parse_nfc_off(Seader* seader) {
response->present = Response_PR_nfcResponse;
response->choice.nfcResponse = *nfcResponse;

seader_send_response(seader_uart, response, 0x44, 0x0a, 0);
seader_send_response(seader, response, 0x44, 0x0a, 0);

free(response);
free(nfcResponse);
Expand Down

0 comments on commit 82300ad

Please sign in to comment.