From 82987b1a4f74074088a414d90898ad19ec8c4b20 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Fri, 25 Nov 2022 18:38:10 +0800 Subject: small security fixes in advtrains_luaautomation/ - fixed file permissions of advtrains_luaautomation/README.md (755->644) - fixed file permissions of advtrains_luaautomation/environment.lua (755->644) - prevented LuaATC section_occupancy() from having direct access to the interlocking section id occupancy table - simplify section_occupancy() logic --- advtrains_luaautomation/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 advtrains_luaautomation/README.md (limited to 'advtrains_luaautomation/README.md') diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md old mode 100755 new mode 100644 -- cgit v1.2.3 From 3a6b1ca8500cad74f95b925b191582c0aa739116 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Thu, 17 Nov 2022 23:19:57 +0800 Subject: Add get_fc() and set_fc() commands get_fc: returns a table of each wagon's FC codes set_fc: set a table to overwrite the FC codes of a train's wagons --- advtrains_luaautomation/README.md | 25 ++++++++++++++++++------- advtrains_luaautomation/atc_rail.lua | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) mode change 100644 => 100755 advtrains_luaautomation/atc_rail.lua (limited to 'advtrains_luaautomation/README.md') diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md index 67a4b80..a885075 100644 --- a/advtrains_luaautomation/README.md +++ b/advtrains_luaautomation/README.md @@ -255,7 +255,10 @@ In addition to the above environment functions, the following functions are avai The interlocking system uses this property for Automatic Routesetting. #### Shunting Functions and Variables -There are several functions available especially for shunting operations. Some of these functions make use of Freight Codes (FC) set in the Wagon Properties of each wagon and/or locomotive: +There are several functions available especially for shunting operations. +Some of these functions make use of Freight Codes (FC) set in the Wagon Properties of each wagon and/or locomotive. +FCs are composed of codes separated by exclamation marks (`!`), for instance `"foo!bar!baz"`. +Each wagon has a current FC, indicating its next destination. - `split_at_index(index, atc_command)` Splits the train at the specified index, into a train with index-1 wagons and a second train starting with the index-th wagon. The `atc_command` specified is sent to the second train after decoupling. `"S0"` or `"B0"` is common to ensure any locomotives in the remaining train don't continue to move. @@ -266,6 +269,18 @@ There are several functions available especially for shunting operations. Some o Command: `split_at_index(4,"S0")` Result: first train (continues at previous speed): `"foo","foo","foo"`, second train (slows at S0): `"bar","bar","bar"` + - `get_fc()` + Returns a table with the entire FC list for each wagon in the train. + Command: `get_fc()` + Result: `{"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"}` + + - `set_fc(fc_list)` + Overwrites the FC list according to a table `fc_list`. A false or nil entry will leave the wagon unaffected, however all others will be overwritten. + Useful for mass-programming freight trains that use FC-shunting instead of walking to each wagon individually. + Example: train has FC lists: `"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"` + Command: `set_fc({"", "foo!turtle", nil, "4tehlulz", false})` + Result: `""` `"foo!turtle"` `"testing"` `"4tehlulz"` `"hello_world"` + - `split_at_fc(atc_command, len)` Splits the train in such a way that all cars with non-empty current FC of the first part of the train have the same FC. The `atc_command` specified is sent to the rear part, as with split_at_index. It returns the fc of the cars of the first part. @@ -289,15 +304,11 @@ There are several functions available especially for shunting operations. Some o first part of the train as above. - `step_fc()` - Steps the FCs of all train cars forward. FCs are composed of codes - separated by exclamation marks (`!`), for instance - `"foo!bar!baz"`. Each wagon has a current FC, indicating its next - destination. Stepping the freight code forward, selects the next - code after the !. If the end of the string is reached, then the + Steps the FCs of all train cars forward, selecting the next + code after the `!`. If the end of the string is reached, then the first code is selected, except if the string ends with a question mark (`?`), then the order is reversed. - - `train_length()` returns the number of cars the train is composed of. diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua old mode 100644 new mode 100755 index 5dde99c..aac11f0 --- a/advtrains_luaautomation/atc_rail.lua +++ b/advtrains_luaautomation/atc_rail.lua @@ -91,6 +91,38 @@ function r.fire_event(pos, evtdata, appr_internal) if not train_id then return false end advtrains.train_step_fc(train) end, + get_fc = function() + if not train_id then return end + local fc_list = {} + for index,wagon_id in ipairs(train.trainparts) do + fc_list[index] = table.concat(advtrains.wagons[wagon_id].fc,"!") or "" + end + return fc_list + end, + set_fc = function(fc_list) + assertt(fc_list, "table") + if not train_id then return false end + -- safety type-check for entered values + for _,v in ipairs(fc_list) do + if v and type(v) ~= "string" then + error("FC entries must be a string") + return + end + end + for index,wagon_id in ipairs(train.trainparts) do + if fc_list[index] then -- has FC to enter to this wagon + local data = advtrains.wagons[wagon_id] + if data then -- wagon actually exists + for _,wagon in pairs(minetest.luaentities) do -- find wagon entity + if wagon.is_wagon and wagon.initialized and wagon.id==wagon_id then + wagon.set_fc(data,fc_list[index]) -- overwrite to new FC + break -- no point cycling through every other entity. we found our wagon + end + end + end + end + end + end, set_shunt = function() -- enable shunting mode if not train_id then return false end -- cgit v1.2.3 From 55108ae38e467e190abd6f9bf087a9a73f953a08 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Sat, 17 Aug 2024 11:43:35 +0800 Subject: LuaATC set_fc(): add argument to reset fc index to 1 --- advtrains_luaautomation/README.md | 6 ++++-- advtrains_luaautomation/atc_rail.lua | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'advtrains_luaautomation/README.md') diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md index a885075..0bf56bb 100644 --- a/advtrains_luaautomation/README.md +++ b/advtrains_luaautomation/README.md @@ -274,9 +274,11 @@ Each wagon has a current FC, indicating its next destination. Command: `get_fc()` Result: `{"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"}` - - `set_fc(fc_list)` + - `set_fc(fc_list, reset_index)` Overwrites the FC list according to a table `fc_list`. A false or nil entry will leave the wagon unaffected, however all others will be overwritten. - Useful for mass-programming freight trains that use FC-shunting instead of walking to each wagon individually. + Useful for mass-programming freight trains that use FC-shunting instead of walking to each wagon individually. If the new FC entry for a wagon is shorter than the old entry, the index will clip to the last FC in the new entry. + If `reset_index` is true, all Current FC values will reset to the first entry in the list, instead of remaining at the current index. + Example: train has FC lists: `"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"` Command: `set_fc({"", "foo!turtle", nil, "4tehlulz", false})` Result: `""` `"foo!turtle"` `"testing"` `"4tehlulz"` `"hello_world"` diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua index ead1031..b98648e 100644 --- a/advtrains_luaautomation/atc_rail.lua +++ b/advtrains_luaautomation/atc_rail.lua @@ -99,7 +99,7 @@ function r.fire_event(pos, evtdata, appr_internal) end return fc_list end, - set_fc = function(fc_list) + set_fc = function(fc_list,reset_index) assertt(fc_list, "table") if not train_id then return false end -- safety type-check for entered values @@ -113,9 +113,9 @@ function r.fire_event(pos, evtdata, appr_internal) if fc_list[index] then -- has FC to enter to this wagon local data = advtrains.wagons[wagon_id] if data then -- wagon actually exists - --direct copy from wagons.lua, allowing for the :split function + --effectively copyied from wagons.lua, allowing for the :split function and reset_index data.fc = fc_list[index]:split("!") - if not data.fcind then + if reset_index or not data.fcind then data.fcind = 1 elseif data.fcind > #data.fc then data.fcind = #data.fc -- cgit v1.2.3 From 852e2f4219c4e7a9bebf7b27bb1c026f98719f97 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Fri, 30 Aug 2024 17:25:01 +0800 Subject: LuaATC add trainparts(train_id) Returns a copy of the trainparts table to allow tracking individual wagon ids Also fixed a couple of file permissions from previous commits --- advtrains_luaautomation/README.md | 3 +++ advtrains_luaautomation/environment.lua | 6 ++++++ advtrains_luaautomation/operation_panel.lua | 0 3 files changed, 9 insertions(+) mode change 100755 => 100644 advtrains_luaautomation/operation_panel.lua (limited to 'advtrains_luaautomation/README.md') diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md index 0bf56bb..f98f7a0 100644 --- a/advtrains_luaautomation/README.md +++ b/advtrains_luaautomation/README.md @@ -93,6 +93,9 @@ Removes any pending interrupts of this node. Make this active component send a digiline message on the specified channel. Not available in init code. + - `trainparts(train_id)` + returns a table with the ids of the cars the train is composed of, or false if `train_id` is invalid. `train_id` can be replaced with `atc_id` when used in LuaATC Rails. + - `atc_send_to_train(, )` Sends the specified ATC command to the train specified by its train id. This happens regardless of where the train is in the world, and can be used to remote-control trains. Returns true on success. If the train ID does not exist, returns false and does nothing. See [atc_command.txt](../atc_command.txt) for the ATC command syntax. diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua index ee7628d..b54d45c 100644 --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -153,6 +153,12 @@ local static_env = { local pos=atlatc.pcnaming.resolve_pos(parpos, "interrupt_pos") atlatc.interrupt.add(0, pos, {type="ext_int", ext_int=true, message=imesg}) end, + train_parts = function(train_id) + if not train_id then return false end + local train = advtrains.trains[train_id] + if not train then return false end + return table.copy(train.trainparts or {}) + end, -- sends an atc command to train regardless of where it is in the world atc_send_to_train = function(train_id, command) assertt(command, "string") diff --git a/advtrains_luaautomation/operation_panel.lua b/advtrains_luaautomation/operation_panel.lua old mode 100755 new mode 100644 -- cgit v1.2.3 From 35167fe928e61ecf35c633014972e36c921a1b78 Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Wed, 4 Sep 2024 10:31:18 +0000 Subject: Update LuaATC documentation * Fix broken link to RWT API documentation. * w_speed is no longer relevant since the 2021 new-ks update. --- advtrains_luaautomation/README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'advtrains_luaautomation/README.md') diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md index f98f7a0..f285d0f 100644 --- a/advtrains_luaautomation/README.md +++ b/advtrains_luaautomation/README.md @@ -145,22 +145,16 @@ asp = { -- the character of call_on and dead_end is purely informative call_on = , -- Call-on route, expect train in track ahead (not implemented yet) dead_end = , -- Route ends on a dead end (e.g. bumper) (not implemented yet) - - w_speed = , - -- "Warning speed restriction". Supposed for short-term speed - -- restrictions which always override any other restrictions - -- imposed by "speed" fields, until lifted by a value of -1 - -- (Example: german Langsamfahrstellen-Signale) } ``` -As of January 2020, the 'dst', 'call_on' and 'dead_end' fields are not used. +As of September 2024, the 'dst', 'call_on' and 'dead_end' fields are not used. #### Lines The advtrains_line_automation component adds a few contraptions that should make creating timeable systems easier. Part of its functionality is also available in LuaATC: -- `rwt.*` - all Railway Time functions are included as documented in [the wiki](https://advtrains.de/wiki/doku.php?id=dev:lines:rwt) +- `rwt.*` - all Railway Time functions are included as documented in [the wiki](https://advtrains.de/wiki/doku.php?id=dev:api:railway_time_api) - `schedule(rw_time, msg)`, `schedule_in(rw_dtime, msg)` Schedules an event of type {type="schedule", schedule=true, msg=msg} at (resp. after) the specified railway time (which can be in any format). You can only schedule one event this way. (uses the new lines-internal scheduler) -- cgit v1.2.3 From 715efe22939bbe472ba4a2c81c74e64c45726bc2 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Wed, 30 Oct 2024 21:06:29 +0800 Subject: Add get_fc_index() fucntion --- advtrains_luaautomation/README.md | 5 +++++ advtrains_luaautomation/atc_rail.lua | 8 ++++++++ 2 files changed, 13 insertions(+) (limited to 'advtrains_luaautomation/README.md') diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md index f285d0f..275653c 100644 --- a/advtrains_luaautomation/README.md +++ b/advtrains_luaautomation/README.md @@ -270,6 +270,11 @@ Each wagon has a current FC, indicating its next destination. Returns a table with the entire FC list for each wagon in the train. Command: `get_fc()` Result: `{"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"}` + + - `get_fc_index()` + Returns a table with the current FC index for each wagon in the train. Use in conjunction with the result from `get_fc()` to find a the current FC for a wagon. + Command: `get_fc_index()` + Result: `{1, 1, 1, 2, 1}` - `set_fc(fc_list, reset_index)` Overwrites the FC list according to a table `fc_list`. A false or nil entry will leave the wagon unaffected, however all others will be overwritten. diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua index 177fa78..dd26f51 100644 --- a/advtrains_luaautomation/atc_rail.lua +++ b/advtrains_luaautomation/atc_rail.lua @@ -99,6 +99,14 @@ function r.fire_event(pos, evtdata, appr_internal) end return fc_list end, + get_fc_index = function() + if not train_id then return end + local fc_index_list = {} + for widx, wagon_id in ipars(train.trainparts) do + fc_index_list[widx] = advtrains.wagons[wagon_id].fcind or 1 + end + return fc_index_list + end, set_fc = function(fc_list,reset_index) assertt(fc_list, "table") if not train_id then return false end -- cgit v1.2.3