• 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 { HdcCommand } from './HdcCommand';
17import { CMDSTR_FILE_RECV, CMDSTR_FILE_SEND, CMDSTR_SHELL } from '../common/ConstantType';
18import { log } from '../../log/Log';
19
20export class FormatCommand {
21  cmdFlag: number; // uint16_t
22  parameters: string; //string
23  bJumpDo: boolean; // boolean
24
25  constructor(cmdFlag: number, parameters: string, bJumpDo: boolean) {
26    this.cmdFlag = cmdFlag;
27    this.parameters = parameters;
28    this.bJumpDo = bJumpDo;
29  }
30
31  static string2FormatCommand(cmd: string): FormatCommand {
32    log('Command  : ' + cmd);
33    let formatCommand = new FormatCommand(-1, '', false);
34    if (cmd.startsWith(CMDSTR_SHELL + ' ')) {
35      formatCommand.cmdFlag = HdcCommand.CMD_UNITY_EXECUTE;
36      formatCommand.parameters = cmd.substring((CMDSTR_SHELL + ' ').length);
37    } else if (cmd.startsWith(CMDSTR_SHELL)) {
38      formatCommand.cmdFlag = HdcCommand.CMD_SHELL_INIT;
39    } else if (cmd.startsWith(CMDSTR_FILE_RECV)) {
40      formatCommand.cmdFlag = HdcCommand.CMD_FILE_INIT;
41      formatCommand.parameters = cmd.substring((CMDSTR_FILE_RECV + ' ').length);
42    } else if (cmd.startsWith(CMDSTR_FILE_SEND)) {
43      formatCommand.cmdFlag = HdcCommand.CMD_FILE_INIT;
44      formatCommand.parameters = cmd.substring((CMDSTR_FILE_SEND + ' ').length);
45    } else {
46      formatCommand.bJumpDo = true;
47    }
48    log('formatCommand  cmdFlag is : ' + formatCommand.cmdFlag);
49    log('formatCommand  parameters is : ' + formatCommand.parameters);
50    log('formatCommand  bJumpDo is : ' + formatCommand.bJumpDo);
51    return formatCommand;
52  }
53}
54