Added support for sending multiple datarefs to the C client.
This commit is contained in:
@@ -365,33 +365,47 @@ int readDATA(XPCSocket sock, float data[][9], int rows)
|
|||||||
/**** DREF functions ****/
|
/**** DREF functions ****/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int sendDREF(XPCSocket sock, const char* dref, float value[], int size)
|
int sendDREF(XPCSocket sock, const char* dref, float value[], int size)
|
||||||
|
{
|
||||||
|
return sendDREFs(sock, &dref, &value, &size, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sendDREFs(XPCSocket sock, const char* drefs[], float* values[], int sizes[], int count)
|
||||||
{
|
{
|
||||||
// Setup command
|
// Setup command
|
||||||
// 5 byte header + max 255 char dref name + max 255 values * 4 bytes per value = 1279
|
// Max size is technically unlimited.
|
||||||
unsigned char buffer[1279] = "DREF";
|
unsigned char buffer[65536] = "DREF";
|
||||||
int drefLen = strnlen(dref, 256);
|
int pos = 5;
|
||||||
if (drefLen > 255)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
printError("setDREF", "dref length is too long. Must be less than 256 characters.");
|
int drefLen = strnlen(drefs[i], 256);
|
||||||
return -1;
|
if (pos + drefLen + sizes[i] * 4 + 2 > 65536)
|
||||||
}
|
{
|
||||||
if (size > 255)
|
printError("sendDREF", "About to overrun the send buffer!");
|
||||||
{
|
return -4;
|
||||||
printError("setDREF", "size is too big. Must be less than 256.");
|
}
|
||||||
return -2;
|
if (drefLen > 255)
|
||||||
}
|
{
|
||||||
int len = 7 + drefLen + size * sizeof(float);
|
printError("sendDREF", "dref %d is too long. Must be less than 256 characters.", i);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (sizes[i] > 255)
|
||||||
|
{
|
||||||
|
printError("sendDREF", "size %d is too big. Must be less than 256.", i);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
// Copy dref to buffer
|
||||||
|
buffer[pos++] = (unsigned char)drefLen;
|
||||||
|
memcpy(buffer + pos, drefs[i], drefLen);
|
||||||
|
pos += drefLen;
|
||||||
|
|
||||||
// Copy dref to buffer
|
// Copy values to buffer
|
||||||
buffer[5] = (unsigned char)drefLen;
|
buffer[pos++] = (unsigned char)sizes[i];
|
||||||
memcpy(buffer + 6, dref, drefLen);
|
memcpy(buffer + pos, values[i], sizes[i] * sizeof(float));
|
||||||
|
pos += sizes[i] * sizeof(float);
|
||||||
// Copy values to buffer
|
}
|
||||||
buffer[6 + drefLen] = (unsigned char)size;
|
|
||||||
memcpy(buffer + 7 + drefLen, value, size * sizeof(float));
|
|
||||||
|
|
||||||
// Send command
|
// Send command
|
||||||
if (sendUDP(sock, buffer, len) < 0)
|
if (sendUDP(sock, buffer, pos) < 0)
|
||||||
{
|
{
|
||||||
printError("setDREF", "Failed to send command");
|
printError("setDREF", "Failed to send command");
|
||||||
return -3;
|
return -3;
|
||||||
|
|||||||
@@ -127,13 +127,27 @@ int sendDATA(XPCSocket sock, float data[][9], int rows);
|
|||||||
/// http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html. The size of values should match
|
/// http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html. The size of values should match
|
||||||
/// the size given on that page. XPC currently sends all values as floats regardless of
|
/// the size given on that page. XPC currently sends all values as floats regardless of
|
||||||
/// the type described on the wiki. This doesn't cause any data loss for most datarefs.
|
/// the type described on the wiki. This doesn't cause any data loss for most datarefs.
|
||||||
/// \param sock The socket to use to send the command.
|
/// \param sock The socket to use to send the command.
|
||||||
/// \param dref The name of the dataref to set.
|
/// \param dref The name of the dataref to set.
|
||||||
/// \param values An array of values representing the data to set.
|
/// \param value An array of values representing the data to set.
|
||||||
/// \param size The number of elements in values.
|
/// \param size The number of elements in values.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
int sendDREF(XPCSocket sock, const char* dref, float value[], int size);
|
int sendDREF(XPCSocket sock, const char* dref, float value[], int size);
|
||||||
|
|
||||||
|
/// Sets the specified datarefs to the specified values.
|
||||||
|
///
|
||||||
|
/// \details dref names and their associated data types can be found on the XPSDK wiki at
|
||||||
|
/// http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html. The size of values should match
|
||||||
|
/// the size given on that page. XPC currently sends all values as floats regardless of
|
||||||
|
/// the type described on the wiki. This doesn't cause any data loss for most datarefs.
|
||||||
|
/// \param sock The socket to use to send the command.
|
||||||
|
/// \param drefs The names of the datarefs to set.
|
||||||
|
/// \param values A multidimensional array containing the values for each dataref to set.
|
||||||
|
/// \param sizes The number of elements in each array in values
|
||||||
|
/// \param count The number of datarefs being set.
|
||||||
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
|
int sendDREFs(XPCSocket sock, const char* drefs[], float* values[], int sizes[], int count);
|
||||||
|
|
||||||
/// Gets the value of the specified dataref.
|
/// Gets the value of the specified dataref.
|
||||||
///
|
///
|
||||||
/// \details dref names and their associated data types can be found on the XPSDK wiki at
|
/// \details dref names and their associated data types can be found on the XPSDK wiki at
|
||||||
|
|||||||
Reference in New Issue
Block a user