|
| 1 | +/******************************************************************** |
| 2 | + * COPYRIGHT -- |
| 3 | + ******************************************************************** |
| 4 | + * Library: VarInfo |
| 5 | + * File: varGetValue.c |
| 6 | + * Author: davidblackburn |
| 7 | + * Created: June 02, 2014 |
| 8 | + ******************************************************************** |
| 9 | + * Implementation of library VarTools |
| 10 | + ********************************************************************/ |
| 11 | + |
| 12 | +#include <bur/plctypes.h> |
| 13 | +#ifdef __cplusplus |
| 14 | + extern "C" |
| 15 | + { |
| 16 | +#endif |
| 17 | + |
| 18 | +#include "varToolsInternal.h" |
| 19 | +#include "VarTools.h" |
| 20 | +#include "varGetAllVarsInternal.h" |
| 21 | + |
| 22 | +#ifdef __cplusplus |
| 23 | + }; |
| 24 | +#endif |
| 25 | + |
| 26 | + |
| 27 | +#include <string.h> |
| 28 | + |
| 29 | + |
| 30 | +//******************************************************************* |
| 31 | +// Get All variables on PLC * |
| 32 | +//******************************************************************* |
| 33 | + |
| 34 | + |
| 35 | +// Fix: Seems to skip some variables |
| 36 | +void varGetAllVars(varGetAllVars_typ* t) |
| 37 | +{ |
| 38 | + // Check for invalid input |
| 39 | + if (t == 0) return; |
| 40 | + |
| 41 | + |
| 42 | + if(t->AcknowledgeError && isError(t)) { |
| 43 | + t->Status = 0; |
| 44 | + } |
| 45 | + |
| 46 | + if(t->Execute && isDone(t)) { |
| 47 | + t->Internal.iVar = 0xFFFF; |
| 48 | + t->Status = 65535; |
| 49 | + t->Internal.NextVariable = 1; |
| 50 | + t->Internal.numUniqueVars = 0; |
| 51 | + } |
| 52 | + |
| 53 | + t->Internal.validVar = 0; |
| 54 | + while(!t->Internal.validVar && isBusy(t)) { |
| 55 | + if(t->Internal.NextVariable) { |
| 56 | + |
| 57 | + getNextVariable(t); |
| 58 | + |
| 59 | + // Set rest of system bits that need to know next var |
| 60 | + t->Internal.moList.first = t->Internal.NextVariable; // moList needs to know to start back at begining |
| 61 | + setCheckGlobal(t); // Every new variable we need to check for global |
| 62 | + resetIsGlobal(t); |
| 63 | + |
| 64 | + t->Internal.NextVariable = 0; |
| 65 | + |
| 66 | + if(isError(t) || isDone(t)) continue; |
| 67 | + } |
| 68 | + |
| 69 | + if(checkGlobal(t)) { |
| 70 | + // Check if variable has global |
| 71 | + varRefresh(&t->Variable); // TODO: move this to getNextVariable |
| 72 | + strcpy(t->Variable.name, t->Internal.xList.name); // TODO: move this to getNextVariable |
| 73 | + |
| 74 | + t->Internal.validVar = checkValidVar(t); |
| 75 | + resetCheckGlobal(t); |
| 76 | + |
| 77 | + // getNextVariable returns all variables without a task perfix. So you can get duplicate variables (ex multiple Configurations) |
| 78 | + // So we record all varables found so we can see if we already checked this one |
| 79 | + // Because global variables cant exist in mulitple tasks we dont need to keep track of those |
| 80 | + if(isUniqueVar(t)) { |
| 81 | + setAsUniqueVar(t); |
| 82 | + } else { |
| 83 | + t->Internal.NextVariable = 1; // Skip this var because we already say this variable |
| 84 | + continue; |
| 85 | + } |
| 86 | + |
| 87 | + if(!t->Internal.validVar) { |
| 88 | + continue; |
| 89 | + } |
| 90 | + |
| 91 | + setIsGlobal(t); |
| 92 | + |
| 93 | + if(variableIsStructure(t) && t->ExpandStructs || variableIsArray(t) && !t->CondenseArrays) { |
| 94 | + goDownALevel(t); |
| 95 | + } |
| 96 | + else if(variableIsArray(t) && t->CondenseArrays) { |
| 97 | + // tODO: Condense array to just [i] |
| 98 | + strcat(t->Variable.name, "["); |
| 99 | + strcat(t->Variable.name, "]"); |
| 100 | + } |
| 101 | + |
| 102 | + if(!variableIsPrimitive(t) && t->PrimitivesOnly) { |
| 103 | + t->Internal.validVar = 0; |
| 104 | + } |
| 105 | + |
| 106 | + if(atTopLevel(t)) |
| 107 | + t->Internal.NextVariable = 1; // Set new varaible here becuase if something is global then its in each task as well but we just want to say global |
| 108 | + |
| 109 | + } |
| 110 | + else if(atTopLevel(t)) { |
| 111 | + if(isGlobal(t)) { |
| 112 | + // We can get here for global structures or global array of strucutres |
| 113 | + t->Internal.NextVariable = 1; // Set new varaible here becuase if something is global then its in each task as well but we just want to say global |
| 114 | + continue; |
| 115 | + } |
| 116 | + |
| 117 | + getNextTask(t); |
| 118 | + |
| 119 | + if(isError(t)) continue; |
| 120 | + |
| 121 | + if(outOfTasks(t)) { |
| 122 | + t->Internal.NextVariable = 1; |
| 123 | + continue; |
| 124 | + } |
| 125 | + |
| 126 | + if(checkValidTask(t)) continue; |
| 127 | + |
| 128 | + t->Internal.validVar = checkValidVar(t); |
| 129 | + |
| 130 | + if(!t->Internal.validVar) continue; |
| 131 | + |
| 132 | + if(variableIsStructure(t) && t->ExpandStructs || variableIsArray(t) && !t->CondenseArrays) { |
| 133 | + goDownALevel(t); |
| 134 | + } |
| 135 | + else if(variableIsArray(t) && t->CondenseArrays) { |
| 136 | + // tODO: Condense array to just [i] |
| 137 | + strcat(t->Variable.name, "["); |
| 138 | + strcat(t->Variable.name, "]"); |
| 139 | + } |
| 140 | + |
| 141 | + if(!variableIsPrimitive(t) && t->PrimitivesOnly) { |
| 142 | + t->Internal.validVar = 0; |
| 143 | + } |
| 144 | + |
| 145 | + } |
| 146 | + else { |
| 147 | + getMembers(t); |
| 148 | + |
| 149 | + while(outOfMembers(t) && !atTopLevel(t)) { |
| 150 | + goUpALevel(t); |
| 151 | + getMembers(t); |
| 152 | + } |
| 153 | + |
| 154 | + if(atTopLevel(t)) continue; |
| 155 | + |
| 156 | + outputMember(t); |
| 157 | + |
| 158 | + incrementMember(t); // Increment member her so if we go down a level we come back to the next member |
| 159 | + |
| 160 | + if(variableIsStructure(t)) { |
| 161 | + goDownALevel(t); // So next pass we will be inside the current variable |
| 162 | + } |
| 163 | + |
| 164 | + t->Internal.validVar = !t->PrimitivesOnly || variableIsPrimitive(t); |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + if(isError(t)) { |
| 169 | + handleErrors(t); |
| 170 | + } |
| 171 | + |
| 172 | + |
| 173 | + if(t->Status == 0) { |
| 174 | + memset(&t->Variable, 0, sizeof(t->Variable)); |
| 175 | + } |
| 176 | + |
| 177 | + return; |
| 178 | +} |
| 179 | + |
0 commit comments