Skip to content

Instantly share code, notes, and snippets.

@jh4xsy
Last active April 8, 2023 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jh4xsy/129be7008664ea4bb202233936de1ce8 to your computer and use it in GitHub Desktop.
Save jh4xsy/129be7008664ea4bb202233936de1ce8 to your computer and use it in GitHub Desktop.
kissファイルからヘキサダンプファイルを作成する
#
# 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