Generic functions

<syntaxhighlight lang="lua"> -- General modules require("Core")

-- Third-party libraries -- https://github.com/silentbicycle/lua-memcached local client = require("memcached") local cache = client.connect()

function getCountryCode(number)

 -- Number should have not less than 3 digits
 if number >= 100
 then
   local value = tostring(number)
   return string.sub(value, 1, 3)
 end
 return nil

end

function getCountryAndRegionCode(number)

 -- Number should have not less than 4 digits
 if number >= 1000
 then
   local value = tostring(number)
   return string.sub(value, 1, 4)
 end
 return nil

end

function validateGeographicRegionCode(number, code)

 local value1 = tostring(code)
 local value2 = tostring(number)
 local length1 = string.len(value1)
 local length2 = string.len(value2)
 return
   (length1 <= length2) and
   (value1 == string.sub(value2, 1, length1))

end

function validateRegularRepeater(parameters)

 return
   -- Link has a repeater kind
   (parameters.kind == LINK_TYPE_REPEATER) and
   -- It is not DV4mini
   (parameters.name ~= "DG1HT DV4mini") and
   -- And not Homebrew Repeater in DMO mode
   ((parameters.name ~= "Homebrew Repeater") or
    (parameters.values[VALUE_HOMEBREW_CONNECTION_MODE] ~= CONNECTION_MODE_HOTSPOT))

end </syntaxhighlight>

Global TalkGroup routing

This function is used to route calls to other BrandMeisters <syntaxhighlight lang="lua"> function makeGlobalRouteForGroup(kind, destination)

 if
   (destination ~= 9) and
   (kind ~= LINK_TYPE_NETWORK) and
   (validateGeographicRegionCode(destination, "8") or
    validateGeographicRegionCode(destination, "9") or
    getCountryCode(destination))
 then
   local contexts = getContextTable()
   for _, parameters in pairs(contexts) do
     if parameters.name == "FastForward"
     then
       newRoute(parameters.object, 0, 0)
     end
   end
 end

end </syntaxhighlight>

National TalkGroup routing

<syntaxhighlight lang="lua"> function makeAutomaticRouteForNationalGroup(kind, number, destination, slot)

 if destination >= 100
 then
   local country = getCountryCode(destination)
   local contexts = getContextTable()
   for _, parameters in pairs(contexts) do
     if
        -- Do not route call back
        ((kind ~= parameters.kind) or
         (number ~= parameters.number)) and
        -- Remote should be a repeater
        validateRegularRepeater(parameters) and
        -- Remote ID length is great than country code
        (parameters.number >= 100) and
        -- Destination ID and Remote ID should have same country code as prefix
        (getCountryCode(parameters.number) == country)
     then
       newRoute(parameters.object, slot, 0)
     end
   end
 end

end </syntaxhighlight>

Regional TalkGroup routing

<syntaxhighlight lang="lua"> function makeAutomaticRouteForRegionalGroup(kind, number, destination, slot)

 if destination >= 1000
 then
   local region = getCountryAndRegionCode(destination)
   local contexts = getContextTable()
   for _, parameters in pairs(contexts) do
     if
        -- Do not route call back
        ((kind ~= parameters.kind) or
         (number ~= parameters.number)) and
        -- Remote should be a repeater
        validateRegularRepeater(parameters) and
        -- Remote ID length is great than region code
        (parameters.number >= 1000) and
        -- Destination ID and Remote ID should have same region code as prefix
        (getCountryAndRegionCode(parameters.number) == region)
     then
       newRoute(parameters.object, slot, 0)
     end
   end
 end

end </syntaxhighlight>

OnDemand/Dynamic TalkGroup routing

A OnDemand TalkGroup is connected by pressing the PTT in the future also possable via RRS <syntaxhighlight lang="lua"> function makeOnDemandRouteForGroup(kind, number, slot, destination, interval)

 -- Keep Group 9 as local
 if destination ~= 9
 then
   -- Subscribe repeater to group
   if kind == LINK_TYPE_REPEATER
   then
     cache:set(number .. "-" .. destination, tostring(slot), interval)
   end
   -- Route to subscribed group
   local contexts = getContextTable()
   for _, parameters in pairs(contexts) do
     if
        -- Do not route call back
        ((kind ~= parameters.kind) or
         (number ~= parameters.number)) and
        -- Remote should be a repeater
        (parameters.kind == LINK_TYPE_REPEATER)
     then
       local slot = cache:get(parameters.number .. "-" .. destination)
       if
          -- Subscription should be available
          (slot ~= nil)
       then
         newRoute(parameters.object, tonumber(slot), 0)
       end
     end
   end
 end

end </syntaxhighlight>