Forums > MaxMSP

Converting long lists of ints to ASCII, for UDP packets

March 13, 2008 | 2:32 am

What’s the easiest way to convert a list (longer than 256, probably a maximum of about 1600) of ints (0-255) to ASCII? Essentially itoa but with more elements. I’ve tried in java but I’m missing the right actual function, and don’t know if javascript can do the "casting" that’s needed. Or a third-party external that does this solidly? or a clever workaround using coll?

Am sending LED data from Max wirelessly via UDP packets. They are :: RGB formatted into DMX, up to 512 channels, so maximum for a standard DMX usage = 1536, + one index byte at front. The setup could use many more channels as well, but this is within DMX specifications, and it’s plenty for our purposes here.

The hardware only wants data formatted as ASCII, ints won’t do it. Essentially, it would be great if the udp.send had a flag: default as-is, or switch on "convert incoming int packet list to ASCII", able to handle lists as long as udp.send can manage. Or, of course, a conversion beforehand.

This is a continued post from about a month ago, where my brother and I were getting an LED installation ready for a wedding. (Thanks to volker and Scott F. for their help during this!) Now there’s no real rush, but this hurdle would save having to make multiple control boards. One of his boards can handle the full # of DMX channels (a lot more, actually, as it’s a SecureDigital video / DMX / whatever playback device as well) so we want to use just one if possible. All it needs is that big ASCII list in.

http://www.celestialaudio.com/MC9S12NE64/index.html

Any help around this probably-quite-simple problem would be fantastic, it’s getting in the way of the fun stuff … thanks !

–CJ


March 13, 2008 | 10:15 am

On 13 Mar 2008, at 02:32, Seejay James wrote:

> What’s the easiest way to convert a list (longer than 256, probably
> a maximum of about 1600) of ints (0-255) to ASCII?

A couple of questions:

(i) given that Max, or parts of Max, don’t like long lists, how do
your lists of integers actually arrive or get generated? (Sequentially
with a count or an end-marker?)

(ii) ASCII is 0..127, so you’re presumably making assumptions about
the device’s character coding for 128…255 – what do you mean by
ASCII containing these values?

Nick Rothwell – nick@cassiel.comhttp://www.cassiel.com
— open-source goodies for MaxMSP: Python, Groovy, Nixie Tubes,
— rotatable text bricks, databases: all at http://www.loadbang.net


March 13, 2008 | 7:38 pm

Tried some more experimentation. Here’s an example patch with comments to show what I’m trying to do. I guess I meant iso-8859, not ASCII, as the hardware responds to a full byte’s worth of values. The patch allows you to see the full range of characters (with a number of non-printable etc. ones).

I get the lists through a jit.bfg, some other jit.effects, then a spill into separate R G B multisliders, then an interleave. The last list is a large multislider, so the user can manually set any specific channel, or run pattrs etc., if they want to(like when the generators are shut off). The interleaving of lists larger than 256 is straightforward via javascript, but only if they are still ints.

Hopefully this makes sense? Achhh ! !

–CJ

———————————————-

#P window setfont "Sans Serif" 14.;
#P number 26 579 43 14 1 255 19 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 17 249 43 14 1 255 19 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 243 249 43 14 1 255 19 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 10.;
#P window linecount 1;
#P hidden message 7 602 65 9109514 set 1 $1;
#P window setfont "Sans Serif" 18.;
#P number 13 550 49 18 1 255 3 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 10.;
#P hidden message 5 275 65 9109514 set 1 $1;
#P hidden message 227 275 65 9109514 set 1 $1;
#P window setfont "Sans Serif" 18.;
#P number 4 220 49 18 1 255 3 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 232 220 49 18 1 255 3 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 12.;
#P window linecount 2;
#P comment 703 247 341 9109516 also I need the full list to be sent as one packet , it can’t be R then G then B as separate packets ;;
#P window linecount 1;
#P comment 310 325 735 9109516 If so… "itoa" is not just ASCII … the hardware definitely responds to the whole 1-255 value range ;;
#P window setfont "Sans Serif" 10.;
#P comment 30 67 334 9109514 Use "Shift" to constrain to single slider ;;
#P comment 280 216 403 9109514 make some ASCII art in the Max window… try some wacky fonts! :) :);
#P window setfont "Sans Serif" 14.;
#P comment 350 374 206 9109518 the above both work fine;
#P window setfont "Sans Serif" 12.;
#P comment 450 300 456 9109516 see the chars: this must be iso-8859-1 since it’s 8-bit? ;;
#P user multiSlider 13 431 28 111 1. 255. 1 2921 47 0 0 2 3 0 0;
#M frgb 255 255 255;
#M brgb 0 0 0;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 0 248 4;
#M rgb5 0 0 255;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 239 110 28 101 1. 255. 1 2921 47 0 0 2 3 0 0;
#M frgb 255 255 255;
#M brgb 0 0 0;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 0 248 4;
#M rgb5 0 0 255;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 7 110 28 101 1. 255. 1 2921 47 0 0 2 3 0 0;
#M frgb 255 255 255;
#M brgb 0 0 0;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 0 248 4;
#M rgb5 0 0 255;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont "Sans Serif" 9.;
#P newex 175 373 170 9109513 udpsend 192.168.1.130 58082;
#B color 3;
#P window setfont "Sans Serif" 12.;
#P window linecount 3;
#P comment 701 181 329 9109516 if we need more than that (up to 512) I use a javascript to interleave… these operations are no problem when the lists are ints , but the "itoa" conversion is where I’m stuck……. ?? ;;
#P window linecount 4;
#P comment 702 93 342 9109516 The real one has separate R G B , generated through a jit.bfg and some other jit.effects… –> jit.spill , then interleave the three channels using a listfunnel and coll (if under 256 total RGB channels) ;;
#P window linecount 1;
#P comment 702 59 329 9109516 Simplified patch to give the idea ;;
#P comment 246 575 909 9109516 Need the "itoa" on this long list… ints don’t work with the hardware….Should be able to do conversion here first ! ;;
#P comment 195 552 523 9109516 1537 points is absolute maximum DMX-compatible total ;;
#P newex 98 572 145 9109516 print 512_channels;
#P comment 44 411 393 9109516 512 max channels possible for DMX = 1536 points;
#P window setfont "Sans Serif" 10.;
#P newex 99 547 92 9109514 prepend 1;
#P user multiSlider 44 431 984 111 1. 255. 1536 2921 47 0 0 2 3 0 0;
#M frgb 255 9 9;
#M brgb 0 0 0;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 0 248 4;
#M rgb5 0 0 255;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont "Sans Serif" 12.;
#P comment 32 24 1006 9109516 Values are 1 – 255 (the 0 value gave weirdness — new page character ? — and is not really needed as "1" is pretty much "off" for the LED’s) ;;
#P comment 361 273 226 9109516 255 + 1 = maximum for itoa ;;
#P comment 274 88 253 9109516 85 max channels with 256 limit;
#P newex 309 299 136 9109516 print 85_channels;
#P newex 308 271 40 9109516 itoa;
#P window setfont "Sans Serif" 10.;
#P newex 308 243 92 9109514 prepend 1;
#P user multiSlider 270 110 341 102 1. 255. 255 2921 47 0 0 2 3 0 0;
#M frgb 255 9 9;
#M brgb 0 0 0;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 0 248 4;
#M rgb5 0 0 255;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont "Sans Serif" 12.;
#P comment 42 88 150 9109516 1 RGB channel;
#P window setfont "Sans Serif" 10.;
#P comment 402 246 150 9109514 need for DMX coding ;;
#P window setfont "Sans Serif" 12.;
#P message 87 331 117 9109516 XX;
#P newex 87 304 106 9109516 prepend set;
#P newex 87 277 40 9109516 itoa;
#P window setfont "Sans Serif" 10.;
#P newex 87 252 92 9109514 prepend 1;
#P user multiSlider 38 110 96 102 1. 255. 3 2921 47 0 0 2 3 0 0;
#M frgb 255 9 9;
#M brgb 0 0 0;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 0 248 4;
#M rgb5 0 0 255;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont "Sans Serif" 14.;
#P comment 70 375 100 9109518 to hardware;
#P hidden connect 25 0 35 0;
#P hidden connect 35 0 37 0;
#P hidden connect 37 0 25 0;
#P hidden connect 38 0 39 0;
#P hidden connect 39 0 27 0;
#P hidden connect 27 0 38 0;
#P connect 35 0 41 0;
#P connect 38 0 42 0;
#P hidden connect 35 0 1 0;
#P hidden connect 25 0 1 0;
#P hidden connect 38 0 15 0;
#P hidden connect 27 0 15 0;
#P hidden connect 1 0 2 0;
#P hidden connect 2 0 3 0;
#P hidden connect 3 0 4 0;
#P hidden connect 4 0 5 0;
#P hidden connect 16 0 18 0;
#P hidden connect 15 0 16 0;
#P hidden connect 10 0 24 0;
#P lcolor 4;
#P hidden connect 3 0 24 0;
#P lcolor 4;
#P hidden connect 34 0 36 0;
#P hidden connect 26 0 34 0;
#P hidden connect 36 0 26 0;
#P connect 34 0 40 0;
#P hidden connect 34 0 8 0;
#P hidden connect 26 0 8 0;
#P hidden connect 8 0 9 0;
#P connect 9 0 10 0;
#P hidden connect 10 0 11 0;
#P window clipboard copycount 43;


Viewing 3 posts - 1 through 3 (of 3 total)