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