{"payload":{"meta":{"Graph":{"@Type":"81297157","@Value":{"Guid":"(Guid)6ea8d1fd-fde9-4f00-b84e-730aaad6d797","ParentGuid":"(Guid)74ccca2f-50e3-4d5a-9d7a-9fd420284f83","Name":"(string)atAnalogAggregate","Properties":{"@Type":"2c41fa04:IDictionary","@Value":[{"@Key":"(Guid)829a18f2-c514-4f6e-9634-1df173429203","@Value":{"@Type":"829a18f2","@Value":{"ParentObjects":{"@Type":"fa2ee218:IDictionary","@Value":[{"@Key":"(Guid)d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84","@Value":"(Guid)12edd256-91dc-473a-b471-cd1232088c37"}]}}}}]},"TypeGuid":"(Guid)6f9dac99-8de1-4efc-8465-68ac443b7d08","EmbeddedTypeGuids":{"@Type":"[Guid]","@Value":["(Guid)a9ed5b7e-75c5-4651-af16-d2c27e98cb94","(Guid)3b83b776-fb25-43b8-99f2-3c507c9143fc"]}}},"TypeInfos":{"2c41fa04":"{2c41fa04-1834-41c1-816e-303c7aa2c05b}","81297157":"{81297157-7ec9-45ce-845e-84cab2b88ade}","829a18f2":"{829a18f2-c514-4f6e-9634-1df173429203}","fa2ee218":"{fa2ee218-a39b-4b6d-b249-49dbddbd168a}","Guid":"System.Guid","string":"System.String"}},"object":{"Graph":{"@Type":"6f9dac99","@Value":{"SpecialFunc":{"@Type":"0db3d7bb:Enum","@Value":"None"},"Implementation":{"@Type":"3b83b776","@Value":{"TextDocument":{"@Type":"f3878285","@Value":{"TextBlobForSerialisation":"(string)//This function generates 24 hour aggregate values\n//2024-05-21 CWD Initial create\n\n\n//Generate pulses using RTC\nSysTimeRtcHighResGet(dateTimeULINT);\nSysTimeRtcConvertHighResToLocal(pTimeStamp:=dateTimeULINT,pDate:= tim);\n//1 seocnd pulse\nsecOS:=FALSE;\nIF lastSecond <> tim.wSecond THEN //Don't pulse on first pass\n\tIF lastSecond <> 65535 THEN\n\t\tsecOS:= TRUE;\n\tEND_IF\n\tlastSecond := tim.wSecond;\nEND_IF\n\n//1 hour pulse\nhourOS:= FALSE;\nIF lastHour <> tim.wHour THEN\n\tIF lastHour <> 65535 THEN //don't do this on first pass\n\t\thourOS:= TRUE;\t\t\n\tEND_IF\n\tlastHour := tim.wHour;\nEND_IF\n\n//Every 1 second add input\nIF secOS THEN\n\tsum:= sum + in;\n\tcount:= count + 1;\n\tIF in < lo THEN\n\t\tlo:= in;\n\tEND_IF\n\tIF in > hi THEN\n\t\thi:= in;\n\tEND_IF\nEND_IF\n\n//Every hour save to storage and reset\nIF hourOS THEN\n\t//save using the hour as the index\n\tstorageSP[tim.wHour].avg := LREAL_TO_REAL(sum / count);\n\tstorageSP[tim.wHour].hi := hi;\n\tstorageSP[tim.wHour].lo := lo;\n\n\t//reset values\n\thi:= in;\n\tlo:= in;\n\tsum:= 0;\n\tcount:= 0;\n\t\n\t//Calculate daily average\n\tout.hi:=storageSP[0].hi;\n\tout.lo:= storageSP[0].lo;\n\tFOR i := 0 TO 23 DO\n\t\t//high\n\t\tIF storageSP[i].hi > out.hi THEN\n\t\t\tout.hi:= storageSP[i].hi;\n\t\tEND_IF\n\t\t//low\n\t\tIF storageSP[i].lo < out.lo THEN\n\t\t\tout.lo:= storageSP[i].lo;\n\t\tEND_IF\n\t\t//average\n\t\tsumDaily:=sumDaily + storageSP[i].avg;\n\tEND_FOR\n\tout.avg := sumDaily/24;\n\t\nEND_IF\n\n\n","LineInfoPersistence":"(string)6ea8d1fd-fde9-4f00-b84e-730aaad6d797_Impl_LineIds"}}}},"Interface":{"@Type":"a9ed5b7e","@Value":{"TextDocument":{"@Type":"f3878285","@Value":{"TextBlobForSerialisation":"(string)FUNCTION_BLOCK atAnalogAggregate\nVAR_INPUT\n\t// Input value\n\tin: REAL;\nEND_VAR\nVAR_IN_OUT\n\tstorageSP: ARRAY[0..23] OF atAnalogAggregateSP;\nEND_VAR\nVAR_OUTPUT\n\tout: atAnalogAggregateSP;\nEND_VAR\nVAR\n\tdateTimeULINT: ULINT;\n\ttim: SYSTIMEDATE;\n\tsecOS: BOOL;\n\tlastSecond: UINT := 65535;\n\thourOS: BOOL;\n\tlastHour: UINT := 65535;\n\tsum: LREAL;\n\tcount: REAL;\n\tlo: REAL := 9999;\n\thi: REAL := -9999;\n\ti: INT;\n\tsumDaily: REAL;\nEND_VAR\n\n","LineInfoPersistence":"(string)6ea8d1fd-fde9-4f00-b84e-730aaad6d797_Decl_LineIds"}}}},"UniqueIdGenerator":"(string)1289","POULevel":{"@Type":"8e575c5b:Enum","@Value":"Standard"},"ChildObjectGuids":{"@Type":"ArrayList:IList","@Value":[]},"AddAttributeSubsequent":"(bool)False"}},"TypeInfos":{"0db3d7bb":"{0db3d7bb-cde0-4416-9a7b-ce49a0124323}","3b83b776":"{3b83b776-fb25-43b8-99f2-3c507c9143fc}","6f9dac99":"{6f9dac99-8de1-4efc-8465-68ac443b7d08}","8e575c5b":"{8e575c5b-1d37-49c6-941b-5c0ec7874787}","a9ed5b7e":"{a9ed5b7e-75c5-4651-af16-d2c27e98cb94}","ArrayList":"System.Collections.ArrayList","bool":"System.Boolean","f3878285":"{f3878285-8e4f-490b-bb1b-9acbb7eb04db}","string":"System.String"}}},"FormatVersion":"1.0"}