Skip to content

Commit

Permalink
updated source in root
Browse files Browse the repository at this point in the history
  • Loading branch information
Grix committed Oct 16, 2016
1 parent 3f4f795 commit d0bdf7b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
16 changes: 9 additions & 7 deletions sdk/HeliosDac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int HeliosDac::SendFrame(int devNum, uint8_t* bufferAddress, int bufferSize)
//returns 1 if successful
int HeliosDac::SendControl(int devNum, uint8_t* bufferAddress, int length)
{
if ((bufferAddress == NULL) || (!inited) || (devNum >= numOfDevices))
if ((bufferAddress == NULL) || (!inited) || (devNum >= numOfDevices) || (length > 32) || (length <= 0))
return 0;

int actualLength = 0;
Expand All @@ -107,21 +107,23 @@ int HeliosDac::SendControl(int devNum, uint8_t* bufferAddress, int length)

//Attempts to receive a response to a previous control transfer.
//Returns length of packet >0 , and populates bufferAddress on success
int HeliosDac::GetControlResponse(int devNum, uint8_t* bufferAddress)
int HeliosDac::GetControlResponse(int devNum, uint8_t* bufferAddress, int length)
{
if ((bufferAddress == NULL) || (!inited) || (devNum >= numOfDevices))
if ((bufferAddress == NULL) || (!inited) || (devNum >= numOfDevices) || (length > 32) || (length <= 0))
return 0;

uint8_t data[32];
int actualLength = 0;
int transferResult = libusb_interrupt_transfer(deviceList[devNum], EP_INT_IN, &data[0], 32, &actualLength, 64);

int transferResult = libusb_interrupt_transfer(deviceList[devNum], EP_INT_IN, &data[0], length, &actualLength, 32);
if (transferResult < 0)
{
return transferResult;
}
else
{
memcpy(bufferAddress, &data[0], actualLength);
return actualLength;
memcpy(bufferAddress, &data[0], length);
return 1;
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/HeliosDac.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class HeliosDac
int OpenDevices();
int CloseDevices();
int SendControl(int devNum, uint8_t* bufferAddress, int length);
int GetControlResponse(int devNum, uint8_t* bufferAddress);
int GetControlResponse(int devNum, uint8_t* bufferAddress, int length);
int SendFrame(int devNum, uint8_t* bufferAddress, int bufferSize);

int numOfDevices = 0;
Expand Down
18 changes: 9 additions & 9 deletions sdk/HeliosDacAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ int GetName(int dacNum, char* name)
if (!inited)
return -1;

uint8_t ctrlBuffer[32] = { 0x05 };
int tx = dacController->SendControl(dacNum, &ctrlBuffer[0], 1);
uint8_t ctrlBuffer[32] = { 0x05, 0 };
int tx = dacController->SendControl(dacNum, &ctrlBuffer[0], 2);
if (tx == 1)
{
tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0]);
if (tx > 0)
tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0], 32);
if (tx == 1)
{
if ((ctrlBuffer[0]) == 0x85) //if received control byte is as expected
{
Expand Down Expand Up @@ -112,8 +112,8 @@ int GetStatus(int dacNum)
if (tx != 1)
return -1;

tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0]);
if (tx > 0)
tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0], 2);
if (tx == 1)
{
if ((ctrlBuffer[0]) == 0x83) //if received control byte is as expected
{
Expand Down Expand Up @@ -147,7 +147,7 @@ int GetFirmwareVersion(int dacNum)
if (tx != 1)
return -1;

tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0]);
tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0], 5);
if (tx == 1)
{
if ((ctrlBuffer[0]) == 0x84) //if received control byte is as expected
Expand All @@ -159,7 +159,7 @@ int GetFirmwareVersion(int dacNum)
}
}
else
return -1;
return 0;
}

int CloseDevices()
Expand Down Expand Up @@ -347,4 +347,4 @@ OLSC_API int __stdcall OLSC_ReadTTL(int device_number, DWORD& data)
return OLSC_ERROR_NONE;
}

#endif
#endif

0 comments on commit d0bdf7b

Please sign in to comment.