static void cmdSetMoveQueue(unsigned char type, unsigned char status, unsigned char length, unsigned char *frame) { unsigned int count; int idx = 0; count = (unsigned int)(*(frame+idx)); idx += 2; moveCmdT move; int i; unsigned char durtemp[4]; unsigned long* dur = (unsigned long*)durtemp; // requires for unsigned long read for(i = 0; i < count; i++){ move = (moveCmdT)malloc(sizeof(moveCmdStruct)); //move->inputL = (int)(*(frame+idx)); move->inputL = frame[idx] + (frame[idx+1] << 8); idx+=2; //idx += 2; //move->inputR = (int)(*(frame+idx)); move->inputR = frame[idx] + (frame[idx+1] << 8); idx+=2; //idx += 2; //apparently this is required to properly read the unsigned long. durtemp[0] = frame[idx]; durtemp[1] = frame[idx+1]; durtemp[2] = frame[idx+2]; durtemp[3] = frame[idx+3]; move->duration = dur[0]; idx += 4; mqPush(moveq, move); } }
static void cmdSetMoveQueue(unsigned char status, unsigned char length, unsigned char *frame) { //The count is read via standard pointer math unsigned int count; count = (unsigned int) (*(frame)); //Unpack unsigned char* frame into structured values //Here, unpacking happens in the loop below. //_args_cmdSetMoveQueue* argsPtr; int idx = sizeof (count); //should be an unsigned int, sizeof(uint) = 2 moveCmdT move; int i; for (i = 0; i < count; i++) { move = (moveCmdT) malloc(sizeof (moveCmdStruct)); //argsPtr = (_args_cmdSetMoveQueue*)(frame+idx); *move = *((moveCmdT) (frame + idx)); mqPush(moveq, move); //idx =+ sizeof(_args_cmdSetMoveQueue); idx += sizeof (moveCmdStruct); } }