Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
portother.cpp
00001 /* 00002 * FreeModbus Libary: lwIP Port 00003 * Copyright (C) 2006 Christian Walter <wolti@sil.at> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * File: $Id: portother.c,v 1.1 2006/08/30 23:18:07 wolti Exp $ 00020 */ 00021 00022 /* ----------------------- System includes ----------------------------------*/ 00023 //#include <sys/types.h> 00024 //#include <sys/stat.h> 00025 //#include <unistd.h> 00026 #include <stdio.h> 00027 #include <stdarg.h> 00028 #include <string.h> 00029 00030 #include "port.h" 00031 #include "mbed.h" 00032 DigitalOut led2(LED2); 00033 00034 /* ----------------------- Defines ------------------------------------------*/ 00035 #define MB_FRAME_LOG_BUFSIZE 512 00036 00037 /* ----------------------- Start implementation -----------------------------*/ 00038 00039 #ifdef MB_TCP_DEBUG 00040 void 00041 prvvMBTCPLogFrame( const CHAR * pucMsg, UCHAR * pucFrame, USHORT usFrameLen ) 00042 { 00043 int i; 00044 int res; 00045 int iBufPos = 0; 00046 size_t iBufLeft = MB_FRAME_LOG_BUFSIZE; 00047 static CHAR arcBuffer[MB_FRAME_LOG_BUFSIZE]; 00048 00049 assert( pucFrame != NULL ); 00050 00051 for( i = 0; i < usFrameLen; i++ ) 00052 { 00053 /* Print some additional frame information. */ 00054 switch ( i ) 00055 { 00056 case 0: 00057 /* TID = Transaction Identifier. */ 00058 res = snprintf( &arcBuffer[iBufPos], iBufLeft, "| TID = " ); 00059 break; 00060 case 2: 00061 /* PID = Protocol Identifier. */ 00062 res = snprintf( &arcBuffer[iBufPos], iBufLeft, " | PID = " ); 00063 break; 00064 case 4: 00065 /* Length */ 00066 res = snprintf( &arcBuffer[iBufPos], iBufLeft, " | LEN = " ); 00067 break; 00068 case 6: 00069 /* UID = Unit Identifier. */ 00070 res = snprintf( &arcBuffer[iBufPos], iBufLeft, " | UID = " ); 00071 break; 00072 case 7: 00073 /* MB Function Code. */ 00074 res = snprintf( &arcBuffer[iBufPos], iBufLeft, "|| FUNC = " ); 00075 break; 00076 case 8: 00077 /* MB PDU rest. */ 00078 res = snprintf( &arcBuffer[iBufPos], iBufLeft, " | DATA = " ); 00079 //res = snprintf (&arcBuffer[1],iBufLeft,"PIMpEK"); 00080 00081 break; 00082 default: 00083 res = 0; 00084 break; 00085 } 00086 if( res == -1 ) 00087 { 00088 break; 00089 } 00090 else 00091 { 00092 iBufPos += res; 00093 iBufLeft -= res; 00094 } 00095 00096 /* Print the data. */ 00097 res = snprintf( &arcBuffer[iBufPos], iBufLeft, "%02X", pucFrame[i] ); 00098 if (pucFrame[11]>5){led2=1;} 00099 else {led2=0;} 00100 00101 if( res == -1 ) 00102 { 00103 break; 00104 } 00105 else 00106 { 00107 iBufPos += res; 00108 iBufLeft -= res; 00109 } 00110 } 00111 00112 if( res != -1 ) 00113 { 00114 /* Append an end of frame string. */ 00115 res = snprintf( &arcBuffer[iBufPos], iBufLeft, " |\r\n" ); 00116 if( res != -1 ) 00117 { 00118 vMBPortLog( MB_LOG_DEBUG, pucMsg, "%s", arcBuffer ); 00119 } 00120 } 00121 } 00122 #endif 00123 00124 #ifdef MB_TCP_DEBUG 00125 void 00126 vMBPortLog( eMBPortLogLevel eLevel, const CHAR * szModule, const CHAR * szFmt, ... ) 00127 { 00128 va_list args; 00129 static const char *arszLevel2Str[] = { "ERROR", "WARN", "INFO", "DEBUG"}; 00130 00131 ( void )printf( "%s: %s: ", arszLevel2Str[eLevel], szModule ); 00132 va_start( args, szFmt ); 00133 vprintf( szFmt, args ); 00134 va_end( args ); 00135 } 00136 #endif
Generated on Tue Jul 12 2022 16:58:42 by
1.7.2