
//2015.4.11
//开始设计闹钟程序. 设置时间的字符串格式为:
// YYYY.MM.DD HH:MM.SS
//分别对应 年.月.日 时:分:秒
//总长度为19个字符
//重要! - 加上了判断 clock0 的 isSafe 标志, 防止中断用户轮询事件的读取DS18B20时间时序

unit Clock
{
	public const uint16 ID = 0;

	link memory Mem {} = #.base;
	
	//[i] var_int32_w second;
	public Mem int32 second;
	//[i] var_int32_w minute;
	public Mem int32 minute;
	//[i] var_int32_w hour;
	public Mem int32 hour;
	//[i] var_int32_w day;
	public Mem int32 day;
	//[i] var_int32_w month;
	public Mem int32 month;
	//[i] var_int32_w year;
	public Mem int32 year;
	
	[int8*6] time_buffer;

	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		second = 0;
		minute = 0;
		hour = 0;
		
		day = 0;
		month = 0;
		year = 0;
	}
	//---------------------------------------------------
	//[i] function_void set_time time;
	void set_time( [#.code int8*?] time )
	{
		int32 D1000 = 1000;
		int32 D100 = 100;
		int32 D10 = 10;
		
		year = (time[0]-'0')*D1000 + (time[1]-'0')*D100 + (time[2]-'0')*D10 + (time[3]-'0');
		month = (time[5]-'0')*D10 + (time[6]-'0');
		day = (time[8]-'0')*D10 + (time[9]-'0');
		
		hour = (time[11]-'0')*D10 + (time[12]-'0');
		minute = (time[14]-'0')*D10 + (time[15]-'0');
		second = (time[17]-'0')*D10 + (time[18]-'0');
	}
	//---------------------------------------------------
	//[i] function_Time get_time;
	[int8*?] get_time()
	{
		time_buffer[0] = (int8)(int16)year;
		time_buffer[1] = (int8)(int16)month;
		time_buffer[2] = (int8)(int16)day;
		time_buffer[3] = (int8)(int16)hour;
		time_buffer[4] = (int8)(int16)minute;
		time_buffer[5] = (int8)(int16)second;
		return time_buffer;
	}
}



