Modbus RTU/ASCII/TCP with lwip TCP working partial, but with errors (retransmitions)
Dependencies: EthernetNetIf mbed
ModBus/mbfuncother.cpp@0:f54e9507171b, 2011-12-05 (annotated)
- Committer:
- tmav123
- Date:
- Mon Dec 05 22:49:02 2011 +0000
- Revision:
- 0:f54e9507171b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tmav123 | 0:f54e9507171b | 1 | /* |
tmav123 | 0:f54e9507171b | 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. |
tmav123 | 0:f54e9507171b | 3 | * Copyright (c) 2006 Christian Walter <wolti@sil.at> |
tmav123 | 0:f54e9507171b | 4 | * All rights reserved. |
tmav123 | 0:f54e9507171b | 5 | * |
tmav123 | 0:f54e9507171b | 6 | * Redistribution and use in source and binary forms, with or without |
tmav123 | 0:f54e9507171b | 7 | * modification, are permitted provided that the following conditions |
tmav123 | 0:f54e9507171b | 8 | * are met: |
tmav123 | 0:f54e9507171b | 9 | * 1. Redistributions of source code must retain the above copyright |
tmav123 | 0:f54e9507171b | 10 | * notice, this list of conditions and the following disclaimer. |
tmav123 | 0:f54e9507171b | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
tmav123 | 0:f54e9507171b | 12 | * notice, this list of conditions and the following disclaimer in the |
tmav123 | 0:f54e9507171b | 13 | * documentation and/or other materials provided with the distribution. |
tmav123 | 0:f54e9507171b | 14 | * 3. The name of the author may not be used to endorse or promote products |
tmav123 | 0:f54e9507171b | 15 | * derived from this software without specific prior written permission. |
tmav123 | 0:f54e9507171b | 16 | * |
tmav123 | 0:f54e9507171b | 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
tmav123 | 0:f54e9507171b | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
tmav123 | 0:f54e9507171b | 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
tmav123 | 0:f54e9507171b | 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
tmav123 | 0:f54e9507171b | 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
tmav123 | 0:f54e9507171b | 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
tmav123 | 0:f54e9507171b | 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
tmav123 | 0:f54e9507171b | 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
tmav123 | 0:f54e9507171b | 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
tmav123 | 0:f54e9507171b | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
tmav123 | 0:f54e9507171b | 27 | * |
tmav123 | 0:f54e9507171b | 28 | * File: $Id: mbfuncother.c,v 1.8 2006/12/07 22:10:34 wolti Exp $ |
tmav123 | 0:f54e9507171b | 29 | */ |
tmav123 | 0:f54e9507171b | 30 | |
tmav123 | 0:f54e9507171b | 31 | /* ----------------------- System includes ----------------------------------*/ |
tmav123 | 0:f54e9507171b | 32 | #include "stdlib.h" |
tmav123 | 0:f54e9507171b | 33 | #include "string.h" |
tmav123 | 0:f54e9507171b | 34 | |
tmav123 | 0:f54e9507171b | 35 | /* ----------------------- Platform includes --------------------------------*/ |
tmav123 | 0:f54e9507171b | 36 | #include "port.h" |
tmav123 | 0:f54e9507171b | 37 | |
tmav123 | 0:f54e9507171b | 38 | /* ----------------------- Modbus includes ----------------------------------*/ |
tmav123 | 0:f54e9507171b | 39 | #include "mb.h" |
tmav123 | 0:f54e9507171b | 40 | #include "mbframe.h" |
tmav123 | 0:f54e9507171b | 41 | #include "mbproto.h" |
tmav123 | 0:f54e9507171b | 42 | #include "mbconfig.h" |
tmav123 | 0:f54e9507171b | 43 | |
tmav123 | 0:f54e9507171b | 44 | #if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0 |
tmav123 | 0:f54e9507171b | 45 | |
tmav123 | 0:f54e9507171b | 46 | /* ----------------------- Static variables ---------------------------------*/ |
tmav123 | 0:f54e9507171b | 47 | static UCHAR ucMBSlaveID[MB_FUNC_OTHER_REP_SLAVEID_BUF]; |
tmav123 | 0:f54e9507171b | 48 | static USHORT usMBSlaveIDLen; |
tmav123 | 0:f54e9507171b | 49 | |
tmav123 | 0:f54e9507171b | 50 | /* ----------------------- Start implementation -----------------------------*/ |
tmav123 | 0:f54e9507171b | 51 | |
tmav123 | 0:f54e9507171b | 52 | eMBErrorCode |
tmav123 | 0:f54e9507171b | 53 | eMBSetSlaveID( UCHAR ucSlaveID, BOOL xIsRunning, |
tmav123 | 0:f54e9507171b | 54 | UCHAR const *pucAdditional, USHORT usAdditionalLen ) |
tmav123 | 0:f54e9507171b | 55 | { |
tmav123 | 0:f54e9507171b | 56 | eMBErrorCode eStatus = MB_ENOERR; |
tmav123 | 0:f54e9507171b | 57 | |
tmav123 | 0:f54e9507171b | 58 | /* the first byte and second byte in the buffer is reserved for |
tmav123 | 0:f54e9507171b | 59 | * the parameter ucSlaveID and the running flag. The rest of |
tmav123 | 0:f54e9507171b | 60 | * the buffer is available for additional data. */ |
tmav123 | 0:f54e9507171b | 61 | if( usAdditionalLen + 2 < MB_FUNC_OTHER_REP_SLAVEID_BUF ) |
tmav123 | 0:f54e9507171b | 62 | { |
tmav123 | 0:f54e9507171b | 63 | usMBSlaveIDLen = 0; |
tmav123 | 0:f54e9507171b | 64 | ucMBSlaveID[usMBSlaveIDLen++] = ucSlaveID; |
tmav123 | 0:f54e9507171b | 65 | ucMBSlaveID[usMBSlaveIDLen++] = ( UCHAR )( xIsRunning ? 0xFF : 0x00 ); |
tmav123 | 0:f54e9507171b | 66 | if( usAdditionalLen > 0 ) |
tmav123 | 0:f54e9507171b | 67 | { |
tmav123 | 0:f54e9507171b | 68 | memcpy( &ucMBSlaveID[usMBSlaveIDLen], pucAdditional, |
tmav123 | 0:f54e9507171b | 69 | ( size_t )usAdditionalLen ); |
tmav123 | 0:f54e9507171b | 70 | usMBSlaveIDLen += usAdditionalLen; |
tmav123 | 0:f54e9507171b | 71 | } |
tmav123 | 0:f54e9507171b | 72 | } |
tmav123 | 0:f54e9507171b | 73 | else |
tmav123 | 0:f54e9507171b | 74 | { |
tmav123 | 0:f54e9507171b | 75 | eStatus = MB_ENORES; |
tmav123 | 0:f54e9507171b | 76 | } |
tmav123 | 0:f54e9507171b | 77 | return eStatus; |
tmav123 | 0:f54e9507171b | 78 | } |
tmav123 | 0:f54e9507171b | 79 | |
tmav123 | 0:f54e9507171b | 80 | eMBException |
tmav123 | 0:f54e9507171b | 81 | eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen ) |
tmav123 | 0:f54e9507171b | 82 | { |
tmav123 | 0:f54e9507171b | 83 | memcpy( &pucFrame[MB_PDU_DATA_OFF], &ucMBSlaveID[0], ( size_t )usMBSlaveIDLen ); |
tmav123 | 0:f54e9507171b | 84 | *usLen = ( USHORT )( MB_PDU_DATA_OFF + usMBSlaveIDLen ); |
tmav123 | 0:f54e9507171b | 85 | return MB_EX_NONE; |
tmav123 | 0:f54e9507171b | 86 | } |
tmav123 | 0:f54e9507171b | 87 | |
tmav123 | 0:f54e9507171b | 88 | #endif |