1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | split the variable path into an array, and determine some object characteristics TO DO: objects and arrays should automatically close, as it is possible that this variable is the last one ========================================================================================================*) //TO DO: use SPLIT function to create an array first, then loop through the array WHILE (StringIndex > 0) DO IF (NameStringPtr^[StringIndex] = ASCII.DOT) THEN //found a "." character VarNameBegin:= StringIndex + 1; //clear array string TO DO: IS THIS NECESSARY? Sysmem.SysMemSet( pDest:= ADR(_VarNameArray[VarNameIndex]), udiValue:= 0, udiCount:= GPL_JSON.MAX_NAME_SIZE ); //copy string between VarNameBegin and VarNameEnd SysMem.SysMemCpy( pSrc:= ADR(NameStringPtr^[VarNameBegin]), udiCount:= INT_TO_UDINT((VarNameEnd - VarNameBegin)+1) //remove leading _ from the name, if present _VarNameArray[VarNameIndex].Name:= RIGHT(STR:= _VarNameArray[VarNameIndex].Name, SIZE:= LEN(_VarNameArray[VarNameIndex].Name) - 1); END_IF startarraystr:= FIND(STR1:= _VarNameArray[VarNameIndex].Name, STR2:= '['); VarNameEnd:= VarNameBegin - 2; //end of the next variable name is known, store for next loop StringIndex:= VarNameBegin - 2; ELSE StringIndex:= StringIndex - 1; END_IF END_WHILE (*VAR_STAT PrevApplicationLevel and PrevNameArray are references to the last JSONVAR variable could also be a variable contained in a completely different JSON structure. its FB_Init() method has not run yet), the characteristics of the last variable in a structure are set in the STRUCT_TO_JSON function block.*) //First variable of a structure IF __ISVALIDREF(PrevNameArray) THEN I don't know if it is possible to determine whether or not this variable is the beginning of a new structure information this program has to work with is the string which contains the path. This string only contains This functionality is now contained in STRUCT_TO_JSON, which is able to determine the first and last difficult to understand, as there's two locations that work on variable characteristics.*) ELSE //every level of the first variable could be either a new object or a new array IF (_VarNameArray[varlevelindex].ArrayIndex = 1) THEN //new array _VarNameArray[varlevelindex].NewArray:= TRUE; ELSIF (varlevelindex > 1) THEN //new object _VarNameArray[varlevelindex].NewObject:= TRUE; END_IF END_FOR ELSE //not the first variable of a new structure //if objects have shifted down, then i-offset will never point to PrevNameArray[1] //the previous variable might need an array closed IF (PrevNameArray[1].ArrayIndex > 0) THEN //end array PrevNameArray[1].EndArray:= TRUE; PrevNameArray[prevvarlevelindex].EndArray:= TRUE; //====================End previous object==================== IF ((varlevelindex-offset) > 1) AND ((_VarNameArray[varlevelindex].Name <> PrevNameArray[prevvarlevelindex].Name) OR (_VarNameArray[varlevelindex].ArrayIndex <> PrevNameArray[prevvarlevelindex].ArrayIndex)) THEN PrevNameArray[prevvarlevelindex].EndObject:= TRUE; //close previous object _VarNameArray[varlevelindex].NewArray:= TRUE; //set a reference to some variables for the next JSON variable PrevApplicationLevel REF= _ApplicationLevel; {a9ed5b7e-75c5-4651-af16-d2c27e98cb94} VAR_INPUT bInitRetains : BOOL; // TRUE: the retain variables are initialized (reset warm / reset cold) |