That makes sense now. Also explains why i've seen *char every now and again.
Heres the solution i've got that seems to work now, although if anyone can tell me how to get away with not passing the length of the msgData array then feel free!
This calls the function:
byte msgDataArray[] = {0x04, 0x01, 0x99, 0xAA};
int msgDataSize = sizeof(msgDataArray);
sendMsg(0x44,0xBF,0x74, msgDataArray, msgDataSize);
The function itself:
void sendMsg(byte source, byte destination, byte msgType, byte *msgData, int msgLen) {
// 1 2 3 4 5 6 7
// [src] [len] [dest] [msgtype] [d0]...[dn] [crc]
//get length of msg data for len field
byte len = msgLen + 3;
//Set known data
byte GetData[255] = {source, len, destination, msgType};
for (int i = 0; i < msgLen; i++) {
int index = i+4;
GetData[index] = msgData[i];
}
//Location of ChkSum
int crcLoc = msgLen + 4;
//Set ChkSum
GetData[crcLoc] = getCheckSum(GetData);
//Print data to serial
for (int i = 0; i < len+2 ; i++) {
Serial.print(GetData[i], HEX);
}
}
and the CRC function:
int getCheckSum(byte *string) {
int i;
int checksum;
int length;
checksum = 0;
length = string[1]+1;
//Serial.print("length: ");
//Serial.println(length);
for (i = 0; i < length; i++) {
checksum ^= string[i];
}
return checksum;
}
Many thanks to those that helped.