Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions Applications/ndiBasicExample.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#if _MSC_VER >= 1700
//----------------------------------------------------------------------------
bool ParallelProbe(ndicapi*& outDevice)
bool ParallelProbe(ndicapi*& outDevice, bool checkDSR)
{
const int MAX_SERIAL_PORT_NUMBER = 20; // the serial port is almost surely less than this number
std::vector<bool> deviceExists(MAX_SERIAL_PORT_NUMBER);
Expand All @@ -27,7 +27,7 @@ bool ParallelProbe(ndicapi*& outDevice)
std::lock_guard<std::mutex> guard(deviceNameMutex);
devName = std::string(ndiSerialDeviceName(i));
}
int errnum = ndiSerialProbe(devName.c_str());
int errnum = ndiSerialProbe(devName.c_str(),checkDSR);
if (errnum == NDI_OKAY)
{
deviceExists[i] = true;
Expand Down Expand Up @@ -56,30 +56,38 @@ bool ParallelProbe(ndicapi*& outDevice)

struct ndicapi;

int main()
int main(int argc, char * argv[])
{
bool checkDSR = false;
ndicapi* device(nullptr);
char* name(nullptr);
const char* name(nullptr);

if(argc > 1)
name = argv[1];
else
{
#if _MSC_VER >= 1700
ParallelProbe(device);
ParallelProbe(device,argc > 1 ? argv[1]: 0, checkDSR);
#else
const int MAX_SERIAL_PORTS = 20;
for (int i = 0; i < MAX_SERIAL_PORTS; ++i)
{
name = ndiSerialDeviceName(i);
int result = ndiSerialProbe(name);
if (result == NDI_OKAY)
{
break;
const int MAX_SERIAL_PORTS = 20;
for (int i = 0; i < MAX_SERIAL_PORTS; ++i)
{
name = ndiSerialDeviceName(i);
int result = ndiSerialProbe(name,checkDSR);
if (result == NDI_OKAY)
{
break;
}
}
}
#endif
}

if (name != nullptr)
{
device = ndiOpenSerial(name);
}
#endif

if (device != nullptr)
{
Expand Down
37 changes: 19 additions & 18 deletions ndicapi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGES.

#include <string.h>
#include <stdlib.h>
#include <iostream>

#include <stdio.h>
#include <math.h>

Expand All @@ -68,7 +70,7 @@ namespace
// call the user-supplied callback function
if (pol->ErrorCallback)
{
pol->ErrorCallback(errnum, ndiErrorString(errnum), pol->ErrorCallbackData);
pol->ErrorCallback(errnum, (char*)ndiErrorString(errnum), pol->ErrorCallbackData);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the return type of ndiErrorString is char*, so this is redundant. Is it the ndicapiExport token in ndicapiExport char* ndiErrorString(int errnum); that causes the warning?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, changes to ndiErrorString below, nevermind.

}

return errnum;
Expand Down Expand Up @@ -491,9 +493,9 @@ ndicapiExport int ndiGetSocketError(ndicapi* pol)
}

//----------------------------------------------------------------------------
ndicapiExport char* ndiErrorString(int errnum)
ndicapiExport const char* ndiErrorString(int errnum)
{
static char* textarray_low[] = // values from 0x01 to 0x21
static const char* textarray_low[] = // values from 0x01 to 0x21
{
"No error",
"Invalid command",
Expand Down Expand Up @@ -546,7 +548,7 @@ ndicapiExport char* ndiErrorString(int errnum)
"Invalid input or output state",
};

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

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

static char* textarray_serial[] = // values specific to serial errors
static const char* textarray_serial[] = // values specific to serial errors
{
"Serial DSR query failure",
"Bad reply from measurement system",
Expand Down Expand Up @@ -597,7 +599,7 @@ ndicapiExport char* ndiErrorString(int errnum)
}

//----------------------------------------------------------------------------
ndicapiExport char* ndiSerialDeviceName(int i)
ndicapiExport const char* ndiSerialDeviceName(int i)
{
#if defined(_WIN32)

Expand Down Expand Up @@ -649,7 +651,7 @@ ndicapiExport char* ndiSerialDeviceName(int i)
{
strncpy(devicenames[j], "/dev/", 5);
strncpy(devicenames[j] + 5, ep->d_name, 255);
devicenames[j][255 + 5] == '\0';
devicenames[j][255 + 5] = '\0';
closedir(dirp);
return devicenames[j];
}
Expand Down Expand Up @@ -744,7 +746,6 @@ ndicapiExport int ndiSerialProbe(const char* device, bool checkDSR)
ndiSerialClose(serial_port);
return NDI_BAD_COMM;
}

// flush the buffers (which are unlikely to contain anything)
ndiSerialFlush(serial_port, NDI_IOFLUSH);

Expand Down Expand Up @@ -2184,7 +2185,7 @@ namespace
int newspeed = 9600;
int newhand = 0;

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

bool isBinary = (strncmp(command, "BX", commandLength) == 0 && commandLength == strlen("BX") ||
strncmp(command, "GETLOG", commandLength) == 0 && commandLength == strlen("GETLOG") ||
strncmp(command, "VGET", commandLength) == 0 && commandLength == strlen("VGET"));
bool isBinary = (strncmp(command, "BX", commandLength) == 0 && commandLength == strlen("BX")) ||
(strncmp(command, "GETLOG", commandLength) == 0 && commandLength == strlen("GETLOG")) ||
(strncmp(command, "VGET", commandLength) == 0 && commandLength == strlen("VGET"));


// if the command is GX, TX, or BX and thread_mode is on, we copy the reply from
// the thread rather than getting it directly from the Measurement System
if (api->IsThreadedMode && api->IsTracking &&
commandLength == 2 && (command[0] == 'G' && command[1] == 'X' ||
command[0] == 'T' && command[1] == 'X' ||
command[0] == 'B' && command[1] == 'X'))
commandLength == 2 && ((command[0] == 'G' && command[1] == 'X') ||
(command[0] == 'T' && command[1] == 'X') ||
(command[0] == 'B' && command[1] == 'X')))
{
// check that the thread is sending the GX/BX/TX command that we want
if (strcmp(command, api->ThreadCommand) != 0)
Expand Down Expand Up @@ -2559,7 +2560,7 @@ ndicapiExport char* ndiCommandVA(ndicapi* api, const char* format, va_list ap)
// check for error code
if (commandReply[0] == 'E' && strncmp(commandReply, "ERROR", 5) == 0)
{
ndiSetError(api, ndiHexToUnsignedLong(&commandReply[5], 2));
ndiSetError(api, (int)ndiHexToUnsignedLong(&commandReply[5], 2));
return commandReply;
}

Expand Down Expand Up @@ -3825,7 +3826,7 @@ static void* ndiThreadFunc(void* userdata)
}

// send the command to the Measurement System
i = strlen(command);
i = (int)strlen(command);
if (errorCode == 0)
{
if (pol->SerialDevice != NDI_INVALID_HANDLE)
Expand Down
4 changes: 2 additions & 2 deletions ndicapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ extern "C" {

If \em i is too large, the return value is zero.
*/
ndicapiExport char* ndiSerialDeviceName(int i);
ndicapiExport const char* ndiSerialDeviceName(int i);

/*! \ingroup NDIMethods
Probe for an NDI device on the specified serial port device.
Expand Down Expand Up @@ -1859,7 +1859,7 @@ ndicapiExport int ndiGetIRCHKSourceXY(ndicapi* pol, int side, int i, double xy[2

An unrecognized error code will return "Unrecognized error code".
*/
ndicapiExport char* ndiErrorString(int errnum);
ndicapiExport const char* ndiErrorString(int errnum);

/*! \ingroup ConversionFunctions
Convert \em n characters of a hexidecimal string into an unsigned long.
Expand Down
4 changes: 2 additions & 2 deletions ndicapi_serial_apple.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ ndicapiExport int ndiSerialRead(int serial_port, char* reply, int numberOfBytesT
}

totalNumberOfBytesRead += numberOfBytesRead;
if (!isBinary && reply[totalNumberOfBytesRead - 1] == '\r' /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
|| isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r')
if ((!isBinary && reply[totalNumberOfBytesRead - 1] == '\r') /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
|| (isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r'))
{
break;
}
Expand Down
4 changes: 2 additions & 2 deletions ndicapi_serial_unix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ ndicapiExport int ndiSerialRead(int serial_port, char* reply, int numberOfBytesT
}

totalNumberOfBytesRead += numberOfBytesRead;
if (!isBinary && reply[totalNumberOfBytesRead - 1] == '\r' /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
|| isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r')
if ((!isBinary && reply[totalNumberOfBytesRead - 1] == '\r') /* done when carriage return received (ASCII) or when ERROR... received (binary)*/
|| (isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r'))
{
break;
}
Expand Down
4 changes: 2 additions & 2 deletions ndicapi_socket_unix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ ndicapiExport int ndiSocketRead(NDISocketHandle socket, char* reply, int numberO
}

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