37 #define LUA_PUSHT_INT(l, k, v) do { \
38 lua_pushliteral(luastate, k); \
39 lua_pushinteger(luastate, v); \
40 lua_settable(luastate, -3); \
49 lua_pushinteger(luastate, i++);
50 lua_newtable(luastate);
52 lua_pushliteral(luastate,
"index");
53 lua_pushinteger(luastate, point->
index);
54 lua_settable(luastate, -3);
58 lua_settable(luastate, -3);
62 static void DNP3PushObjects(
lua_State *luastate, DNP3ObjectList *objects)
68 lua_pushinteger(luastate, i++);
69 lua_newtable(luastate);
71 lua_pushliteral(luastate,
"group");
72 lua_pushinteger(luastate, object->
group);
73 lua_settable(luastate, -3);
75 lua_pushliteral(luastate,
"variation");
76 lua_pushinteger(luastate, object->
variation);
77 lua_settable(luastate, -3);
79 lua_pushliteral(luastate,
"points");
80 lua_newtable(luastate);
81 DNP3PushPoints(luastate,
object);
82 lua_settable(luastate, -3);
84 lua_settable(luastate, -3);
88 static void DNP3PushLinkHeader(
lua_State *luastate, DNP3LinkHeader *header)
90 LUA_PUSHT_INT(luastate,
"len", header->len);
91 LUA_PUSHT_INT(luastate,
"control", header->control);
92 LUA_PUSHT_INT(luastate,
"dst", header->dst);
93 LUA_PUSHT_INT(luastate,
"src", header->src);
94 LUA_PUSHT_INT(luastate,
"crc", header->crc);
97 static void DNP3PushApplicationHeader(
lua_State *luastate,
98 DNP3ApplicationHeader *header)
100 LUA_PUSHT_INT(luastate,
"control", header->control);
101 LUA_PUSHT_INT(luastate,
"function_code", header->function_code);
107 lua_pushliteral(luastate,
"link_header");
108 lua_newtable(luastate);
109 DNP3PushLinkHeader(luastate, &tx->
lh);
110 lua_settable(luastate, -3);
113 LUA_PUSHT_INT(luastate,
"transport_header", tx->
th);
116 lua_pushliteral(luastate,
"application_header");
117 lua_newtable(luastate);
118 DNP3PushApplicationHeader(luastate, &tx->
ah);
119 lua_settable(luastate, -3);
121 lua_pushliteral(luastate,
"objects");
122 lua_newtable(luastate);
123 DNP3PushObjects(luastate, &tx->
objects);
124 lua_settable(luastate, -3);
130 lua_pushliteral(luastate,
"link_header");
131 lua_newtable(luastate);
132 DNP3PushLinkHeader(luastate, &tx->
lh);
133 lua_settable(luastate, -3);
136 LUA_PUSHT_INT(luastate,
"transport_header", tx->
th);
139 lua_pushliteral(luastate,
"application_header");
140 lua_newtable(luastate);
141 DNP3PushApplicationHeader(luastate, &tx->
ah);
142 lua_settable(luastate, -3);
145 LUA_PUSHT_INT(luastate,
"indicators", tx->
iin.iin1 << 8 | tx->
iin.iin2);
147 lua_pushliteral(luastate,
"objects");
148 lua_newtable(luastate);
149 DNP3PushObjects(luastate, &tx->
objects);
150 lua_settable(luastate, -3);
153 static int DNP3GetTx(
lua_State *luastate)
156 return LuaCallbackError(luastate,
"error: protocol not dnp3");
161 return LuaCallbackError(luastate,
"error: no tx");
164 lua_newtable(luastate);
166 lua_pushliteral(luastate,
"tx_num");
167 lua_pushinteger(luastate, tx->
tx_num);
168 lua_settable(luastate, -3);
170 LUA_PUSHT_INT(luastate,
"has_request", tx->
is_request ? 1 : 0);
172 lua_pushliteral(luastate,
"request");
173 lua_newtable(luastate);
174 LUA_PUSHT_INT(luastate,
"done", tx->
done);
175 LUA_PUSHT_INT(luastate,
"complete", tx->
complete);
176 DNP3PushRequest(luastate, tx);
177 lua_settable(luastate, -3);
180 LUA_PUSHT_INT(luastate,
"has_response", tx->
is_request ? 0 : 1);
182 lua_pushliteral(luastate,
"response");
183 lua_newtable(luastate);
184 LUA_PUSHT_INT(luastate,
"done", tx->
done);
185 LUA_PUSHT_INT(luastate,
"complete", tx->
complete);
186 DNP3PushResponse(luastate, tx);
187 lua_settable(luastate, -3);
193 int LuaRegisterDNP3Functions(
lua_State *luastate)
195 lua_pushcfunction(luastate, DNP3GetTx);
196 lua_setglobal(luastate,
"DNP3GetTx");