CmdMessenger and a 48 item array

hey people,

i’ve been working on an interface for 3 TLC5940s using Max and CmdMessenger (aka messenger, simplemessagesystem)

I finally got it working to the point of taking full advantage of the 12 bit duty cycle of a general red green and blue variables, but now I’m looking to expand to a full 48 (16 RGB) channel control system.

A switch statement took care of parsing and atoi for those 3 variables from the earlier sketch, but now that i’ve upsized nothing seems to happen. everything on the max side is fine, but I think I’m missing something from my sketch.

I’m using ben’s callback method only, I’m pretty positive it’s from the buffer length, but i have no clue what to put it at for the number of bytes I need to parse.

void bens_msg()
{
  int seq;
  long value;

  // Message data is any ASCII bytes (0-255 value). But can't contain the field
  // separator, command separator chars you decide (eg ',' and ';')
  cmdMessenger.sendCmd(kACK,"bens cmd recieved");


  for (seq = 0; cmdMessenger.available(); seq ++ )
  {
    char buf[64] = { '\0' };
    cmdMessenger.copyString(buf, 350);
    if(buf[0])
      cmdMessenger.sendCmd(kACK, buf);

    value = strtol(buf, NULL, 10);
    switch (seq) {

         case 0:
               r1 = value;
               break;

         case 1:
               g1 = value;
               break;
               
         case 2:
               b1 = value;
               break;
         case 3:
               r2 = value;
               break;

         case 4:
               g2 = value;
               break;
               
         case 5:
               b2 = value;
               break;
         case 6:
               r3 = value;
               break;

         case 7:
               g3 = value;
               break;
               
         case 8:
               b3 = value;
               break;
         case 9:
               r4 = value;
               break;

         case 10:
               g4 = value;
               break;
               
         case 11:
               b4 = value;
               break;
               
         case 12:
               r5 = value;
               break;

         case 13:
               g5 = value;
               break;
               
         case 14:
               b5 = value;
               break;
               
         case 15:
               r6 = value;
               break;

         case 16:
               g6 = value;
               break;
               
         case 17:
               b6 = value;
               break;
         case 18:
               r7 = value;
               break;

         case 19:
               g7 = value;
               break;
               
         case 20:
               b7 = value;
               break;
               
         case 21:
               r8 = value;
               break;

         case 22:
               g8 = value;
               break;
               
         case 23:
               b8 = value;
               break;
               
         case 24:
               r9 = value;
               break;

         case 25:
               g9 = value;
               break;
               
         case 26:
               b9 = value;
               break;
         case 27:
               r10 = value;
               break;

         case 28:
               g10 = value;
               break;
               
         case 29:
               b10 = value;
               break;
         case 30:
               r11 = value;
               break;

         case 31:
               g11 = value;
               break;
               
         case 32:
               b11 = value;
               break;
         case 33:
               r12 = value;
               break;
               
         case 34:
               g12 = value;
               break;
               
         case 35:
               b12 = value;
               break;
               
         case 36:
               r13 = value;
               break;

         case 37:
               g13 = value;
               break;
               
         case 38:
               b13 = value;
               break;
         case 39:
               r14 = value;
               break;

         case 40:
               g14 = value;
               break;
               
         case 41:
               b14 = value;
               break;
         case 42:
               r15 = value;
               break;

         case 43:
               g15 = value;
               break;
               
         case 44:
               b15 = value;
               break;
         case 45:
               r16 = value;
               break;

         case 46:
               g16 = value;
               break;
               
         case 47:
               b16 = value;
               break;
    }
  }
}

everything compiles fine btw.

best,
zeef

also, at most the packet I would be sending would be 240 bytes (4 bytes per value with one after each for delimiters on 48 values)

somehow a giant switch statement doesn't seem like the most efficient way to go about this.

You don’t show what your r, g and b variables are but I would suggest an array of them so that entire switch is more like

byte myRGBarray[48*3];

myRGBarray [seq] = value;


Rob

From messenger.h:

#define MESSENGERBUFFERSIZE 64
private:
  char buffer[MESSENGERBUFFERSIZE]; // Buffer that holds the data

also, at most the packet I would be sending would be 240 bytes (4 bytes per value with one after each for delimiters on 48 values)

So, no, the maximum packet size you send will not be 240 bytes.

alas. thanks for pointing that out.

would changing that number be a bad idea? should I find some way to split the message and re-combine?

I've tried some different solutions using an array with strtok but i get serial freezes (unresponsiveness) even on a much simplified set of data. such is not the case with cmdMessenger.

i've looked around the forum but I can't find a similar example of PC-Arduino communication with as many values. If someone could point me to one / show me a bit a path to follow i'd be very appreciative.

should I find some way to split the message and re-combine?

I think you do need to find a way to split the message. I don't though, see a need to re-combine them. Send however many values fit a 64 byte message, with a message number. Based on the message number, the values go somewhere in the array.