-3

我是凯泰的新手,请帮我解决这些异常。

代码:

meta:
  id: picosat.ksy
  file-extension: picosat.ksy
  endian: be
  doc: |
  
    :field dest_callsign: ax25_frame.ax25_header.dest_callsign_raw.callsign_ror.callsign
    :field src_callsign: ax25_frame.ax25_header.src_callsign_raw.callsign_ror.callsign
    :field src_ssid: ax25_frame.ax25_header.src_ssid_raw.ssid
    :field dest_ssid: ax25_frame.ax25_header.dest_ssid_raw.ssid
    :field ctl: ax25_frame.ax25_header.ctl
    :field pid: ax25_frame.payload.pid
    :field epic_frame_Command_Token: ax25_frame.ax25_info.epic_frame.Command_Token
    :field epic_header_Source_SatelliteID: ax25_frame.ax25_info.epic_frame.epic_header.Source_SatelliteID
    :field epic_header_Session_ID: ax25_frame.ax25_info.epic_frame.epic_header.Session_ID
    :field epic_header_Destination_SatelliteID: ax25_frame.ax25_info.epic_frame.epic_header.Destination_SatelliteID
    :field epic_header_Source_MCUID: ax25_frame.ax25_info.epic_frame.epic_header.Source_MCUID
    :field epic_header_Desination_MCUID: ax25_frame.ax25_info.epic_frame.epic_header.Desination_MCUID
    :field epic_header_Command_Source: ax25_frame.ax25_info.epic_frame.epic_header.Command_Source
    :field epic_header_Command_Type: ax25_frame.ax25_info.epic_frame.epic_header.Command_Type
    :field epic_header_Get_AX25_state: ax25_frame.ax25_info.epic_frame.epic_header.Get_AX25_state
    :field epic_header_AX25_state: ax25_frame.ax25_info.epic_frame.epic_header.AX25_state
    :field epic_header_Command_Length: ax25_frame.ax25_info.epic_frame.epic_header.Command_Length
    :field epic_frame_Command_Payload: ax25_frame.ax25_info.epic_frame.epic_header.Command_Payload
    :field Command_Payload_Payload_Data: ax25_frame.ax25_info.Command_Payload.Payload_Data
    :field Command_Payload_TX_Buffer_AX25_Dec: ax25_frame.ax25_info.epic_frame.Command_Payload.TX_Buffer_AX25_Dec
    :field Command_Payload_TX_Buffer_AX25_HEX: ax25_frame.ax25_info.epic_frame.Command_Payload.TX_Buffer_AX25_HEX
    :field Command_Payload_TX_Buffer_EPIC_Dec: ax25_frame.ax25_info.epic_frame.Command_Payload.TX_Buffer_EPIC_Dec
    :field Command_Payload_TX_Buffer_EPIC_HEX: ax25_frame.ax25_info.epic_frame.Command_Payload.TX_Buffer_EPIC_HEX
    :field epic_frame_Cyclic_check: ax25_frame.ax25_info.epic_frame.Cyclic_check
    :field epic_frame_Command_Token: ax25_frame.ax25_info.epic_frame.Command_Token
    :field pyld_chksm: ax25_frame.ax25_info.pyld_chksm
  
  seq:
    - id: ax25_frame
      type: ax25_frame
  types:
    ax25_frame:
      seq:
        - id: ax25_header
          type: ax25_header
        - id: epic_frame
          type:
            switch-on: ax25_header.ctl & 0x13
            cases:
              0x03: ui_frame
              0x13: ui_frame
              0x00: i_frame
              0x02: i_frame
              0x10: i_frame
              0x12: i_frame
              # 0x11: s_frame
    ax25_header:
      seq:
        - id: dest_callsign_raw
          type: callsign_raw
        - id: dest_ssid_raw
          type: ssid_mask
        - id: src_callsign_raw
          type: callsign_raw
        - id: src_ssid_raw
          type: ssid_mask
        - id: ctl
          type: u1
    callsign_raw:
      seq:
        - id: callsign_ror
          process: ror(1)
          size: 6
          type: callsign
    callsign:
      seq:
        - id: callsign
          type: str
          encoding: ASCII
          size: 6
    ssid_mask:
      seq:
        - id: ssid_mask
          type: u1
      instances:
        ssid:
          value: (ssid_mask & 0x0f) >> 1
    ax25_info:
      seq:
        - id: epic_header
          type: epic_header
        - id: Command_Payload
          type: Command_Payload
        - id: Cyclic_check
          type: Cyclic_check
        - id: Command_Token
          type: Command_Token
    epic_header:
      seq:
        - id: Source_SatelliteID
          type: u1
          size: 0x06
        - id: Session_ID
          type: u1
          size: 0x06
        - id: Destination_SatelliteID
          type: u1
          size: 0x06
        - id: Source_MCUID
          type: u1
          size: 0x06
        - id: Destination_MCUID
          type: u1
          size: 0x06
        - id: Command_Source
          type: u1
          size: 0x01
        - id: Command_Type
          type: u1
          size: 0x07
        - id: Payload_Length
          type: u1
          size: 1
    Command_Type:
      seq:
        - id: Get_AX25_state
          type: u1
          doc: "get the state of AX25"
        - id: AX25_state
          type: u1
          size: 0x08
    Command_Payload:
      seq:
        - id: Payload_Data
          type: u1
        - id: TX_Buffer_AX25_Dec
          type: u1
        - id: TX_Buffer_AX25_HEX
          type: u4
        - id: TX_Buffer_epic_Dec
          type: u1
        - id: TX_Buffer_epic_HEX
          type: u4
        - id: pyld_chksm
          type: u4

我得到的例外:

Parse error: undefined
Call stack: Error
    at $c_Lio_kaitai_struct_format_YAMLParseException.fillInStackTrace__jl_Throwable (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:24379:14)
    at $c_Lio_kaitai_struct_format_YAMLParseException.init___T__jl_Throwable__Z__Z (kaitai-struct-compiler.js:24485:10)
    at $c_Lio_kaitai_struct_format_YAMLParseException.init___T__sci_List (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:40914:58)
    at $c_Lio_kaitai_struct_format_ParseUtils$.ensureLegalKeys__sci_Map__sci_Set__sci_List__s_Option__V (/kaitai-struct-compiler.js:7832:66)
    at $c_Lio_kaitai_struct_format_MetaSpec$.fromYaml__O__sci_List__Lio_kaitai_struct_format_MetaSpec /kaitai-struct-compiler.js:28883:45)
    at $c_Lio_kaitai_struct_format_ClassSpec$.fromYaml__O__sci_List__Lio_kaitai_struct_format_MetaSpec__Lio_kaitai_struct_format_ClassSpec (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:28028:83)
    at $c_Lio_kaitai_struct_format_JavaScriptKSYParser$.yamlToSpecs__O__Lio_kaitai_struct_JavaScriptImporter__Lio_kaitai_struct_RuntimeConfig__s_concurrent_Future (kaitai-struct-compiler.js:7636:26)
    at $c_Lio_kaitai_struct_MainJs$.compile__T__sjs_js_Object__Lio_kaitai_struct_JavaScriptImporter__Z__sjs_js_Promise (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:3988:66)
    at $c_Lio_kaitai_struct_MainJs$.$$js$exported$meth$compile__T__sjs_js_Object__Lio_kaitai_struct_JavaScriptImporter__Z__O (kaitai-struct-compiler.js:3942:15)
    at $c_Lio_kaitai_struct_MainJs$.compile (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:4123:15)
    at CompilerService.compile (https://ide.kaitai.io/js/v1/KaitaiServices.js:85:82)
    at AppController.compile (https://ide.kaitai.io/js/v1/app.js:58:41)
    at AppController.recompile  io.kaitai.struct.format.YAMLParseException: /meta/doc: unknown key found, expected: application, bit-endian, encoding, endian, file-extension, id, imports, ks-debug, ks-opaque-types, ks-version, license, tags, title, xref
4

1 回答 1

1

附属免责声明:我是Kaitai Struct维护者(请参阅我的GitHub 个人资料)。

首先,请始终将代码片段放在带有相应语言标识符的防护代码块中(例如lang-yaml,对于 YAML 语言代码,它适用于 .ksy 规范,因为 KSY 语言基于 YAML) - 请参阅Markdown 帮助以获取更多信息。这是它的样子:

```lang-yaml
meta:
  id: test
seq:
  # ...
```

如果有一个代码块您不希望出现语法突出显示(如解析错误堆栈跟踪),请使用lang-text标签:

```lang-text
Parse error: undefined
Call stack: Error
    at $c_Lio_kaitai_struct_format_YAMLParseException.fillInStackTrace
    ...
```

我会解决您的问题,以便代码片段的格式正确,但 Stack Overflow 阻止我提交编辑,除非我在其中写更多文本,我真的不知道我还应该问自己什么。


无论如何,您的代码存在以下问题,其结构如下:

meta:
  id: picosat # "picosat.ksy" is invalid, KS identifiers must satisfy /^[a-z][a-z0-9_]*$/
              #  -> it must start with a lowercase letter and optionally
              #     continue with alphanumeric characters and underscores
  file-extension: picosat
  endian: be
  doc: |
    ...
  
  seq:
    # ...
  types:
    # ...

是你有doc,seq并且types /meta地图内作为它的子键。但是,它们应该与meta(即没有缩进)处于同一级别,因此您需要将这些部分的缩进减少一级(这可以在许多编辑器中作为Shift+来完成):Tab

meta:
  id: picosat.ksy
  file-extension: picosat.ksy
  endian: be
# doc: |
#   ...
doc: |
  ...

# seq:
#   # ...
# types:
#   # ...
seq:
  # ...
types:
  # ...

您收到错误/meta/doc: unknown key found是因为 Kaitai Struct 编译器无法识别doc下的键meta,并为您提供有效meta子键的列表。

如果您对 .ksy 中支持哪些键以及在什么级别有疑问,请查看KSY 语法图

于 2021-06-20T14:44:44.753 回答