Iterate over string and/or split incoming data message

Discuss issues and ideas you have to configuring displays with PowerVision
cconner_aie
Posts: 93
Joined: Thu Jun 11, 2015 10:12 am

Iterate over string and/or split incoming data message

Post by cconner_aie » Wed Mar 22, 2017 10:07 am

I'm trying to figure out how to process the J1939 CI PGN request, but I can't seem to find a way to iterate through the string.

The string I recieve is "KBTA *EG54670000*7DC0643*1*" which matches the format of the component id request (quoted below). My question is how do I split up this string into it's respective fields, from what I can tell AngelScript doesn't have a char array representation so iterating over it is not obvious (for me anyway). My other thought was to use the CANMessageBuffer passed in the complete event, however that's a lot of translating from hex to ascii I'd rather avoid.

I saw in another post that there should be a way for the Free From Data Message to do this for me using one of the filters. It looks like the Continue Packet Definition would work for this, but I can't see how to implement this.

Can anyone point me towards an example of filtering a string?

Image

Code: Select all

void $E_PGNRequest_ProcessComponentID$ (CANMessageBuffer @buffer) 
{
	// E.G.
	// [make]*[model]*[serial]*[unit number]*
	// incoming string = "KBTA *EG54670000*7DC0643*1*"
	// make = KBTA
	// model = EG54670000
	// serial = 7DC0643
	// unit = 1
	
	// TODO?	
}
PGN 65259 Component Identification CI
NOTE - The make, model, serial number and unit number fields in this message are optional and separated by an ASCII “*”. It is not necessary to include all fields; however, the delimiter (“*”) is always required.

Field:
a Make
Delimiter (ASCII “*”)
b Model
Delimiter (ASCII “*”)
c Serial number
Delimiter (ASCII “*”)
d Unit number (Power unit)
Delimiter (ASCII “*”)

Transmission Repetition Rate: On request
Data Length: Variable
Extended Data Page: 0
Data Page: 0
PDU Format: 254
PDU Specific: 235 PGN Supporting Information:
Default Priority: 6
Parameter Group Number: 65259 (0x00FEEB)
Start Position Length Parameter Name SPN
a - (Make) Variable - up to 5 bytes followed by an "*" delimiter
b - (Model) Variable - up to 200 bytes followed by an "*" delimiter
c - (Serial) Variable - up to 200 bytes followed by an "*" delimiter
d - (Unit) Variable - up to 200 bytes followed by an "*" delimiter
Coleby Conner
Controls Engineer, Anderson Industrial Engines
cconner_aie
Posts: 93
Joined: Thu Jun 11, 2015 10:12 am

Re: Iterate over string and/or split incoming data message

Post by cconner_aie » Wed Mar 22, 2017 3:28 pm

Update:

Turns out there is no char[] data type, however you can address each byte in the sting using the [] operators. This is great, however I get the ASCII decimal value back as a result and I can't find a way to convert this to string to append onto a string buffer.

E.G.

Code: Select all


string make = "";

cultureGetString(StringIDs.S_PGNRequest_ComponentID, componentID, 0);

for (i = 0; i < componentID.length(); i++) {
	
	// I still get the ascii decimal back, even trying to cast it to string	
	//string char = componentID[i];
			
	// looking for '*'
	if (char == 42) {
		cultureSetString(StringIDs.S_Information_EngineMake, make, true);
		break;
	}
			
	make += char;	
}

This results in "7566846532" which is the ascii decimals for "KBTA ".

I feel like I am close, the link below led me onto the [] operator's being an option - I just can't figure out how to get an ascii value out of it without writing my own conversion method.

http://www.angelcode.com/angelscript/sd ... rings.html

Any help would be appreciated, thanks!
Coleby Conner
Controls Engineer, Anderson Industrial Engines
cconner_aie
Posts: 93
Joined: Thu Jun 11, 2015 10:12 am

Re: Iterate over string and/or split incoming data message

Post by cconner_aie » Wed Mar 22, 2017 4:12 pm

I ended up writing my own conversion class for now, I'll roll with this unless someone else has a better example.

Thanks!

Code: Select all


string decToASCII(int decimal)
{

	switch (decimal)
	{		
		case 32:	return " ";
		case 33:	return "!";
		case 34:	return """;
		case 35:	return "#";
		case 36:	return "$";
		case 37:	return "%";
		case 38:	return "&";
		case 39:	return "'";
		case 40:	return "(";
		case 41:	return ")";
		case 42:	return "*";
		case 43:	return "+";
		case 44:	return ",";
		case 45:	return "-";
		case 46:	return ".";
		case 47:	return "/";
		case 48:	return "0";
		case 49:	return "1";
		case 50:	return "2";
		case 51:	return "3";
		case 52:	return "4";
		case 53:	return "5";
		case 54:	return "6";
		case 55:	return "7";
		case 56:	return "8";
		case 57:	return "9";
		case 58:	return ":";
		case 59:	return ";";
		case 60:	return "<";
		case 61:	return "=";
		case 62:	return ">";
		case 63:	return "?";
		case 64:	return "@";
		case 65:	return "A";
		case 66:	return "B";
		case 67:	return "C";
		case 68:	return "D";
		case 69:	return "E";
		case 70:	return "F";
		case 71:	return "G";
		case 72:	return "H";
		case 73:	return "I";
		case 74:	return "J";
		case 75:	return "K";
		case 76:	return "L";
		case 77:	return "M";
		case 78:	return "N";
		case 79:	return "O";
		case 80:	return "P";
		case 81:	return "Q";
		case 82:	return "R";
		case 83:	return "S";
		case 84:	return "T";
		case 85:	return "U";
		case 86:	return "V";
		case 87:	return "W";
		case 88:	return "X";
		case 89:	return "Y";
		case 90:	return "Z";
		case 91:	return "[";
		case 92:	return "\\";
		case 93:	return "]";
		case 94:	return "^";
		case 95:	return "_";
		case 96:	return "`";
		case 97:	return "a";
		case 98:	return "b";
		case 99:	return "c";
		case 100:	return "d";
		case 101:	return "e";
		case 102:	return "f";
		case 103:	return "g";
		case 104:	return "h";
		case 105:	return "i";
		case 106:	return "j";
		case 107:	return "k";
		case 108:	return "l";
		case 109:	return "m";
		case 110:	return "n";
		case 111:	return "o";
		case 112:	return "p";
		case 113:	return "q";
		case 114:	return "r";
		case 115:	return "s";
		case 116:	return "t";
		case 117:	return "u";
		case 118:	return "v";
		case 119:	return "w";
		case 120:	return "x";
		case 121:	return "y";
		case 122:	return "z";
		case 123:	return "{";
		case 124:	return "|";
		case 125:	return "}";
		case 126:	return "~";
		case 127:	return "";
	}
	
	return "";
}
Coleby Conner
Controls Engineer, Anderson Industrial Engines
boyce
Enovation Controls Development
Enovation Controls Development
Posts: 322
Joined: Wed Sep 08, 2010 5:09 pm

Re: Iterate over string and/or split incoming data message

Post by boyce » Thu Mar 23, 2017 11:16 am

I was looking at using strings in scripting and began running into problems. I could do something like this, without having to handle each ASCII code:

Code: Select all

string decToString(int c)
{
	string s = " ";
	s[0] = c;
	return s;
}
Your code works fine and it kept you going.
Boyce Schrack
Enovation Controls