Last active
April 8, 2023 05:07
-
-
Save jh4xsy/129be7008664ea4bb202233936de1ce8 to your computer and use it in GitHub Desktop.
kissファイルからヘキサダンプファイルを作成する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# kissファイルからヘキサダンプファイルを作成 | |
# | |
# - http://www.ax25.net/kiss.aspx | |
# - https://www.eonet.ne.jp/~ja3tdw/pdf/%E6%8A%80%E8%A1%93%E8%A7%A3%E8%AA%AC%E8%B3%87%E6%96%99%EF%BC%94.pdf | |
FEND = 0xC0 | |
FESC = 0xDB | |
TFEND = 0xDC | |
TFESC = 0xDD | |
if ARGV[0].nil? then | |
print "\nusage: % ruby kissdump.rb in.kss > out.hex\n" | |
exit | |
end | |
f = open(ARGV[0], "rb") | |
state = 1 | |
cnt = 0 | |
prev = 0 | |
f.each_byte do |c| | |
if ( c == FEND && state == 99 ) # FEND / KISSデータフレーム・終了 | |
printf("\n") | |
state = 1 | |
end | |
# ---8<--- | |
if ( state == 99 ) | |
if cnt >= 16 # AX.25ヘッダをスキップ | |
# -- 透過性処理 | |
if prev == FESC && c == TFEND | |
printf("%02X",FEND) # 'dbdc' を 'c0' に置換 | |
elsif prev == FESC && c == TFESC | |
printf("%02X",FESC) # 'dbdd' を 'db' に置換 | |
elsif c != FESC | |
printf("%02X",c) | |
end | |
# -- | |
prev = c | |
end | |
cnt += 1 | |
end | |
# ---8<-- | |
if ( c == FEND && state == 1 ) # FEND | |
state = 2 | |
end | |
if ( c == 0 && state == 2 ) # FEND + 0 / KISSデータフレーム・開始 | |
state = 99 | |
cnt = 0 | |
end | |
end | |
print "\n" | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment