• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2021 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15set -e
16
17IFS=$'\n'
18read_log_file="./acm_read_xts"
19usb_dir="/sys/bus/usb/devices/1-1"
20max_ts=0
21pid=$(ps -ef | grep 'usbhost_ddk_test' | grep -v grep | cut -F 2)
22if [ ! "${pid}x" == "x" ];then
23    killall usbhost_ddk_test
24fi
25usbhost_ddk_test -Ar &
26cat /dev/null > $read_log_file
27while true
28do
29    lines=$(cat $read_log_file)
30    cat /dev/null > $read_log_file
31    for line in $lines
32    do
33        ts=$(echo $line | grep 'XTSCHECK' | cut -F 2 | cut -d ',' -f 1)
34        if [ $(echo "$ts > $max_ts" | bc) -eq 1 ];then
35            max_ts=$ts
36            data=$(echo $line | grep 'XTSCHECK' | cut -F 4 | cut -d '[|]' -f 2 )
37            echo "[$(date +%s.%N)]" $data
38            usbhost_ddk_test -Aw $data
39        fi
40        if [ "$data" == "GET_DESCRIPTOR" ];then
41            id_vendor=$(cat ${usb_dir}/idVendor)
42            id_product=$(cat ${usb_dir}/idProduct)
43            bcd_device=$(cat ${usb_dir}/bcdDevice)
44            b_configuration_value=$(cat ${usb_dir}/bConfigurationValue)
45            echo "[$(date +%s.%N)]" "$id_vendor $id_product $bcd_device $b_configuration_value"
46            usbhost_ddk_test -Aw "$id_vendor $id_product $bcd_device $b_configuration_value"
47        fi
48    done
49    sleep 0.1
50done