#include <unistd.h>
+#include <stdint.h>
+#include <stdio.h>
+#define MAX_RAM 502
void main()
{
- unsigned char c,out=0;
- int count =0;
- while (read(0,&c,1))
+ unsigned char input[MAX_RAM*8+1];
+ unsigned char output[MAX_RAM];
+ uint16_t i=0;
+ uint16_t len=0;
+ uint16_t len_net=0;
+ for(i=0; i<MAX_RAM;i++)
{
- out<<=1;
- if (c=='1')
- out |=1;
- count++;
- if (count ==8)
- {
- write(1,&out,1);
- count=0;
- out=0;
- }
+ output[i] = 0;
}
- out<<=8-count;
- out |= 0xff>>count;
- write(1,&out,1);
+
+ len=read(0,input,MAX_RAM*8+1);
+ if (len<1)
+ {
+ perror("read(): ");
+ } else if (len==MAX_RAM*8+1) {
+ printf("File to big");
+ }
+ for(i=0; i<len;i++)
+ {
+ if (input[i]=='1')
+ output[i/8] |= 1<< (i%8);
+ }
+ len_net=htons(len);
+ write(1,&len_net,sizeof(len_net));
+ write(1,output, (len%8)?len/8+1:len/8);
}
void sendstr(char * tosend)
{
- rawhid_send(0, tosend, strlen(tosend),100);
+ rawhid_send(0, tosend, strlen(tosend),1000);
}
int main (int argc, char *argv[])
FILE * f = fopen (argv[1], "r");
if (!f)
return -3;
+ printf("Clearing Buffer\n");
sendstr("c"); // clear the buffer
buf[0]='f';
- 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
+ while ( fread(buf+1, 1, 63, f) )
+ {
+
+ rawhid_send(0, buf, 64, 1000); //fill the buffer
+ printf("Sending Buffer\n");
+ }
+ printf("Executing Send command\n");
sendstr("s\x10"); // send 4 times
- len = rawhid_recv(0, buf, 64, 255);
+ size_t len = rawhid_recv(0, buf, 64, 255);
for(i=0;i<len;i++)
{
printf("%02x ",(unsigned char) buf[i]);
#include "usb_rawhid.h"
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
-#define RF_SEND_BUFFER_LEN_MAX 128
+#define RF_SEND_BUFFER_LEN_MAX 502
volatile uint16_t output_count=0;
volatile uint8_t active_buffer=0;
volatile uint16_t send_buffer=0;
volatile uint8_t capture=0;
-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;
+volatile uint16_t rf_send_buf_pos=0; //count of bits in rf_send_buffer that should be sent
+volatile uint16_t rf_send_buf_len=0; //count of bits in rf_send_buffer that should be sent
+volatile uint8_t rf_send_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
-volatile uint16_t rf_send_buffer_len=0;
+uint16_t rf_send_buf_offset=0;
void reset()
DDRF|=3;
PORTF&=~1;
// Configure timer 0 to generate a timer overflow interrupt every
- // 200*8 clock cycles, 100us
+ // 100*8 clock cycles, 50us
TCCR0A = 1<<WGM01;
TCCR0B = 1<<CS01;
- OCR0A = 249;
+ OCR0A = 99;
TCNT0 = 0;
TIMSK0 = (1<<OCIE0A);
capture=0;
else if (read_buffer[0]=='f') //fill send buffer
{
- int8_t buffer_pos = 1;
- while(buffer_pos < r && rf_send_buffer_len<RF_SEND_BUFFER_LEN_MAX)
+ uint8_t buffer_pos = 1;
+ if(!rf_send_buf_offset) {
+ rf_send_buf_len=read_buffer[2] | (read_buffer[1]<<8); //rf_send_buf_offset*8;
+ buffer_pos+=2;
+ }
+ while(buffer_pos < r && rf_send_buf_offset<RF_SEND_BUFFER_LEN_MAX)
{
- rf_send_buffer[rf_send_buffer_len]=read_buffer[buffer_pos];
- rf_send_buffer_len++;
+ rf_send_buffer[rf_send_buf_offset]=read_buffer[buffer_pos];
+ rf_send_buf_offset++;
buffer_pos++;
}
}
else if (read_buffer[0]=='c') // clear send buffer
{
- rf_send_buffer_len=0;
+ rf_send_buf_offset=0;
}
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
- 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;
+ rf_send_buf_pos=0;
+ rf_send_count=read_buffer[1]+1;
}
}
if (send_buffer)
{
send_buffer=0;
- usb_rawhid_send(write_buffer[active_buffer?0:1], 45);
+ usb_rawhid_send(write_buffer[active_buffer?0:1], 23);
}
}
}
ISR(TIMER0_COMPA_vect)
{
PORTF^=2;
- if (rf_send)
+ if (rf_send_count && rf_send_buf_pos<rf_send_buf_len)
{
- if ( ( rf_send_buffer[rf_send/8] >> ( (rf_send%8)?8-(rf_send%8):0 ) ) & 1)
+ if ( rf_send_buffer[rf_send_buf_pos/8] & (1<< (rf_send_buf_pos%8)))
{
PORTF&=~1;
} else {
PORTF|=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--;
+ rf_send_buf_pos++;
+ } else if (rf_send_count) {
+ rf_send_buf_pos=0;
+ rf_send_count--;
} else {
PORTF&=~1;
if (capture) {