Skip to content

Commit c37d61d

Browse files
eruffaldiadamrankin
authored andcommitted
various changes for removing warning in macOS and Linux compilation: const char, error in probe python, || and && (#16)
added BX to Python
1 parent 7267df1 commit c37d61d

7 files changed

Lines changed: 154 additions & 52 deletions

File tree

Applications/ndiBasicExample.cxx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#if _MSC_VER >= 1700
1313
//----------------------------------------------------------------------------
14-
bool ParallelProbe(ndicapi*& outDevice)
14+
bool ParallelProbe(ndicapi*& outDevice, bool checkDSR)
1515
{
1616
const int MAX_SERIAL_PORT_NUMBER = 20; // the serial port is almost surely less than this number
1717
std::vector<bool> deviceExists(MAX_SERIAL_PORT_NUMBER);
@@ -27,7 +27,7 @@ bool ParallelProbe(ndicapi*& outDevice)
2727
std::lock_guard<std::mutex> guard(deviceNameMutex);
2828
devName = std::string(ndiSerialDeviceName(i));
2929
}
30-
int errnum = ndiSerialProbe(devName.c_str());
30+
int errnum = ndiSerialProbe(devName.c_str(),checkDSR);
3131
if (errnum == NDI_OKAY)
3232
{
3333
deviceExists[i] = true;
@@ -56,30 +56,38 @@ bool ParallelProbe(ndicapi*& outDevice)
5656

5757
struct ndicapi;
5858

59-
int main()
59+
int main(int argc, char * argv[])
6060
{
61+
bool checkDSR = false;
6162
ndicapi* device(nullptr);
62-
char* name(nullptr);
63+
const char* name(nullptr);
6364

65+
if(argc > 1)
66+
name = argv[1];
67+
else
68+
{
6469
#if _MSC_VER >= 1700
65-
ParallelProbe(device);
70+
ParallelProbe(device,argc > 1 ? argv[1]: 0, checkDSR);
6671
#else
67-
const int MAX_SERIAL_PORTS = 20;
68-
for (int i = 0; i < MAX_SERIAL_PORTS; ++i)
69-
{
70-
name = ndiSerialDeviceName(i);
71-
int result = ndiSerialProbe(name);
72-
if (result == NDI_OKAY)
7372
{
74-
break;
73+
const int MAX_SERIAL_PORTS = 20;
74+
for (int i = 0; i < MAX_SERIAL_PORTS; ++i)
75+
{
76+
name = ndiSerialDeviceName(i);
77+
int result = ndiSerialProbe(name,checkDSR);
78+
if (result == NDI_OKAY)
79+
{
80+
break;
81+
}
82+
}
7583
}
84+
#endif
7685
}
7786

7887
if (name != nullptr)
7988
{
8089
device = ndiOpenSerial(name);
8190
}
82-
#endif
8391

8492
if (device != nullptr)
8593
{

ndicapi.cxx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGES.
4242

4343
#include <string.h>
4444
#include <stdlib.h>
45+
#include <iostream>
46+
4547
#include <stdio.h>
4648
#include <math.h>
4749

@@ -68,7 +70,7 @@ namespace
6870
// call the user-supplied callback function
6971
if (pol->ErrorCallback)
7072
{
71-
pol->ErrorCallback(errnum, ndiErrorString(errnum), pol->ErrorCallbackData);
73+
pol->ErrorCallback(errnum, (char*)ndiErrorString(errnum), pol->ErrorCallbackData);
7274
}
7375

7476
return errnum;
@@ -491,9 +493,9 @@ ndicapiExport int ndiGetSocketError(ndicapi* pol)
491493
}
492494

493495
//----------------------------------------------------------------------------
494-
ndicapiExport char* ndiErrorString(int errnum)
496+
ndicapiExport const char* ndiErrorString(int errnum)
495497
{
496-
static char* textarray_low[] = // values from 0x01 to 0x21
498+
static const char* textarray_low[] = // values from 0x01 to 0x21
497499
{
498500
"No error",
499501
"Invalid command",
@@ -546,7 +548,7 @@ ndicapiExport char* ndiErrorString(int errnum)
546548
"Invalid input or output state",
547549
};
548550

549-
static char* textarray_high[] = // values from 0xf6 to 0xf4
551+
static const char* textarray_high[] = // values from 0xf6 to 0xf4
550552
{
551553
"Too much environmental infrared",
552554
"Unrecognized error code",
@@ -556,7 +558,7 @@ ndicapiExport char* ndiErrorString(int errnum)
556558
"Unable to read Flash EPROM",
557559
};
558560

559-
static char* textarray_api[] = // values specific to the API
561+
static const char* textarray_api[] = // values specific to the API
560562
{
561563
"Bad CRC on reply from Measurement System",
562564
"Error opening serial connection",
@@ -568,7 +570,7 @@ ndicapiExport char* ndiErrorString(int errnum)
568570
"Measurement System not found on specified port"
569571
};
570572

571-
static char* textarray_serial[] = // values specific to serial errors
573+
static const char* textarray_serial[] = // values specific to serial errors
572574
{
573575
"Serial DSR query failure",
574576
"Bad reply from measurement system",
@@ -597,7 +599,7 @@ ndicapiExport char* ndiErrorString(int errnum)
597599
}
598600

599601
//----------------------------------------------------------------------------
600-
ndicapiExport char* ndiSerialDeviceName(int i)
602+
ndicapiExport const char* ndiSerialDeviceName(int i)
601603
{
602604
#if defined(_WIN32)
603605

@@ -649,7 +651,7 @@ ndicapiExport char* ndiSerialDeviceName(int i)
649651
{
650652
strncpy(devicenames[j], "/dev/", 5);
651653
strncpy(devicenames[j] + 5, ep->d_name, 255);
652-
devicenames[j][255 + 5] == '\0';
654+
devicenames[j][255 + 5] = '\0';
653655
closedir(dirp);
654656
return devicenames[j];
655657
}
@@ -744,7 +746,6 @@ ndicapiExport int ndiSerialProbe(const char* device, bool checkDSR)
744746
ndiSerialClose(serial_port);
745747
return NDI_BAD_COMM;
746748
}
747-
748749
// flush the buffers (which are unlikely to contain anything)
749750
ndiSerialFlush(serial_port, NDI_IOFLUSH);
750751

@@ -2184,7 +2185,7 @@ namespace
21842185
int newspeed = 9600;
21852186
int newhand = 0;
21862187

2187-
if (command[5] >= '0' && command[5] <= '7' || command[5] == 'A')
2188+
if ((command[5] >= '0' && command[5] <= '7') || command[5] == 'A')
21882189
{
21892190
if (command[5] != 'A')
21902191
{
@@ -2353,17 +2354,17 @@ ndicapiExport char* ndiCommandVA(ndicapi* api, const char* format, va_list ap)
23532354
command[i++] = '\r'; // tack on carriage return
23542355
command[i] = '\0'; // terminate for good luck
23552356

2356-
bool isBinary = (strncmp(command, "BX", commandLength) == 0 && commandLength == strlen("BX") ||
2357-
strncmp(command, "GETLOG", commandLength) == 0 && commandLength == strlen("GETLOG") ||
2358-
strncmp(command, "VGET", commandLength) == 0 && commandLength == strlen("VGET"));
2357+
bool isBinary = (strncmp(command, "BX", commandLength) == 0 && commandLength == strlen("BX")) ||
2358+
(strncmp(command, "GETLOG", commandLength) == 0 && commandLength == strlen("GETLOG")) ||
2359+
(strncmp(command, "VGET", commandLength) == 0 && commandLength == strlen("VGET"));
23592360

23602361

23612362
// if the command is GX, TX, or BX and thread_mode is on, we copy the reply from
23622363
// the thread rather than getting it directly from the Measurement System
23632364
if (api->IsThreadedMode && api->IsTracking &&
2364-
commandLength == 2 && (command[0] == 'G' && command[1] == 'X' ||
2365-
command[0] == 'T' && command[1] == 'X' ||
2366-
command[0] == 'B' && command[1] == 'X'))
2365+
commandLength == 2 && ((command[0] == 'G' && command[1] == 'X') ||
2366+
(command[0] == 'T' && command[1] == 'X') ||
2367+
(command[0] == 'B' && command[1] == 'X')))
23672368
{
23682369
// check that the thread is sending the GX/BX/TX command that we want
23692370
if (strcmp(command, api->ThreadCommand) != 0)
@@ -2559,7 +2560,7 @@ ndicapiExport char* ndiCommandVA(ndicapi* api, const char* format, va_list ap)
25592560
// check for error code
25602561
if (commandReply[0] == 'E' && strncmp(commandReply, "ERROR", 5) == 0)
25612562
{
2562-
ndiSetError(api, ndiHexToUnsignedLong(&commandReply[5], 2));
2563+
ndiSetError(api, (int)ndiHexToUnsignedLong(&commandReply[5], 2));
25632564
return commandReply;
25642565
}
25652566

@@ -3825,7 +3826,7 @@ static void* ndiThreadFunc(void* userdata)
38253826
}
38263827

38273828
// send the command to the Measurement System
3828-
i = strlen(command);
3829+
i = (int)strlen(command);
38293830
if (errorCode == 0)
38303831
{
38313832
if (pol->SerialDevice != NDI_INVALID_HANDLE)

ndicapi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ extern "C" {
209209
210210
If \em i is too large, the return value is zero.
211211
*/
212-
ndicapiExport char* ndiSerialDeviceName(int i);
212+
ndicapiExport const char* ndiSerialDeviceName(int i);
213213

214214
/*! \ingroup NDIMethods
215215
Probe for an NDI device on the specified serial port device.
@@ -1859,7 +1859,7 @@ ndicapiExport int ndiGetIRCHKSourceXY(ndicapi* pol, int side, int i, double xy[2
18591859
18601860
An unrecognized error code will return "Unrecognized error code".
18611861
*/
1862-
ndicapiExport char* ndiErrorString(int errnum);
1862+
ndicapiExport const char* ndiErrorString(int errnum);
18631863

18641864
/*! \ingroup ConversionFunctions
18651865
Convert \em n characters of a hexidecimal string into an unsigned long.

ndicapi_serial_apple.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ ndicapiExport int ndiSerialRead(int serial_port, char* reply, int numberOfBytesT
356356
}
357357

358358
totalNumberOfBytesRead += numberOfBytesRead;
359-
if (!isBinary && reply[totalNumberOfBytesRead - 1] == '\r' /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
360-
|| isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r')
359+
if ((!isBinary && reply[totalNumberOfBytesRead - 1] == '\r') /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
360+
|| (isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r'))
361361
{
362362
break;
363363
}

ndicapi_serial_unix.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ ndicapiExport int ndiSerialRead(int serial_port, char* reply, int numberOfBytesT
433433
}
434434

435435
totalNumberOfBytesRead += numberOfBytesRead;
436-
if (!isBinary && reply[totalNumberOfBytesRead - 1] == '\r' /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
437-
|| isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r')
436+
if ((!isBinary && reply[totalNumberOfBytesRead - 1] == '\r') /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
437+
|| (isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r'))
438438
{
439439
break;
440440
}

ndicapi_socket_unix.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ ndicapiExport int ndiSocketRead(NDISocketHandle socket, char* reply, int numberO
132132
}
133133

134134
totalNumberOfBytesRead += numberOfBytesRead;
135-
if (!isBinary && reply[totalNumberOfBytesRead - 1] == '\r' /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
136-
|| isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r')
135+
if ((!isBinary && reply[totalNumberOfBytesRead - 1] == '\r') /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
136+
|| (isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r'))
137137
{
138138
break;
139139
}

0 commit comments

Comments
 (0)