Index: apps/iap.c =================================================================== --- apps/iap.c (revision 22234) +++ apps/iap.c (working copy) @@ -29,6 +29,7 @@ #include "system.h" #include "kernel.h" #include "serial.h" +#include "ata_idle_notify.h" #include "appevents.h" #include "playlist.h" @@ -54,10 +55,72 @@ unsigned char serbuf[RX_BUFLEN]; static int serbuf_i = 0; +static int serbuf_size = 0; static unsigned char response[TX_BUFLEN]; static int responselen; +#define MAX_LOGBUF 2048 +static char logbuf[MAX_LOGBUF]; +static int logbuf_end = 0; +#define SERIAL_LOGFILE "/seriallog.txt" + +bool serial_log_flush(void) +{ + int fd; + + fd = open (SERIAL_LOGFILE,O_APPEND|O_CREAT|O_RDWR); + if (fd>=0) + { + if (logbuf_end+1= 0; +} +static char* chartohex(char val) +{ + static char ret[2]; + const char hexdigit[] = "0123456789ABCDEF"; + ret[0] = hexdigit[(val&0xf0)>>4]; + ret[1] = hexdigit[val&0xf]; + return ret; +} +void serial_log_packet (const int in_packet, const char* data, const int size) +{ + int i; + int startindex; + char incoming[] = "IN "; + char outgoing[] = "OUT "; + const int message_additions = sizeof(incoming)+1; /* +1 is for the "\n" */ + if (logbuf_end + size + message_additions > MAX_LOGBUF-1) + serial_log_flush(); + if (in_packet) + { + memcpy(&logbuf[logbuf_end], incoming, sizeof(incoming)); + logbuf_end += sizeof(incoming); + startindex = 0; + } + else + { + memcpy(&logbuf[logbuf_end], outgoing, sizeof(outgoing)); + logbuf_end += sizeof(outgoing); + /* we don't need to print the heading marker FF 55 */ + startindex = 2; + } + + /* size-1 : don't print checksum */ + for (i=startindex;i= RX_BUFLEN) + { serbuf_i = 0; + serbuf_size = 0; + } serbuf[serbuf_i++] = x; + serbuf_size++; chksum += x; } last_x = x; @@ -224,6 +295,7 @@ queue_post(&button_queue, SYS_IAP_HANDLEPKT, 0); return; } + serial_log_packet (1,serbuf,serbuf_size); /* Handle Mode 0 */ if (serbuf[1] == 0x00)