sending works

This commit is contained in:
schneider 2011-07-14 00:13:16 +02:00
parent 59bb6ba046
commit b8bc4e837a
2 changed files with 11 additions and 6 deletions

View File

@ -5,6 +5,7 @@
OBJS = OBJS =
OBJS += nrf24l01p.o OBJS += nrf24l01p.o
OBJS += rftransfer.o
LIBNAME=funk LIBNAME=funk

View File

@ -3,9 +3,10 @@
#include <basic/basic.h> #include <basic/basic.h>
#include <core/systick/systick.h> #include <core/systick/systick.h>
#define MAXPACKET 30
void rftransfer_send(uint16_t size, uint8_t *data) void rftransfer_send(uint16_t size, uint8_t *data)
{ {
uint8_t buf[30]; uint8_t buf[MAXPACKET];
buf[0] = 'L'; buf[0] = 'L';
buf[1] = size >> 8; buf[1] = size >> 8;
buf[2] = size & 0xFF; buf[2] = size & 0xFF;
@ -15,34 +16,37 @@ void rftransfer_send(uint16_t size, uint8_t *data)
buf[4] = rand & 0xFF; buf[4] = rand & 0xFF;
nrf_snd_pkt_crc(5,buf); //setup packet nrf_snd_pkt_crc(5,buf); //setup packet
delayms(10);
uint16_t index = 0; uint16_t index = 0;
uint8_t i; uint8_t i;
uint16_t crc = crc16(data,size);
while(size){ while(size){
buf[0] = 'D'; buf[0] = 'D';
buf[1] = index >> 8; buf[1] = index >> 8;
buf[2] = index & 0xFF; buf[2] = index & 0xFF;
buf[3] = rand >> 8; buf[3] = rand >> 8;
buf[4] = rand & 0xFF; buf[4] = rand & 0xFF;
for(i=5; i<30 && size>0; i++,size--){ for(i=5; i<MAXPACKET && size>0; i++,size--){
buf[i] = *data++; buf[i] = *data++;
} }
index++; index++;
nrf_snd_pkt_crc(i,buf); //data packet nrf_snd_pkt_crc(i,buf); //data packet
delayms(10);
} }
uint16_t crc = crc16(data,size);
buf[0] = 'C'; buf[0] = 'C';
buf[1] = crc >> 8; buf[1] = crc >> 8;
buf[2] = crc & 0xFF; buf[2] = crc & 0xFF;
buf[3] = rand >> 8; buf[3] = rand >> 8;
buf[4] = rand & 0xFF; buf[4] = rand & 0xFF;
nrf_snd_pkt_crc(5,buf); //crc packet nrf_snd_pkt_crc(5,buf); //crc packet
delayms(10);
} }
uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
{ {
uint8_t buf[30]; uint8_t buf[MAXPACKET];
uint8_t state = 0; uint8_t state = 0;
uint16_t pos = 0, seq = 0, size = 0, rand = 0, crc = 0; uint16_t pos = 0, seq = 0, size = 0, rand = 0, crc = 0;
int n,i; int n,i;
@ -50,7 +54,7 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
unsigned int startTick = currentTick; unsigned int startTick = currentTick;
while(currentTick < (startTick+timeout) ){//this fails if either overflows while(currentTick < (startTick+timeout) ){//this fails if either overflows
n = nrf_rcv_pkt_time(10, 30, buf); n = nrf_rcv_pkt_time(10, MAXPACKET, buf);
switch(state){ switch(state){
case 0: case 0:
if( n == 5 && buf[0] == 'L' ){ if( n == 5 && buf[0] == 'L' ){