Windows XP
- nbtstat
- arp
Fedora
- arp
- nbtscan
I2C 인터페이스인 TCN75 칩의 온도를 가져오기 위한 응용이다.
... #define I2C_ADDR_TCN75 0x4f // 하드웨어 설계에 따라 달라진다. ... void tcn75_init(void) { int fd; fd = open("/dev/i2c-0", O_RDWR); // mknod /dev/i2c-0 c 89 0 if(fd < 0) { fprintf(stderr, "can't open /dev/i2c-0\n"); exit(2); } ioctl(fd, I2C_SLAVE, I2C_ADDR_TCN75); unsigned char cmd, read_data[2]; int read_value; cmd = 0x00; // TEMP write(fd, &cmd, 1); // Pointer Byte close(fd); } float tcn75_get_temperature(void) { int fd; fd = open("/dev/i2c-0", O_RDWR); if(fd < 0) { fprintf(stderr, "can't open /dev/i2c-0\n"); exit(2); } ioctl(fd, I2C_SLAVE, I2C_ADDR_TCN75); unsigned char read_data[2]; int read_value; float temperature; read(fd, read_data, 2); read_value = (read_data[0]<<8) | read_data[1]; read_value >>= 7; if(read_value > 256) read_value = read_value - 512; temperature = read_value / 2.0; close(fd); return temperature; } int main(int argc, char** argv) { tcn75_init(); while(1) { printf("temp = %f\n", tcn75_get_temperature()); sleep(1); } return 0; }
// 유닉스타임스탬프를 인자로 주면 현재일시를 스트링으로 반환한다. char* from_unixtime(time_t unix_timestamp) { static char szDatetime[25]; struct tm *tm_infop; tm_infop = localtime(&unix_timestamp); memcpy(szDatetime, asctime(tm_infop), 24); szDatetime[24] = '\0'; return szDatetime; }
#define POLY 0x8408 /* // 16 12 5 // this is the CCITT CRC 16 polynomial X + X + X + 1. // This works out to be 0x1021, but the way the algorithm works // lets us use 0x8408 (the reverse of the bit pattern). The high // bit is always assumed to be set, thus we only use 16 bits to // represent the 17 bit value. */ UINT16 CCITT_CRC16(char *data_p, UINT16 length) { unsigned char i; unsigned int data; unsigned int crc = 0xffff; if (length == 0) return (~crc); do { for (i=0, data=(unsigned int)0xff & *data_p++;i < 8; i++, data >>= 1) { if ((crc & 0x0001) ^ (data & 0x0001)) crc = (crc >> 1) ^ POLY; else crc >>= 1; } } while (--length); crc = ~crc; data = crc; crc = (crc << 8) | ((data >> 8) & 0xff); return (crc); }
X^16+X^12+X^5+1에서 X가 의미하는게 뭐죠?