Skip to content

Commit

Permalink
Change versioning to single varible -> easier to handle
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Jun 10, 2023
1 parent d6b7fc9 commit fe98387
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 86 deletions.
7 changes: 3 additions & 4 deletions dev/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,9 @@ lwesp_evt(lwesp_evt_t* evt) {
lwesp_get_min_at_fw_version(&v_min);
lwesp_get_current_at_fw_version(&v_curr);

safeprintf("Current ESP[8266/32[-C3]] AT version is not supported by library\r\n");
safeprintf("Minimum required AT version is: %d.%d.%d\r\n", (int)v_min.major, (int)v_min.minor,
(int)v_min.patch);
safeprintf("Current AT version is: %d.%d.%d\r\n", (int)v_curr.major, (int)v_curr.minor, (int)v_curr.patch);
safeprintf("Current ESP[8266/32[-C3]] AT version is not supported by the library\r\n");
safeprintf("Minimum required AT version is: %08X\r\n", (unsigned)v_min.version);
safeprintf("Current AT version is: %08X\r\n", (unsigned)v_curr.version);
break;
}
case LWESP_EVT_WIFI_GOT_IP: {
Expand Down
10 changes: 3 additions & 7 deletions lwesp/src/include/lwesp/lwesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,12 @@ lwespr_t lwesp_get_min_at_fw_version(lwesp_sw_version_t* const version);
/**
* \brief Set and format major, minor and patch values to firmware version
* \param[in] v: Version output, pointer to \ref lwesp_sw_version_t structure
* \param[in] major_: Major version
* \param[in] minor_: Minor version
* \param[in] patch_: Patch version
* \param[in] version_: Version in 32-bit format
* \hideinitializer
*/
#define lwesp_set_fw_version(v, major_, minor_, patch_) \
#define lwesp_set_fw_version(v, version_) \
do { \
(v)->major = (major_); \
(v)->minor = (minor_); \
(v)->patch = (patch_); \
(v)->version = (version_); \
} while (0)

#if LWESP_CFG_ESP8266 || __DOXYGEN__
Expand Down
14 changes: 5 additions & 9 deletions lwesp/src/include/lwesp/lwesp_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -876,15 +876,11 @@ void * my_memset(void* dst, int b, size_t len);
* \{
*/

#define LWESP_MIN_AT_VERSION_MAJOR_ESP8266 2 /*!< Minimal major version for ESP8266 */
#define LWESP_MIN_AT_VERSION_MINOR_ESP8266 2 /*!< Minimal minor version for ESP8266 */
#define LWESP_MIN_AT_VERSION_PATCH_ESP8266 1 /*!< Minimal patch version for ESP8266 */
#define LWESP_MIN_AT_VERSION_MAJOR_ESP32 2 /*!< Minimal major version for ESP32 */
#define LWESP_MIN_AT_VERSION_MINOR_ESP32 2 /*!< Minimal minor version for ESP32 */
#define LWESP_MIN_AT_VERSION_PATCH_ESP32 0 /*!< Minimal patch version for ESP32 */
#define LWESP_MIN_AT_VERSION_MAJOR_ESP32_C3 2 /*!< Minimal major version for ESP32-C3 */
#define LWESP_MIN_AT_VERSION_MINOR_ESP32_C3 3 /*!< Minimal minor version for ESP32-C3 */
#define LWESP_MIN_AT_VERSION_PATCH_ESP32_C3 0 /*!< Minimal patch version for ESP32-C3 */
/* Define minimum versions required for each of device */
/* Format is (major << 24 | minor << 16 | patch << 8)*/
#define LWESP_MIN_AT_VERSION_ESP8266 (2 << 24 | 2 << 16 | 1 << 8)
#define LWESP_MIN_AT_VERSION_ESP32 (2 << 24 | 2 << 16 | 0 << 8)
#define LWESP_MIN_AT_VERSION_ESP32_C3 (2 << 24 | 3 << 16 | 0 << 8)

/**
* \}
Expand Down
8 changes: 4 additions & 4 deletions lwesp/src/include/lwesp/lwesp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ typedef struct {

/**
* \ingroup LWESP_TYPES
* \brief SW version in semantic versioning format
* \brief SW version handle object.
*
* Format is (major << 24 | minor << 16 | patch << 8 | 0)
*/
typedef struct {
uint8_t major; /*!< Major version */
uint8_t minor; /*!< Minor version */
uint8_t patch; /*!< Patch version */
uint32_t version; /*!< Version in single hex format */
} lwesp_sw_version_t;

/**
Expand Down
25 changes: 11 additions & 14 deletions lwesp/src/lwesp/lwesp.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ lwesp_init(lwesp_evt_fn evt_func, const uint32_t blocking) {
memset(&esp, 0x00, sizeof(esp)); /* Reset structure to all zeros */
esp.status.f.initialized = 0; /* Clear possible init flag */
def_evt_link.fn = evt_func != NULL ? evt_func : prv_def_callback;
esp.evt_func = &def_evt_link; /* Set callback function */
esp.evt_server = NULL; /* Set default server callback function */
esp.evt_func = &def_evt_link; /* Set callback function */
esp.evt_server = NULL; /* Set default server callback function */

if (!lwesp_sys_init()) { /* Init low-level system */
if (!lwesp_sys_init()) { /* Init low-level system */
goto cleanup;
}

Expand Down Expand Up @@ -154,10 +154,10 @@ lwesp_init(lwesp_evt_fn evt_func, const uint32_t blocking) {
lwesp_buff_init(&esp.buff, LWESP_CFG_RCV_BUFF_SIZE); /* Init buffer for input data */
#endif /* !LWESP_CFG_INPUT_USE_PROCESS */

esp.status.f.initialized = 1; /* We are initialized now */
esp.status.f.dev_present = 1; /* We assume device is present at this point */
esp.status.f.initialized = 1; /* We are initialized now */
esp.status.f.dev_present = 1; /* We assume device is present at this point */

lwespi_send_cb(LWESP_EVT_INIT_FINISH); /* Call user callback function */
lwespi_send_cb(LWESP_EVT_INIT_FINISH); /* Call user callback function */

/*
* Call reset command and call default
Expand All @@ -171,7 +171,7 @@ lwesp_init(lwesp_evt_fn evt_func, const uint32_t blocking) {
#endif /* LWESP_CFG_KEEP_ALIVE */

#if LWESP_CFG_RESTORE_ON_INIT
if (esp.status.f.dev_present) { /* In case device exists */
if (esp.status.f.dev_present) { /* In case device exists */
lwesp_core_unlock();
res = lwesp_restore(NULL, NULL, blocking); /* Restore device */
lwesp_core_lock();
Expand Down Expand Up @@ -409,7 +409,7 @@ lwesp_device_set_present(uint8_t present, const lwesp_api_cmd_evt_fn evt_fn, voi
lwesp_core_unlock();
res = lwesp_reset_with_delay(LWESP_CFG_RESET_DELAY_DEFAULT, evt_fn, evt_arg, blocking);
lwesp_core_lock();
#endif /* LWESP_CFG_RESET_ON_DEVICE_PRESENT */
#endif /* LWESP_CFG_RESET_ON_DEVICE_PRESENT */
}
lwespi_send_cb(LWESP_EVT_DEVICE_PRESENT); /* Send present event */
}
Expand Down Expand Up @@ -533,18 +533,15 @@ lwesp_get_min_at_fw_version(lwesp_sw_version_t* const version) {
if (0) {
#if LWESP_CFG_ESP8266
} else if (esp.m.device == LWESP_DEVICE_ESP8266) {
lwesp_set_fw_version(version, LWESP_MIN_AT_VERSION_MAJOR_ESP8266, LWESP_MIN_AT_VERSION_MINOR_ESP8266,
LWESP_MIN_AT_VERSION_PATCH_ESP8266);
lwesp_set_fw_version(version, LWESP_MIN_AT_VERSION_ESP8266);
#endif /* LWESP_CFG_ESP8266 */
#if LWESP_CFG_ESP32
} else if (esp.m.device == LWESP_DEVICE_ESP32) {
lwesp_set_fw_version(version, LWESP_MIN_AT_VERSION_MAJOR_ESP32, LWESP_MIN_AT_VERSION_MINOR_ESP32,
LWESP_MIN_AT_VERSION_PATCH_ESP32);
lwesp_set_fw_version(version, LWESP_MIN_AT_VERSION_ESP32);
#endif /* LWESP_CFG_ESP32 */
#if LWESP_CFG_ESP32_C3
} else if (esp.m.device == LWESP_DEVICE_ESP32_C3) {
lwesp_set_fw_version(version, LWESP_MIN_AT_VERSION_MAJOR_ESP32_C3, LWESP_MIN_AT_VERSION_MINOR_ESP32_C3,
LWESP_MIN_AT_VERSION_PATCH_ESP32_C3);
lwesp_set_fw_version(version, LWESP_MIN_AT_VERSION_ESP32_C3);
#endif /* LWESP_CFG_ESP32_C3 */
} else {
res = lwespERR;
Expand Down
42 changes: 11 additions & 31 deletions lwesp/src/lwesp/lwesp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,8 @@ lwespi_parse_received(lwesp_recv_t* rcv) {
}
} else if (CMD_IS_CUR(LWESP_CMD_GMR)) {
if (!strncmp(rcv->data, "AT version", 10)) {
uint8_t ok = 1, major = 99, minor = 99, patch = 99;
uint32_t min_version = (uint32_t)-1;
uint8_t ok = 1;
lwespi_parse_at_sdk_version(&rcv->data[11], &esp.m.version_at);

/*
Expand All @@ -994,27 +995,21 @@ lwespi_parse_received(lwesp_recv_t* rcv) {
#if LWESP_CFG_ESP8266
} else if (strstr(rcv->data, "- ESP8266 -") != NULL) {
esp.m.device = LWESP_DEVICE_ESP8266;
major = LWESP_MIN_AT_VERSION_MAJOR_ESP8266;
minor = LWESP_MIN_AT_VERSION_MINOR_ESP8266;
patch = LWESP_MIN_AT_VERSION_PATCH_ESP8266;
min_version = LWESP_MIN_AT_VERSION_ESP8266;
LWESP_DEBUGF(LWESP_CFG_DBG_INIT | LWESP_DBG_TYPE_TRACE,
"[LWESP GMR] Detected Espressif device is %s\r\n", "ESP8266");
#endif /* LWESP_CFG_ESP8266 */
#if LWESP_CFG_ESP32
} else if (strstr(rcv->data, "- ESP32 -") != NULL) {
esp.m.device = LWESP_DEVICE_ESP32;
major = LWESP_MIN_AT_VERSION_MAJOR_ESP32;
minor = LWESP_MIN_AT_VERSION_MINOR_ESP32;
patch = LWESP_MIN_AT_VERSION_PATCH_ESP32;
min_version = LWESP_MIN_AT_VERSION_ESP32;
LWESP_DEBUGF(LWESP_CFG_DBG_INIT | LWESP_DBG_TYPE_TRACE,
"[LWESP GMR] Detected Espressif device is %s\r\n", "ESP32");
#endif /* LWESP_CFG_ESP32 */
#if LWESP_CFG_ESP32_C3
} else if (strstr(rcv->data, "- ESP32C3 -") != NULL || strstr(rcv->data, "- ESP32-C3 -") != NULL) {
esp.m.device = LWESP_DEVICE_ESP32_C3;
major = LWESP_MIN_AT_VERSION_MAJOR_ESP32_C3;
minor = LWESP_MIN_AT_VERSION_MINOR_ESP32_C3;
patch = LWESP_MIN_AT_VERSION_PATCH_ESP32_C3;
min_version = LWESP_MIN_AT_VERSION_ESP32_C3;
LWESP_DEBUGF(LWESP_CFG_DBG_INIT | LWESP_DBG_TYPE_TRACE,
"[LWESP GMR] Detected Espressif device is %s\r\n", "ESP32-C3");
#endif /* LWESP_CFG_ESP32_C3 */
Expand All @@ -1024,34 +1019,19 @@ lwespi_parse_received(lwesp_recv_t* rcv) {
rcv->data);
ok = 0;
}
LWESP_DEBUGF(LWESP_CFG_DBG_INIT | LWESP_DBG_TYPE_TRACE, "[LWESP GMR] AT version minimum required: %08X\r\n",
(unsigned)min_version);
LWESP_DEBUGF(LWESP_CFG_DBG_INIT | LWESP_DBG_TYPE_TRACE,
"[LWESP GMR] AT version minimum required: %d.%d.%d\r\n", (int)major, (int)minor, (int)patch);
LWESP_DEBUGF(LWESP_CFG_DBG_INIT | LWESP_DBG_TYPE_TRACE,
"[LWESP GMR] AT version detected on device: %d.%d.%d\r\n", (int)esp.m.version_at.major,
(int)esp.m.version_at.minor, (int)esp.m.version_at.patch);
"[LWESP GMR] AT version detected on device: %08X\r\n", (int)esp.m.version_at.version);

/* Compare versions, but only if device is well detected */
if (ok) {
ok = 0;
if (esp.m.version_at.major > major) {
ok = 1;
} else if (esp.m.version_at.major == major) {
if (esp.m.version_at.minor > minor) {
ok = 1;
} else if (esp.m.version_at.minor == minor) {
if ((int8_t)esp.m.version_at.patch >= (int8_t)patch) {
ok = 1;
} else {
LWESP_DEBUGF(LWESP_CFG_DBG_INIT | LWESP_DBG_TYPE_TRACE | LWESP_DBG_LVL_SEVERE,
"[LWESP GMR] AT version comparison failed with patch version\r\n");
}
} else {
LWESP_DEBUGF(LWESP_CFG_DBG_INIT | LWESP_DBG_TYPE_TRACE | LWESP_DBG_LVL_SEVERE,
"[LWESP GMR] AT version comparison failed with minor version\r\n");
}
if (esp.m.version_at.version >= min_version) {
ok = 1; /* OK */
} else {
LWESP_DEBUGF(LWESP_CFG_DBG_INIT | LWESP_DBG_TYPE_TRACE | LWESP_DBG_LVL_SEVERE,
"[LWESP GMR] AT version comparison failed with major version\r\n");
"[LWESP GMR] Minimum AT required is higher than AT version loaded on the device\r\n");
}
}

Expand Down
30 changes: 16 additions & 14 deletions lwesp/src/lwesp/lwesp_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int32_t
lwespi_parse_number(const char** str) {
int32_t val = 0;
uint8_t minus = 0;
const char* p = *str; /* */
const char* p = *str; /* */

INC_IF_CHAR_EQUAL(p, '"'); /* Skip leading quotes */
INC_IF_CHAR_EQUAL(p, ','); /* Skip leading comma */
Expand Down Expand Up @@ -92,7 +92,7 @@ lwespi_parse_port(const char** str) {
uint32_t
lwespi_parse_hexnumber(const char** str) {
int32_t val = 0;
const char* p = *str; /* */
const char* p = *str; /* */

INC_IF_CHAR_EQUAL(p, '"'); /* Skip leading quotes */
INC_IF_CHAR_EQUAL(p, ','); /* Skip leading comma */
Expand Down Expand Up @@ -161,7 +161,7 @@ lwespi_parse_ip(const char** src, lwesp_ip_t* ip) {
const char* p = *src;
#if LWESP_CFG_IPV6
char c;
#endif /* LWESP_CFG_IPV6 */
#endif /* LWESP_CFG_IPV6 */

INC_IF_CHAR_EQUAL(p, '"'); /* Skip leading quotes */

Expand Down Expand Up @@ -208,7 +208,7 @@ lwespi_parse_ip(const char** src, lwesp_ip_t* ip) {
}
INC_IF_CHAR_EQUAL(p, '"'); /* Skip trailing quotes */

*src = p; /* Set new pointer */
*src = p; /* Set new pointer */
return 1;
}

Expand Down Expand Up @@ -249,8 +249,8 @@ lwespr_t
lwespi_parse_cipstatus_cipstate(const char* str) {
uint8_t cn_num = 0;

cn_num = lwespi_parse_number(&str); /* Parse connection number */
esp.m.active_conns |= 1 << cn_num; /* Set flag as active */
cn_num = lwespi_parse_number(&str); /* Parse connection number */
esp.m.active_conns |= 1 << cn_num; /* Set flag as active */

lwespi_parse_string(&str, NULL, 0, 1); /* Parse string and ignore result */
lwespi_parse_ip(&str, &esp.m.conns[cn_num].remote_ip);
Expand Down Expand Up @@ -316,12 +316,14 @@ lwespi_parse_ipd(const char* str) {
*/
uint8_t
lwespi_parse_at_sdk_version(const char* str, lwesp_sw_version_t* version_out) {
version_out->major = ((uint8_t)lwespi_parse_number(&str));
uint32_t version = 0;

version |= ((uint8_t)lwespi_parse_number(&str)) << 24;
++str;
version_out->minor = ((uint8_t)lwespi_parse_number(&str));
version |= ((uint8_t)lwespi_parse_number(&str)) << 16;
++str;
version_out->patch = ((uint8_t)lwespi_parse_number(&str));

version |= ((uint8_t)lwespi_parse_number(&str)) << 8;
version_out->version = version;
return 1;
}

Expand Down Expand Up @@ -400,15 +402,15 @@ lwespi_parse_cwlap(const char* str, lwesp_msg_t* msg) {
#if LWESP_CFG_ACCESS_POINT_STRUCT_FULL_FIELDS
msg->msg.ap_list.aps[msg->msg.ap_list.apsi].scan_type = (uint8_t)lwespi_parse_number(&str); /* Scan type */
msg->msg.ap_list.aps[msg->msg.ap_list.apsi].scan_time_min =
(uint16_t)lwespi_parse_number(&str); /* Scan time minimum */
(uint16_t)lwespi_parse_number(&str); /* Scan time minimum */
msg->msg.ap_list.aps[msg->msg.ap_list.apsi].scan_time_max =
(uint16_t)lwespi_parse_number(&str); /* Scan time maximum */
(uint16_t)lwespi_parse_number(&str); /* Scan time maximum */
msg->msg.ap_list.aps[msg->msg.ap_list.apsi].freq_offset = (int16_t)lwespi_parse_number(&str); /* Freq offset */
msg->msg.ap_list.aps[msg->msg.ap_list.apsi].freq_cal = (int16_t)lwespi_parse_number(&str); /* Freqcal value */
msg->msg.ap_list.aps[msg->msg.ap_list.apsi].pairwise_cipher =
(lwesp_ap_cipher_t)lwespi_parse_number(&str); /* Pairwise cipher */
(lwesp_ap_cipher_t)lwespi_parse_number(&str); /* Pairwise cipher */
msg->msg.ap_list.aps[msg->msg.ap_list.apsi].group_cipher =
(lwesp_ap_cipher_t)lwespi_parse_number(&str); /* Group cipher */
(lwesp_ap_cipher_t)lwespi_parse_number(&str); /* Group cipher */
#else
/* Read and ignore values */
lwespi_parse_number(&str);
Expand Down
6 changes: 3 additions & 3 deletions snippets/examples_common_lwesp_callback_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ examples_common_lwesp_callback_func(lwesp_evt_t* evt) {
lwesp_get_min_at_fw_version(&v_min);
lwesp_get_current_at_fw_version(&v_curr);

printf("Current ESP[8266/32[-C3]] AT version is not supported by library\r\n");
printf("Minimum required AT version is: %d.%d.%d\r\n", (int)v_min.major, (int)v_min.minor, (int)v_min.patch);
printf("Current AT version is: %d.%d.%d\r\n", (int)v_curr.major, (int)v_curr.minor, (int)v_curr.patch);
printf("Current ESP[8266/32[-C3]] AT version is not supported by the library\r\n");
printf("Minimum required AT version is: %08X\r\n", (unsigned)v_min.version);
printf("Current AT version is: %08X\r\n", (unsigned)v_curr.version);
break;
}
case LWESP_EVT_INIT_FINISH: {
Expand Down

0 comments on commit fe98387

Please sign in to comment.