2011年1月17日(月) 21:57
----------------------ここから----------------------
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <malloc.h>
#include "kuro_rs.h"
#include "kuro_rs_common.h"
int main(int argc,char *argv[])
{
unsigned char buf[255];
char *data_file = NULL;
char *device = "/dev/ttyUSB0";
FILE *fp;
RS *rp;
if( argc >= 2 && argv[1] && *argv[1] )
data_file = argv[1];
if( !data_file ) {
printf("%s data file\n", argv[0]);
exit(1);
}
if( !(rp = open_rs(device, 1)) ) {
printf("device open error(%s)\n", device);
exit(1);
}
if( recive_irdata(rp, buf) ) {
printf("recive error\n");
exit(1);
}
close_rs(rp);
if( !(fp = fopen(data_file, "wb")) ) {
printf("file open err(%s)\n", data_file);
exit(1);
} else {
fwrite(buf, sizeof(unsigned char), REC_DATA_SIZE, fp);
fclose(fp);
}
printf("Rec File : %s\n", data_file);
exit(0);
}
----------------------ここまで----------------------
----------------------ここから----------------------
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <malloc.h>
#include "kuro_rs.h"
#include "kuro_rs_common.h"
int main(int argc,char *argv[])
{
unsigned char buf[255];
char *port = "1";
char *data_file = NULL;
char *device = "/dev/ttyUSB0";
FILE *fp;
RS *rp;
if( argc >= 2 && argv[1] && *argv[1] )
data_file = argv[1];
if( argc >= 3 && argv[1] && *argv[2] )
port = argv[2];
if( !data_file ) {
printf("%s data file [port]\n", argv[0]);
exit(1);
}
if( !(fp = fopen(data_file, "rb")) ) {
printf("file open err(%s)\n", data_file);
exit(1);
} else {
fread(buf, sizeof(unsigned char), REC_DATA_SIZE, fp);
fclose(fp);
}
if( !port || (*port < '1' || *port > '4') )
*port = '1';
if( !(rp = open_rs(device, 1)) ) {
printf("device open error(%s)\n", device);
exit(1);
}
if( send_irdata(rp, *port, buf) ) {
printf("can't send data\n");
exit(1);
}
close_rs(rp);
printf("Send File : %s\n", data_file);
exit(0);
}
----------------------ここまで----------------------
written by sirius [KURO-RS] [この記事のURL] [コメントを書く] [コメント(0)] [TB(0)]
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)]
2011年1月12日(水) 22:11
----------------------ここから----------------------
#include <stdio.h>
#include <stdlib.h>
#define bits(x) ((x) < 0 ? 0 : (buf[(x)/8]>>((x)%8))&0x1)
#define max(x, y) (((x) > (y)) ? (x) : (y))
int main(int argc, char *argv[])
{
FILE *fp;
unsigned char buf[255];
int i, max_on, max_off, on, off, count;
if( argc != 2 ) exit(1);
if( !(fp = fopen(argv[1], "rb")) ) exit(1);
fread(buf, sizeof(unsigned char), 240, fp);
max_on = max_off = on = off = count = 0;
for( i = 0; i < 240*8; i++ ) {
if( bits(i) ) {
if( bits(i-1) ) on++;
else {
if( i ) {
count++;
printf("%-3d, " , off);
if( (count % 8) == 7 ) printf("\n");
} else count--;
max_off = max(max_off, off);
on = 1;
}
} else {
if( bits(i-1) ) {
count++;
printf("%-3d, ", on);
if( (count % 8) == 7 ) printf("\n");
max_on = max(max_on, on);
off = 1;
} else off++;
}
}
if( bits(i-2) == bits(i-1) ) {
if( bits(i-1) ) {
printf("%-3d\n", on);
max_on = max(max_on, on);
} else {
printf("%-3d\n", off);
max_off = max(max_off, off);
}
}
printf("max on bit %d, off bit %d\n", max_on, max_off);
}
----------------------ここまで----------------------
written by sirius [KURO-RS] [この記事のURL] [コメントを書く] [コメント(0)] [TB(0)]
2011年1月11日(火) 20:50
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fp;
int i, j;
int msb, byte;
unsigned char buf[255], c;
if( argc != 3 ) exit(1);
msb = byte = 0;
if( *(argv[2]) == '1' ) msb = 1;
if( *(argv[2]+1) == '1' ) byte = 1;
if( !(fp = fopen(argv[1], "rb")) ) exit(1);
fread(buf, sizeof(unsigned char), 240, fp);
for( i = 0; i < 240; i++ ) {
if( byte ) {
if( i % 2 ) c = buf[i-1];
else c = buf[i+1];
} else c = buf[i];
for( j = 0; j < 8; j++ ) {
if( msb ) printf("%d", (c>>j) &0x1);
else printf("%d", (c>>(7-j)) &0x1);
}
if( (i % 8) == 7 ) printf("\n");
else printf(" ");
}
printf("\n");
}
written by sirius [KURO-RS] [この記事のURL] [コメントを書く] [コメント(0)] [TB(0)]
2011年1月7日(金) 20:16
written by sirius [KURO-RS] [この記事のURL] [コメントを書く] [コメント(0)] [TB(0)]
2011年1月4日(火) 10:38
written by sirius [KURO-RS] [この記事のURL] [コメントを書く] [コメント(0)] [TB(0)]
2007年6月4日(月) 00:08
written by sirius [KURO-RS] [この記事のURL] [コメントを書く] [コメント(0)] [TB(0)]
MySketch 2.7.2 written by 夕雨