(****** QuickLD compiler *******************************)
(****** Copyright Rockwell Automation Canada, Ltd ******)
(****** ST *********************************************)

(*************** Rung **********************************)
(*Sync Interval Timer*)
__STEPPRAGMA
0,1
__ENDSTEPPRAGMA
(*Label :*)(**)
(* FB call: TON *)
Time_UpdateTimer(NOT(TIME_UPDATETIMER.Q), T#60S) ;

(*************** Code for the end of Rung **************)


(*************** Rung **********************************)
(*CIP - Get Attribute Single - TimeSync Module - Time Attribute*)
__STEPPRAGMA
0,4
__ENDSTEPPRAGMA
(*Label :*)(**)
(* FB call: MSG_CIPGENERIC *)
Time_MSG_CIPGeneric(TIME_UPDATETIMER.Q, TIME_CIPCTRLCONFIG, TIME_CIPAPPCFG, TIME_CIPTARGETCFG, TIME_REQDATA, 0, TIME_RESDATA, , ) ;
TIME_CIPSTATUS := Time_MSG_CIPGeneric.Status ;
TIME_RESLENGTH := Time_MSG_CIPGeneric.ResLength ;

(*************** Code for the end of Rung **************)


(*************** Rung **********************************)
(*Detect MSG Complete and Successful*)
__STEPPRAGMA
0,14
__ENDSTEPPRAGMA
(*Label :*)(**)
(* FB call: R_TRIG *)
Time_R_TRIG_1(TIME_MSG_CIPGENERIC.Q AND NOT(TIME_CIPSTATUS.ERROR)) ;
TIME_READOKPULSE := Time_R_TRIG_1.Q ;

(*************** Code for the end of Rung **************)


(*************** Rung **********************************)
(*Decode Year, Month , Day*)
__STEPPRAGMA
0,16
__ENDSTEPPRAGMA
(*Label :*)(**)
(* FB call: COP *)
Time_COP_1(TIME_READOKPULSE, TIME_RESDATA, 8, TIME_RTC.YEAR, 0, 1, TRUE, 0, 0, 0, 0) ;
__MO_COP_1 := TIME_READOKPULSE ;
__EDTB1 := TIME_READOKPULSE ;
IF __EDTB1 THEN
TIME_RTC.MONTH := ANY_TO_UINT(TIME_RESDATA[10]) ;
END_IF ;
__MO_ANY_TO_UINT_1 := __EDTB1 ;
__EDTB2 := __EDTB1 ;
IF __EDTB2 THEN
TIME_RTC.DAY := ANY_TO_UINT(TIME_RESDATA[11]) ;
END_IF ;
__MO_ANY_TO_UINT_2 := __EDTB2 ;

(*************** Code for the end of Rung **************)


(*************** Rung **********************************)
(*Decode Hour, Minute, Second*)
__STEPPRAGMA
0,28
__ENDSTEPPRAGMA
(*Label :*)(**)
__EDTB3 := TIME_READOKPULSE ;
IF __EDTB3 THEN
TIME_RTC.HOURS := ANY_TO_UINT(TIME_RESDATA[12]) ;
END_IF ;
__MO_ANY_TO_UINT_3 := __EDTB3 ;
__EDTB4 := __EDTB3 ;
IF __EDTB4 THEN
TIME_RTC.MINUTES := ANY_TO_UINT(TIME_RESDATA[13]) ;
END_IF ;
__MO_ANY_TO_UINT_4 := __EDTB4 ;
__EDTB5 := __EDTB4 ;
IF __EDTB5 THEN
TIME_RTC.SECONDS := ANY_TO_UINT(TIME_RESDATA[14]) ;
END_IF ;
__MO_ANY_TO_UINT_5 := __EDTB5 ;

(*************** Code for the end of Rung **************)


(*************** Rung **********************************)
(*Set Real Time Clock Object*)
__STEPPRAGMA
0,31
__ENDSTEPPRAGMA
(*Label :*)(**)
(* FB call: RTC_SET *)
Time_RTCSet(TIME_SETRTC_ENABLE AND TIME_READOKPULSE, TRUE, TIME_RTC) ;
TIME_RTC_PRESENT := Time_RTCSet.RTCEnabled ;
TIME_RTC_ENABLED := Time_RTCSet.RTCBatLow ;
TIME_RTC_STATUS := Time_RTCSet.Sts ;

(*************** Code for the end of Rung **************)


(*************** Rung **********************************)
(**)
__STEPPRAGMA
0,36
__ENDSTEPPRAGMA
(*Label :*)(**)

(*************** Code for the end of Rung **************)


(*************** Code for the end of File **************)
__GL __LG0000 ;



(*************** Local Symbols table *******************)
(* __EDTB1 *)
(* __EDTB2 *)
(* __EDTB3 *)
(* __EDTB4 *)
(* __EDTB5 *)

