--- /dev/null
+#include <unistd.h>
+
+
+void main()
+{
+ unsigned char c,out=0;
+ int count =0;
+ while (read(0,&c,1))
+ {
+ out<<=1;
+ if (c=='1')
+ out |=1;
+ count++;
+ if (count ==8)
+ {
+ write(1,&out,1);
+ count=0;
+ out=0;
+ }
+ }
+ out<<=8-count;
+ out |= 0xff>>count;
+ write(1,&out,1);
+}
$binarydata[int($bitcount/8)]|=$bits;
$bitcount++;
}
- $binarydata[int($bitcount/8)]<<= 7 - ($bitcount % 8);
+ $binarydata[int($bitcount/8)]<<= 8 - ($bitcount % 8) if $bitcount % 8;
my @chars = map { chr($_) } @binarydata;
print STDERR join '',@chars;
# print STDERR "\ns\x04"; # send 4 times
--- /dev/null
+#!/usr/bin/perl
+use strict;
+print $ARGV[2]-$ARGV[1], "samples\n";
+my @data = split /,/,<>;
+my @samples = $ARGV[0]..$ARGV[1];
+print join ',', @data[@samples];
+print "\n";
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
#if defined(OS_LINUX) || defined(OS_MACOSX)
#include <sys/ioctl.h>
static char get_keystroke(void);
+void sendstr(char * tosend)
+{
+ rawhid_send(0, tosend, strlen(tosend),100);
+}
int main (int argc, char *argv[])
{
int i, r, num;
char c, buf[64];
-
// C-based example is 16C0:0480:FFAB:0200
r = rawhid_open(1, 0x16C0, 0x0480, 0xFFAB, 0x0200);
if (r <= 0) {
FILE * f = fopen (argv[1], "r");
if (!f)
return -3;
+ sendstr("c"); // clear the buffer
buf[0]='f';
- size_t len= fread(buf+1, 63, 1, f);
- rawhid_send(0, buf, 1+len, 100);
- buf[0]='s';
- buf[1]=4;
- rawhid_send(0, buf, 2, 100);
+ size_t len= fread(buf+1, 1, 63, f);
+ for(i=len+1;i<64;i++)
+ buf[i]=0xff;
+ rawhid_send(0, buf, 64, 100); //fill the buffer
+ sendstr("s\x10"); // send 4 times
+ len = rawhid_recv(0, buf, 64, 255);
+ for(i=0;i<len;i++)
+ {
+ printf("%02x ",(unsigned char) buf[i]);
+ }
+ printf("\n");
return 0;
} else {
while (1) {
volatile uint8_t active_buffer=0;
volatile uint16_t send_buffer=0;
volatile uint8_t capture=0;
-volatile uint8_t rf_send=0; //count of bits in rf_send_buffer that should be sent
-volatile uint8_t rf_send_reload=0; //count of bits in rf_send_buffer that should be sent
+volatile uint16_t rf_send=0; //count of bits in rf_send_buffer that should be sent
+volatile uint16_t rf_send_reload=0; //count of bits in rf_send_buffer that should be sent
volatile uint8_t rf_send_reload_count=0; // number of repetitions (times rf_send gets reloaded;
uint8_t read_buffer[64]; // buffer for reading usb signals
uint8_t write_buffer[2][64]; // buffer for writing usb signals
uint8_t rf_send_buffer[RF_SEND_BUFFER_LEN_MAX]; // buffer for sending rf433 signals
-uint8_t rf_send_buffer_len=0;
+volatile uint16_t rf_send_buffer_len=0;
void reset()
capture=0;
else if (read_buffer[0]=='f') //fill send buffer
{
- int8_t byte_rem = r-1;
- while(byte_rem && rf_send_buffer_len<RF_SEND_BUFFER_LEN_MAX)
+ int8_t buffer_pos = 1;
+ while(buffer_pos < r && rf_send_buffer_len<RF_SEND_BUFFER_LEN_MAX)
{
- rf_send_buffer[rf_send_buffer_len]=read_buffer[r-byte_rem];
+ rf_send_buffer[rf_send_buffer_len]=read_buffer[buffer_pos];
rf_send_buffer_len++;
- byte_rem--;
+ buffer_pos++;
}
}
else if (read_buffer[0]=='c') // clear send buffer
else if (read_buffer[0]=='s') //send
{
capture=0;
- if (r>2)
- rf_send_reload=rf_send_buffer_len*8-read_buffer[2]; // substract bit offset
- else
- rf_send_reload=rf_send_buffer_len*8;
+ //if (r>2)
+ // rf_send_reload=rf_send_buffer_len*8-read_buffer[2]; // substract bit offset
+ //else
+ usb_rawhid_send(rf_send_buffer, 145);
+ rf_send=0;
+ rf_send_reload=rf_send_buffer_len*8;
rf_send_reload_count=read_buffer[1];
+ //read_buffer[0]=rf_send_reload;
+ //read_buffer[1]=rf_send_reload>>8;
+ //read_buffer[2]=0;
}
}
if (send_buffer)
PORTF^=2;
if (rf_send)
{
- if (rf_send_buffer[rf_send/8] & 0x80)
+ if ( ( rf_send_buffer[rf_send/8] >> ( (rf_send%8)?8-(rf_send%8):0 ) ) & 1)
{
- PORTF|=1;
- } else {
PORTF&=~1;
+ } else {
+ PORTF|=1;
}
- rf_send_buffer[rf_send/8]<<=1;
+ //rf_send_buffer[rf_send/8]>>=1;
rf_send--;
} else if (rf_send_reload_count) {
rf_send=rf_send_reload;
+ rf_send_reload_count--;
} else {
- PORTF&=~1;
+ PORTF&=~1;
if (capture) {
write_buffer[active_buffer][output_count/8]<<=1;
write_buffer[active_buffer][output_count++/8]|=PINB&1;