-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__hex_decode.lua
More file actions
38 lines (36 loc) · 1.41 KB
/
__hex_decode.lua
File metadata and controls
38 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
return {
m = 'iec60870',
name = 'IEC60870',
desc = 'IEC101/104 Protocol Library',
settings = {
{ name = 'FRAME_NO_ADDR', desc = 'Frame has no address field', dt = 'boolean', default = false },
{ name = 'FRAME_ADDR_SIZE', desc = 'Frame address size(链路地址长度)', dt = 'number', default = 2 },
{ name = 'FT12_FIXED_LEN', desc = 'FIXED Frame FT1.2 ASDU length', dt = 'number', default = 0 },
{ name = 'ADDR_SIZE', desc = 'ASDU Command address size (ASDU公共地址长度)', dt = 'number', default = 2 },
{ name = 'COT_SIZE', desc = 'ASDU cause of transfer field size (COT传输原因长度)', dt = 'number', default = 1 },
{ name = 'OBJ_ADDR_SIZE', desc = 'ASDU ojbect address size (信息体地址长度)', dt = 'number', default = 2 },
},
decode = function(text, conf)
local basexx = require 'basexx'
local ft12 = require 'iec60870.frame.ft12'
local c = require 'iec60870.conf'
local helper = require 'iec60870.common.helper'
local cjson = require 'cjson.safe'
for k, v in pairs(c) do
if conf[k] ~= nil then c[k] = conf[k] end
end
print('CONF:', cjson.encode(c))
local str = string.gsub(text, ' ', '')
print('SRC:', str)
print('SRC len:', string.len(str))
local raw = basexx.from_hex(str)
local frame = ft12:new()
local r, next_index, err = frame:valid_hex(raw, 1)
if not r then
print(next_index, err)
return next_index, err
end
frame:from_hex(raw, 1)
return frame
end
}