<?xml version="1.0" encoding="utf-8"?>
<Pou FileVersion="200.00.003" Name="Epoch_Time" ElementGuid="1f8f8d8a-87f5-4e34-b071-ff772e5f5dfd" Comment="" SingleTextLine="" Language="ST" CustomFbd="0" Localization="Prj" GroupName="(User defined)" GenDebugInfo="false" UseResPassword="true" GenerateSymbMon="true" Is1499="false">
  <FunctionBlock IdentifierNb="0" Keyword="" InitInstance="false" SymbMonExtraBytes="128" />
  <LocalVars>
    <Variable Name="RTC_READ_ENABLED" DataType="BOOL" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="VarInput" Alias="" AccessRights="Read" StringSize="0" Direction="Input" CommentFields="" Attributes="0" />
    <Variable Name="Epoch" DataType="ULINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="VarOutput" Alias="" AccessRights="Write" StringSize="0" Direction="Output" CommentFields="" Attributes="0" />
    <Variable Name="year" DataType="UINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="VarOutput" Alias="" AccessRights="Write" StringSize="0" Direction="Output" CommentFields="" Attributes="0" />
    <Variable Name="month" DataType="UINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="VarOutput" Alias="" AccessRights="Write" StringSize="0" Direction="Output" CommentFields="" Attributes="0" />
    <Variable Name="day" DataType="UINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="VarOutput" Alias="" AccessRights="Write" StringSize="0" Direction="Output" CommentFields="" Attributes="0" />
    <Variable Name="hour" DataType="UINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="VarOutput" Alias="" AccessRights="Write" StringSize="0" Direction="Output" CommentFields="" Attributes="0" />
    <Variable Name="minute" DataType="UINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="VarOutput" Alias="" AccessRights="Write" StringSize="0" Direction="Output" CommentFields="" Attributes="0" />
    <Variable Name="second" DataType="UINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="VarOutput" Alias="" AccessRights="Write" StringSize="0" Direction="Output" CommentFields="" Attributes="0" />
    <Variable Name="RTC_READ_1" DataType="RTC_READ" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="Var" Alias="" AccessRights="ReadWrite" StringSize="0" Direction="Local" CommentFields="" Attributes="0" />
    <Variable Name="prev_months_days" DataType="UINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="Var" Alias="" AccessRights="ReadWrite" StringSize="0" Direction="Local" CommentFields="" Attributes="0" />
    <Variable Name="year_seconds" DataType="ULINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="Var" Alias="" AccessRights="ReadWrite" StringSize="0" Direction="Local" CommentFields="" Attributes="0" />
    <Variable Name="day_seconds" DataType="ULINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="Var" Alias="" AccessRights="ReadWrite" StringSize="0" Direction="Local" CommentFields="" Attributes="0" />
    <Variable Name="min_seconds" DataType="ULINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="Var" Alias="" AccessRights="ReadWrite" StringSize="0" Direction="Local" CommentFields="" Attributes="0" />
    <Variable Name="hour_seconds" DataType="ULINT" InitialValue="" Comment="" Address="" Modifier="Constant" Kind="Var" Alias="" AccessRights="ReadWrite" StringSize="0" Direction="Local" CommentFields="" Attributes="0" />
  </LocalVars>
  <PouBody><![CDATA[FUNCTION_BLOCK Epoch_Time
RTC_READ_1(RTC_READ_ENABLED);
CASE RTC_READ_1.RTCData.Month OF
	1: prev_months_days := 0;
	2: prev_months_days := 31;
	3: prev_months_days := 59;
	4: prev_months_days := 90;
	5: prev_months_days := 121;
	6: prev_months_days := 151;
	7: prev_months_days := 181;
	8: prev_months_days := 212;
	9: prev_months_days := 243;
	10: prev_months_days := 273;
	11: prev_months_days := 304;
	12: prev_months_days := 334;
END_CASE;

IF MOD(ANY_TO_DINT(RTC_READ_1.RTCData.Year), 4) = 0 THEN
	IF RTC_READ_1.RTCData.Month > 2 THEN
		prev_months_days := prev_months_days + 1;
	END_IF;
END_IF;

year_seconds := ANY_TO_ULINT(RTC_READ_1.RTCData.Year - ANY_TO_UINT(1970)) * ANY_TO_ULINT(31556926);
day_seconds := ANY_TO_ULINT((prev_months_days + RTC_READ_1.RTCData.Day) * ANY_TO_UINT(86400));
hour_seconds := ANY_TO_ULINT(RTC_READ_1.RTCData.Hours * 3600);
min_seconds := ANY_TO_ULINT(RTC_READ_1.RTCData.Minutes * 60);

Epoch := year_seconds + day_seconds + hour_Seconds + min_seconds + ANY_TO_ULINT(RTC_READ_1.RTCData.Seconds);
END_FUNCTION_BLOCK]]></PouBody>
  <PouUIProperties>
    <Root Version="6">
  <LanguageContainerStyle CommentTextColor="Green" CommentFont="Courier New, 10pt" PonctuationTextColor="Black" PonctuationFont="Courier New, 10pt" IdentifierTextColor="Black" IdentifierFont="Courier New, 10pt" OperatorTextColor="Black" OperatorFont="Courier New, 10pt" ReservedWordTextColor="Fuchsia" ReservedWordFont="Courier New, 10pt" PouTextColor="BlueViolet" PouFont="Courier New, 10pt" NumberTextColor="Firebrick" NumberFont="Courier New, 10pt" StringTextColor="Gray" StringFont="Courier New, 10pt" EditorTextAreaBackgroundColor="White" EditorFont="Courier New, 10pt" Index="0" />
</Root>
  </PouUIProperties>
</Pou>