示例#1
0
文件: adb_packet.c 项目: 21rcc/ioio
static void ADBPacketSendTasks() {
  BYTE ret_val;
  switch (adb_packet_send_state) {
   case ADB_PACKET_STATE_START:
    if (USBHostAndroidWrite((BYTE*) &adb_packet_send_header,
                            sizeof(ADB_PACKET_HEADER),
                            ANDROID_INTERFACE_ADB) != USB_SUCCESS) {
      CHANGE_STATE(adb_packet_send_state, ADB_PACKET_STATE_ERROR);
      break;
    }
    CHANGE_STATE(adb_packet_send_state, ADB_PACKET_STATE_WAIT_HEADER);
    break;

   case ADB_PACKET_STATE_WAIT_HEADER:
    if (USBHostAndroidTxIsComplete(&ret_val, ANDROID_INTERFACE_ADB)) {
      if (ret_val != USB_SUCCESS) {
        CHANGE_STATE(adb_packet_send_state, ADB_PACKET_STATE_ERROR);
        break;
      }
      if (adb_packet_send_header.data_length == 0) {
        CHANGE_STATE(adb_packet_send_state, ADB_PACKET_STATE_IDLE);
        break;
      }
      if (USBHostAndroidWrite(adb_packet_send_data,
                              adb_packet_send_header.data_length,
                              ANDROID_INTERFACE_ADB) != USB_SUCCESS) {
        CHANGE_STATE(adb_packet_send_state, ADB_PACKET_STATE_ERROR);
        break;
      }
      CHANGE_STATE(adb_packet_send_state, ADB_PACKET_STATE_WAIT_DATA);
    }
    break;

   case ADB_PACKET_STATE_WAIT_DATA:
    if (USBHostAndroidTxIsComplete(&ret_val, ANDROID_INTERFACE_ADB)) {
      if (ret_val != USB_SUCCESS) {
        CHANGE_STATE(adb_packet_send_state, ADB_PACKET_STATE_ERROR);
        break;
      }
      CHANGE_STATE(adb_packet_send_state, ADB_PACKET_STATE_IDLE);
    }
    break;

   case ADB_PACKET_STATE_IDLE:
   case ADB_PACKET_STATE_ERROR:
    break;
  }
}
示例#2
0
int AccessoryTasks() {
  DWORD size;
  BYTE err;

  switch (channel_state) {
    case CHANNEL_INIT:
      USBHostAndroidRead(rx_buf, 1, ANDROID_INTERFACE_ACC);
      channel_state = CHANNEL_WAIT_OPEN;
      break;

    case CHANNEL_WAIT_OPEN:
      if (USBHostAndroidRxIsComplete(&err, &size, ANDROID_INTERFACE_ACC)) {
        if (err != USB_SUCCESS) {
          log_printf("Read failed with error code %d", err);
          return -1;
        }
        USBHostAndroidWrite(&is_channel_open, 1, ANDROID_INTERFACE_ACC);
        if (is_channel_open) {
          USBHostAndroidRead(rx_buf, rx_buf_size, ANDROID_INTERFACE_ACC);
          channel_state = CHANNEL_OPEN;
        } else {
          channel_state = CHANNEL_WAIT_CLOSED;
        }
      }
      break;

    case CHANNEL_OPEN:
      if (USBHostAndroidRxIsComplete(&err, &size, ANDROID_INTERFACE_ACC)) {
        if (err != USB_SUCCESS) {
          log_printf("Read failed with error code %d", err);
          return -1;
        }
        if (size) {
          callback(0, rx_buf, size);
        }
        // Channel might have been closed from within the callback.
        if (channel_state == CHANNEL_OPEN) {
          USBHostAndroidRead(rx_buf, rx_buf_size, ANDROID_INTERFACE_ACC);
        }
      }
      break;

    case CHANNEL_WAIT_CLOSED:
      if (USBHostAndroidTxIsComplete(&err, ANDROID_INTERFACE_ACC)) {
        if (err != USB_SUCCESS) {
          log_printf("Write failed with error code %d", err);
          return -1;
        }
        callback(0, NULL, 0);
        channel_state = CHANNEL_INIT;
      }
      break;
  }
  return channel_state == CHANNEL_INIT;
}
示例#3
0
void AccessoryWrite(CHANNEL_HANDLE h, const void *data, int size) {
  assert(h == 0);
  assert(channel_state == CHANNEL_OPEN);
  USBHostAndroidWrite(data, size, ANDROID_INTERFACE_ACC);
}
示例#4
0
static void AccessoryTasks() {
  DWORD size;
  BYTE err;

  // handle detach
  if (channel_state > CHANNEL_DETACHED
      && !USBHostAndroidIsInterfaceAttached(ANDROID_INTERFACE_ACC)) {
    if (is_channel_open) {
      callback(NULL, 1, callback_arg);
      is_channel_open = 0;
    }
    channel_state = CHANNEL_DETACHED;
  }

  switch (channel_state) {
    case CHANNEL_DETACHED:
      if (USBHostAndroidIsInterfaceAttached(ANDROID_INTERFACE_ACC)) {
        channel_state = CHANNEL_INIT;
      }
      break;

    case CHANNEL_INIT:
      USBHostAndroidRead(rx_buf, 1, ANDROID_INTERFACE_ACC);
      channel_state = CHANNEL_WAIT_OPEN;
      break;

    case CHANNEL_WAIT_OPEN:
      if (USBHostAndroidRxIsComplete(&err, &size, ANDROID_INTERFACE_ACC)) {
        if (err != USB_SUCCESS) {
          log_printf("Read failed with error code %d", err);
          return;
        }
        USBHostAndroidWrite(&is_channel_open, 1, ANDROID_INTERFACE_ACC);
        if (is_channel_open) {
          USBHostAndroidRead(rx_buf, rx_buf_size, ANDROID_INTERFACE_ACC);
          channel_state = CHANNEL_OPEN;
        } else {
          channel_state = CHANNEL_WAIT_CLOSED;
        }
      }
      break;

    case CHANNEL_OPEN:
      if (USBHostAndroidRxIsComplete(&err, &size, ANDROID_INTERFACE_ACC)) {
        if (err != USB_SUCCESS) {
          log_printf("Read failed with error code %d", err);
          return;
        }
        if (size) {
          callback(rx_buf, size, callback_arg);
        }
        // Channel might have been closed from within the callback.
        if (channel_state == CHANNEL_OPEN) {
          USBHostAndroidRead(rx_buf, rx_buf_size, ANDROID_INTERFACE_ACC);
        }
      }
      break;

    case CHANNEL_WAIT_CLOSED:
      if (USBHostAndroidTxIsComplete(&err, ANDROID_INTERFACE_ACC)) {
        if (err != USB_SUCCESS) {
          log_printf("Write failed with error code %d", err);
          return;
        }
        callback(NULL, 0, callback_arg);
        channel_state = CHANNEL_INIT;
      }
      break;
  }
}