2011年1月13日(木) 22:12
------------------------ここから------------------------
#include <stdio.h>
#include <stdlib.h>
#define bits(x) ((x) < 0 ? 0 : (buf[(x)/8]>>((x)%8))&0x1)
#define is_one(on, off) ((on) >= 3 && (off) >= 10)
#define is_zero(on, off) ((on) >= 3 && (off) <= 9)
int main(int argc, char *argv[])
{
FILE *fp;
unsigned char buf[255];
int i, on, off, count, leader, tailer;
unsigned long code;
if( argc != 2 ) exit(1);
if( !(fp = fopen(argv[1], "rb")) ) exit(1);
fread(buf, sizeof(unsigned char), 240, fp);
fclose(fp);
printf("%-14s ", argv[1]);
on = off = code = count = leader = tailer = 0;
for( i = 0 ; i < 240*8; i++ ) {
if( bits(i) && bits(i-1) ) on++;
else if( !bits(i) && !bits(i-1) ) {
off++;
if( off > 90 ) {
tailer = 1;
break;
}
} else if( !bits(i) && bits(i-1) ) off = 1;
else if( bits(i) && !bits(i-1) ) {
if( on > 20 && off > 10 ) leader = 1;
else if( is_one(on, off) ) code = (code<<1) + 1,count++;
else if( is_zero(on, off) ) code = (code<<1), count++;
on = 1;
}
}
printf("code = %-8lx(%d bit) %s-%s ", code, count,
leader ? "true " : "false", tailer ? "true " : "false");
if( count == 32 ) {
if( ((code>>16) & 0xff) != (~(code>>24) & 0xff) )
printf("Vender = 0x%04x ", (code>>16)&0xffff);
else
printf("Vender = 0x%02x ", (code>>24)&0xff);
if( (code & 0xff) == (~(code>>8) & 0xff) )
printf("Data = 0x%02x\n", (code>>8)&0xff);
else
printf("data error\n");
} else
printf("\n");
}
------------------------ここまで------------------------
HDUS_Power code = 50ef817e(32 bit) true -true Vender = 0x50ef Data = 0x81
written by sirius [KURO-RS] [この記事のURL] [コメントを書く] [コメント(0)] [TB(0)]
MySketch 2.7.2 written by 夕雨