#include "../Inc/utils.h" char* concat_strings(const char *str1, const char *str2) { size_t len = strlen(str1) + strlen(str2) + 1; char *result = (char*) malloc(len); if (result == NULL) { log_error("Ошибка выделения памяти!\n"); return NULL; } strcpy(result, str1); strcat(result, str2); return result; } cJSON *cJSON_GetObject(cJSON *object, uint8_t *key){ cJSON *objectJSON = cJSON_GetObjectItemCaseSensitive(object, key); if (objectJSON == NULL) { log_error("Ошибка: объект '%s' не найден\n", key); return EXIT_FAILURE; } return objectJSON; } uint8_t InitializationProject(uint8_t* api_url, uint8_t pin_nss, uint8_t pin_rst, uint8_t pin_dio0, uint8_t pin_koncevik, uint8_t pin_air_input, uint8_t pin_air_output, int8_t* serial_port, uint8_t* serial_device){ log_info("Initialization..."); Set_New_ButtonMain_Label("Initialization..."); // int connection_init = CURL_Check_connection(api_url); // if(connection_init < 0){ // log_error("Conncection ERROR"); // return 1; // } log_info("SX1278Init..."); Set_New_ButtonMain_Label("SX1278Init..."); int sx_init = SX1278_Init(pin_nss, pin_rst, pin_dio0); if(sx_init < 0){ log_error("SX1278 Initialization ERROR"); return 1; } pinMode(pin_koncevik, INPUT); pinMode(pin_air_input, OUTPUT); pinMode(pin_air_output, OUTPUT); log_info("SX1278_load..."); Set_New_ButtonMain_Label("SX1278_load..."); SX1278_load(); // delay(500); // *serial_port = GODEX500_setup_serial(&serial_device); // if (*serial_port < 0) { // log_error("GODEX500 Initialization ERROR"); // return 1; // } log_info("Initialization completed!"); Set_New_ButtonMain_Label("Initialization completed!"); return 0; } void print_bytes(SxResive* ptr, size_t size){ uint8_t* byte_ptr = (uint8_t*)ptr; for(size_t i = 0; i < size; i++){ printf("0x%02X, ", byte_ptr[i]); } printf("\n"); } // Функция для упаковки структуры в массив байтов void packSxTransmit(SxTransmit* data, uint8_t* buffer) { int index = 0; // Упаковка полей структуры в буфер memcpy(&buffer[index], &data->payload, sizeof(data->payload)); index += sizeof(data->payload); memcpy(&buffer[index], &data->type, sizeof(data->type)); index += sizeof(data->type); memcpy(&buffer[index], &data->id_sensor, sizeof(data->id_sensor)); index += sizeof(data->id_sensor); memcpy(&buffer[index], &data->pressure, sizeof(data->pressure)); index += sizeof(data->pressure); memcpy(&buffer[index], &data->temperature, sizeof(data->temperature)); index += sizeof(data->temperature); memcpy(&buffer[index], data->otherData, sizeof(data->otherData)); }