File: gsUtilRevolution.c

package info (click to toggle)
openmohaa 0.81.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 29,124 kB
  • sloc: ansic: 270,865; cpp: 250,173; sh: 234; asm: 141; xml: 64; makefile: 7
file content (108 lines) | stat: -rw-r--r-- 2,911 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#include "../gsCommon.h"
#include "../gsPlatformUtil.h"

void gsiRevolutionSleep(u32 msec);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
static OSAlarm gAlarm;
static OSThreadQueue gQueue;
static BOOL          gQueueInitialized;


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
static const char * GOAGetUniqueID_Internal(void)
{
	static char keyval[17];
	u8 aMac[ETH_ALEN];
	int aMacLen;

	// check if we already have the Unique ID
	if(keyval[0])
		return keyval;
	
	aMacLen = ETH_ALEN;
	SOGetInterfaceOpt (NULL, SO_SOL_CONFIG, SO_CONFIG_MAC_ADDRESS,
                   	   aMac, &aMacLen);
	
	// format it
	sprintf(keyval, "%02X%02X%02X%02X%02X%02X0000",
		aMac[0] & 0xFF,
		aMac[1] & 0xFF,
		aMac[2] & 0xFF,
		aMac[3] & 0xFF,
		aMac[4] & 0xFF,
		aMac[5] & 0xFF);

	return keyval;
}


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Time Functions
static char GSIMonthNames[12][3] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
static char GSIWeekDayNames[7][3] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

time_t gsiTimeInSec(time_t *timer)
{
	time_t t = 0;
	t = (gsi_i32)OSTicksToSeconds(OSGetTime());
	
	if (timer)
		*timer = t;
	
	return t;
}


struct tm *gsiGetGmTime(time_t *theTime)
{
	static struct tm aTimeStruct;
	static struct tm *aRetVal = &aTimeStruct;
	OSCalendarTime aCalTimeStruct;
	
	OSTicksToCalendarTime(*theTime, &aCalTimeStruct);
	
	aRetVal->tm_sec  = aCalTimeStruct.sec;
	aRetVal->tm_min  = aCalTimeStruct.min;
	aRetVal->tm_hour = aCalTimeStruct.hour;
	aRetVal->tm_mday  = aCalTimeStruct.mday;
	aRetVal->tm_mon  = aCalTimeStruct.mon;
	aRetVal->tm_year  = aCalTimeStruct.year - 1900;
	aRetVal->tm_wday  = aCalTimeStruct.wday;
	aRetVal->tm_yday = 0;
	aRetVal->tm_isdst = 0;
	return aRetVal;
}

char *gsiCTime(time_t *theTime)
{
	static char str[26];
	struct tm *ptm = gsiGetGmTime(theTime);

	// e.g.: "Wed Jan 02 02:03:55 1980\n\0"
	sprintf(str, "%s %s %02d %02d:%02d:%02d %d\n",
		GSIWeekDayNames[ptm->tm_wday],
		GSIMonthNames[ptm->tm_mon], ptm->tm_mday,
		ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
		ptm->tm_year + 1900);

	return str;
}

gsi_i64 gsiStringToInt64(const char *theNumberStr)
{
	return atoll(theNumberStr);
}

void gsiInt64ToString(char theNumberStr[33], gsi_i64 theNumber)
{
	// you want to fit the number! 
	// give me a valid string!
	GS_ASSERT(theNumberStr != NULL);

	sprintf(theNumberStr, "%lld", theNumber);
}