This commit is contained in:
Dennis Gunia
2025-09-19 00:27:20 +02:00
parent 8330fcbd43
commit 2fe870a68d

View File

@@ -143,15 +143,15 @@ void sfbus_send_frame(int fd, u_int16_t address, u_int8_t length, char *buffer)
*/ */
void sfbus_send_frame_v2(int fd, u_int16_t address, u_int8_t length, char *buffer) void sfbus_send_frame_v2(int fd, u_int16_t address, u_int8_t length, char *buffer)
{ {
int frame_size_complete = length + 7; // calculate size of complete transmission int frame_size_complete = length + 7; // calculate size of complete transmission
// (including header, payload and crc) // (header + frame)
char *frame = malloc(frame_size_complete); char *frame = malloc(frame_size_complete); // allocate frame buffer
// assemble tx data // assemble tx data
*(frame + 0) = '+'; // startbyte (0x2B) *(frame + 0) = 0x2B; // startbyte
*(frame + 1) = 0x01; // protocol version (v2.0) *(frame + 1) = 0x01; // protocol version (v2.0)
*(frame + 2) = length + 4; // length of frame *(frame + 2) = length + 4; // length of frame
*(frame + 3) = (address); // addres high byte *(frame + 3) = (address); // address high byte
*(frame + 4) = ((address >> 8)); // address low byte *(frame + 4) = ((address >> 8)); // address low byte
memcpy(frame + 5, buffer, length); // copy payload to packet memcpy(frame + 5, buffer, length); // copy payload to packet