/************************************************************* ** : RTCRead ** : read RTC ** : INPUT RTCAddr ** [BCD7] = sec,min,hour,day,mon,year,week ** ** : pmj ** : 2006-9-20 **************************************************************/ void RTCRead(unsigned char *RTCAddr) { unsigned char buff[7]; unsigned char buffr = 0x02; unsigned char err; buff[0] = 0; buff[1] = 0; buff[2] = 0; DISICNT = 0x3FFF; /* disable interrupts */ while(1) { if(I2cWrite(0xa2, &buff[0], 3) != 0) {error_i2();} else break; } while(1) { if(I2cRead(0xa2, buff, &buffr, 1, 7) != 0) {error_i2();} else break; } DISICNT = 0x0000; /* enable interrupts */ buff[4] = buff[4]&0x07; // if(buff[4] == 0) buff[4] = 0x07; buff[4] = buff[4] << 5; *RTCAddr = buff[0]&0x7f; //sec *(RTCAddr+1) = buff[1]&0x7f; //min *(RTCAddr+2) = buff[2]&0x3f; //hour *(RTCAddr+3) = buff[3]&0x3f; //day *(RTCAddr+4) = (buff[5]&0x1f)|buff[4]; //week-mon *(RTCAddr+5) = buff[6]; //year // soft rtc sys_date.year = *(RTCAddr+5); sys_date.month = *(RTCAddr+4); sys_date.day = *(RTCAddr+3); sys_date.hour = *(RTCAddr+2); sys_date.minute = *(RTCAddr+1); sys_date.second = *RTCAddr; softMin = b2h(*(RTCAddr+1)); softSec = b2h(*RTCAddr); softMS = 0; // soft rtc end }
static void do_one (char *host_name) { int i; int res; char c; soc_host host; /* Try with host name or ip notation */ if ( (res = soc_host_of (host_name, &host) ) == SOC_OK) { if (soc_host_name_of (&host, host_name, sizeof(host_name)) != SOC_OK) { /* Host not found */ host_name[0] = '\0'; } print_ip (&host, host_name); } else if (strlen (host_name) == 8) { /* Try with 8 hexa digits */ res = 0; for (i = 0; i < 8; i++) { c = host_name[i]; if ( ( (c >= '0') && (c <= '9') ) || ( (c >= 'a') && (c <= 'f') ) || ( (c >= 'A') && (c <= 'F') ) ) { ; } else { res = 1; } } if (res == 0) { /* Looks like a host id */ for (i = 0; i < 8; i++, i++) { host.bytes[i/2] = (b2h(host_name[i]) * 16) + b2h(host_name[i+1]); } if (soc_host_name_of (&host, host_name, sizeof(host_name)) != SOC_OK) { /* Host not found */ host_name[0] = '\0'; } print_ip (&host, host_name); } else { fprintf (stderr, "Invalid argument %s\n", host_name); } } }
void bs2hs(byte * bytes, char * res, uint lres) { uint i = 0; for(i = 0; i < lres/2;i++) { b2h( bytes[i], res+(2*i) ); } }
/************************************************************* ** : RTCWrite ** : set RTC ** : INPUT RTCAddr ** [BCD7] = sec,min,hour,day,mon,year,week ** ** : pmj ** : 2006-9-20 **************************************************************/ void RTCWrite(unsigned char *RTCAddr) { unsigned char buff[20]; unsigned char i,bbc[2]; unsigned char err; #if 0 // soft rtc start sys_date.year = *(RTCAddr+5); sys_date.month = *(RTCAddr+4); sys_date.day = *(RTCAddr+3); sys_date.hour = *(RTCAddr+2); sys_date.minute = *(RTCAddr+1); sys_date.second = *RTCAddr; softMin = b2h(*(RTCAddr+1)); softSec = b2h(*RTCAddr); #endif #if 1 sys_date.year = 0x08; sys_date.month = 0xb0; sys_date.day = 0x17; sys_date.hour = 0x16; sys_date.minute = 0x35; sys_date.second = 0x16; softMin = b2h(0x35); softSec = b2h(0x16); #endif softMS = 0; // soft rtc end buff[0] = 0; buff[2] = 0; buff[1] = 0x20; #if 0 for(i = 0; i < 4; i++) { buff[i+3] = *(RTCAddr+i); } buff[7] = (*(RTCAddr+4)) >> 5; if(buff[7] == 7) buff[7] = 0; buff[8] = (*(RTCAddr+4))&0x1f; buff[9] = *(RTCAddr+5); #endif #if 1 buff[3] = _time_chk.sec;//0x18; buff[4] = _time_chk.min;//0x35; // 分 buff[5] = _time_chk.hr;//0x16; //16时 buff[6] = _time_chk.day;//0x31; //31日 buff[7] = _time_chk.wkd;//(0x72) >> 5; // 星期三 // if(buff[7] == 7) buff[7] = 0; buff[8] = _time_chk.mth;//0x72&0x1f; // 12月 buff[9] = _time_chk.yr;//0x08;// year #else buff[3] = 0x18; buff[4] = 0x35; // 分 buff[5] = 0x16; //16时 buff[6] = 0x31; //31日 buff[7] = (0x72) >> 5; // 星期三 if(buff[7] == 7) buff[7] = 0; buff[8] = 0x72&0x1f; // 12月 buff[9] = 0x08; // year #endif for(i = 10; i < 14; i++) { buff[i] = 0x80; } buff[14] = 0x80; buff[15] = 0; buff[16] = 0x00; while(1) { if(I2cWrite(0xa2, &buff[0], 17) != 0) {error_i2();} else break; } buff[0] = 0; buff[1] = 0; buff[2] = 0; while(1) { if(I2cWrite(0xa2, &buff[0], 3) != 0) {error_i2();} else break; } }
int get_one_str(char *buf,void *data,T_PkgType *typ,char CURDLM) { register char *cp1,*cp2; int cnt,J,len; char datebuf[31]; char *sp; //short iTiny; T_PkgType Char_Type[2]; cp1=buf; *cp1=0; cnt=0; cp2 = (char *)data+typ->offset; sp=cp2; if(isnull(cp2,typ->type)) return cnt; switch(typ->type) { case CH_BYTE: cnt=b2h(cp1,cp2,typ->len); break; case CH_CLOB: Char_Type[0].type=CH_CHAR; Char_Type[0].len=-1; Char_Type[0].offset=0; Char_Type[1].type=-1; Char_Type[1].len=0; J=get_one_str(buf,*(char **)cp2,Char_Type,CURDLM); cnt += J; break; case CH_DATE: case CH_CNUM: case CH_CHAR: len=(typ->len>0)?typ->len-1:strlen(cp2); for(J=0;J<len&&*cp2;J++,cnt++) { if(!CURDLM) goto norm; switch(*cp2) { case ESC_CHAR: if(cp2>sp && GBK_flag && firstcc((unsigned char *)sp,(unsigned char *)cp2-1)) goto norm; *cp1++=*cp2; *cp1++=*cp2++; cnt++; break; case '\n': if(cp2>sp && firstcc((unsigned char *)sp,(unsigned char *)cp2-1)) cp1[-1]&=0x7f; *cp1++=ESC_CHAR; *cp1++='n'; cp2++; cnt++; break; default: if(*cp2==CURDLM) { if(cp2>sp && GBK_flag && firstcc((unsigned char *)sp,(unsigned char *)cp2-1)) goto norm; *cp1++=ESC_CHAR; *cp1++='G'; cp2++; cnt++; break; } norm: *cp1++=*cp2++; break; } } *cp1=0; if(cp2>sp) { if(firstcc((unsigned char *)sp,(unsigned char *)cp2-1)) cp1[-1] &= 0x7f; } break; case CH_FLOAT: if(!typ->format) cnt=sprintf(cp1,"%g", (double)*(float *)cp2); else cnt=sprintf(cp1,typ->format,(double)*(float *)cp2); break; case CH_DOUBLE: if(!typ->format) cnt=sprintf(cp1,"%g", *(double *)cp2); else cnt=sprintf(cp1,typ->format,*(double *)cp2); break; case CH_LDOUBLE: if(!typ->format) cnt=sprintf(cp1,"%Lg", *(long double *)cp2); else cnt=sprintf(cp1,typ->format,*(long double *)cp2); break; case CH_TINY: if(typ->format) cnt=sprintf(cp1,typ->format,255&*cp2); else cnt=itoStr((int)(*cp2),cp1)-cp1; break; case CH_SHORT: if(typ->format) cnt=sprintf(cp1,typ->format,0XFFFF&*(short *)cp2); else cnt=itoStr((int)(*(short *)cp2),cp1)-cp1; break; case CH_INT: if(typ->format) cnt=sprintf(cp1,typ->format,*(int *)cp2); else cnt=itoStr(*(int *)cp2,cp1)-cp1; break; case CH_LONG: if(typ->format) cnt=sprintf(cp1,typ->format,*(long *)cp2); else cnt=lltoStr((INT64)(*(long *)cp2),cp1)-cp1; break; case CH_INT64: if(typ->format) cnt=sprintf(cp1,typ->format,*(INT64 *)cp2); else cnt=lltoStr(*(INT64 *)cp2,cp1)-cp1; break; case CH_CJUL: case CH_JUL: if(typ->format) { rjultostrfmt(datebuf,*(int *)cp2, typ->format); } else { rjultostrfmt(datebuf,*(int *)cp2, "YYYYMMDD"); } cnt=sprintf(cp1,"%s",datebuf); break; case CH_MINUTS: case CH_CMINUTS: if(typ->format) { rminstrfmt(datebuf,*(INT4 *)cp2,typ->format); } else rminstr(datebuf,*(INT4 *)cp2); cnt=sprintf(cp1,"%s",datebuf); break; case CH_TIME: case CH_CTIME: if(typ->format) { rsecstrfmt(datebuf,*(INT64 *)cp2,typ->format); } else rsecstrfmt(datebuf,*(INT64 *)cp2,"YYYYMMDDHH24MISS"); cnt=sprintf(cp1,"%s",datebuf); break; case CH_USEC: if(typ->format) { rusecstrfmt(datebuf,*(INT64 *)cp2,typ->format); } else rusecstrfmt(datebuf,*(INT64 *)cp2,"YYYYMMDDHH24MISS.FF6"); cnt=sprintf(cp1,"%s",datebuf); break; default: break; } return cnt; }