From 76a84b354f504b15901ffa7632e6c5c525f922ae Mon Sep 17 00:00:00 2001 From: schneider Date: Sat, 23 Jul 2011 17:58:56 +0200 Subject: [PATCH] vcard: small clean up --- firmware/applications/vcard.c | 79 ++++++----------------------------- firmware/funk/filetransfer.c | 24 ++++++++--- firmware/funk/rftransfer.c | 35 +++++++--------- firmware/funk/rftransfer.h | 2 +- 4 files changed, 47 insertions(+), 93 deletions(-) diff --git a/firmware/applications/vcard.c b/firmware/applications/vcard.c index 1cab24b..a5bf28a 100644 --- a/firmware/applications/vcard.c +++ b/firmware/applications/vcard.c @@ -58,7 +58,6 @@ int receiveKey(uint8_t type, uint8_t *x, uint8_t *y) uint8_t n; n = nrf_rcv_pkt_time(1000, 32, buf); - lcdPrint("pkt:"); lcdPrintInt(n);lcdPrintln(""); lcdRefresh(); if( n == 32 && buf[0] == type && buf[1] == 'X' ){ for(int i=0; i MAXSIZE ) return 1; //file to big //if(fileexists(metadata)) return 1; //file already exists - lcdPrint("open"); lcdPrintln((const char*)metadata); lcdRefresh(); + //lcdPrint("open"); lcdPrintln((const char*)metadata); lcdRefresh(); res = f_open(&file, (const char*)metadata, FA_OPEN_ALWAYS|FA_WRITE); //lcdPrintln("file opened"); lcdRefresh(); @@ -94,9 +97,18 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4]) uint16_t wordcount = (size+3)/4; //nrf_set_rx_mac(0, 32, 5, mac); - lcdPrintln("get file"); lcdRefresh(); - rftransfer_receive(buf, wordcount*4, 1000); - lcdPrintln("got file"); lcdRefresh(); + //lcdPrintln("get file"); lcdRefresh(); + int fres = rftransfer_receive(buf, wordcount*4, 1000); + if( fres == -1 ){ + lcdPrintln("checksum wrong"); + }else if( fres == -2 ){ + lcdPrintln("timeout"); + }else{ + //lcdPrintln("got file"); + } + lcdRefresh(); + if( fres < 0 ) + return; //nrf_set_rx_mac(0, 32, 5, macbuf); xxtea_decode_words((uint32_t *)buf, wordcount, k); @@ -107,6 +119,8 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4]) return res; if( written != size ) return 1; //error while writing + lcdClear(); + lcdPrintln("Received"); lcdPrintln((const char*)metadata); lcdRefresh(); return 0; } diff --git a/firmware/funk/rftransfer.c b/firmware/funk/rftransfer.c index 88022fb..7c52423 100644 --- a/firmware/funk/rftransfer.c +++ b/firmware/funk/rftransfer.c @@ -16,7 +16,6 @@ void rftransfer_send(uint16_t size, uint8_t *data) buf[3] = rand >> 8; buf[4] = rand & 0xFF; - //nrf_snd_pkt_crc(5,buf); //setup packet nrf_snd_pkt_crc(32,buf); //setup packet delayms(20); uint16_t index = 0; @@ -42,13 +41,11 @@ void rftransfer_send(uint16_t size, uint8_t *data) buf[2] = crc & 0xFF; buf[3] = rand >> 8; buf[4] = rand & 0xFF; - //nrf_snd_pkt_crc(5,buf); //crc packet nrf_snd_pkt_crc(32,buf); //setup packet delayms(20); - lcdPrint("crc="); lcdPrintIntHex(crc);lcdPrintln("");lcdRefresh(); } -uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) +int16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) { uint8_t buf[MAXPACKET]; uint8_t state = 0; @@ -57,7 +54,7 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) unsigned int currentTick = systickGetTicks(); unsigned int startTick = currentTick; - while(currentTick < (startTick+timeout) ){//this fails if either overflows + while(systickGetTicks() < (startTick+timeout) ){//this fails if either overflows n = nrf_rcv_pkt_time(1000, MAXPACKET, buf); switch(state){ case 0: @@ -67,49 +64,45 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) seq = 0; pos = 0; if( size <= maxlen ){ - lcdClear(); - lcdPrint("got l="); lcdPrintInt(size); - lcdPrintln(""); lcdRefresh(); + //lcdClear(); + //lcdPrint("got l="); lcdPrintInt(size); + //lcdPrintln(""); lcdRefresh(); state = 1; } } break; case 1: if( n == 32 && buf[0] == 'D' && ((buf[3]<<8)|buf[4])==rand ){ - lcdPrint("got d"); lcdRefresh(); + //lcdPrint("got d"); lcdRefresh(); if( seq == ((buf[1]<<8)|buf[2]) ){ - lcdPrintln(" in seq"); lcdRefresh(); - //if( (pos + n - 5) void rftransfer_send(uint16_t size, uint8_t *data); -uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout); +int16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout); #endif