Hi all,
I am almost give up and this is my last resort!!
I am spending weeks now trying to calculate the checksum of a set of hex / characters data in Teensy code. I have all the info, even from manufacturer.
If any of you is willing to help me i would be very happy. I do guess i do not have the knowledge at this point to get to the result. Or i am totally looking it the wrong way but… i just run out of juice.
Hope some one good give a look and help this noob on his way
Here is what i am trying to do:
Trimble send out true serial this kind of information:
I need this part:
I have edit the pgn in aog like this:
//AutoSteerData
public class CPGN_FE
{
/// <summary>
/// 8 bytes
/// </summary>
public byte[] pgn = new byte[] { 0x80, 0x81, 0x7f, 0xFE, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xCC };
public int speedLo = 5;
public int speedHi = 6;
public int status = 7;
public int steerAngleLo = 8;
public int steerAngleHi = 9;
public int lineDistance = 10;
public int sc1to8 = 11;
public int sc9to16 = 12;
public short SwathoffSetLow = 13;
public int ROXTE = 14;
public void Reset()
{
}
}
In Teensy autosteer code i use this:
typ of plak hier code
//XTE // SwathOffset
if (autoSteerUdpData[3] == 0xFE && Autosteer_running) //XTE Data // is off Pin A7 TX on pcb is output
{
static uint8_t hzCounter = 0;
hzCounter++;
if (hzCounter > 9)
{
XTE = (int16_t)(autoSteerUdpData[9] << 8) + autoSteerUdpData[8];
ROSwathOffset = (int8_t)autoSteerUdpData[13];
buildSwath();
buildXTE();
//buildROSwathOffset(ROSwathOffset);
//Serial.write("ROSwathOffSet: " & ROSwathOffset);
//Serial.print("ROSwathOffSet: ");
//Serial.write(ROSwathOffset);
}
}
Then building the string i tried this:
void buildSwath()
{
strcpy(SwathOffSet, "");
strcat(SwathOffSet, "¿@ ROSwathOffset: ");
dtostrf(ROSwathOffset, 0, 0, stringSwath);
strcat(SwathOffSet, stringSwath);
strcat(SwathOffSet, "");
CalculateChecksum2();
strcat(SwathOffSet, "");
strcat(SwathOffSet, "\r\n");
Serial.write(SwathOffSet);
}
And as checksum calculation i use this ( I have edit the if (tmp == '') alot dont know wich one is good anymore)
void CalculateChecksum2() // XTE
{
int16_t sum = 0;
int16_t inx = 0;
char tmp;
// The checksum calc starts after '$' and ends before '*'
for (inx = 3; inx < 200; inx++)
{
tmp = SwathOffSet[inx];
// * Indicates end of data and start of checksum
if (tmp == '')
{
break;
}
sum ^= tmp; // Build checksum
}
byte chk = (sum >> 4);
char hex[2] = { asciiHex[chk], 0 };
strcat(SwathOffSet, hex);
chk = (sum % 16);
char hex2[2] = { asciiHex[chk], 0 };
strcat(SwathOffSet, hex2);
}
So in example from Trimble Swath line -1 gives a checksum in serial with sign “/” wich in hex is “2F”
In hex the line = 10 BF 40 14 20 52 4F 53 77 61 74 68 4F 66
66 73 65 74 3A 20 2D 31 14 06 2F 10 03 10
So i tried calculating checksum between 40 and 06 and all possible ways. But never get to this / result.
I maybe sound a bit messy, but spending weeks trying to solve this makes me crazy
I also have the original manufacturer code that checks the trimble checksum on this line of output.
But i can only send it private to be sure its not gonna go in public!! Sorry bout that!!
The thing i want to do is control this plough control and it only needs the ROXTE and the ROSWATHOFFSET.
According to this developer checksum should be calculated in whats marked yellow:
Hope its clear for you all.