1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //=================================================================
27 // eCosTestDownloadFilter.h
29 // Socket/serial download filter class
31 //=================================================================
32 //=================================================================
33 //#####DESCRIPTIONBEGIN####
36 // Contributors: jskov
38 //####DESCRIPTIONEND####
39 #ifndef _CECOSDOWNLOADFILTER_H
40 #define _CECOSDOWNLOADFILTER_H
44 #include "eCosSocket.h"
45 #include "eCosSerial.h"
47 //----------------------------------------------------------------------------
48 // Macros to help extract values from the argument string.
49 // Note: This is probably not an ideal solution, but it was easy to make :)
51 #define INIT_VALUE(__args) unsigned int v; char *__ptr1, *__ptr2 = (__args)
53 #define SET_VALUE(__type, __slot) { \
54 __ptr1 = strchr(__ptr2, (int) ':'); \
55 if (*__ptr2 == '\0') \
56 (__slot) = (__type)-1; \
61 __ptr1 = strchr( __ptr2, 0) - 1; \
64 (__slot) = (__type) v; \
68 #define SET_STRING(__slot) { __ptr1 = strchr(__ptr2, (int) ':'); if (__ptr1) *__ptr1 = 0; __slot = __ptr2; __ptr2 = __ptr1+1; }
71 //----------------------------------------------------------------------------
73 class CeCosTestDownloadFilter;
75 class CeCosTestDownloadFilter {
78 CeCosTestDownloadFilter();
79 ~CeCosTestDownloadFilter();
81 // Configuration methods
82 void SetSerialDebug(bool bSerialDebug)
83 { m_bOptSerDebug = bSerialDebug; }
84 void SetFilterTrace(bool bFilterTrace)
85 { m_bOptFilterTrace = bFilterTrace; }
88 bool ContinueSession()
89 { bool r = m_bContinueSession; m_bContinueSession = false; return r; }
91 bool FilterFunctionProper(void*& pBuf,
97 // If we can guarantee a minimum buffer size in the stub, we can
99 enum {MAX_CMD_LEN=128, PBUFSIZ=400};
100 enum data_origin_t {SF_TARGET=0, SF_FILTER} ;
103 void ConsoleWrite(const char* pszStr);
104 void Trace(const char* pszFormat, ...);
106 void PrintHex(const unsigned char* d1, int len,
107 data_origin_t origin=SF_TARGET);
109 // Target read/write methods
110 void TargetWrite(CeCosSerial &pSer,
111 const unsigned char* buffer, int len);
115 int hexnumstr(unsigned char* buf, unsigned long num);
116 int hexnumlen(unsigned long num);
117 int put_binary (unsigned char* buf, int cnt, unsigned long dl_address,
118 int packet_size, CeCosSerial& serial);
120 // Options used for configuring behavior.
123 bool m_bOptFilterTrace;
128 char m_aCmd[MAX_CMD_LEN];
129 bool m_bContinueSession; // set true only after a successfull dl
132 extern bool CALLBACK DownloadFilterFunction(void*& pBuf,
138 #endif // _CECOSDOWNLOADFILTER_H