• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 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 */
15
16import { BaseBean } from './BaseBean.js';
17
18export class USBHead extends Object implements BaseBean {
19  private _flag: number[]; // uint8_t 'flag', ct.c_uint8 * 2 flag[2] 2
20  private _option: number; // uint8_t 1
21  private _sessionId: number; // uint32_t 4
22  private _dataSize: number; // uint32_t 4
23
24  constructor(flag: number[], option: number, sessionId: number, dataSize: number) {
25    super();
26    this._flag = flag;
27    this._option = option;
28    this._sessionId = sessionId;
29    this._dataSize = dataSize;
30  }
31  static getFlag0Length() {
32    return 1;
33  }
34
35  static getFlag1Length() {
36    return 1;
37  }
38
39  static getOptionLength() {
40    return 1;
41  }
42
43  static getSessionIdLength() {
44    return 4;
45  }
46
47  static getDataSizeLength() {
48    return 4;
49  }
50
51  static getUSBHeadLength() {
52    return 11;
53  }
54
55  getDataView(): DataView {
56    let dataView = new DataView(new ArrayBuffer(11));
57    dataView.setUint8(0, this._flag[0]);
58    dataView.setUint8(1, this._flag[1]);
59    dataView.setUint8(2, this._option);
60    dataView.setUint32(3, this._sessionId);
61    dataView.setUint32(7, this._dataSize);
62    return dataView;
63  }
64
65  static parseHeadData(data: DataView): USBHead {
66    let flagZero = data.getUint8(0);
67    let flagOne = data.getUint8(1);
68    let option = data.getUint8(2);
69    let sessionId = data.getUint32(3);
70    let dataSize = data.getUint32(7);
71    return new USBHead([flagZero, flagOne], option, sessionId, dataSize);
72  }
73
74  get flag(): number[] {
75    return this._flag;
76  }
77
78  set flag(value: number[]) {
79    this._flag = value;
80  }
81
82  get option(): number {
83    return this._option;
84  }
85
86  set option(value: number) {
87    this._option = value;
88  }
89
90  get sessionId(): number {
91    return this._sessionId;
92  }
93
94  set sessionId(value: number) {
95    this._sessionId = value;
96  }
97
98  get dataSize(): number {
99    return this._dataSize;
100  }
101
102  set dataSize(value: number) {
103    this._dataSize = value;
104  }
105
106  toString(): string {
107    return (
108      'flag: ' +
109      this._flag +
110      ' option: ' +
111      this._option +
112      ' sessionId: ' +
113      this._sessionId +
114      ' dataSize: ' +
115      this._dataSize
116    );
117  }
118}
119