000
20.07.2004, 10:09 Uhr
~wasa
Gast
|
tagchen! kann mir jemand erklären was der folgende Code zu sagen hat bzw. was da gemacht wird!? DANKE SCHONMAL!!!!!! Ich komme damit echt nicht zurecht!!!
DANKE cu wasa
C++: |
int digit(int x) { int dig[10]={0xd7,0x05,0x5b,0x1f,0x27,0x3e, 0x7e,0x15,0x7f, 0x3f}; int n; x=x&0x7f; for(n=0;n<10;n++) if (x==dig[n]) return n; return 0; } /*---------------------------------------------------------------------*/ char *dvm_unit(int y, int x, char *s) { char *prefix=""; char *unit=""; char *ext=""; char *ext1="";
if (x&0x2000) ext="delta"; else if (x&0x100000) ext="Diode"; else if (x&0x10000) ext="Beep"; if (x&0x080000) prefix="m"; else if (x&0x800000) prefix="u"; else if (x&0x400000) prefix="n"; else if (x&0x020000) prefix="M"; else if (x&0x200000) prefix="k";
if (x&0x0800) unit="A"; else if (x&0x0200) unit="Hz"; else if (x&0x40000) unit="%"; else if (x&0x10) unit="°C"; else if (x&0x4000) unit="Ohm"; else if (x&0x0400) unit="V"; else if (x&0x8000) unit="F";
sprintf(s,"%s%s %s (%s)",prefix, unit, (y&0x8?"AC":""), ext); } /*---------------------------------------------------------------------*/ int main(int argc,char **argv) { unsigned char data; unsigned char buffer[100]; unsigned char buffer1[9]; char units[20]; int n; float it; unsigned int t,tf; fd=open_serial("/dev/ttyS0", 2400); set_rts_dtr(fd); // DTR/RTS setzen
while(1) { n=0; memset(buffer,0,20); while(1) { read(fd,&buffer[n],1); if ((buffer[n]&0xf0)==0xe0 || (n==16)) break; n++; } #if 0 // Raw output for(n=0;n<16;n++) printf("%02x ",buffer[n]); #endif
buffer1[0]=buffer[0]&15;
for(n=0;n<8;n++) buffer1[1+n]=((buffer[2*n+1]&15)<<4)|(buffer[2*n+2]&15);
#if 0 // Nibble compacted data for(n=0;n<8;n++) printf("%02x ",buffer1[n]);
printf("%i%i%i%i\n",digit(buffer1[1]),digit(buffer1[2]), digit(buffer1[3]),digit(buffer1[4])); #endif
if ((buffer1[3]&0x7f)==0x68) it=9999999; else it=1000.0*digit(buffer1[1])+100.0*digit(buffer1[2]) +10*digit(buffer1[3])+1*digit(buffer1[4]);
if (buffer1[4]&0x80) it=it/10.0;
if (buffer1[3]&0x80) it=it/100.0;
if (buffer1[2]&0x80) it=it/1000.0; if (buffer1[1]&0x80) it=-it; dvm_unit(buffer1[0], (buffer1[5]<<16)|(buffer1[6]<<8)|buffer1[7],units); timestamp(); printf("%0.3f %s\n",it, units); fflush(stdout); } }
|
|