Merge remote-tracking branch 'refs/remotes/dervomsee/patch-1'

This commit is contained in:
Valerio De Benedetto 2024-04-11 13:23:43 +02:00
commit d7ecb2ce8c
2 changed files with 13 additions and 5 deletions

View File

@ -93,8 +93,8 @@ bool InitCommPort(HANDLE* hComm, int PortNumber) {
}
bool CloseCommPort(HANDLE* hComm) {
if (hComm != INVALID_HANDLE_VALUE)
CloseHandle(hComm);
if (*hComm != INVALID_HANDLE_VALUE)
CloseHandle(*hComm);
else
return false;
@ -104,7 +104,6 @@ bool CloseCommPort(HANDLE* hComm) {
int32_t ReadCommPort(HANDLE hComm, uint8_t* buf, uint16_t count, int32_t byte_timeout_ms) {
int TotalBytesRead = 0;
bool Status = false;
bool TimedOut = false;
ULONGLONG StartTime = 0;
uint8_t b;
int tmpByteCount;
@ -126,11 +125,10 @@ int32_t ReadCommPort(HANDLE hComm, uint8_t* buf, uint16_t count, int32_t byte_ti
// did we time out yet??
if (GetTickCount64() - StartTime > byte_timeout_ms) {
TimedOut = true;
break;
}
} while (TotalBytesRead < count);
return TotalBytesRead;
}
}

View File

@ -56,9 +56,11 @@ static void discard_1(nmbs_t* nmbs) {
}
#ifndef NMBS_SERVER_DISABLED
static void discard_n(nmbs_t* nmbs, uint16_t n) {
nmbs->msg.buf_idx += n;
}
#endif
static uint16_t get_2(nmbs_t* nmbs) {
@ -76,6 +78,7 @@ static void put_2(nmbs_t* nmbs, uint16_t data) {
}
#ifndef NMBS_SERVER_DISABLED
static void set_1(nmbs_t* nmbs, uint8_t data, uint8_t index) {
nmbs->msg.buf[index] = data;
}
@ -85,6 +88,7 @@ static void set_2(nmbs_t* nmbs, uint16_t data, uint8_t index) {
nmbs->msg.buf[index] = (uint8_t) ((data >> 8) & 0xFFU);
nmbs->msg.buf[index + 1] = (uint8_t) data;
}
#endif
static uint8_t* get_n(nmbs_t* nmbs, uint16_t n) {
@ -94,6 +98,7 @@ static uint8_t* get_n(nmbs_t* nmbs, uint16_t n) {
}
#ifndef NMBS_SERVER_DISABLED
static void put_n(nmbs_t* nmbs, const uint8_t* data, uint8_t size) {
memcpy(&nmbs->msg.buf[nmbs->msg.buf_idx], data, size);
nmbs->msg.buf_idx += size;
@ -108,8 +113,10 @@ static uint16_t* get_regs(nmbs_t* nmbs, uint16_t n) {
}
return msg_buf_ptr;
}
#endif
#ifndef NMBS_CLIENT_DISABLED
static void put_regs(nmbs_t* nmbs, const uint16_t* data, uint16_t n) {
uint16_t* msg_buf_ptr = (uint16_t*) (nmbs->msg.buf + nmbs->msg.buf_idx);
nmbs->msg.buf_idx += n * 2;
@ -117,6 +124,7 @@ static void put_regs(nmbs_t* nmbs, const uint16_t* data, uint16_t n) {
msg_buf_ptr[n] = (data[n] << 8) | ((data[n] >> 8) & 0xFF);
}
}
#endif
static void swap_regs(uint16_t* data, uint16_t n) {
@ -359,12 +367,14 @@ static void put_msg_header(nmbs_t* nmbs, uint16_t data_length) {
}
#ifndef NMBS_SERVER_DISABLED
static void set_msg_header_size(nmbs_t* nmbs, uint16_t data_length) {
if (nmbs->platform.transport == NMBS_TRANSPORT_TCP) {
data_length += 2;
set_2(nmbs, data_length, 4);
}
}
#endif
static nmbs_error send_msg(nmbs_t* nmbs) {