Seperate into language folders
This commit is contained in:
22
cpp/telemetry_common.cpp
Normal file
22
cpp/telemetry_common.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
||||
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "telemetry_common.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
uint16_t crc16_ccitt(const uint8_t *data, uint16_t length) {
|
||||
uint16_t crc = 0xFFFF;
|
||||
|
||||
for (uint16_t i = 0; i < length; i++) {
|
||||
crc ^= (uint16_t)data[i] << 8;
|
||||
|
||||
for (uint8_t j = 0; j < 8; j++) {
|
||||
if (crc & 0x8000)
|
||||
crc = (crc << 1) ^ 0x1021;
|
||||
else
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
40
cpp/telemetry_common.h
Normal file
40
cpp/telemetry_common.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
||||
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
#include <inttypes.h>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct TelemetryPacket1 {
|
||||
char ping_[4] = {'P', 'I', 'N', 'G'};
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct TelemetryPacket2 {
|
||||
float vbat;
|
||||
float teng;
|
||||
float lat;
|
||||
float lng;
|
||||
float speed;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct TelemetryLoRaHeader {
|
||||
uint8_t source_;
|
||||
uint8_t dest_;
|
||||
uint8_t version_;
|
||||
uint8_t size_;
|
||||
uint16_t crc16_;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct TelemetryUARTHeader {
|
||||
uint8_t magic_[4] = {0xAA, 0x55, 0xAA, 0x55};
|
||||
uint8_t size_;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
uint16_t crc16_ccitt(const uint8_t *data, uint16_t length);
|
||||
Reference in New Issue
Block a user