AIS报文定义整理

本文详细介绍了AIS消息的标准格式及组成元素,包括消息的具体定义、字段构成和特殊用途的字段组合规则。此外还列举了多种AIS消息类型及其含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

AIS消息具体定义参考标准 IEC61162 IEC91993-2

语句最长82字符(也有84字符),包括一个起始字符和两个结束字符 <CR><LF>
$/!<address field>[","<data field>]"*"<checksum field> <CR><LF>

$  conform to the conventional [parametric] and delimited field composition rules as described in 7.3.3
$aaccc,[","<data field>]"*"<checksum field> <CR><LF>

!  conform to the special-purpose [encapsulation and non-delimited] field composition rules as described in 7.3.3
!aaccc,x1,x2,x3,x5[","<data field>]x4"*"<checksum field> <CR><LF>

x1: total number of sentences field
x2: sentence number field
x3: sequential message identifier field
x4: fill bits field
x5: AIS channel A 或 B

aa:  talker(见下表)
ccc: mnemonic code 语句格式标识(见下表)

MT-1 ATS Main口共有8条输出语句
!AIVDM: AIS VHF data-link message 该句型含有船舶动态信息和静态信息、航行信息
!AIVDO: AIS VHF data-link Own-vessel report 该句型含有本船报告信息
!AIABM: AIS addressed binary and safety related message  支持寻址二进制电文
$AIABK
$AIACA
$AITXT
$AIALR
$AISSD

【talker】
AI:船载A或B类
AB:独立的AIS基站
BS:AIS基站(早期)
更多见标准

【mnemonic code】
$--AAM: waypoint arrival alarm
$--ABK: AIS addressed and binary broadcast acknowledgement
!--ABM: AIS addressed binary and safety related message 支持寻址二进制电文
$--ACA: AIS channel assignment message
$--ACK: Acknowledge alarm
$--ACN: Alert command
$--ACS:AIS channel management information source
$--AIR: AIS interrogation request
$--AKD: AIS Acknowledge detail alarm condition
$--ALA: Report detailed alarm condition
$--ALC: Cyclic alert list
$--ALF: Alert sentence
$--ALR: Set alarm state
$--APB: Heading/track controller(autopilot)sentence B
$--ARC: Alert command refused
!--BBM:AIS broadcast binary message 广播二进制电文
$--BEC: Bearing and distance to waypoint - Dead reckoning
$--BOD: Bearing origin to destination
$--BWC: Bearing and distance to waypoint - Great circle
$--BWR: Bearing and distance to waypoint - Rhumb line
$--BWW: Bearing waypoint to waypoint
$--CUR: Water current layer - Multi-layer water current data
$--DBT: Depth below transducer
$--DDC: Desplay dimming control
$--DOR: Door status detecion
$--DPT: Depth
$--DSC: Digital selective calling information
$--DSE: Expanded digital selective calling
$--DTM: Datum reference
$--EPV: Command or report equipment property value
$--ETL: Engine telegraph operation status
$--EVE: General event message
$--FIR: Fire detecion
$--FSI: Frequency set information
$--GBS: GNSS satellite fault detection
$--GEN: Generic binary information
$--GFA: GNSS fix accuracy and integrity
$--GGA: Global positioning system (GPS) fix data
$--GLL: Geographic position - Latitude/longitude
$--GNS: GNSS fix data
$--GRS: GNSS range residuals
$--GSA: GNSS DOP and active satellites
$--GST: GNSS pseudorange nois statistics
$--GSV: GNSS satellites in view
$--HBT: Heartbeat supervision sentence
$--HDG: Heading deviation and variation
$--HDT: Heading ture
$--HMR: Heading monitor receive
$--HMS: Heading monitor set
$--HSC: Heading steering command
$--HSS: Hull stress surveillance systems
$--HTC/HTD: Heading/track control command
$--HTD: Heading/track control data
$--LR1: AIS long-range reply sentence 1
$--LR2: AIS long-range reply sentence 2
$--LR3: AIS long-range reply sentence 3
$--LRF: AIS long-range funcion
$--LRI: AIS long-range interrogation
$--MEB: Message input for broadcast command
$--MSK: MSK receiver interface
$--MSS: MSK receiver signal status
$--MTW: Water temperature
$--MWD: Wind direction and speed
$--MWV: Wind speed and angle
$--NAK: Negative acknowledgement
$--NRM: NAVTEX receiver mask
$--NRX: NAVTEX receiver message
$--OSD: Own ship data
$--POS: Device position and ship dimensions report or configuration command
$--PRC: Propuision remote control status
$--RMA: Recommended minimum specific LORAN-C data
$--RMB: Recommended minimum navigation information
$--RMC: Recommended minimum specific GNSS data
$--ROR: Rudder order status
$--ROT: Rate of trun
$--RPM: Revolutions
$--RSA: Rudder sensor angle
$--RSD: Radar system data
$--RTE: Routes
$--SFI: Scanning frequency information
$--SSD: AIS ship static data(this sentence isused to enter parameters into a shipboard AIS unit.
        The parameters in this sentence support a number of the ITU-R M.1371 Messages)
$--STN: Multiple data ID
$--THS: True heading and status
$--TLB: Target label
$--TLL: Target latitude and longitude
$--TRC: Thruster control data
$--TRD: Thruster response data
$--TTD: Tracked target data
$--TTM: Tracked target message
$--TUT: Transmission of multi-language text
$--TXT: Text transmission
$--UID: User indentification code transmission
$--VBW: Dual ground/water speed
!--VDM: AIS VHF data-link message 该句型含有船舶动态信息和静态信息、航行信息
!--VDO: AIS VHF data-link Own-vessel report 该句型含有本船报告信息
$--VDR: Set and drift
$--VER: Version
$--VHW: Water speed and heading
$--VLW: Dual ground/water distance
$--VPW: Speed measured parallel to wind
$--VSD: AIS voyage static data
$--VTG: Gourse over ground and ground speed
$--WAT: Water level detection
$--WCV: Waypoint closure velocity
$--WNC: Distance waypoint to waypoint
$--WPL: Waypoint location
$--XDR: Transducer measurements
$--XTE: Cross-track error, measured
$--XTR: Cross-track error, dead reckoning
$--ZDA: Time and date
$--ZDL: Time and distance to variable point
$--ZFO: UTC and time from origin waypoint
$--ZTG: UTC and time to destination waypoint

【AIS消息类型】
1、2、3 船位动态
4 基站报         
5 静态报
6 二进制编址        
7 对消息6的二进制确认   
8 广播二进制        
9 SAR飞机位置        
10 UTC时间询问
11 UTC时间回应
12 编址安全信息
13 对消息12的安全确认
14 安全广播
15 询问            
16 分配模式指令        
17 卫星广播二进制    
18 B类船位
19 扩展B类船位
20 数据链管理信息    
21 助航设备报告        
22 信道管理
23 群组指配
24 B类静态,分A和B两类
25 单时隙二进制
26 多时隙二进制
27 远距离位置报
28-63 未定义

<think>嗯,用户想用Python解析EDI BAPLIE报文并导出到Excel,包含很多字段。首先,我需要回忆一下EDI报文的格式,尤其是BAPLIE的结构。BAPLIE是用于舱位计划的报文,里面应该包含集装箱的信息。用户提到的字段比如船名、航次、箱号、尺寸等等,这些可能在报文的不同段里。 然后,用户需要解析这些报文。Python处理文本的话,可能需要用到正则表达式或者分割字符串的方法。比如,EDI报文通常由段组成,每个段以换行符分隔,段内的元素用+或者:分隔。例如,UNH段是消息头,BGM是报文开始,TDT可能包含运输细节,LOC是地点,EQD是设备详情等等。 接下来,如何将这些解析后的数据导出到Excel呢?可能需要用到pandas库,把数据整理成DataFrame,然后用to_excel方法输出。用户提供的引用中有一个exportToExcel的函数,可能参考那个结构,但具体可能需要调整字段映射。 然后,考虑代码的结构。可能需要先读取EDI文件,逐行解析,识别各个段,提取所需字段。比如,船名可能在TDT段里的TDT+13+船名',航次在RFF段,RFF+VON:航次编号。集装箱信息可能在EQD段,里面有箱号、尺寸、类型等等。每个EQD段可能对应一个集装箱,需要循环处理。 还要处理一些特殊字段,比如是否冷箱、危险品,这些可能在EQD的附加代码里,比如DIMSEL可能表示危险品,或者有特定的标识符。需要查看具体的EDI规范,但用户可能没有提供,所以可能需要假设一些字段的位置。 然后,导出到Excel时,要确保所有字段对应正确,比如箱经营人代码可能在EQD+EET'里面,或者在其他段。可能需要更多的示例数据来测试解析是否正确。 可能遇到的问题包括:EDI报文的编码问题,字段位置的变化,不同版本的BAPLIE结构不同。需要用户确认报文的版本,比如UNH+1+VESDEP:D:95B:UN',这里可能版本是95B,需要根据对应的EDI规范来解析。 另外,用户提供的引用中有关于AIS系统和EDI报文结构的说明,可能需要参考这些结构,比如UNB、UNH等段的意义,帮助正确解析。 总结步骤:1. 读取EDI文件,分割成段。2. 遍历每个段,识别段标识(如TDT、RFF、EQD等)。3. 根据段类型提取所需字段,并存储到数据结构中。4. 将所有数据整理成表格,用pandas导出Excel。 可能需要处理多个集装箱,每个集装箱对应多个段,比如每个EQD段一个集装箱,然后收集该集装箱的其他信息,如箱毛重可能在MEA段,或者其他的段里。所以可能需要维护一个当前集装箱的变量,当遇到EQD时创建新集装箱记录,然后在后续的段中填充其他字段,直到下一个EQD出现。 此外,处理日期和时间可能需要用到DTM段,但用户需求中没有明确提到,但航次的时间可能需要。不过用户要求的字段主要是箱相关和船名、航次等,所以可能集中在TDT、RFF、EQD、LOC等段。 最后,测试代码时需要示例EDI报文,但用户没有提供,可能需要构造一个样本,或者建议用户提供样例数据以便调整解析逻辑。</think>根据需求,编写Python解析EDI BAPLIE报文并导出Excel的实现步骤如下: ### 一、EDI报文结构解析 BAPLIE报文主要包含以下关键段: 1. **UNH段**:报文头标识 2. **TDT段**:运输细节(含船名) $$TDT+13+船名+...$$ 3. **RFF段**:航次编号 $$RFF+VON:航次编号$$ 4. **EQD段**:集装箱详细信息(核心数据段)[^2] $$EQD+CN+箱号+尺寸代码:箱高代码:箱型代码+空/重标识...$$ ### 二、Python实现代码 ```python import pandas as pd from dataclasses import dataclass @dataclass class Container: ship_name: str = "" voyage: str = "" container_no: str = "" size_type: str = "" weight: str = "" # 其他字段定义... def parse_baplie(file_path): containers = [] current_container = Container() with open(file_path, 'r', encoding='utf-8') as f: segments = f.read().split("'") # EDI标准分隔符 for seg in segments: elements = seg.split('+') if not elements: continue # 解析船名 if elements[0] == 'TDT': current_container.ship_name = elements[2] # 解析航次 elif elements[0] == 'RFF' and 'VON' in elements[1]: current_container.voyage = elements[1].split(':')[-1] # 解析集装箱信息 elif elements[0] == 'EQD' and elements[1] == 'CN': if current_container.container_no: # 前一个箱完成解析 containers.append(current_container) current_container = Container() current_container.container_no = elements[2] size_info = elements[3].split(':') current_container.size_type = f"{size_info[0]}x{size_info[1]}" return containers def export_to_excel(data, filename): df = pd.DataFrame([vars(c) for c in data]) df.to_excel(filename, index=False) # 使用示例 containers = parse_baplie("baplie.edi") export_to_excel(containers, "集装箱数据.xlsx") ``` ### 三、关键字段映射说明 | EDI字段 | 对应数据段 | 提取逻辑 | |---------------|----------------|---------------------------| | 船名 | TDT段第3元素 | `segments[2]` | | 航次编号 | RFF+VON段 | `split(':')[-1]` | | 箱号 | EQD段第3元素 | 直接读取 | | 尺寸 | EQD段第4元素 | 拆分`22G1`为"22x8.5" | ### 四、优化建议 1. 使用`pyedifact`库增强EDI解析能力 2. 添加异常处理应对报文格式变化 3. 使用OpenPyXL引擎处理大数据量导出
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值