|
|
|
|
@ -11,27 +11,7 @@
|
|
|
|
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <md5.h>
|
|
|
|
|
#include <openssl/sha.h>
|
|
|
|
|
#include <libgen.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "librnode.h"
|
|
|
|
|
#include "libs/framing.h"
|
|
|
|
|
#include "libs/serial.h"
|
|
|
|
|
#include "libs/logging/log.h"
|
|
|
|
|
#include "libs/util.h"
|
|
|
|
|
#include "libs/slip_enc.h"
|
|
|
|
|
#include "libs/eeprom.h"
|
|
|
|
|
#include "libs/zip.h"
|
|
|
|
|
|
|
|
|
|
// flashing
|
|
|
|
|
#include "libs/flashers/nrf/dfu.h"
|
|
|
|
|
#include "libs/flashers/nrf/uart_drv.h"
|
|
|
|
|
#include "libs/flashers/esp32/esputil.h"
|
|
|
|
|
|
|
|
|
|
/* Handles incoming RNode communications from serial
|
|
|
|
|
* Scope: private
|
|
|
|
|
@ -45,7 +25,7 @@ int rnode_handle_resp(struct RNode* rn, bool* in_frame, uint8_t* cmd, uint8_t* c
|
|
|
|
|
uint8_t sbyte;
|
|
|
|
|
uint8_t resp_buf[RESP_BUF_SIZE] = {0};
|
|
|
|
|
|
|
|
|
|
len = read_port(rn->fd, resp_buf, RESP_BUF_SIZE);
|
|
|
|
|
len = read_port(&rn->handle, resp_buf, RESP_BUF_SIZE);
|
|
|
|
|
|
|
|
|
|
if (len > 0) {
|
|
|
|
|
log_trace("Read %d bytes", len);
|
|
|
|
|
@ -281,9 +261,9 @@ int rnode_detect(struct RNode* rn) {
|
|
|
|
|
uint16_t frame_len = 0;
|
|
|
|
|
|
|
|
|
|
memcpy(tx_buf, (uint8_t[16]){FEND, CMD_DETECT, DETECT_REQ, FEND, FEND, CMD_FW_VERSION, 0x00, FEND, FEND, CMD_PLATFORM, 0x00, FEND, FEND, CMD_MCU, 0x00, FEND}, 16*sizeof(uint8_t));
|
|
|
|
|
err_code = write_port(rn->fd, tx_buf, 16);
|
|
|
|
|
err_code = write_port(&rn->handle, tx_buf, 16);
|
|
|
|
|
if (!err_code) {
|
|
|
|
|
sleep_ms(100);
|
|
|
|
|
sleep_mils(100);
|
|
|
|
|
err_code = rnode_handle_resp(rn, &in_frame, &cmd, cmd_buf, &cmd_buf_l, &frame_len);
|
|
|
|
|
return (err_code == -1) ? -1 : rn->connected;
|
|
|
|
|
} else {
|
|
|
|
|
@ -303,9 +283,9 @@ int rnode_detect(struct RNode* rn) {
|
|
|
|
|
int rnode_init(struct RNode* rn, char* port, uint32_t baud, bool detect, bool force_detect) {
|
|
|
|
|
rn->port = port;
|
|
|
|
|
rn->baud = baud;
|
|
|
|
|
rn->fd = open_port(rn->port, baud);
|
|
|
|
|
open_port(&rn->handle, rn->port, baud);
|
|
|
|
|
|
|
|
|
|
if (rn->fd > 0) {
|
|
|
|
|
if (&rn->handle > 0) {
|
|
|
|
|
if (detect) {
|
|
|
|
|
if (rnode_detect(rn)) {
|
|
|
|
|
log_info("RNode detected successfully on port %s", port);
|
|
|
|
|
@ -335,7 +315,7 @@ int rnode_init(struct RNode* rn, char* port, uint32_t baud, bool detect, bool fo
|
|
|
|
|
int rnode_reset(struct RNode* rn) {
|
|
|
|
|
uint8_t tx_buf[4];
|
|
|
|
|
memcpy(tx_buf, (uint8_t[4]){FEND, CMD_RESET, CMD_RESET_BYTE, FEND}, 4*sizeof(uint8_t));
|
|
|
|
|
return write_port(rn->fd, tx_buf, 4);
|
|
|
|
|
return write_port(&rn->handle, tx_buf, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sets an RNode's platform attribute manually
|
|
|
|
|
@ -367,7 +347,7 @@ int rnode_set_bt(struct RNode* rn, uint8_t val) {
|
|
|
|
|
}
|
|
|
|
|
uint8_t tx_buf[4];
|
|
|
|
|
memcpy(tx_buf, (uint8_t[4]){FEND, CMD_BT_CTRL, val, FEND}, 4*sizeof(uint8_t));
|
|
|
|
|
err_code = write_port(rn->fd, tx_buf, 4);
|
|
|
|
|
err_code = write_port(&rn->handle, tx_buf, 4);
|
|
|
|
|
|
|
|
|
|
return err_code;
|
|
|
|
|
}
|
|
|
|
|
@ -399,7 +379,7 @@ int rnode_get_bt_pin(struct RNode* rn, uint32_t timeout) {
|
|
|
|
|
|
|
|
|
|
while (current <= start + timeout) {
|
|
|
|
|
if (err_code >= 0) {
|
|
|
|
|
sleep_ms(50);
|
|
|
|
|
sleep_mils(50);
|
|
|
|
|
err_code = rnode_handle_resp(rn, &in_frame, &cmd, cmd_buf, &cmd_buf_l, &frame_len);
|
|
|
|
|
time(<ime); current = ltime;
|
|
|
|
|
if (rn->bt_pairing_pin != 0) {
|
|
|
|
|
@ -426,7 +406,7 @@ int rnode_set_disp_int(struct RNode* rn, uint8_t disp_int) {
|
|
|
|
|
int err_code = 0;
|
|
|
|
|
uint8_t tx_buf[4];
|
|
|
|
|
memcpy(tx_buf, (uint8_t[4]){FEND, CMD_DISP_INT, disp_int, FEND}, 4*sizeof(uint8_t));
|
|
|
|
|
err_code = write_port(rn->fd, tx_buf, 4);
|
|
|
|
|
err_code = write_port(&rn->handle, tx_buf, 4);
|
|
|
|
|
|
|
|
|
|
return err_code;
|
|
|
|
|
}
|
|
|
|
|
@ -441,7 +421,7 @@ int rnode_set_disp_timeout(struct RNode* rn, uint8_t timeout) {
|
|
|
|
|
int err_code = 0;
|
|
|
|
|
uint8_t tx_buf[4];
|
|
|
|
|
memcpy(tx_buf, (uint8_t[4]){FEND, CMD_DISP_INT, timeout, FEND}, 4*sizeof(uint8_t));
|
|
|
|
|
err_code = write_port(rn->fd, tx_buf, 4);
|
|
|
|
|
err_code = write_port(&rn->handle, tx_buf, 4);
|
|
|
|
|
|
|
|
|
|
return err_code;
|
|
|
|
|
}
|
|
|
|
|
@ -456,7 +436,7 @@ int rnode_set_disp_addr(struct RNode* rn, uint8_t addr) {
|
|
|
|
|
int err_code = 0;
|
|
|
|
|
uint8_t tx_buf[4];
|
|
|
|
|
memcpy(tx_buf, (uint8_t[4]){FEND, CMD_DISP_ADDR, addr, FEND}, 4*sizeof(uint8_t));
|
|
|
|
|
err_code = write_port(rn->fd, tx_buf, 4);
|
|
|
|
|
err_code = write_port(&rn->handle, tx_buf, 4);
|
|
|
|
|
|
|
|
|
|
return err_code;
|
|
|
|
|
}
|
|
|
|
|
@ -474,7 +454,7 @@ int rnode_set_disp_rot(struct RNode* rn, uint8_t rot) {
|
|
|
|
|
|
|
|
|
|
uint8_t tx_buf[4];
|
|
|
|
|
memcpy(tx_buf, (uint8_t[4]){FEND, CMD_DISP_ROT, rot, FEND}, |