Another question arose about calculating the checksum of the structure…
In the transmitter, I form a static structure (for testing) and send it.
#pragma pack(push, 1)
struct LoraData {
char type[3] = "ND"; // Тип структуры (навигационные данные)
uint8_t dev_id = 1; // ID Устройства
int32_t latitude = 2; // Широта (миллионные доли градуса)
int32_t longitude = 3; // Долгота (миллионные доли градуса)
int32_t altitude = 4; // Высота (миллиметр)
int32_t speed = 5; // Скорость
int32_t course = 6; // Курс (тысячные доли градуса по часовой стрелке от севера)
uint8_t num_satellites = 7; // Количество видимых спутников (штук)
uint8_t hdop = 8; // Точность позиционирования (десятые доли, 11 соответствует 1.1)
uint16_t sdeg = 9; // Текущий угол серво машинки
uint8_t crc8; // Контрольная сумма структуры
} lora_data;
#pragma pack(pop)
lora_data.crc8 = get_crc_8((const char *)&lora_data, sizeof(lora_data) - sizeof(lora_data.type) - sizeof(lora_data.crc8));
ResponseStatus response_status = LORA_E32.sendFixedMessage(BASE_ADDR_H, BASE_ADDR_L, BASE_RF_CHANNEL, &lora_data, sizeof(LoraData));
The checksum is 0x88 (without the type and crc8 fields)
Receiver code
void Task_LoRa(void) {
if (LORA_E32.available() > 1) {
/* Извлекаем тип пакета */
char type[3];
ResponseContainer rs = LORA_E32.receiveInitialMessage(sizeof(type));
String type_str = rs.data;
if (type_str == "ND") {
/* Пакет с навигационными данными */
/* Создаем структуру с точным количеством выделенной памяти */
#pragma pack(push, 1)
struct NavData {
uint8_t dev_id; // ID Устройства
int32_t latitude; // Широта (миллионные доли градуса)
int32_t longitude; // Долгота (миллионные доли градуса)
int32_t altitude; // Высота (миллиметр)
int32_t speed; // Скорость
int32_t course; // Курс (тысячные доли градуса по часовой стрелке от севера)
uint8_t num_satellites; // Количество видимых спутников (штук)
uint8_t hdop; // Точность позиционирования (десятые доли, 11 соответствует 1.1)
uint16_t sdeg; // Текущий угол серво машинки
uint8_t crc8; // Контрольная сумма структуры
} nav_data;
#pragma pack(pop)
ResponseStructContainer rsc = LORA_E32.receiveMessage(sizeof(NavData));
nav_data = *(NavData *)rsc.data;
/* Проверяем контрольную сумму */
uint8_t crc8_calc = get_crc_8((const char *)&nav_data, sizeof(nav_data) - sizeof(nav_data.crc8));
char buffer_crc[256];
snprintf(buffer_crc, sizeof(buffer_crc),
"ID: %d | Rem CRC8: 0x%02X | Cal CRC8: 0x%02X",
nav_data.dev_id, nav_data.crc8, crc8_calc);
SEND_DEBUG_MSG(buffer_crc);
if (crc8_calc != nav_data.crc8) {
SEND_DEBUG_MSG("ER! CRC8 Navigation Data");
rsc.close();
return;
}
rsc.close();
} else {
Serial.println("Something Goes Wrong!");
}
}
}
But the checksum is 0x04 (without crc8 fields)
I use receiveInitialMessage.
What could be the problem with the checksum calculation?
The calculation function is the same on both sides.
This reply was modified 3 months, 3 weeks ago by poe.
I have two ESP32 modules and two LoRa E32-443T33D.
One set sends data (structure).
The second set receive data.
I output a formatted string with the values in the structure to the console.
Both structures are the same (transmitter and receiver).
The types of variables in the structure are also the same.
For example, I send dev_id = 1, and receive 54.
On the sender’s side?
Compilation error: initializer-string for ‘char [3]’ is too long [-fpermissive]
Author
Posts
Viewing 5 posts - 1 through 5 (of 5 total)
Follow:
More
Welcome to Our Family!
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.