Initial import
This commit is contained in:
63
arnet_cli.c
Normal file
63
arnet_cli.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* armando modem - iz4kll
|
||||
* https://ciapini.wiki.esiliati.org/index.php/Armando47/ArNetCLI
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../../mini-printf.h"
|
||||
|
||||
#include "../net.h"
|
||||
#include "arnet.h"
|
||||
#include "arnet_cli.h"
|
||||
#include "arnet_types.h"
|
||||
|
||||
uint8_t arnet_cli_print_packet(net_packet net_pck, arnet_packet arnet_pck, uint8_t *Buffer) {
|
||||
uint8_t q = 0;
|
||||
q += mini_snprintf((char*) (&Buffer[q]), 24, "%c%u%c%c%u", ARNET_CLI_SRC_ADDR, arnet_pck.dh.src_addr, ARNET_CLI_ELEMENT_SEPARATOR, ARNET_CLI_DST_ADDR, arnet_pck.dh.dst_addr);
|
||||
|
||||
if (arnet_pck.vc.enabled == 1) {
|
||||
q += mini_snprintf((char*) (&Buffer[q]), 24, "N%u", arnet_pck.vc.sequence);
|
||||
}
|
||||
|
||||
if (arnet_pck.ec.enabled == 1) {
|
||||
q += mini_snprintf((char*) (&Buffer[q]), 24, "%c%c%u", ARNET_CLI_ELEMENT_SEPARATOR, ARNET_CLI_EC_ENABLED, arnet_pck.ec.ARQ);
|
||||
}
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
uint8_t arnet_cli_print_state(uint8_t *Buffer) {
|
||||
uint8_t q = 0;
|
||||
// indirizzi
|
||||
q += mini_snprintf((char*) (&Buffer[q]), 24, "%c%c%u%c%c%c%u", ARNET_CLI_SRC_ADDR, ARNET_CLI_KV_SEPARATOR, node.address, ARNET_CLI_ELEMENT_SEPARATOR, ARNET_CLI_DST_ADDR, ARNET_CLI_KV_SEPARATOR, node.current_peer);
|
||||
// ec
|
||||
q += mini_snprintf((char*) (&Buffer[q]), 24, "%c%c%c%u", ARNET_CLI_ELEMENT_SEPARATOR, ARNET_CLI_EC_ENABLED, ARNET_CLI_KV_SEPARATOR, node.enabled.ec);
|
||||
return q;
|
||||
}
|
||||
|
||||
// esegui
|
||||
|
||||
uint8_t arnet_cli_exec(uint8_t name, uint32_t value) {
|
||||
uint8_t err = ARNET_CLI_ERR_OK;
|
||||
if (name == ARNET_CLI_SRC_ADDR) {
|
||||
if (value >= ARNET_ADDRESS_SIZE) {
|
||||
err = ARNET_CLI_ERR_INVALID_VALUE;
|
||||
} else {
|
||||
node.address = value;
|
||||
}
|
||||
} else if (name == ARNET_CLI_DST_ADDR) {
|
||||
if (value >= ARNET_ADDRESS_SIZE) {
|
||||
err = ARNET_CLI_ERR_INVALID_VALUE;
|
||||
} else {
|
||||
node.current_peer = value;
|
||||
}
|
||||
} else if (name == ARNET_CLI_EC_ENABLED) {
|
||||
if (value == 0) node.enabled.ec = 0;
|
||||
else {
|
||||
node.enabled.ec = 1;
|
||||
}
|
||||
} else {
|
||||
err = ARNET_CLI_ERR_INVALID_NAME;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
Reference in New Issue
Block a user