Skip to content

Commit

Permalink
fix tidy bugprone-reserved-identifier
Browse files Browse the repository at this point in the history
this was partially automatic and partially manual.
  • Loading branch information
tsteven4 committed Nov 20, 2022
1 parent da2d306 commit 368e897
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 46 deletions.
12 changes: 6 additions & 6 deletions gbser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <cstdarg>
#include <cstdio>

void gbser__db(int l, const char* msg, ...)
void gbser_db(int l, const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
Expand Down Expand Up @@ -109,7 +109,7 @@ int gbser_setup(void* handle, const char* spec)
*/
int gbser_avail(void* handle)
{
return gbser__fill_buffer(handle, 1, nullptr);
return gbser_fill_buffer(handle, 1, nullptr);
}

/* Read as many bytes as are available without blocking. At most |len|
Expand All @@ -121,15 +121,15 @@ int gbser_read(void* handle, void* buf, unsigned len)
int got = 0;

while (len > 0) {
int rc = gbser__fill_buffer(handle, len, nullptr);
int rc = gbser_fill_buffer(handle, len, nullptr);
if (rc < 0) {
/* error */
return rc;
} else if (rc == 0) {
/* nothing available */
break;
}
got += gbser__read_buffer(handle, &buf, &len);
got += gbser_read_buffer(handle, &buf, &len);
}

return got;
Expand All @@ -144,10 +144,10 @@ int gbser_read_wait(void* handle, void* buf, unsigned len, unsigned ms)

while (len > 0 && ms != 0) {
int rc;
if (rc = gbser__fill_buffer(handle, len, &ms), rc < 0) {
if (rc = gbser_fill_buffer(handle, len, &ms), rc < 0) {
return rc;
}
got += gbser__read_buffer(handle, &buf, &len);
got += gbser_read_buffer(handle, &buf, &len);
}

return got;
Expand Down
6 changes: 3 additions & 3 deletions gbser.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/

#ifndef __GBSER_H
#define __GBSER_H
#ifndef GBSER_H_INCLUDED_
#define GBSER_H_INCLUDED_

#include <cstddef> // for size_t

Expand Down Expand Up @@ -136,4 +136,4 @@ int gbser_is_serial(const char* port_name);
const char* fix_win_serial_name_r(const char* comname, char* obuf, size_t len);
const char* fix_win_serial_name(const char* comname);

#endif /* GBSER_H */
#endif /* GBSER_H_INCLUDED_ */
22 changes: 11 additions & 11 deletions gbser_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct gbser_handle {
};

/* Wrapper to safely cast a void * into a gbser_handle */
static gbser_handle* gbser__get_handle(void* p)
static gbser_handle* gbser_get_handle(void* p)
{
auto* h = (gbser_handle*) p;
assert(h->magic == MYMAGIC);
Expand Down Expand Up @@ -133,7 +133,7 @@ void* gbser_init(const char* port_name)
{
gbser_handle* h;

gbser__db(4, "gbser_init(\"%s\")\n", port_name);
gbser_db(4, "gbser_init(\"%s\")\n", port_name);

h = (gbser_handle*) xcalloc(sizeof *h, 1);
h->magic = MYMAGIC;
Expand Down Expand Up @@ -173,7 +173,7 @@ void* gbser_init(const char* port_name)
*/
void gbser_deinit(void* handle)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);

tcsetattr(h->fd, TCSAFLUSH, &h->old_tio);
close(h->fd);
Expand All @@ -183,7 +183,7 @@ void gbser_deinit(void* handle)

int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity, unsigned stop)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);
speed_t s;

static unsigned bit_flags[] = {
Expand Down Expand Up @@ -251,9 +251,9 @@ int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity,
return tcsetattr(h->fd, TCSADRAIN, &h->new_tio) ? gbser_ERROR : gbser_OK;
}

unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len)
unsigned gbser_read_buffer(void* handle, void** buf, unsigned* len)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);
unsigned count = *len;
auto* cp = (unsigned char*) *buf;
if (count > h->inbuf_used) {
Expand All @@ -276,10 +276,10 @@ unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len)
* be updated to indicate the remaining time on exit.
* Returns the number of bytes available (>=0) or an error code (<0).
*/
int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms)
int gbser_fill_buffer(void* handle, unsigned want, unsigned* ms)
{
int rc;
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);

if (want > BUFSIZE) {
want = BUFSIZE;
Expand Down Expand Up @@ -362,7 +362,7 @@ int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms)
*/
int gbser_flush(void* handle)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);
h->inbuf_used = 0;
if (tcflush(h->fd, TCIFLUSH)) {
return gbser_ERROR;
Expand All @@ -375,7 +375,7 @@ int gbser_flush(void* handle)
*/
int gbser_write(void* handle, const void* buf, unsigned len)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);
const char* bp = (const char*) buf;
int rc;
while (len > 0) {
Expand All @@ -402,7 +402,7 @@ int gbser_is_serial(const char* port_name)
int is_port = 0;

if (fd = open(port_name, O_RDWR | O_NOCTTY), fd == -1) {
gbser__db(1, "Failed to open port (%s) to check its type\n", strerror(errno));
gbser_db(1, "Failed to open port (%s) to check its type\n", strerror(errno));
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions gbser_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
#define MYMAGIC 0x91827364
#define BUFSIZE 512

void gbser__db(int l, const char* msg, ...);
int gbser__fill_buffer(void* h, unsigned want, unsigned* ms);
unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len);
void gbser_db(int l, const char* msg, ...);
int gbser_fill_buffer(void* h, unsigned want, unsigned* ms);
unsigned gbser_read_buffer(void* handle, void** buf, unsigned* len);
20 changes: 10 additions & 10 deletions gbser_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct gbser_handle {
#define DEV_PREFIX "\\\\.\\\\"

/* Wrapper to safely cast a void * into a gbser_handle */
static gbser_handle* gbser__get_handle(void* p)
static gbser_handle* gbser_get_handle(void* p)
{
gbser_handle* h = (gbser_handle*) p;
assert(h->magic == MYMAGIC);
Expand Down Expand Up @@ -182,7 +182,7 @@ void* gbser_init(const char* port_name)
gbser_handle* h = (gbser_handle*) xcalloc(1, sizeof(*h));
const char* xname = fix_win_serial_name(port_name);

gbser__db(2, "Translated port name: \"%s\"\n", xname);
gbser_db(2, "Translated port name: \"%s\"\n", xname);

h->magic = MYMAGIC;

Expand Down Expand Up @@ -214,7 +214,7 @@ void* gbser_init(const char* port_name)
*/
void gbser_deinit(void* handle)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);

CloseHandle(h->comport);

Expand All @@ -223,7 +223,7 @@ void gbser_deinit(void* handle)

int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity, unsigned stop)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);
DCB tio;

if (bits < 5 || bits > 8) {
Expand Down Expand Up @@ -266,9 +266,9 @@ int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity,
return gbser_OK;
}

unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len)
unsigned gbser_read_buffer(void* handle, void** buf, unsigned* len)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);
unsigned count = *len;
unsigned char* cp = (unsigned char*) *buf;
if (count > h->inbuf_used) {
Expand All @@ -291,10 +291,10 @@ unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len)
* be updated to indicate the remaining time on exit.
* Returns the number of bytes available (>=0) or an error code (<0).
*/
int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms)
int gbser_fill_buffer(void* handle, unsigned want, unsigned* ms)
{
int rc;
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);

if (want > BUFSIZE) {
want = BUFSIZE;
Expand Down Expand Up @@ -353,7 +353,7 @@ int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms)
*/
int gbser_flush(void* handle)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);
h->inbuf_used = 0;
if (!PurgeComm(h->comport, PURGE_RXCLEAR)) {
return gbser_ERROR;
Expand All @@ -365,7 +365,7 @@ int gbser_flush(void* handle)
*/
int gbser_write(void* handle, const void* buf, unsigned len)
{
gbser_handle* h = gbser__get_handle(handle);
gbser_handle* h = gbser_get_handle(handle);
DWORD nwritten;
const char* bp = (const char*) buf;
/* Not sure we need to spin here - but this'll work even if we don't */
Expand Down
41 changes: 28 additions & 13 deletions wbt-200.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <array> // for array
#include <cctype> // for isprint
#include <cstdarg> // for va_end, va_list, va_start
#include <cstdio> // for size_t, sprintf, fread, fclose, feof
#include <cstdint> // for uint32_t, int32_t, int16_t, uint16_t
#include <cstdlib> // for strtod, strtoul
#include <cstring> // for strlen, memcmp, memcpy
#include <ctime> // for time_t, tm

#include <QByteArray> // for QByteArray
#include <QIntegerForSize> // for qPrintable
#include <QString> // for QString
#include <QVector> // for QVector

#include "defs.h"
#include "gbser.h"
#include "grtcirc.h"
#include <cstdio>
#include <cstdlib>
#include "gbser.h" // for gbser_set_port, gbser_deinit, gbse...


#define MYNAME "WBT-100/200"
#define NL "\x0D\x0A"
Expand Down Expand Up @@ -499,17 +511,20 @@ static double get_param_float(const char* cmd)
}

/* Decompose binary date into discreet fields */
#define _SPLIT_DATE(tim) \
int sec = (((tim) >> 0) & 0x3F); \
int min = (((tim) >> 6) & 0x3F); \
int hour = (((tim) >> 12) & 0x1F); \
int mday = (((tim) >> 17) & 0x1F); \
int mon = (((tim) >> 22) & 0x0F); \
int year = (((tim) >> 26) & 0x3F);
std::array<int, 6> split_date(uint32_t tim)
{
int sec = (((tim) >> 0) & 0x3F);
int min = (((tim) >> 6) & 0x3F);
int hour = (((tim) >> 12) & 0x1F);
int mday = (((tim) >> 17) & 0x1F);
int mon = (((tim) >> 22) & 0x0F);
int year = (((tim) >> 26) & 0x3F);
return {sec, min, hour, mday, mon, year};
}

static time_t decode_date(uint32_t tim)
{
_SPLIT_DATE(tim)
auto [sec, min, hour, mday, mon, year] = split_date(tim);
struct tm t;

t.tm_sec = sec;
Expand All @@ -524,7 +539,7 @@ static time_t decode_date(uint32_t tim)

static int check_date(uint32_t tim)
{
_SPLIT_DATE(tim)
auto [sec, min, hour, mday, mon, year] = split_date(tim);

/* Sanity check the date. We don't allow years prior to 2004 because zero in
* those bits will usually indicate that we have an altitude instead of a
Expand Down

0 comments on commit 368e897

Please sign in to comment.