code optimized

This commit is contained in:
strawmanbobi
2026-02-16 17:37:23 +08:00
parent 058ba0ec3d
commit afc8ff9430
5 changed files with 20 additions and 20 deletions

View File

@@ -46,7 +46,7 @@ extern int g_mqtt_port;
// private variable definitions
static bool force_disconnected = false;
static PubSubClient* emqx_client = NULL;
static PubSubClient* emqx_client = nullptr;
// private function declarations
@@ -55,7 +55,7 @@ static PubSubClient* emqx_client = NULL;
int connectToEMQXBroker(PubSubClient &mqtt_client) {
int retry_times = 0;
if (NULL == emqx_client) {
if (nullptr == emqx_client) {
emqx_client = &mqtt_client;
}
emqx_client->setServer(g_mqtt_server.c_str(), g_mqtt_port);

View File

@@ -166,7 +166,7 @@ void checkIot() {
void iotCallback(char *topic, uint8_t *data, uint32_t length) {
INFOF("Downstream message received, topic = %s, length = %d\n", topic, length);
if (NULL != g_downstream_topic.c_str() && 0 == strcmp(topic, g_downstream_topic.c_str())) {
if (nullptr != g_downstream_topic.c_str() && 0 == strcmp(topic, g_downstream_topic.c_str())) {
handleIrisKitMessage((const char*) data, length);
}
}

View File

@@ -92,7 +92,7 @@ event_handler_t event_handler_table[] = {
// public function definitions
int getIRISKitVersion(char *buffer, int buffer_size) {
if (NULL == buffer) {
if (nullptr == buffer) {
return -1;
}
memset(buffer, 0, buffer_size);
@@ -123,7 +123,7 @@ int authIrisKit(String credential_token,
http_error_t http_ret = HTTP_ERROR_GENERIC;
if (NULL != strstr(iris_server_address, "http://")) {
if (nullptr != strstr(iris_server_address, "http://")) {
protocol_prefix = true;
}
if (protocol_prefix) {
@@ -185,7 +185,7 @@ bool downloadBin(int remote_id) {
String download_bin_url;
http_error_t http_ret = HTTP_ERROR_GENERIC;
if (NULL != strstr(iris_server_address, "http://")) {
if (nullptr != strstr(iris_server_address, "http://")) {
protocol_prefix = true;
}
if (protocol_prefix) {
@@ -223,7 +223,7 @@ void sendIrisKitHeartBeat() {
void handleIrisKitMessage(const char* data, int length) {
int ret = 0;
char* payload = (char*) malloc(length + 1);
if (NULL != payload) {
if (nullptr != payload) {
strncpy(payload, data, length);
payload[length] = '\0';
INFOF("--> %s\n", payload);
@@ -238,7 +238,7 @@ void handleIrisKitMessage(const char* data, int length) {
}
}
if (NULL != payload) {
if (nullptr != payload) {
free(payload);
}
}

View File

@@ -113,11 +113,11 @@ void setup() {
INFOF("Password is empty ? %s\n", iris_kit_settings.password.isEmpty() ? "yes" : "no");
}
if (!iris_kit_settings.credential_token.isEmpty() &&
!iris_kit_settings.credential_token.equalsIgnoreCase("NULL") &&
!iris_kit_settings.credential_token.equalsIgnoreCase("nullptr") &&
!iris_kit_settings.server_address.isEmpty() &&
!iris_kit_settings.server_address.equalsIgnoreCase("NULL") &&
!iris_kit_settings.server_address.equalsIgnoreCase("nullptr") &&
!iris_kit_settings.password.isEmpty() &&
!iris_kit_settings.password.equalsIgnoreCase("NULL")) {
!iris_kit_settings.password.equalsIgnoreCase("nullptr")) {
iris_kit_settings_loaded = true;
}
@@ -210,7 +210,7 @@ void setup() {
loadIRPin(send_pin, recv_pin);
// prepare MQTT connection params
if (NULL != strstr(iris_server_address, "iris.irext.net")) {
if (nullptr != strstr(iris_server_address, "iris.irext.net")) {
g_mqtt_server = String(MQTT_HOST_REL);
g_runtime_env = RUNTIME_RELEASE;
} else {

View File

@@ -32,31 +32,31 @@
MD5Builder md5_builder;
int split_string(const String source, char* parts[], const char* delimiter) {
char* pch = NULL;
char* copy = NULL;
char* tmp = NULL;
char* pch = nullptr;
char* copy = nullptr;
char* tmp = nullptr;
int i = 0;
copy = strdup(source.c_str());
if (NULL == copy) {
if (nullptr == copy) {
goto exit;
}
pch = strtok(copy, delimiter);
tmp = strdup(pch);
if (NULL == tmp) {
if (nullptr == tmp) {
goto exit;
}
parts[i++] = tmp;
while (pch) {
pch = strtok(NULL, delimiter);
if (NULL == pch) break;
pch = strtok(nullptr, delimiter);
if (nullptr == pch) break;
tmp = strdup(pch);
if (NULL == tmp) {
if (nullptr == tmp) {
goto exit;
}