12 void fill_usb_buffer(
int opCodeNumber,
int p1,
int p2,
int p3,
int p4, uint8_t *
data,
int dataLength, uint8_t * bufferToSend,
int &
length)
16 uint8_t * writePtr = bufferToSend;
20 *(uint16_t *)(writePtr + cur_index) = preHeaderData;
21 cur_index +=
sizeof(uint16_t);
22 *(
int *)(writePtr + cur_index) = opCodeNumber;
23 cur_index +=
sizeof(uint32_t);
24 *(
int *)(writePtr + cur_index) = p1;
25 cur_index +=
sizeof(uint32_t);
26 *(
int *)(writePtr + cur_index) = p2;
27 cur_index +=
sizeof(uint32_t);
28 *(
int *)(writePtr + cur_index) = p3;
29 cur_index +=
sizeof(uint32_t);
30 *(
int *)(writePtr + cur_index) = p4;
31 cur_index +=
sizeof(uint32_t);
35 memcpy(writePtr + cur_index, data, dataLength);
36 cur_index += dataLength;
40 *(uint16_t *)bufferToSend = (uint16_t)(length - header_size);
44 void execute_usb_command(uvc::device & device, std::timed_mutex & mutex, uint8_t *out,
size_t outSize, uint32_t & op, uint8_t *
in,
size_t & inSize)
51 if (!mutex.try_lock_for(std::chrono::milliseconds(
IVCAM_MONITOR_MUTEX_TIMEOUT)))
throw std::runtime_error(
"timed_mutex::try_lock_for(...) timed out");
52 std::lock_guard<std::timed_mutex> guard(mutex, std::adopt_lock);
56 std::this_thread::sleep_for(std::chrono::milliseconds(20));
65 if (outXfer < (
int)
sizeof(uint32_t))
throw std::runtime_error(
"incomplete bulk usb transfer");
67 op = *(uint32_t *)buf;
68 if (outXfer > (
int)inSize)
throw std::runtime_error(
"bulk transfer failed - user buffer too small");
70 memcpy(in, buf, inSize);
97 uint32_t opCodeXmit = (uint32_t)newCommand.
cmd;
101 details.TimeOut = newCommand.
TimeOut;
110 details.sendCommandData,
111 details.sizeOfSendCommandData);
120 memcpy(newCommand.
receivedCommandData, details.receivedCommandData, details.receivedCommandDataLength);
124 uint32_t opCodeAsUint32 =
pack(details.receivedOpcode[3], details.receivedOpcode[2], details.receivedOpcode[1], details.receivedOpcode[0]);
125 if (opCodeAsUint32 != opCodeXmit)
127 throw std::runtime_error(
"opcodes do not match");
133 uint32_t opCodeXmit = (uint32_t)newCommand.
cmd;
137 details.TimeOut = newCommand.
TimeOut;
146 details.sendCommandData,
147 details.sizeOfSendCommandData);
156 memcpy(newCommand.
receivedCommandData, details.receivedCommandData, details.receivedCommandDataLength);
160 uint32_t opCodeAsUint32 =
pack(details.receivedOpcode[3], details.receivedOpcode[2], details.receivedOpcode[1], details.receivedOpcode[0]);
161 if (opCodeAsUint32 != opCodeXmit)
163 throw std::runtime_error(
"opcodes do not match");
170 cmd.
Param1 = slave_address;
174 memcpy(cmd.
data, &value,
sizeof(value));
177 std::timed_mutex mutex;
188 cmd.
Param1 = slave_address;
191 const int num_retries = 10;
192 std::timed_mutex mutex;
208 std::this_thread::sleep_for(std::chrono::milliseconds(100));
209 if (retries == num_retries)
215 }
while (retries < num_retries);
222 i2c_read_reg(IRB_opcode, device, 0x42, 0x70,
sizeof(uint32_t), (
byte*)&value);
225 throw std::runtime_error(
to_string() <<
"EEPRom Error" << value);
235 command &= 0x00001FFF;
239 command &= 0xFFFFDFFF;
245 unsigned int lengthR =
size;
246 lengthR = lengthR << 16;
256 i2c_read_reg(IRB_opcode, device, 0x42, 0x70,
sizeof(uint32_t), (
byte*)&value);
259 i2c_read_reg(IRB_opcode, device, 0x42, 0xD0, size, data);
262 void get_raw_data(uint8_t opcode, uvc::device & device, std::timed_mutex & mutex, uint8_t *
data,
size_t & bytesReturned)
const uint8_t IVCAM_MONITOR_ENDPOINT_IN
size_t receivedCommandDataLength
uint8_t receivedOpcode[4]
int sizeOfSendCommandData
uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
void fill_usb_buffer(int opCodeNumber, int p1, int p2, int p3, int p4, uint8_t *data, int dataLength, uint8_t *bufferToSend, int &length)
uint8_t data[HW_MONITOR_BUFFER_SIZE]
void check_eeprom_read_write_status(int IRB_opcode, uvc::device &device)
GLenum GLuint GLenum GLsizei const GLchar * buf
uint8_t receivedCommandData[HW_MONITOR_BUFFER_SIZE]
const uint16_t IVCAM_MONITOR_MAGIC_NUMBER
uint8_t sendCommandData[HW_MONITOR_COMMAND_SIZE]
void perform_and_send_monitor_command(uvc::device &device, std::timed_mutex &mutex, hwmon_cmd &newCommand)
void execute_usb_command(uvc::device &device, std::timed_mutex &mutex, uint8_t *out, size_t outSize, uint32_t &op, uint8_t *in, size_t &inSize)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
void read_from_eeprom(int IRB_opcode, int IWB_opcode, uvc::device &device, unsigned int offset, int size, byte *data)
const uint16_t IVCAM_MONITOR_MAX_BUFFER_SIZE
GLsizei const GLfloat * value
size_t receivedCommandDataLength
uint8_t receivedCommandData[HW_MONITOR_BUFFER_SIZE]
const uint16_t HW_MONITOR_BUFFER_SIZE
void bulk_transfer(device &device, unsigned char endpoint, void *data, int length, int *actual_length, unsigned int timeout)
void i2c_write_reg(int command, uvc::device &device, uint16_t slave_address, uint16_t reg, uint32_t value)
GLuint GLsizei GLsizei * length
int sizeOfSendCommandData
void i2c_read_reg(int command, uvc::device &device, uint16_t slave_address, uint16_t reg, uint32_t size, byte *data)
void send_hw_monitor_command(uvc::device &device, std::timed_mutex &mutex, hwmon_cmd_details &details)
void get_raw_data(uint8_t opcode, uvc::device &device, std::timed_mutex &mutex, uint8_t *data, size_t &bytesReturned)
const uint8_t IVCAM_MONITOR_ENDPOINT_OUT
const uint16_t IVCAM_MONITOR_MUTEX_TIMEOUT
uint8_t receivedOpcode[4]