Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, const char * argv[])
- {
- #pragma mark - Constants
- static const UInt32 GDHEM6310FProductID = 0x0094;
- static const UInt32 GDHEM6310FVendorID = 0x0590;
- static const size_t AccessEndOkResonposeSize = 9;
- static const size_t AccessStartResonposeSize = 25;
- #pragma mark - Variables
- int response;
- bool found = FALSE;
- unsigned char buf[64];
- hid_device *device;
- int i;
- size_t buffer_length = 0;
- #pragma mark - Params (When converted to a function)
- unsigned char buffer[2850];
- int user = 1;
- #pragma mark - Device Lookup
- struct hid_device_info *devs, *cur_dev;
- devs = hid_enumerate(GDHEM6310FVendorID, GDHEM6310FProductID);
- cur_dev = devs;
- hid_free_enumeration(devs);
- // Open the device using the VID, PID, last param optional
- device = hid_open(GDHEM6310FVendorID, GDHEM6310FProductID, NULL);
- if (device == NULL) {
- printf("NFC Tray not found\n");
- return 1;
- }
- hid_set_nonblocking(device, 0);
- #pragma mark - Access Start Command
- for (i = 0; i < 24; i++)
- {
- printf("\nSending AccessStart Command\n");
- buf[0] = 0x02; // reportID
- buf[1] = 0x08;
- buf[2] = 0x00;
- buf[3] = 0x00;
- buf[4] = 0x00;
- buf[5] = 0x00;
- buf[6] = 0x10;
- buf[7] = 0x00;
- buf[8] = 0x18;
- printf("\nBytes to Write \n");
- for (size_t i = 0; i < sizeof(buf); i++) {
- printf("%02X ", buf[i]);
- }
- //send acces start command
- bool result = hid_write(device, buf, 9);
- if (!result) {
- printf("Device Error");
- printf("Error: %ls\n", hid_error(device));
- return 1;
- }
- // Read start command response from device
- response = hid_read(device, buf, AccessStartResonposeSize);
- // Log out our response
- printf("\n");
- printf("\nResponse Size: %i\n", response);
- for (size_t i = 0; i < sizeof(buf); i++){
- printf("%02X ", buf[i]);
- }
- if (response < 0) {
- printf("Unable to read()\n");
- }
- if (buf[2] == 0xFF) {
- printf("Device Error buf[1] == 0xFF");
- printf("Error: %ls\n", hid_error(device));
- return 1;
- }
- if (buf[1] == 0x08 && buf[7] == 0x00) {
- printf("Device Error buf[0] == 0x08 && buf[6] == 0x00 \n");
- printf("Error: %ls\n", hid_error(device));
- return 1;
- }
- if (buf[1] != 0x18) {
- continue;
- }
- if (buf[7] != 0x00 ||
- buf[8] != 0x00 ||
- buf[9] != 0x00 ||
- buf[10] != 0x94 ||
- buf[11] != 0x00 ||
- buf[12] != 0x03 )
- {
- printf("unknown model \n");
- printf("Error: %ls\n", hid_error(device));
- }
- found = TRUE;
- // Add elements to the buffer array
- memcpy(buffer + buffer_length, buf + 8, 16);
- buffer_length += 16;
- break;
- }
- if (!found) {
- printf("\nDevice not found \n");
- printf("Error: %ls\n", hid_error(device));
- return 1;
- }
- #pragma mark - Read Settings Index
- if (true)
- {
- printf("\nReading setting index \n");
- buf[0] = 0x02;
- buf[1] = 0x08;
- buf[2] = 0x01;
- buf[3] = 0x00;
- buf[4] = 0x0F;
- buf[5] = 0x74;
- buf[6] = 0x1E;
- buf[7] = 0x00;
- buf[8] = 0x6C;
- // TODO: Check for Cancellation Here
- printf("Bytes to write for setting index: \n");
- for (size_t i = 0; i < sizeof(buf); i++) {
- printf("%02X ", buf[i]);
- }
- // Write Command
- bool result = hid_write(device, buf, 64);
- if (!result) {
- printf("Device Error result from write failed");
- printf("Error: %ls\n", hid_error(device));
- return 1;
- }
- // TODO: Check For Cancellation
- // Read Report
- response = hid_read(device, buf, 64);
- printf("\n");
- printf("Bytes read from setting index \n");
- for (size_t i = 0; i < 64; i++) {
- printf("%02X ", buf[i]);
- }
- // TODO: Check For Cancellation
- if (buf[2] == 0xFF) {
- printf("\nDevice Error on setting index read\n");
- printf("Error: %ls\n", hid_error(device));
- return 1;
- }
- // Add items to buffer
- memcpy(buffer + buffer_length, buf + 8, 30);
- buffer_length += 30;
- }
- #pragma mark - Read Data
- for (int address = 0x0370; address < 0x0370 + 1400 + 1400; address += 28)
- {
- printf("\nReading Data: 0x%04x \n", address);
- buf[0] = 0x02;
- buf[1] = 0x08;
- buf[2] = 0x01;
- buf[3] = 0x00;
- buf[4] = (address >> 8) & 0xff;
- buf[5] = (address & 0xff);
- buf[6] = 0x1C;
- buf[7] = 0x00;
- buf[8] = (buf[1] ^ buf[2] ^ buf[3] ^ buf[4] ^ buf[5] ^ buf[6] ^ buf[7]);
- // TODO: Check For Cancellation
- printf("\nBytes to write for reading data: \n");
- for (size_t i = 0; i < 64; i++) {
- printf("%02X ", buf[i]);
- }
- // Write Command
- bool result = hid_write(device, buf, 64);
- if (!result) {
- printf("Device Error result from write failed");
- printf("Error: %ls\n", hid_error(device));
- return 1;
- }
- // TODO: Check For Cancellation
- // Read Report
- response = hid_read(device, buf, 64);
- // Log out our response
- printf("\n");
- printf("\nRead Data response size: %i\n", response);
- for (size_t i = 0; i < 64; i++) {
- printf("%02X ", buf[i]);
- }
- // TODO: Check For Cancellation
- if (buf[2] == 0xFF) {
- printf("read data device error");
- return 1;
- }
- // Add elements to buffer array
- memcpy(buffer + buffer_length, buf + 8, 28);
- buffer_length += 28;
- printf("buffer_length = %zu", buffer_length);
- }
- #pragma mark - User Conditions
- if (user == 1)
- {
- // Zero out setting index, block 0, bytes 3 and 4
- for (size_t i = 16 + 2; i < 16; i++){
- buffer[i] = 0x00;
- }
- // Zero out setting index, block 0, bytes 7 and 8
- for (size_t i = 16 + 6; i < 16 + 2; i++){
- buffer[i] = 0x00;
- }
- // Zero out setting index, block 2
- for (size_t i = 16 + 8 + 6; i < 16 + 8 + 6 + 6; i++){
- buffer[i] = 0x00;
- }
- // Zero out user2 blood pressure data
- for (size_t i = 16 + 30 + 1400; i < 16 + 30 + 1400 + 1400; i++){
- buffer[i] = 0x00;
- }
- // Log out the buffer
- for (size_t i= 0; i < sizeof(buffer); i++) {
- printf("%02X ", buffer[i]);
- }
- }
- else
- {
- // Zero out setting index, block 0, bytes 1 and 2
- for (size_t i = 16; i < 16 + 2; i++){
- buffer[i] = 0x00;
- }
- // Zero out setting index, block 0, bytes 5 and 6
- for (size_t i = 16 + 4; i < 16 + 4 +2; i++){
- buffer[i] = 0x00;
- }
- // Zero out setting index, block 1
- for (size_t i = 16 + 8; i < 16 + 8 + 6; i++){
- buffer[i] = 0x00;
- }
- // Zero out user1 blood pressure data
- for (size_t i = 16 + 30; i < 16 + 30 + 1400; i++){
- buffer[i] = 0x00;
- }
- // Log out the buffer
- for (size_t i= 0; i < sizeof(buffer); i++) {
- printf("%02X ", buffer[i]);
- }
- }
- # pragma mark - Access End Command
- if (true)
- {
- printf("\nSending AccessEnd Command \n");
- buf[0] = 0x02;
- buf[1] = 0x08;
- buf[2] = 0x0f;
- buf[3] = 0x00;
- buf[4] = 0x00;
- buf[5] = 0x00;
- buf[6] = 0x00;
- buf[7] = 0x00;
- buf[8] = 0x07;
- printf("\nBytes to write for AccessEnd command \n");
- for (int i = 0; i < 9; i++){
- printf("%02X ", buf[i]);
- }
- // Write Commmand
- bool result = hid_write(device, buf, 9);
- if (!result){
- printf("Device Error writing AccessEnd Command");
- return 1;
- }
- // Read Response
- response = hid_read(device, buf, AccessEndOkResonposeSize);
- // Log Response
- printf("\n");
- printf("\nresponse size: %i\n", response);
- for (int i = 0; i < AccessEndOkResonposeSize; i++){
- printf("%02X ", buf[i]);
- }
- if (buf[2] == 0xFF){
- printf("\nDevice error in AccessEnd Command \n");
- return 1;
- }
- printf("Closing Device");
- //hid_close(device);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement