(Dongle Reflector/TalkGroup routing)
 
(Dongle Reflector/TalkGroup routing)
 
Line 157: Line 157:
 
     end
 
     end
 
   end
 
   end
end
 
</syntaxhighlight>
 
== Dongle Reflector/TalkGroup routing ==
 
The function is used for mapping reflectors to TalkGroups
 
<syntaxhighlight lang="lua">
 
local state = 0;
 
 
function makeRouteForDV4mini(kind, name, number, destination, map)
 
  -- 1) Forward new Group calls to LoopBack
 
  if name ~= "LoopBack"
 
  then
 
    for reflector, group in pairs(map) do
 
      if destination == group
 
      then
 
        state = reflector
 
        newRoute(LINK_TYPE_APPLICATION, LOOPBACK, 0, 9)
 
        return REGISTRY_CONTINUE_APPENDING
 
      end
 
    end
 
  end
 
  -- 2) Forward calls from LoopBack to DV4mini connected to reflector
 
  if (destination == 9) and
 
    (name == "LoopBack")
 
  then
 
    local contexts = getContextTable()
 
    for _, parameters in pairs(contexts) do
 
      if (parameters.name == "DG1HT DV4mini") and
 
        (parameters.values[VALUE_REFLECTOR] == state)
 
      then
 
        newRoute(parameters.object, 0, 0)
 
      end
 
    end
 
    return REGISTRY_STOP_APPENDING
 
  end
 
  -- 3) Forward DV4mini calls of reflector to LoopBack
 
  if (destination == 9) and
 
    (name == "DG1HT DV4mini")
 
  then
 
    -- 3.1) Get current reflector of DV4mini
 
    local reflector = nil
 
    local contexts = getContextTable()
 
    for _, parameters in pairs(contexts) do
 
      if (parameters.number == number) and
 
        (parameters.name == "DG1HT DV4mini")
 
      then
 
        reflector = parameters.values[VALUE_REFLECTOR];
 
        break
 
      end
 
    end
 
    -- 3.2) Get group number from map
 
    local group = map[reflector]
 
    if group == nil
 
    then
 
      -- Group was not found, should be processed by TorsenHelper
 
      report("Mapped group not found for reflector DCS" .. reflector)
 
      return REGISTRY_CONTINUE_APPENDING
 
    end
 
    -- 3.3) Route call to other DVmini
 
    for _, parameters in pairs(contexts) do
 
      if (parameters.number ~= number) and
 
        (parameters.name == "DG1HT DV4mini") and
 
        (parameters.values[VALUE_REFLECTOR] == reflector)
 
      then
 
        newRoute(parameters.object, 0, 0)
 
      end
 
    end
 
    -- 3.4) Route call to LoopBack
 
    newRoute(LINK_TYPE_APPLICATION, LOOPBACK, 0, group)
 
    -- 3.5) Publish user event with reference to the reflector
 
    report("Processing call for mapped reflector DCS" .. reflector)
 
    publishEvent("reflector = " .. reflector)
 
    return REGISTRY_STOP_APPENDING
 
  end
 
  return REGISTRY_CONTINUE_APPENDING
 
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 00:34, 6 January 2021

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)

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

end

function getCountryAndRegionCode(number)

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

end

function validateGeographicRegionCode(number, code)

  1. local value1 = tostring(code)
  2. local value2 = tostring(number)
  3. local length1 = string.len(value1)
  4. local length2 = string.len(value2)
  5. return
  6. (length1 <= length2) and
  7. (value1 == string.sub(value2, 1, length1))

end

function validateRegularRepeater(parameters)

  1. return
  2. -- Link has a repeater kind
  3. (parameters.kind == LINK_TYPE_REPEATER) and
  4. -- It is not DV4mini
  5. (parameters.name ~= "DG1HT DV4mini") and
  6. -- And not Homebrew Repeater in DMO mode
  7. ((parameters.name ~= "Homebrew Repeater") or
  8. (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)

  1. if
  2. (destination ~= 9) and
  3. (kind ~= LINK_TYPE_NETWORK) and
  4. (validateGeographicRegionCode(destination, "8") or
  5. validateGeographicRegionCode(destination, "9") or
  6. getCountryCode(destination))
  7. then
  8. local contexts = getContextTable()
  9. for _, parameters in pairs(contexts) do
  10. if parameters.name == "FastForward"
  11. then
  12. newRoute(parameters.object, 0, 0)
  13. end
  14. end
  15. end

end </syntaxhighlight>

National TalkGroup routing

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

  1. if destination >= 100
  2. then
  3. local country = getCountryCode(destination)
  4. local contexts = getContextTable()
  5. for _, parameters in pairs(contexts) do
  6. if
  7. -- Do not route call back
  8. ((kind ~= parameters.kind) or
  9. (number ~= parameters.number)) and
  10. -- Remote should be a repeater
  11. validateRegularRepeater(parameters) and
  12. -- Remote ID length is great than country code
  13. (parameters.number >= 100) and
  14. -- Destination ID and Remote ID should have same country code as prefix
  15. (getCountryCode(parameters.number) == country)
  16. then
  17. newRoute(parameters.object, slot, 0)
  18. end
  19. end
  20. end

end </syntaxhighlight>

Regional TalkGroup routing

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

  1. if destination >= 1000
  2. then
  3. local region = getCountryAndRegionCode(destination)
  4. local contexts = getContextTable()
  5. for _, parameters in pairs(contexts) do
  6. if
  7. -- Do not route call back
  8. ((kind ~= parameters.kind) or
  9. (number ~= parameters.number)) and
  10. -- Remote should be a repeater
  11. validateRegularRepeater(parameters) and
  12. -- Remote ID length is great than region code
  13. (parameters.number >= 1000) and
  14. -- Destination ID and Remote ID should have same region code as prefix
  15. (getCountryAndRegionCode(parameters.number) == region)
  16. then
  17. newRoute(parameters.object, slot, 0)
  18. end
  19. end
  20. 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)

  1. -- Keep Group 9 as local
  2. if destination ~= 9
  3. then
  4. -- Subscribe repeater to group
  5. if kind == LINK_TYPE_REPEATER
  6. then
  7. cache:set(number .. "-" .. destination, tostring(slot), interval)
  8. end
  9. -- Route to subscribed group
  10. local contexts = getContextTable()
  11. for _, parameters in pairs(contexts) do
  12. if
  13. -- Do not route call back
  14. ((kind ~= parameters.kind) or
  15. (number ~= parameters.number)) and
  16. -- Remote should be a repeater
  17. (parameters.kind == LINK_TYPE_REPEATER)
  18. then
  19. local slot = cache:get(parameters.number .. "-" .. destination)
  20. if
  21. -- Subscription should be available
  22. (slot ~= nil)
  23. then
  24. newRoute(parameters.object, tonumber(slot), 0)
  25. end
  26. end
  27. end
  28. end

end </syntaxhighlight>

Generic functions[edit]

<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)

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

end

function getCountryAndRegionCode(number)

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

end

function validateGeographicRegionCode(number, code)

  1. local value1 = tostring(code)
  2. local value2 = tostring(number)
  3. local length1 = string.len(value1)
  4. local length2 = string.len(value2)
  5. return
  6. (length1 <= length2) and
  7. (value1 == string.sub(value2, 1, length1))

end

function validateRegularRepeater(parameters)

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

end </syntaxhighlight>

Global TalkGroup routing[edit]

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

  1. if
  2. (destination ~= 9) and
  3. (kind ~= LINK_TYPE_NETWORK) and
  4. (validateGeographicRegionCode(destination, "8") or
  5. validateGeographicRegionCode(destination, "9") or
  6. getCountryCode(destination))
  7. then
  8. local contexts = getContextTable()
  9. for _, parameters in pairs(contexts) do
  10. if parameters.name == "FastForward"
  11. then
  12. newRoute(parameters.object, 0, 0)
  13. end
  14. end
  15. end

end </syntaxhighlight>

National TalkGroup routing[edit]

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

  1. if destination >= 100
  2. then
  3. local country = getCountryCode(destination)
  4. local contexts = getContextTable()
  5. for _, parameters in pairs(contexts) do
  6. if
  7. -- Do not route call back
  8. ((kind ~= parameters.kind) or
  9. (number ~= parameters.number)) and
  10. -- Remote should be a repeater
  11. validateRegularRepeater(parameters) and
  12. -- Remote ID length is great than country code
  13. (parameters.number >= 100) and
  14. -- Destination ID and Remote ID should have same country code as prefix
  15. (getCountryCode(parameters.number) == country)
  16. then
  17. newRoute(parameters.object, slot, 0)
  18. end
  19. end
  20. end

end </syntaxhighlight>

Regional TalkGroup routing[edit]

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

  1. if destination >= 1000
  2. then
  3. local region = getCountryAndRegionCode(destination)
  4. local contexts = getContextTable()
  5. for _, parameters in pairs(contexts) do
  6. if
  7. -- Do not route call back
  8. ((kind ~= parameters.kind) or
  9. (number ~= parameters.number)) and
  10. -- Remote should be a repeater
  11. validateRegularRepeater(parameters) and
  12. -- Remote ID length is great than region code
  13. (parameters.number >= 1000) and
  14. -- Destination ID and Remote ID should have same region code as prefix
  15. (getCountryAndRegionCode(parameters.number) == region)
  16. then
  17. newRoute(parameters.object, slot, 0)
  18. end
  19. end
  20. end

end </syntaxhighlight>

OnDemand/Dynamic TalkGroup routing[edit]

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)

  1. -- Keep Group 9 as local
  2. if destination ~= 9
  3. then
  4. -- Subscribe repeater to group
  5. if kind == LINK_TYPE_REPEATER
  6. then
  7. cache:set(number .. "-" .. destination, tostring(slot), interval)
  8. end
  9. -- Route to subscribed group
  10. local contexts = getContextTable()
  11. for _, parameters in pairs(contexts) do
  12. if
  13. -- Do not route call back
  14. ((kind ~= parameters.kind) or
  15. (number ~= parameters.number)) and
  16. -- Remote should be a repeater
  17. (parameters.kind == LINK_TYPE_REPEATER)
  18. then
  19. local slot = cache:get(parameters.number .. "-" .. destination)
  20. if
  21. -- Subscription should be available
  22. (slot ~= nil)
  23. then
  24. newRoute(parameters.object, tonumber(slot), 0)
  25. end
  26. end
  27. end
  28. end

end </syntaxhighlight>