![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test public
Fork of Probleme_implementation_lwip by
portother.cpp@2:9e76d51d9fb6, 2018-07-02 (annotated)
- Committer:
- TomTom83
- Date:
- Mon Jul 02 15:18:18 2018 +0000
- Revision:
- 2:9e76d51d9fb6
- Parent:
- 1:a3ee8cb24540
probl?mes d'adaptation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TomTom83 | 1:a3ee8cb24540 | 1 | /* |
TomTom83 | 1:a3ee8cb24540 | 2 | * FreeModbus Libary: lwIP Port |
TomTom83 | 1:a3ee8cb24540 | 3 | * Copyright (C) 2006 Christian Walter <wolti@sil.at> |
TomTom83 | 1:a3ee8cb24540 | 4 | * |
TomTom83 | 1:a3ee8cb24540 | 5 | * This library is free software; you can redistribute it and/or |
TomTom83 | 1:a3ee8cb24540 | 6 | * modify it under the terms of the GNU Lesser General Public |
TomTom83 | 1:a3ee8cb24540 | 7 | * License as published by the Free Software Foundation; either |
TomTom83 | 1:a3ee8cb24540 | 8 | * version 2.1 of the License, or (at your option) any later version. |
TomTom83 | 1:a3ee8cb24540 | 9 | * |
TomTom83 | 1:a3ee8cb24540 | 10 | * This library is distributed in the hope that it will be useful, |
TomTom83 | 1:a3ee8cb24540 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
TomTom83 | 1:a3ee8cb24540 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
TomTom83 | 1:a3ee8cb24540 | 13 | * Lesser General Public License for more details. |
TomTom83 | 1:a3ee8cb24540 | 14 | * |
TomTom83 | 1:a3ee8cb24540 | 15 | * You should have received a copy of the GNU Lesser General Public |
TomTom83 | 1:a3ee8cb24540 | 16 | * License along with this library; if not, write to the Free Software |
TomTom83 | 1:a3ee8cb24540 | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
TomTom83 | 1:a3ee8cb24540 | 18 | * |
TomTom83 | 1:a3ee8cb24540 | 19 | * File: $Id: portother.c,v 1.2 2006/09/04 14:39:20 wolti Exp $ |
TomTom83 | 1:a3ee8cb24540 | 20 | */ |
TomTom83 | 1:a3ee8cb24540 | 21 | |
TomTom83 | 1:a3ee8cb24540 | 22 | /* ----------------------- System includes ----------------------------------*/ |
TomTom83 | 1:a3ee8cb24540 | 23 | #include <stdio.h> |
TomTom83 | 1:a3ee8cb24540 | 24 | #include <stdarg.h> |
TomTom83 | 1:a3ee8cb24540 | 25 | #include <string.h> |
TomTom83 | 1:a3ee8cb24540 | 26 | |
TomTom83 | 1:a3ee8cb24540 | 27 | #include "port.h" |
TomTom83 | 1:a3ee8cb24540 | 28 | |
TomTom83 | 1:a3ee8cb24540 | 29 | /* ----------------------- Defines ------------------------------------------*/ |
TomTom83 | 1:a3ee8cb24540 | 30 | #define MB_FRAME_LOG_BUFSIZE 512 |
TomTom83 | 1:a3ee8cb24540 | 31 | |
TomTom83 | 1:a3ee8cb24540 | 32 | /* ----------------------- Start implementation -----------------------------*/ |
TomTom83 | 1:a3ee8cb24540 | 33 | |
TomTom83 | 1:a3ee8cb24540 | 34 | #ifdef MB_TCP_DEBUG |
TomTom83 | 1:a3ee8cb24540 | 35 | void |
TomTom83 | 1:a3ee8cb24540 | 36 | prvvMBTCPLogFrame( UCHAR * pucMsg, UCHAR * pucFrame, USHORT usFrameLen ) |
TomTom83 | 1:a3ee8cb24540 | 37 | { |
TomTom83 | 1:a3ee8cb24540 | 38 | int i; |
TomTom83 | 1:a3ee8cb24540 | 39 | int res = 0; |
TomTom83 | 1:a3ee8cb24540 | 40 | int iBufPos = 0; |
TomTom83 | 1:a3ee8cb24540 | 41 | size_t iBufLeft = MB_FRAME_LOG_BUFSIZE; |
TomTom83 | 1:a3ee8cb24540 | 42 | static CHAR arcBuffer[MB_FRAME_LOG_BUFSIZE]; |
TomTom83 | 1:a3ee8cb24540 | 43 | |
TomTom83 | 1:a3ee8cb24540 | 44 | assert( pucFrame != NULL ); |
TomTom83 | 1:a3ee8cb24540 | 45 | |
TomTom83 | 1:a3ee8cb24540 | 46 | for( i = 0; i < usFrameLen; i++ ) |
TomTom83 | 1:a3ee8cb24540 | 47 | { |
TomTom83 | 1:a3ee8cb24540 | 48 | /* Print some additional frame information. */ |
TomTom83 | 1:a3ee8cb24540 | 49 | switch ( i ) |
TomTom83 | 1:a3ee8cb24540 | 50 | { |
TomTom83 | 1:a3ee8cb24540 | 51 | case 0: |
TomTom83 | 1:a3ee8cb24540 | 52 | /* TID = Transaction Identifier. */ |
TomTom83 | 1:a3ee8cb24540 | 53 | res = snprintf( &arcBuffer[iBufPos], iBufLeft, "| TID = " ); |
TomTom83 | 1:a3ee8cb24540 | 54 | break; |
TomTom83 | 1:a3ee8cb24540 | 55 | case 2: |
TomTom83 | 1:a3ee8cb24540 | 56 | /* PID = Protocol Identifier. */ |
TomTom83 | 1:a3ee8cb24540 | 57 | res = snprintf( &arcBuffer[iBufPos], iBufLeft, " | PID = " ); |
TomTom83 | 1:a3ee8cb24540 | 58 | break; |
TomTom83 | 1:a3ee8cb24540 | 59 | case 4: |
TomTom83 | 1:a3ee8cb24540 | 60 | /* Length */ |
TomTom83 | 1:a3ee8cb24540 | 61 | res = snprintf( &arcBuffer[iBufPos], iBufLeft, " | LEN = " ); |
TomTom83 | 1:a3ee8cb24540 | 62 | break; |
TomTom83 | 1:a3ee8cb24540 | 63 | case 6: |
TomTom83 | 1:a3ee8cb24540 | 64 | /* UID = Unit Identifier. */ |
TomTom83 | 1:a3ee8cb24540 | 65 | res = snprintf( &arcBuffer[iBufPos], iBufLeft, " | UID = " ); |
TomTom83 | 1:a3ee8cb24540 | 66 | break; |
TomTom83 | 1:a3ee8cb24540 | 67 | case 7: |
TomTom83 | 1:a3ee8cb24540 | 68 | /* MB Function Code. */ |
TomTom83 | 1:a3ee8cb24540 | 69 | res = snprintf( &arcBuffer[iBufPos], iBufLeft, "|| FUNC = " ); |
TomTom83 | 1:a3ee8cb24540 | 70 | break; |
TomTom83 | 1:a3ee8cb24540 | 71 | case 8: |
TomTom83 | 1:a3ee8cb24540 | 72 | /* MB PDU rest. */ |
TomTom83 | 1:a3ee8cb24540 | 73 | res = snprintf( &arcBuffer[iBufPos], iBufLeft, " | DATA = " ); |
TomTom83 | 1:a3ee8cb24540 | 74 | break; |
TomTom83 | 1:a3ee8cb24540 | 75 | default: |
TomTom83 | 1:a3ee8cb24540 | 76 | res = 0; |
TomTom83 | 1:a3ee8cb24540 | 77 | break; |
TomTom83 | 1:a3ee8cb24540 | 78 | } |
TomTom83 | 1:a3ee8cb24540 | 79 | if( res == -1 ) |
TomTom83 | 1:a3ee8cb24540 | 80 | { |
TomTom83 | 1:a3ee8cb24540 | 81 | break; |
TomTom83 | 1:a3ee8cb24540 | 82 | } |
TomTom83 | 1:a3ee8cb24540 | 83 | else |
TomTom83 | 1:a3ee8cb24540 | 84 | { |
TomTom83 | 1:a3ee8cb24540 | 85 | iBufPos += res; |
TomTom83 | 1:a3ee8cb24540 | 86 | iBufLeft -= res; |
TomTom83 | 1:a3ee8cb24540 | 87 | } |
TomTom83 | 1:a3ee8cb24540 | 88 | |
TomTom83 | 1:a3ee8cb24540 | 89 | /* Print the data. */ |
TomTom83 | 1:a3ee8cb24540 | 90 | res = snprintf( &arcBuffer[iBufPos], iBufLeft, "%02X", pucFrame[i] ); |
TomTom83 | 1:a3ee8cb24540 | 91 | if( res == -1 ) |
TomTom83 | 1:a3ee8cb24540 | 92 | { |
TomTom83 | 1:a3ee8cb24540 | 93 | break; |
TomTom83 | 1:a3ee8cb24540 | 94 | } |
TomTom83 | 1:a3ee8cb24540 | 95 | else |
TomTom83 | 1:a3ee8cb24540 | 96 | { |
TomTom83 | 1:a3ee8cb24540 | 97 | iBufPos += res; |
TomTom83 | 1:a3ee8cb24540 | 98 | iBufLeft -= res; |
TomTom83 | 1:a3ee8cb24540 | 99 | } |
TomTom83 | 1:a3ee8cb24540 | 100 | } |
TomTom83 | 1:a3ee8cb24540 | 101 | |
TomTom83 | 1:a3ee8cb24540 | 102 | if( res != -1 ) |
TomTom83 | 1:a3ee8cb24540 | 103 | { |
TomTom83 | 1:a3ee8cb24540 | 104 | /* Append an end of frame string. */ |
TomTom83 | 1:a3ee8cb24540 | 105 | res = snprintf( &arcBuffer[iBufPos], iBufLeft, " |\r\n" ); |
TomTom83 | 1:a3ee8cb24540 | 106 | if( res != -1 ) |
TomTom83 | 1:a3ee8cb24540 | 107 | { |
TomTom83 | 1:a3ee8cb24540 | 108 | vMBPortLog( MB_LOG_DEBUG, (const char*)pucMsg, "%s", arcBuffer ); |
TomTom83 | 1:a3ee8cb24540 | 109 | } |
TomTom83 | 1:a3ee8cb24540 | 110 | } |
TomTom83 | 1:a3ee8cb24540 | 111 | } |
TomTom83 | 1:a3ee8cb24540 | 112 | #endif |
TomTom83 | 1:a3ee8cb24540 | 113 | |
TomTom83 | 1:a3ee8cb24540 | 114 | void |
TomTom83 | 1:a3ee8cb24540 | 115 | vMBPortLog( eMBPortLogLevel eLevel, const CHAR * szModule, const CHAR * szFmt, ... ) |
TomTom83 | 1:a3ee8cb24540 | 116 | { |
TomTom83 | 1:a3ee8cb24540 | 117 | va_list args; |
TomTom83 | 1:a3ee8cb24540 | 118 | static const char *arszLevel2Str[] = { "DEBUG", "INFO", "WARN", "ERROR" }; |
TomTom83 | 1:a3ee8cb24540 | 119 | |
TomTom83 | 1:a3ee8cb24540 | 120 | ( void )printf( "%s: %s: ", arszLevel2Str[eLevel], szModule ); |
TomTom83 | 1:a3ee8cb24540 | 121 | va_start( args, szFmt ); |
TomTom83 | 1:a3ee8cb24540 | 122 | vprintf( szFmt, args ); |
TomTom83 | 1:a3ee8cb24540 | 123 | va_end( args ); |
TomTom83 | 1:a3ee8cb24540 | 124 | } |
TomTom83 | 1:a3ee8cb24540 | 125 |