Need more help :( I've got initial FCM input parsing down, but it's terminating the loop far too early. Code is below:
public FCMControllerData(ref byte[] byteArray, int controllerDataOffset, int controllerDataLength)
{
controllerData = new ArrayList();
int position = controllerDataOffset;
int frameCount = 0;
int[] joop = {0,0,0,0};
while (controllerDataLength > 0)
{
int updateType = byteArray[position] >> 7;
int NDelta = (byteArray[position] >> 5 ) & 3;
int delta = 0;
int data = byteArray[position] & 0x1F;
++position; --controllerDataLength;
switch (NDelta)
{
case 0:
break;
case 1:
delta |= byteArray[position++];
break;
case 2:
delta |= byteArray[position++];
delta |= byteArray[position++] << 8;
break;
case 3:
delta |= byteArray[position++];
delta |= byteArray[position++] << 8;
delta |= byteArray[position++] <<16> 0)
while(delta > 0)
{
// Save the controlled data
controllerData.Add(parseControllerData(joop));
++frameCount;
--delta;
}
if (controllerDataLength > NDelta)
controllerDataLength -= NDelta;
else
controllerDataLength = 0;
if (updateType == 0) // Controller data
{
int ctrlno = (data >> 3);
joop[ctrlno] ^= (1 << (data & 7));
if (ctrlno == 0) { controller1 = true; }
if (ctrlno == 1) { controller2 = true; }
if (ctrlno == 2) { controller3 = true; }
if (ctrlno == 3) { controller4 = true; }
}
}
}
The problem seems to be with the initial decrement of the controllerDataLength (byte read in from fcm at 0x14). Bisqwit's been helpful, but i'm mildly retarded so I can't seem to figure this out. I can't take the decrement out or the array will read itself out of bounds.
Any ideas are welcome. Once I can get this working, a new version should be available :)
EDIT: Turns out the problem was that i'm retarded and wasn't reading enough info in from the header (1 byte vs. 4 bytes). Problem solved. Thanks everyone.