• 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
75    get flag(): number[] {
76        return this._flag;
77    }
78
79    set flag(value: number[]) {
80        this._flag = value;
81    }
82
83    get option(): number {
84        return this._option;
85    }
86
87    set option(value: number) {
88        this._option = value;
89    }
90
91    get sessionId(): number {
92        return this._sessionId;
93    }
94
95    set sessionId(value: number) {
96        this._sessionId = value;
97    }
98
99    get dataSize(): number {
100        return this._dataSize;
101    }
102
103    set dataSize(value: number) {
104        this._dataSize = value;
105    }
106
107    toString(): string {
108        return "flag: " + this._flag
109            + " option: " + this._option
110            + " sessionId: " + this._sessionId
111            + " dataSize: " + this._dataSize;
112    }
113}
114