Home AMX User Forum AMX General Discussion

'Catch all' event

Has anyone got any techniques they'd be nice enough to share when it comes to having events which catch everything from all ports of a device? eg. one event to catch events from 41001:1:0, 41001:2:0 ... 41001:n:0. Currently I build an array on boot that contains up to port n, where n is the max port I'm interested in, then rebuild the event tables. Just wondering if anyone's got a more elegant solution.

P.S. yes i've tried and event for 41001:0:0, unfortunately it doesn't play nice like the channels do.

Comments

  • mushmush Posts: 287
    G'day Phreak,

    Just to make sure I understand you correctly, you want something more elegant than this?
    dev dvARRAY [41001:1:0, 41001:2:0 ... 41001:n:0]
    
    DATA_EVENT[dvARRAY]
    {
      COMMAND:
      {
            // Command processing goes here
      }
      STRING:
      {
            // String processing goes here
      }
    }
    
    CHANNEL_EVENT[dvARRAY]
    {
      ON:
      {
            // On processing goes here
      }
      OFF:
      {
            // Off processing goes here
      }
    }
    

    Am I understanding correctly?

    Cheers

    Mush
  • PhreaKPhreaK Posts: 966
    The actual events are fine. The problem is building that array when it's contents are unknown at compile time. Currently I do something like this:
    /**
     * Builds the device component array required for the 'catch all' events.
     */
    define_function DSPBuildComponentArray ()
    {
        stack_var char dsp_id
        stack_var char component
    	
        for (dsp_id = 1; dsp_id <= length_array(vdvDSP); dsp_id++) {
            for (component = 1; component <= DSP_MAX_COMPONENTS; component--) {
                vdvDSPComponents[((dsp_id - 1) * DSP_MAX_COMPONENTS) + component] = vdvDSP[dsp_id].number:component:vdvDSP[dsp_id].system
            }
        }
    	
        rebuild_event()
    	
        debug_msg(debug_info, "'DSP device component array rebuilt'")
    }
    

    Which is called in DEFINE_START. Just curious as to how others approach it.
  • mushmush Posts: 287
    PhreaK wrote: »
    The actual events are fine. The problem is building that array when it's contents are unknown at compile time. Currently I do something like this:
    /**
     * Builds the device component array required for the 'catch all' events.
     */
    define_function DSPBuildComponentArray ()
    {
        stack_var char dsp_id
        stack_var char component
    	
        for (dsp_id = 1; dsp_id <= length_array(vdvDSP); dsp_id++) {
            for (component = 1; component <= DSP_MAX_COMPONENTS; component--) {
                vdvDSPComponents[((dsp_id - 1) * DSP_MAX_COMPONENTS) + component] = vdvDSP[dsp_id].number:component:vdvDSP[dsp_id].system
            }
        }
    	
        rebuild_event()
    	
        debug_msg(debug_info, "'DSP device component array rebuilt'")
    }
    

    Which is called in DEFINE_START. Just curious as to how others approach it.

    Ahh.. I see.
    I presume this is in a comms module for an unknown amount of separate modules that 'plug in' at run time?
  • a_riot42a_riot42 Posts: 1,624
    PhreaK wrote: »
    The actual events are fine. The problem is building that array when it's contents are unknown at compile time. Currently I do something like this:
    /**
     * Builds the device component array required for the 'catch all' events.
     */
    define_function DSPBuildComponentArray ()
    {
        stack_var char dsp_id
        stack_var char component
    	
        for (dsp_id = 1; dsp_id <= length_array(vdvDSP); dsp_id++) {
            for (component = 1; component <= DSP_MAX_COMPONENTS; component--) {
                vdvDSPComponents[((dsp_id - 1) * DSP_MAX_COMPONENTS) + component] = vdvDSP[dsp_id].number:component:vdvDSP[dsp_id].system
            }
        }
    	
        rebuild_event()
    	
        debug_msg(debug_info, "'DSP device component array rebuilt'")
    }
    

    Which is called in DEFINE_START. Just curious as to how others approach it.

    In your inner for loop you are initializing component to 1 and decrementing. Is that what you want to do? Is there some reason they are chars instead of integers?

    Are you saying that you don't know the value of DSP_MAX_COMPONENTS until run time? That shouldn't matter, just get it at some point and then run your for loops.
    Paul
  • mushmush Posts: 287
    a_riot42 wrote: »
    Are you saying that you don't know the value of DSP_MAX_COMPONENTS until run time?

    I think he is saying he doesn't know the length of vdvDSP until run time?
  • PhreaKPhreaK Posts: 966
    @a_riot42
    Inner loop decriment was a typo, removed some other guff as I pasted.
    I'm using chars because it's impossible for those values to ever be larger than 255. Every byte is precious, especially when the code is on old NI-X000's.

    @mush
    Exactly. The code has to be flexible to allow for an unknown number of devices, each with an unknown number of components.
  • mushmush Posts: 287
    Kim,
    PhreaK wrote: »
    @mush
    Exactly. The code has to be flexible to allow for an unknown number of devices, each with an unknown number of components.

    Interesting way of doing it and I guess it depends on which device you are trying to program.
    When we send a string to the comms module we include the device number of who sent it, the ID of the device we are trying to reach and the data we are trying to send.
    The comms module then knows who to send what and doesn't need to keep a list of devices.
    Not as refined as your way but it works well!

    Mush
  • a_riot42a_riot42 Posts: 1,624
    PhreaK wrote: »
    @a_riot42
    I'm using chars because it's impossible for those values to ever be larger than 255. Every byte is precious, especially when the code is on old NI-X000's.

    I wouldn't worry about using one more byte in a stack_var that is reallocated as soon as the function ends. That seems a bit extreme.

    If 256 is the max for those values can't you just make the array that big? At some point during runtime you will know how many DSPs there are so set the variable in the for loop guard to that and run your loops. You can prune your array using set_length_array if need be.
    Paul
  • PhreaKPhreaK Posts: 966
    a_riot42 wrote: »
    That seems a bit extreme.
    Force of habbit - doesn't do any damage.

    If I was to just set it to the max it would end up being a 65536 element array (256 devices * 256 components).
Sign In or Register to comment.