Jump to content

llMUX


Cid Jacobs
 Share

You are about to reply to a thread that has been inactive for 1394 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

// llMUX
// Copyright (C) 2020  Cid Jacobs
// Created by: Cid Jacobs
// Original by: Cid Jacobs
// Created: 06-17-20
// Last Updated: 06-17-20
//
//
//--------------------Notes
//llMUX is a method which allows multiple signals to be combined (multiplexing) into one signal fed through a timer event. The aim is to share a scarce relinkNumber. In this case, timer event calls.
//
//
//--------------------License
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// A copy of the GNU General Public License is available at http://www.gnu.org/copyleft/gpl.html
//
//
//--------------------Support
// I do not guarantee to support this script or any modifications of this script.
//
//
//--------------------Features
//  - Supports 16 "channel" dual encoded events.
//  - Easily outputs to linked message events.
//
//
//--------------------Contraints
//  - Only allows for frequency values as integers.
//  - Only allows for period values as integers.
//  - FIFO (First in first out) if "channels" beyond 16 are created.
//
//
//--------------------Credits
// I would like to thank the following for beta testing.
//          NightCatsMeow  (rebecca.wendell)
//
//
//--------------------Change Log
//V0.1.0 - Release
//  - Added encoding and linkNumber mapping
//V0.0.1 - Non-Release
//  - Added channel switching
//V0.0.0 - Non-Release
//  - Added MUX frequency and signal plexing
//
//
//--------------------Globals
integer gPeriod = 60;//Interval to raise timer library call 
integer gDMX;
list    gFrequencyList;
list    gLinkList;
list    gChannelList;
list    gSignalList;
list    gEncodingList;
//--------------------User Defined Functions
//Causes llDMX to trigger at rate of (Frequency * Period) per second. Multiplex Channel, Signal and Encoding to members of link set identified by linkNumber. linkNumber is either a linked number (available through llGetLinkNumber) or a LINK_* constant.
llMUX(integer frequency, integer linkNumber, integer channel, string signal, key encoding)
{
    gFrequencyList  += frequency;
    gLinkList     += linkNumber;
    gChannelList    += channel;
    gSignalList     += signal;
    gEncodingList   += encoding;
    if(llGetListLength(gSignalList) > 16)
    {
        gFrequencyList  = llDeleteSubList(gFrequencyList,0,0);
        gLinkList       = llDeleteSubList(gLinkList,0,0);
        gChannelList    = llDeleteSubList(gChannelList,0,0);
        gSignalList     = llDeleteSubList(gSignalList,0,0);
        gEncodingList   = llDeleteSubList(gEncodingList,0,0);
    }
}
llDMX()
{
    ++gDMX;
    integer c = 0;
    for(;c < llGetListLength(gSignalList);++c)
    {
        integer frequency   = llList2Integer(gFrequencyList,c);
        integer linkNumber  = llList2Integer(gLinkList,c);
        integer channel     = llList2Integer(gChannelList,c);
        string signal       = llList2String(gSignalList,c);
        key encoding        = llList2Key(gEncodingList,c);
        if(gDMX%frequency == 0)
        {
            llMessageLinked(linkNumber,channel,signal,encoding);
        }
    }
}
//
//
//--------------------States
//Required Default State
default
{
    state_entry()
    {
        llMUX(1,LINK_SET,100,"Hello, world.",llGetOwner());
        llSetTimerEvent((float)gPeriod);
    }
    timer()
    {
        llDMX();
    }
    link_message(integer linkNumber,integer channel,string signal,key encoding)
    {
        llOwnerSay((string)linkNumber + "|" + (string)channel + "|" + signal + "|" + (string)encoding);
    }
}

 

Link to comment
Share on other sites

By request, this update allows for removal of individual channels:

// llMUX
// Copyright (C) 2020  Cid Jacobs
// Created by: Cid Jacobs
// Original by: Cid Jacobs
// Created: 06-17-20
// Last Updated: 06-17-20
//
//
//--------------------Notes
//llMUX is a method which allows multiple signals to be combined (multiplexing) into one signal fed through a timer event. The aim is to share a scarce resource. In this case, timer event calls.
//
//
//--------------------License
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// A copy of the GNU General Public License is available at http://www.gnu.org/copyleft/gpl.html
//
//
//--------------------Support
// I do not guarantee to support this script or any modifications of this script.
//
//
//--------------------Features
//  - Supports 16 "channel" dual encoded events.
//  - Easily outputs to linked message events.
//  - Allows for removal of chanels individually.
//
//
//--------------------Contraints
//  - Only allows for frequency values as integers.
//  - Only allows for period values as integers.
//  - FIFO (First in first out) if "channels" beyond 16 are created.
//
//
//--------------------Credits
// I would like to thank the following for beta testing.
//          NightCatsMeow  (rebecca.wendell)
//
//
//--------------------Change Log
//V0.1.1 - Release
//  - Added boolean for removing channels individually
//V0.1.0 - Release
//  - Added encoding and linkNumber mapping
//V0.0.1 - Non-Release
//  - Added channel switching
//V0.0.0 - Non-Release
//  - Added MUX frequency and signal plexing
//
//
//--------------------Globals
integer gPeriod = 60;//Interval to raise timer library call 
integer gDMX;
integer gToggle;
list    gFrequencyList;
list    gLinkList;
list    gChannelList;
list    gSignalList;
list    gEncodingList;
//--------------------User Defined Functions
//Causes llDMX to trigger at rate of (Frequency * Period) per second. Multiplex Channel, Signal and Encoding to members of link set identified by linkNumber. linkNumber is either a linked number (available through llGetLinkNumber) or a LINK_* constant.
llMUX(integer frequency, integer linkNumber, integer channel, string signal, key encoding, integer toggle)
{
    if(toggle)
    {
        gFrequencyList  += frequency;
        gLinkList     += linkNumber;
        gChannelList    += channel;
        gSignalList     += signal;
        gEncodingList   += encoding;
        if(llGetListLength(gSignalList) > 16)
        {
            gFrequencyList  = llDeleteSubList(gFrequencyList,0,0);
            gLinkList       = llDeleteSubList(gLinkList,0,0);
            gChannelList    = llDeleteSubList(gChannelList,0,0);
            gSignalList     = llDeleteSubList(gSignalList,0,0);
            gEncodingList   = llDeleteSubList(gEncodingList,0,0);
        }
    }
    else
    {
        integer sortIndex = llListFindList(gFrequencyList, [frequency]);
        if(sortIndex != -1)
        {
            gFrequencyList  = llDeleteSubList(gFrequencyList,sortIndex,sortIndex);
            gLinkList       = llDeleteSubList(gLinkList,sortIndex,sortIndex);
            gChannelList    = llDeleteSubList(gChannelList,sortIndex,sortIndex);
            gSignalList     = llDeleteSubList(gSignalList,sortIndex,sortIndex);
            gEncodingList   = llDeleteSubList(gEncodingList,sortIndex,sortIndex);
        }
    }
}
llDMX()
{
    ++gDMX;
    integer c = 0;
    for(;c < llGetListLength(gSignalList);++c)
    {
        integer frequency   = llList2Integer(gFrequencyList,c);
        integer linkNumber  = llList2Integer(gLinkList,c);
        integer channel     = llList2Integer(gChannelList,c);
        string signal       = llList2String(gSignalList,c);
        key encoding        = llList2Key(gEncodingList,c);
        if(gDMX%frequency == 0)
        {
            llMessageLinked(linkNumber,channel,signal,encoding);
        }
    }
}
//
//
//--------------------States
//Required Default State
default
{
    state_entry()
    {
        llSetTimerEvent((float)gPeriod);
    }
    touch_start(integer num)
    {
        if(gToggle)
        {
            llMUX(1,LINK_SET,100,"Hello, world.",llGetOwner(),FALSE);
        }
        else
        {
            llMUX(1,LINK_SET,100,"Hello, world.",llGetOwner(),TRUE);
        }
        gToggle = !gToggle;
    }
    timer()
    {
        llDMX();
    }
    link_message(integer linkNumber,integer channel,string signal,key encoding)
    {
        llOwnerSay((string)linkNumber + "|" + (string)channel + "|" + signal + "|" + (string)encoding);
    }
}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1394 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...