#include "common_api.h"
#include "luat_rtos.h"
#include "luat_debug.h"

#include "luat_rtc.h"

#include "sr_config.h"
#include "sr_shell.h"
#include "sr_log.h"

#include <stdlib.h>




static int hzrtc_get(int argc, char *argv[])
{
	struct tm tblock = {0};
	luat_rtc_get(&tblock);
	
	SR_PRINTF("[RTC] raw: %04d/%02d/%02d/ %02d:%02d:%02d %02d", tblock.tm_year, tblock.tm_mon, tblock.tm_mday, tblock.tm_hour, tblock.tm_min,tblock.tm_sec,tblock.tm_wday);
	SR_PRINTF("[RTC] cal: %04d/%02d/%02d/ %02d:%02d:%02d %02d", tblock.tm_year+1900, tblock.tm_mon+1, tblock.tm_mday, tblock.tm_hour, tblock.tm_min,tblock.tm_sec,tblock.tm_wday);


}
SR_SHELL_CMD_EXPORT(hzrtc_get, hzrtc_get);

//cmd: hzrtc_set <year> <mon> <mday> <h> <m> <s>
static int hzrtc_set(int argc, char *argv[])
{
	struct tm tblock = {0};

	if(argc<7 ) 
	{
    	SR_PRINTF("hzrtc_set <year> <mon> <mday> <h> <m> <s>");
	}

	tblock.tm_year = atoi(argv[1])-1900; 
	tblock.tm_mon  = atoi(argv[2])-1;  
	tblock.tm_mday = atoi(argv[3]);  
	tblock.tm_hour = atoi(argv[4]);  
	tblock.tm_min  = atoi(argv[5]); 
	tblock.tm_sec  = atoi(argv[6]); 
	luat_rtc_set(&tblock);

}
SR_SHELL_CMD_EXPORT(hzrtc_set, hzrtc_set);

static int hzrtc_zone_set(int argc, char *argv[])
{
   int zone =28;
   int ret;
   if(argc<2 ) 
	{
    	SR_PRINTF("hzrtc_zone_set <zone>");
		return -1;
	}
    
    zone = atoi(argv[1]);
	ret = luat_rtc_timezone(&zone);

	SR_PRINTF("[RTC] zone set,zone=%d , ret=%d",zone,ret);

	return 0;
}
SR_SHELL_CMD_EXPORT(hzrtc_zone_set, hzrtc_zone_set);


extern void luat_rtc_set_timezone(int zone);

static int hzrtc_zone_set2(int argc, char *argv[])
{
   int zone =32;
   if(argc<2 ) 
	{
    	SR_PRINTF("hzrtc_zone_set <zone>");
		return -1;
	}
    


    zone = atoi(argv[1]);
	luat_rtc_set_timezone(atoi(argv[1]));

	
	SR_PRINTF("[RTC] zone set,zone=%d",zone);

	return 0;
}
SR_SHELL_CMD_EXPORT(hzrtc_zone_set2, hzrtc_zone_set2);


