i'm currently developing a cross platform application to control MWC via wifi for my Final year project, but i already hit the wall, i can't find out how to create a checksum, im using socket test and type the message directly to test it before starting with the code
lets say i want to send an
MSP_IDENT:
$M<[0][100][crc?]
36 77 60 49 48 48 [Checksum?]
_________
Solved and implimented using C# but,
________________________
Now im having a diffrent problem i've been searching for few days but i can't find the solution, after converting values and assembling the socket and send it i couldn't get any answer from the arduino considering that when i send it via a socket test android app i.e write the socket manually exp:(24 4d 3c 00 64 64) in Hex, i get an answer, i think it has somethink with the speed of transmission, this is my code:
Code: Select all
public void setupSocket() { // Socket setup here
try {
mySocket = new TcpClient(Host, Port);
theStream = mySocket.GetStream();
theWriter = new StreamWriter(theStream);
theReader = new StreamReader(theStream);
socketReady = true;
cnx.Play (); //voice assistant "connected"
}
catch (Exception e) {
Debug.Log("Socket error:" + e); // catch any exceptions
lostcnx.Play (); //Disconnected voice assistant
}
}
public void writeSocket(string theLine) { // function to write data out
if (!socketReady)
return;
string tmpString = theLine;
theWriter.WriteLine(tmpString);
theWriter.Flush();
/************i've tried also*************/
//tmpString = System.Convert.ToByte ("244d3c006464");
//String nx="24 4d 3c 00 64 64";
//writer(theLine, 0, theLine.Length);
}
public string readSocket() { // function to read data in
if (!socketReady)
return "";
if (theStream.DataAvailable)
return theReader.ReadLine();
return "NoData";
}
And this is the MSP code :
Code: Select all
//send msp with payload
private List<Byte> requestMSP(int msp, byte[] payload)
{
if (msp < 0)
{
return null;
}
List<Byte> bf = new List<Byte>();
foreach (byte c in MSP_HEADER.ToCharArray())
{
bf.Add(c);
}
byte checksum = 0;
byte pl_size = (byte)((payload != null ? (int)(payload.Length) : 0) & 0xFF);
bf.Add(pl_size);
checksum ^= (byte)(pl_size & 0xFF);
bf.Add((byte)(msp & 0xFF));
checksum ^= (byte)(msp & 0xFF);
if (payload != null)
{
foreach (byte b in payload)
{
bf.Add((byte)(b & 0xFF));
checksum ^= (byte)(b & 0xFF);
}
}
bf.Add(checksum);
return (bf);
}
void sendRequestMSP(List<Byte> msp)
{
byte[] arr = new byte[msp.Count];
int i = 0;
foreach (byte b in msp)
{
arr[i++] = b;
}
client.writeSocket(BitConverter.ToString(arr)); // send the complete byte sequence in one go
string output=BitConverter.ToString(arr);
Debug.Log (output);
}
i've tried many possible solution the socket looks correct in the debug messages but i guess the hex values is converted in wrong way before sending, and i don't know if i can control the speed of transmition some how, the same as in the serial port baudrate !!
Thanks in advance