dos2unix format conversion for the files
authorHongmei Gou <a0271529@ti.com>
Tue, 19 Sep 2017 19:09:04 +0000 (15:09 -0400)
committerHongmei Gou <a0271529@ti.com>
Tue, 19 Sep 2017 19:09:04 +0000 (15:09 -0400)
Signed-off-by: Hongmei Gou <a0271529@ti.com>
30 files changed:
CCIEF-BASIC_Master/library/include/SLMP.h
CCIEF-BASIC_Master/library/src/SLMP.c
CCIEF-BASIC_Master/readme.txt
CCIEF-BASIC_Master/sample/MasterParameter.csv
CCIEF-BASIC_Master/sample/include/CCIEF_BASIC_MASTER.h
CCIEF-BASIC_Master/sample/include/CCIEF_BASIC_SLAVES.h
CCIEF-BASIC_Master/sample/include/SOCKET.h
CCIEF-BASIC_Master/sample/include/TIMER.h
CCIEF-BASIC_Master/sample/include/USER_SAMPLE.h
CCIEF-BASIC_Master/sample/src/CCIEF_BASIC_MASTER.c
CCIEF-BASIC_Master/sample/src/CCIEF_BASIC_SLAVES.c
CCIEF-BASIC_Master/sample/src/SOCKET.c
CCIEF-BASIC_Master/sample/src/TIMER.c
CCIEF-BASIC_Master/sample/src/USER_SAMPLE.c
CCIEF-BASIC_Master/version.txt
CCIEF-BASIC_Slave/library/include/SLMP.h
CCIEF-BASIC_Slave/library/src/SLMP.c
CCIEF-BASIC_Slave/readme.txt
CCIEF-BASIC_Slave/sample/SlaveParameter.csv
CCIEF-BASIC_Slave/sample/include/CCIEF_BASIC_SLAVE.h
CCIEF-BASIC_Slave/sample/include/SLMP_SERVER.h
CCIEF-BASIC_Slave/sample/include/SOCKET.h
CCIEF-BASIC_Slave/sample/include/TIMER.h
CCIEF-BASIC_Slave/sample/include/USER_SAMPLE.h
CCIEF-BASIC_Slave/sample/src/CCIEF_BASIC_SLAVE.c
CCIEF-BASIC_Slave/sample/src/SLMP_SERVER.c
CCIEF-BASIC_Slave/sample/src/SOCKET.c
CCIEF-BASIC_Slave/sample/src/TIMER.c
CCIEF-BASIC_Slave/sample/src/USER_SAMPLE.c
CCIEF-BASIC_Slave/version.txt

index 355726fa68941dfba4d02ca0b49b9bf9d1a6ec94..7c4bca5681b1c71856a0b8d2c68b213adae86fa5 100644 (file)
-/*\r
- * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
- * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/\r
- * \r
- * \r
- *  Redistribution and use in source and binary forms, with or without \r
- *  modification, are permitted provided that the following conditions \r
- *  are met:\r
- *\r
- *    Redistributions of source code must retain the above copyright \r
- *    notice, this list of conditions and the following disclaimer.\r
- *\r
- *    Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the \r
- *    documentation and/or other materials provided with the   \r
- *    distribution.\r
- *\r
- *    Neither the name of Texas Instruments Incorporated nor the names of\r
- *    its contributors may be used to endorse or promote products derived\r
- *    from this software without specific prior written permission.\r
- *\r
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
-*/\r
-\r
-#ifndef                __SLMP_H__\r
-#define                __SLMP_H__\r
-\r
-#include <stdint.h>\r
-\r
-/*[ Structure of SLMP Info  ]*/\r
-typedef struct \r
-{\r
-       uint32_t        ulFrameType;                    /* Frame Type */\r
-       uint16_t        usSerialNumber;                 /* Serial Number */\r
-       uint16_t        usNetNumber;                    /* Network Number */\r
-       uint16_t        usNodeNumber;                   /* Node Number */\r
-       uint16_t        usProcNumber;                   /* Processor Number */\r
-       uint16_t        usDataLength;                   /* Data Length */\r
-       uint16_t        usTimer;                                /* Timer Value */\r
-       uint16_t        usCommand;                              /* Command */\r
-       uint16_t        usSubCommand;                   /* Sub Command */\r
-       uint16_t        usEndCode;                              /* End Code */\r
-       uint8_t *       pucData;                                /* Data */\r
-}SLMP_INFO;\r
-\r
-/*[ Definition of Frame Type ]*/\r
-#define        SLMP_FTYPE_BIN_REQ_ST                                                   (0x5000)\r
-#define SLMP_FTYPE_BIN_RES_ST                                                  (0xD000)\r
-#define        SLMP_FTYPE_BIN_REQ_MT                                                   (0x5400)\r
-#define SLMP_FTYPE_BIN_RES_MT                                                  (0xD400)\r
-#define        SLMP_FTYPE_ASCII_REQ_ST                                                 (0x35303030) /* '5000' */\r
-#define        SLMP_FTYPE_ASCII_RES_ST                                                 (0x44303030) /* 'D000' */\r
-#define        SLMP_FTYPE_ASCII_REQ_MT                                                 (0x35343030) /* '5400' */\r
-#define        SLMP_FTYPE_ASCII_RES_MT                                                 (0x44343030) /* 'D400' */\r
-\r
-/*[ Definition of Index per frame type ]*/\r
-#define        SLMP_FTYPE_BIN_REQ_ST_INDEX                                             (0x00)\r
-#define SLMP_FTYPE_BIN_RES_ST_INDEX                                            (0x01)\r
-#define        SLMP_FTYPE_BIN_REQ_MT_INDEX                                             (0x02)\r
-#define SLMP_FTYPE_BIN_RES_MT_INDEX                                            (0x03)\r
-#define        SLMP_FTYPE_ASCII_REQ_ST_INDEX                                   (0x04)\r
-#define        SLMP_FTYPE_ASCII_RES_ST_INDEX                                   (0x05)\r
-#define        SLMP_FTYPE_ASCII_REQ_MT_INDEX                                   (0x06)\r
-#define        SLMP_FTYPE_ASCII_RES_MT_INDEX                                   (0x07)\r
-\r
-/*[ Definition of Data Code ]*/\r
-#define        SLMP_DATA_CODE_BIN                                                              0\r
-#define        SLMP_DATA_CODE_ASCII                                                    1\r
-#define SLMP_DATA_CODE(a)\\r
-       (((a == SLMP_FTYPE_BIN_REQ_ST) | (a == SLMP_FTYPE_BIN_RES_ST) | (a == SLMP_FTYPE_BIN_REQ_MT) | (a == SLMP_FTYPE_BIN_RES_MT)) ? SLMP_DATA_CODE_BIN :\\r
-        ((a == SLMP_FTYPE_ASCII_REQ_ST) | (a == SLMP_FTYPE_ASCII_RES_ST) | (a == SLMP_FTYPE_ASCII_REQ_MT) | (a == SLMP_FTYPE_ASCII_RES_MT)) ? SLMP_DATA_CODE_ASCII : -1)\r
-\r
-/*[ Definition of Response Frame Type ]*/\r
-#define SLMP_RESPONSE_FRAME_TYPE(a)\\r
-       ((a == SLMP_FTYPE_BIN_REQ_ST) ? SLMP_FTYPE_BIN_RES_ST :\\r
-       ((a == SLMP_FTYPE_BIN_REQ_MT) ? SLMP_FTYPE_BIN_RES_MT :\\r
-       ((a == SLMP_FTYPE_ASCII_REQ_ST) ? SLMP_FTYPE_ASCII_RES_ST :\\r
-       ((a == SLMP_FTYPE_ASCII_REQ_MT) ? SLMP_FTYPE_ASCII_RES_MT : -1))))\r
-\r
-/*[ Definition of SLMP Frame Header Size ]*/\r
-#define SLMP_HEADER_SIZE(a)\\r
-       (((a == SLMP_FTYPE_BIN_REQ_ST) | (a == SLMP_FTYPE_BIN_RES_ST)) ? 11 :\\r
-       (((a == SLMP_FTYPE_BIN_REQ_MT) | (a == SLMP_FTYPE_BIN_RES_MT)) ? 15 :\\r
-       (((a == SLMP_FTYPE_ASCII_REQ_ST) | (a == SLMP_FTYPE_ASCII_RES_ST)) ? 22 :\\r
-       (((a == SLMP_FTYPE_ASCII_REQ_MT) | (a == SLMP_FTYPE_ASCII_RES_MT)) ? 30 : 0))))\r
-\r
-/*[ Definition of SLMP Commands ]*/\r
-/* Device */\r
-#define        SLMP_COMMAND_DEVICE_READ                                                        (0x0401)\r
-#define        SLMP_COMMAND_DEVICE_WRITE                                                       (0x1401)\r
-#define        SLMP_COMMAND_DEVICE_READ_RANDOM                                         (0x0403)\r
-#define        SLMP_COMMAND_DEVICE_WRITE_RANDOM                                        (0x1402)\r
-#define        SLMP_COMMAND_DEVICE_ENTRY_MONITOR_DEVICE                        (0x0801)\r
-#define        SLMP_COMMAND_DEVICE_EXECUTE_MONITOR                                     (0x0802)\r
-#define        SLMP_COMMAND_DEVICE_READ_BLOCK                                          (0x0406)\r
-#define SLMP_COMMAND_DEVICE_WRITE_BLOCK                                                (0x1406)\r
-\r
-/* Memory */\r
-#define        SLMP_COMMAND_MEMORY_READ                                                        (0x0613)\r
-#define        SLMP_COMMAND_MEMORY_WRITE                                                       (0x1613)\r
-\r
-/* ExtendUnit */\r
-#define        SLMP_COMMAND_EXTEND_UNIT_READ                                           (0x0601)\r
-#define        SLMP_COMMAND_EXTEND_UNIT_WRITE                                          (0x1601)\r
-\r
-/* RemoteControl */\r
-#define        SLMP_COMMAND_REMOTE_RUN                                                         (0x1001)\r
-#define        SLMP_COMMAND_REMOTE_STOP                                                        (0x1002)\r
-#define        SLMP_COMMAND_REMOTE_PAUSE                                                       (0x1003)\r
-#define        SLMP_COMMAND_REMOTE_LATCH_CLEAR                                         (0x1005)\r
-#define        SLMP_COMMAND_REMOTE_RESET                                                       (0x1006)\r
-#define        SLMP_COMMAND_REMOTE_READ_TYPE_NAME                                      (0x0101)\r
-\r
-/* Drive */\r
-#define        SLMP_COMMAND_DRIVE_READ_DISK_STATE                                      (0x0205)\r
-#define        SLMP_COMMAND_DRIVE_DEFRAG                                                       (0x1207)\r
-\r
-/* FILE */\r
-#define SLMP_COMMAND_FILE_READ_FILE_INFO                                       (0x0201)\r
-#define        SLMP_COMMAND_FILE_READ_FILE_INFO_DETAIL                         (0x0202)\r
-#define        SLMP_COMMAND_FILE_READ_FILE_INFO_FILE_NUMBER_USAGE      (0x0204)\r
-#define        SLMP_COMMAND_FILE_CHANGE_FILE_INFO                                      (0x1204)\r
-#define        SLMP_COMMAND_FILE_SEARCH                                                        (0x0203)\r
-#define        SLMP_COMMAND_FILE_READ_ACCESS_TYPE_A                            (0x0206)\r
-#define        SLMP_COMMAND_FILE_WRITE_ACCESS_TYPE_A                           (0x1203)\r
-#define        SLMP_COMMAND_FILE_LOCK_CONTROL                                          (0x0808)\r
-#define        SLMP_COMMAND_FILE_COPY_ACCESS_TYPE_A                            (0x1206)\r
-#define        SLMP_COMMAND_FILE_COPY_ACCESS_TYPE_B                            (0x1824)\r
-#define        SLMP_COMMAND_FILE_DELETE_ACCESS_TYPE_A                          (0x1205)\r
-#define        SLMP_COMMAND_FILE_DELETE_ACCESS_TYPE_B                          (0x1822)\r
-#define        SLMP_COMMAND_FILE_READ_DEIRECTORY_FILE                          (0x1810)\r
-#define        SLMP_COMMAND_FILE_SEARCH_DIRECTORY_FILE                         (0x1811)\r
-#define        SLMP_COMMAND_FILE_CREATE_NEW_FILE_ACCESS_TYPE_A         (0x1202)\r
-#define        SLMP_COMMAND_FILE_CREATE_NEW_FILE_ACCESS_TYPE_B         (0x1820)\r
-#define        SLMP_COMMAND_FILE_CHANGE_FILE_STATE                                     (0x1825)\r
-#define        SLMP_COMMAND_FILE_CHANGE_FILE_DATE                                      (0x1826)\r
-#define        SLMP_COMMAND_FILE_OPEN_FILE                                                     (0x1827)\r
-#define        SLMP_COMMAND_FILE_READ_ACCESS_TYPE_B                            (0x1828)\r
-#define        SLMP_COMMAND_FILE_WRITE_ACCESS_TYPE_B                           (0x1829)\r
-#define        SLMP_COMMAND_FILE_CLOSE_FILE                                            (0x182A)\r
-\r
-/* TEST */\r
-#define        SLMP_COMMAND_SELF_TEST                                                          (0x0619)\r
-\r
-/* CLEAR ERROR */\r
-#define        SLMP_COMMAND_CLEAR_ERROR_CODE                                           (0x1617)\r
-\r
-/* REMOTE PASSWORD */\r
-#define        SLMP_COMMAND_PASSWORD_LOCK                                                      (0x1630)\r
-#define        SLMP_COMMAND_PASSWORD_UNLOCK                                            (0x1631)\r
-\r
-/* ONDEMAND */\r
-#define        SLMP_COMMAND_ONDEMAND                                                           (0x2101)\r
-\r
-/* NODE CONNECT */\r
-#define        SLMP_COMMAND_NODE_SEARCH                                                        (0x0E30)\r
-#define        SLMP_COMMAND_IP_ADDRESS_SET                                                     (0x0E31)\r
-\r
-/* PARAMETER SETTING */\r
-#define        SLMP_COMMAND_DEVICE_INFO_COMPARE                                        (0x0E32)\r
-#define        SLMP_COMMAND_PARAMETER_GET                                                      (0x0E33)\r
-#define        SLMP_COMMAND_PARAMETER_SET                                                      (0x0E34)\r
-#define        SLMP_COMMAND_PARAMETER_SET_START                                        (0x0E35)\r
-#define        SLMP_COMMAND_PARAMETER_SET_END                                          (0x0E36)\r
-#define        SLMP_COMMAND_PARAMETER_SET_CANCEL                                       (0x0E3A)\r
-\r
-/* NODE MONITORING */\r
-#define        SLMP_COMMAND_STATUS_READ                                                        (0x0E44)\r
-#define        SLMP_COMMAND_COMMUNICATION_SETTING_GET                          (0x0E45)\r
-#define        SLMP_COMMAND_STATUS_READ2                                                       (0x0E53)\r
-\r
-/* CCIEF-BASIC */\r
-#define        SLMP_COMMAND_CYCLIC_DATA                                                        (0x0E70)\r
-\r
-/*[ Definition of Processor Number ]*/\r
-#define        SLMP_CPU_ACTIVE                                                                         (0x03D0)\r
-#define        SLMP_CPU_STANDBY                                                                        (0x03D1)\r
-#define        SLMP_CPU_TYPE_A                                                                         (0x03D2)\r
-#define SLMP_CPU_TYPE_B                                                                                (0x03D3)\r
-#define        SLMP_CPU_1                                                                                      (0x03E0)\r
-#define        SLMP_CPU_2                                                                                      (0x03E1)\r
-#define        SLMP_CPU_3                                                                                      (0x03E2)\r
-#define        SLMP_CPU_4                                                                                      (0x03E3)\r
-#define        SLMP_CPU_DEFAULT                                                                        (0x03FF)\r
-\r
-/*[ Definition of Timer Value ]*/\r
-#define        SLMP_TIMER_WAIT_FOREVER                                                         (0x0000)\r
-\r
-/*[ Definition of SLMP Error Codes ]*/\r
-#define SLMP_ERR_COMMAND_SUBCOMMAND                                                    (0xC059)\r
-#define SLMP_ERR_WRONG_DATA                                                                    (0xC05C)\r
-#define SLMP_ERR_DATA_LENGTH                                                           (0xC061)\r
-#define SLMP_ERR_UNDER_EXECUTION                                                       (0xCEE0)\r
-#define SLMP_ERR_REQ_DATA_SIZE                                                         (0xCEE1)\r
-#define SLMP_ERR_RES_DATA_SIZE                                                         (0xCEE2)\r
-#define SLMP_ERR_NO_EXIST_SERVER_NO                                                    (0xCF10)\r
-#define SLMP_ERR_CAN_NOT_COMMUNICATION_SETTING                         (0xCF20)\r
-#define SLMP_ERR_NO_EXIST_PARAM_ID                                                     (0xCF30)\r
-#define SLMP_ERR_CAN_NOT_PARAMETER_SET                                         (0xCF31)\r
-\r
-/*[ Definition for CCIEF-BASIC End Code ]*/\r
-#define        SLMP_END_DUPLICATE_MASTER                                                       (0xCFE0)\r
-#define        SLMP_END_INVALID_NUMBER_OF_OCCUPIED_STATIONS            (0xCFE1)\r
-#define        SLMP_END_SLAVE                                                                          (0xCFF0)\r
-#define SLMP_END_DISCONNECTED_REQUEST                                          (0xCFFF)\r
-\r
-/*[ Definition of value ]*/\r
-#define SLMP_ERR_OK            0\r
-#define SLMP_ERR_NG            (-1)\r
-#ifndef        NULL\r
-#define NULL                   0\r
-#endif\r
-\r
-/*[ Definition of mask value ]*/\r
-#define MASK_UPPER4BIT         (0xF0)\r
-#define MASK_LOWER4BIT         (0x0F)\r
-\r
-/*[ Definition of bit operation ]*/\r
-#define SHIFT_R24(a)                   ((uint8_t)(((a) >> 24) & 0xFF ))\r
-#define SHIFT_R20(a)                   ((uint8_t)(((a) >> 20) & 0xFF ))\r
-#define SHIFT_R16(a)                   ((uint8_t)(((a) >> 16) & 0xFF ))\r
-#define SHIFT_R12(a)                   ((uint8_t)(((a) >> 12) & 0xFF ))\r
-#define SHIFT_R8(a)                            ((uint8_t)(((a) >>  8) & 0xFF ))\r
-#define SHIFT_R7(a)                            ((uint8_t)(((a) >>  7) & 0xFF ))\r
-#define SHIFT_R6(a)                            ((uint8_t)(((a) >>  6) & 0xFF ))\r
-#define SHIFT_R5(a)                            ((uint8_t)(((a) >>  5) & 0xFF ))\r
-#define SHIFT_R4(a)                            ((uint8_t)(((a) >>  4) & 0xFF ))\r
-#define SHIFT_R3(a)                            ((uint8_t)(((a) >>  3) & 0xFF ))\r
-#define SHIFT_R2(a)                            ((uint8_t)(((a) >>  2) & 0xFF ))\r
-#define SHIFT_R1(a)                            ((uint8_t)(((a) >>  1) & 0xFF ))\r
-#define SHIFT_R0(a)                            ((uint8_t)(((a)      ) & 0xFF ))\r
-\r
-#define SHIFT_L0(a)                            ((uint8_t) (((a)      ) & 0xFF ))\r
-#define SHIFT_L1(a)                            ((uint8_t) (((a) <<  1) & 0xFF ))\r
-#define SHIFT_L2(a)                            ((uint8_t) (((a) <<  2) & 0xFF ))\r
-#define SHIFT_L3(a)                            ((uint8_t) (((a) <<  3) & 0xFF ))\r
-#define SHIFT_L4(a)                            ((uint8_t) (((a) <<  4) & 0xFF ))\r
-#define SHIFT_L5(a)                            ((uint8_t) (((a) <<  5) & 0xFF ))\r
-#define SHIFT_L6(a)                            ((uint8_t) (((a) <<  6) & 0xFF ))\r
-#define SHIFT_L7(a)                            ((uint8_t) (((a) <<  7) & 0xFF ))\r
-#define SHIFT_L8(a)                            ((uint16_t)(((a) <<  8) & 0xFFFF))\r
-#define SHIFT_L16(a)                   ((uint32_t)( (a) << 16))\r
-#define SHIFT_L24(a)                   ((uint32_t)( (a) << 24))\r
-\r
-#define CONCAT_2ASCII(a, b)                            (((uint16_t)(a) <<  4) | (b))\r
-#define CONCAT_4ASCII(a, b, c, d)              (((uint16_t)(a) << 12) | ((uint16_t)(b) <<  8) | ((uint16_t)(c) << 4) | (d))\r
-#define CONCAT_6ASCII(a, b, c, d, e, f)        (((uint16_t)(a) << 20) | ((uint16_t)(b) << 16) | ((uint16_t)(c) << 12) |\\r
-                                                                                ((uint16_t)(d) <<  8) | ((uint16_t)(e) <<  4) | (f))\r
-#define CONCAT_8ASCII(a, b, c, d, e, f, g, h)  (((uint16_t)(a) << 28) | ((uint16_t)(b) << 24) | ((uint16_t)(c) << 20) |\\r
-                                                                                                ((uint16_t)(d) << 16) | ((uint16_t)(e) << 12) | ((uint16_t)(f) << 8) |\\r
-                                                                                                ((uint16_t)(g) << 4) | (h))\r
-#define CONCAT_2BIN(a, b)                      (((uint16_t)(a) <<  8) | (b))\r
-#define CONCAT_3BIN(a, b, c)           (((uint16_t)(a) << 16) | ((uint16_t)(b) << 8) | (c))\r
-#define CONCAT_4BIN(a, b, c, d)                (((uint32_t) (a) << 24) | ((uint32_t)(b) << 16) | ((uint32_t)(c) << 8) | (d))\r
-\r
-#define BIT_GET(a, b)                          (((((uint8_t*)a)[(b)/8]) >> ((b)%8)) & 0x01)\r
-#define BIT_SET(a, b, c)                       ((((c) & 0x01) == 0x01) ? ((((uint8_t*)a)[(b)/8]) |= (0x01 << ((b)%8))) : \\r
-                                                                       ((((uint8_t*)a)[(b)/8]) &= ~(0x01 << ((b)%8))))\r
-\r
-\r
-/*[ Definition of Public API ]*/\r
-int SLMP_MakePacketStream ( uint32_t ulFrameType, const SLMP_INFO *p, uint8_t *pucStream );\r
-int SLMP_GetSlmpInfo ( SLMP_INFO *p, const uint8_t *pucStream );\r
-int SLMP_MakeErrorData ( const SLMP_INFO *p, uint8_t *pucStream, uint16_t *pusDataSize );\r
-uint8_t local_itoa( uint8_t ucInt );\r
-uint8_t local_atoi( uint8_t ucInt );\r
-\r
-#endif\r
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/
+ * 
+ * 
+ *  Redistribution and use in source and binary forms, with or without 
+ *  modification, are permitted provided that the following conditions 
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the   
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#ifndef                __SLMP_H__
+#define                __SLMP_H__
+
+#include <stdint.h>
+
+/*[ Structure of SLMP Info  ]*/
+typedef struct 
+{
+       uint32_t        ulFrameType;                    /* Frame Type */
+       uint16_t        usSerialNumber;                 /* Serial Number */
+       uint16_t        usNetNumber;                    /* Network Number */
+       uint16_t        usNodeNumber;                   /* Node Number */
+       uint16_t        usProcNumber;                   /* Processor Number */
+       uint16_t        usDataLength;                   /* Data Length */
+       uint16_t        usTimer;                                /* Timer Value */
+       uint16_t        usCommand;                              /* Command */
+       uint16_t        usSubCommand;                   /* Sub Command */
+       uint16_t        usEndCode;                              /* End Code */
+       uint8_t *       pucData;                                /* Data */
+}SLMP_INFO;
+
+/*[ Definition of Frame Type ]*/
+#define        SLMP_FTYPE_BIN_REQ_ST                                                   (0x5000)
+#define SLMP_FTYPE_BIN_RES_ST                                                  (0xD000)
+#define        SLMP_FTYPE_BIN_REQ_MT                                                   (0x5400)
+#define SLMP_FTYPE_BIN_RES_MT                                                  (0xD400)
+#define        SLMP_FTYPE_ASCII_REQ_ST                                                 (0x35303030) /* '5000' */
+#define        SLMP_FTYPE_ASCII_RES_ST                                                 (0x44303030) /* 'D000' */
+#define        SLMP_FTYPE_ASCII_REQ_MT                                                 (0x35343030) /* '5400' */
+#define        SLMP_FTYPE_ASCII_RES_MT                                                 (0x44343030) /* 'D400' */
+
+/*[ Definition of Index per frame type ]*/
+#define        SLMP_FTYPE_BIN_REQ_ST_INDEX                                             (0x00)
+#define SLMP_FTYPE_BIN_RES_ST_INDEX                                            (0x01)
+#define        SLMP_FTYPE_BIN_REQ_MT_INDEX                                             (0x02)
+#define SLMP_FTYPE_BIN_RES_MT_INDEX                                            (0x03)
+#define        SLMP_FTYPE_ASCII_REQ_ST_INDEX                                   (0x04)
+#define        SLMP_FTYPE_ASCII_RES_ST_INDEX                                   (0x05)
+#define        SLMP_FTYPE_ASCII_REQ_MT_INDEX                                   (0x06)
+#define        SLMP_FTYPE_ASCII_RES_MT_INDEX                                   (0x07)
+
+/*[ Definition of Data Code ]*/
+#define        SLMP_DATA_CODE_BIN                                                              0
+#define        SLMP_DATA_CODE_ASCII                                                    1
+#define SLMP_DATA_CODE(a)\
+       (((a == SLMP_FTYPE_BIN_REQ_ST) | (a == SLMP_FTYPE_BIN_RES_ST) | (a == SLMP_FTYPE_BIN_REQ_MT) | (a == SLMP_FTYPE_BIN_RES_MT)) ? SLMP_DATA_CODE_BIN :\
+        ((a == SLMP_FTYPE_ASCII_REQ_ST) | (a == SLMP_FTYPE_ASCII_RES_ST) | (a == SLMP_FTYPE_ASCII_REQ_MT) | (a == SLMP_FTYPE_ASCII_RES_MT)) ? SLMP_DATA_CODE_ASCII : -1)
+
+/*[ Definition of Response Frame Type ]*/
+#define SLMP_RESPONSE_FRAME_TYPE(a)\
+       ((a == SLMP_FTYPE_BIN_REQ_ST) ? SLMP_FTYPE_BIN_RES_ST :\
+       ((a == SLMP_FTYPE_BIN_REQ_MT) ? SLMP_FTYPE_BIN_RES_MT :\
+       ((a == SLMP_FTYPE_ASCII_REQ_ST) ? SLMP_FTYPE_ASCII_RES_ST :\
+       ((a == SLMP_FTYPE_ASCII_REQ_MT) ? SLMP_FTYPE_ASCII_RES_MT : -1))))
+
+/*[ Definition of SLMP Frame Header Size ]*/
+#define SLMP_HEADER_SIZE(a)\
+       (((a == SLMP_FTYPE_BIN_REQ_ST) | (a == SLMP_FTYPE_BIN_RES_ST)) ? 11 :\
+       (((a == SLMP_FTYPE_BIN_REQ_MT) | (a == SLMP_FTYPE_BIN_RES_MT)) ? 15 :\
+       (((a == SLMP_FTYPE_ASCII_REQ_ST) | (a == SLMP_FTYPE_ASCII_RES_ST)) ? 22 :\
+       (((a == SLMP_FTYPE_ASCII_REQ_MT) | (a == SLMP_FTYPE_ASCII_RES_MT)) ? 30 : 0))))
+
+/*[ Definition of SLMP Commands ]*/
+/* Device */
+#define        SLMP_COMMAND_DEVICE_READ                                                        (0x0401)
+#define        SLMP_COMMAND_DEVICE_WRITE                                                       (0x1401)
+#define        SLMP_COMMAND_DEVICE_READ_RANDOM                                         (0x0403)
+#define        SLMP_COMMAND_DEVICE_WRITE_RANDOM                                        (0x1402)
+#define        SLMP_COMMAND_DEVICE_ENTRY_MONITOR_DEVICE                        (0x0801)
+#define        SLMP_COMMAND_DEVICE_EXECUTE_MONITOR                                     (0x0802)
+#define        SLMP_COMMAND_DEVICE_READ_BLOCK                                          (0x0406)
+#define SLMP_COMMAND_DEVICE_WRITE_BLOCK                                                (0x1406)
+
+/* Memory */
+#define        SLMP_COMMAND_MEMORY_READ                                                        (0x0613)
+#define        SLMP_COMMAND_MEMORY_WRITE                                                       (0x1613)
+
+/* ExtendUnit */
+#define        SLMP_COMMAND_EXTEND_UNIT_READ                                           (0x0601)
+#define        SLMP_COMMAND_EXTEND_UNIT_WRITE                                          (0x1601)
+
+/* RemoteControl */
+#define        SLMP_COMMAND_REMOTE_RUN                                                         (0x1001)
+#define        SLMP_COMMAND_REMOTE_STOP                                                        (0x1002)
+#define        SLMP_COMMAND_REMOTE_PAUSE                                                       (0x1003)
+#define        SLMP_COMMAND_REMOTE_LATCH_CLEAR                                         (0x1005)
+#define        SLMP_COMMAND_REMOTE_RESET                                                       (0x1006)
+#define        SLMP_COMMAND_REMOTE_READ_TYPE_NAME                                      (0x0101)
+
+/* Drive */
+#define        SLMP_COMMAND_DRIVE_READ_DISK_STATE                                      (0x0205)
+#define        SLMP_COMMAND_DRIVE_DEFRAG                                                       (0x1207)
+
+/* FILE */
+#define SLMP_COMMAND_FILE_READ_FILE_INFO                                       (0x0201)
+#define        SLMP_COMMAND_FILE_READ_FILE_INFO_DETAIL                         (0x0202)
+#define        SLMP_COMMAND_FILE_READ_FILE_INFO_FILE_NUMBER_USAGE      (0x0204)
+#define        SLMP_COMMAND_FILE_CHANGE_FILE_INFO                                      (0x1204)
+#define        SLMP_COMMAND_FILE_SEARCH                                                        (0x0203)
+#define        SLMP_COMMAND_FILE_READ_ACCESS_TYPE_A                            (0x0206)
+#define        SLMP_COMMAND_FILE_WRITE_ACCESS_TYPE_A                           (0x1203)
+#define        SLMP_COMMAND_FILE_LOCK_CONTROL                                          (0x0808)
+#define        SLMP_COMMAND_FILE_COPY_ACCESS_TYPE_A                            (0x1206)
+#define        SLMP_COMMAND_FILE_COPY_ACCESS_TYPE_B                            (0x1824)
+#define        SLMP_COMMAND_FILE_DELETE_ACCESS_TYPE_A                          (0x1205)
+#define        SLMP_COMMAND_FILE_DELETE_ACCESS_TYPE_B                          (0x1822)
+#define        SLMP_COMMAND_FILE_READ_DEIRECTORY_FILE                          (0x1810)
+#define        SLMP_COMMAND_FILE_SEARCH_DIRECTORY_FILE                         (0x1811)
+#define        SLMP_COMMAND_FILE_CREATE_NEW_FILE_ACCESS_TYPE_A         (0x1202)
+#define        SLMP_COMMAND_FILE_CREATE_NEW_FILE_ACCESS_TYPE_B         (0x1820)
+#define        SLMP_COMMAND_FILE_CHANGE_FILE_STATE                                     (0x1825)
+#define        SLMP_COMMAND_FILE_CHANGE_FILE_DATE                                      (0x1826)
+#define        SLMP_COMMAND_FILE_OPEN_FILE                                                     (0x1827)
+#define        SLMP_COMMAND_FILE_READ_ACCESS_TYPE_B                            (0x1828)
+#define        SLMP_COMMAND_FILE_WRITE_ACCESS_TYPE_B                           (0x1829)
+#define        SLMP_COMMAND_FILE_CLOSE_FILE                                            (0x182A)
+
+/* TEST */
+#define        SLMP_COMMAND_SELF_TEST                                                          (0x0619)
+
+/* CLEAR ERROR */
+#define        SLMP_COMMAND_CLEAR_ERROR_CODE                                           (0x1617)
+
+/* REMOTE PASSWORD */
+#define        SLMP_COMMAND_PASSWORD_LOCK                                                      (0x1630)
+#define        SLMP_COMMAND_PASSWORD_UNLOCK                                            (0x1631)
+
+/* ONDEMAND */
+#define        SLMP_COMMAND_ONDEMAND                                                           (0x2101)
+
+/* NODE CONNECT */
+#define        SLMP_COMMAND_NODE_SEARCH                                                        (0x0E30)
+#define        SLMP_COMMAND_IP_ADDRESS_SET                                                     (0x0E31)
+
+/* PARAMETER SETTING */
+#define        SLMP_COMMAND_DEVICE_INFO_COMPARE                                        (0x0E32)
+#define        SLMP_COMMAND_PARAMETER_GET                                                      (0x0E33)
+#define        SLMP_COMMAND_PARAMETER_SET                                                      (0x0E34)
+#define        SLMP_COMMAND_PARAMETER_SET_START                                        (0x0E35)
+#define        SLMP_COMMAND_PARAMETER_SET_END                                          (0x0E36)
+#define        SLMP_COMMAND_PARAMETER_SET_CANCEL                                       (0x0E3A)
+
+/* NODE MONITORING */
+#define        SLMP_COMMAND_STATUS_READ                                                        (0x0E44)
+#define        SLMP_COMMAND_COMMUNICATION_SETTING_GET                          (0x0E45)
+#define        SLMP_COMMAND_STATUS_READ2                                                       (0x0E53)
+
+/* CCIEF-BASIC */
+#define        SLMP_COMMAND_CYCLIC_DATA                                                        (0x0E70)
+
+/*[ Definition of Processor Number ]*/
+#define        SLMP_CPU_ACTIVE                                                                         (0x03D0)
+#define        SLMP_CPU_STANDBY                                                                        (0x03D1)
+#define        SLMP_CPU_TYPE_A                                                                         (0x03D2)
+#define SLMP_CPU_TYPE_B                                                                                (0x03D3)
+#define        SLMP_CPU_1                                                                                      (0x03E0)
+#define        SLMP_CPU_2                                                                                      (0x03E1)
+#define        SLMP_CPU_3                                                                                      (0x03E2)
+#define        SLMP_CPU_4                                                                                      (0x03E3)
+#define        SLMP_CPU_DEFAULT                                                                        (0x03FF)
+
+/*[ Definition of Timer Value ]*/
+#define        SLMP_TIMER_WAIT_FOREVER                                                         (0x0000)
+
+/*[ Definition of SLMP Error Codes ]*/
+#define SLMP_ERR_COMMAND_SUBCOMMAND                                                    (0xC059)
+#define SLMP_ERR_WRONG_DATA                                                                    (0xC05C)
+#define SLMP_ERR_DATA_LENGTH                                                           (0xC061)
+#define SLMP_ERR_UNDER_EXECUTION                                                       (0xCEE0)
+#define SLMP_ERR_REQ_DATA_SIZE                                                         (0xCEE1)
+#define SLMP_ERR_RES_DATA_SIZE                                                         (0xCEE2)
+#define SLMP_ERR_NO_EXIST_SERVER_NO                                                    (0xCF10)
+#define SLMP_ERR_CAN_NOT_COMMUNICATION_SETTING                         (0xCF20)
+#define SLMP_ERR_NO_EXIST_PARAM_ID                                                     (0xCF30)
+#define SLMP_ERR_CAN_NOT_PARAMETER_SET                                         (0xCF31)
+
+/*[ Definition for CCIEF-BASIC End Code ]*/
+#define        SLMP_END_DUPLICATE_MASTER                                                       (0xCFE0)
+#define        SLMP_END_INVALID_NUMBER_OF_OCCUPIED_STATIONS            (0xCFE1)
+#define        SLMP_END_SLAVE                                                                          (0xCFF0)
+#define SLMP_END_DISCONNECTED_REQUEST                                          (0xCFFF)
+
+/*[ Definition of value ]*/
+#define SLMP_ERR_OK            0
+#define SLMP_ERR_NG            (-1)
+#ifndef        NULL
+#define NULL                   0
+#endif
+
+/*[ Definition of mask value ]*/
+#define MASK_UPPER4BIT         (0xF0)
+#define MASK_LOWER4BIT         (0x0F)
+
+/*[ Definition of bit operation ]*/
+#define SHIFT_R24(a)                   ((uint8_t)(((a) >> 24) & 0xFF ))
+#define SHIFT_R20(a)                   ((uint8_t)(((a) >> 20) & 0xFF ))
+#define SHIFT_R16(a)                   ((uint8_t)(((a) >> 16) & 0xFF ))
+#define SHIFT_R12(a)                   ((uint8_t)(((a) >> 12) & 0xFF ))
+#define SHIFT_R8(a)                            ((uint8_t)(((a) >>  8) & 0xFF ))
+#define SHIFT_R7(a)                            ((uint8_t)(((a) >>  7) & 0xFF ))
+#define SHIFT_R6(a)                            ((uint8_t)(((a) >>  6) & 0xFF ))
+#define SHIFT_R5(a)                            ((uint8_t)(((a) >>  5) & 0xFF ))
+#define SHIFT_R4(a)                            ((uint8_t)(((a) >>  4) & 0xFF ))
+#define SHIFT_R3(a)                            ((uint8_t)(((a) >>  3) & 0xFF ))
+#define SHIFT_R2(a)                            ((uint8_t)(((a) >>  2) & 0xFF ))
+#define SHIFT_R1(a)                            ((uint8_t)(((a) >>  1) & 0xFF ))
+#define SHIFT_R0(a)                            ((uint8_t)(((a)      ) & 0xFF ))
+
+#define SHIFT_L0(a)                            ((uint8_t) (((a)      ) & 0xFF ))
+#define SHIFT_L1(a)                            ((uint8_t) (((a) <<  1) & 0xFF ))
+#define SHIFT_L2(a)                            ((uint8_t) (((a) <<  2) & 0xFF ))
+#define SHIFT_L3(a)                            ((uint8_t) (((a) <<  3) & 0xFF ))
+#define SHIFT_L4(a)                            ((uint8_t) (((a) <<  4) & 0xFF ))
+#define SHIFT_L5(a)                            ((uint8_t) (((a) <<  5) & 0xFF ))
+#define SHIFT_L6(a)                            ((uint8_t) (((a) <<  6) & 0xFF ))
+#define SHIFT_L7(a)                            ((uint8_t) (((a) <<  7) & 0xFF ))
+#define SHIFT_L8(a)                            ((uint16_t)(((a) <<  8) & 0xFFFF))
+#define SHIFT_L16(a)                   ((uint32_t)( (a) << 16))
+#define SHIFT_L24(a)                   ((uint32_t)( (a) << 24))
+
+#define CONCAT_2ASCII(a, b)                            (((uint16_t)(a) <<  4) | (b))
+#define CONCAT_4ASCII(a, b, c, d)              (((uint16_t)(a) << 12) | ((uint16_t)(b) <<  8) | ((uint16_t)(c) << 4) | (d))
+#define CONCAT_6ASCII(a, b, c, d, e, f)        (((uint16_t)(a) << 20) | ((uint16_t)(b) << 16) | ((uint16_t)(c) << 12) |\
+                                                                                ((uint16_t)(d) <<  8) | ((uint16_t)(e) <<  4) | (f))
+#define CONCAT_8ASCII(a, b, c, d, e, f, g, h)  (((uint16_t)(a) << 28) | ((uint16_t)(b) << 24) | ((uint16_t)(c) << 20) |\
+                                                                                                ((uint16_t)(d) << 16) | ((uint16_t)(e) << 12) | ((uint16_t)(f) << 8) |\
+                                                                                                ((uint16_t)(g) << 4) | (h))
+#define CONCAT_2BIN(a, b)                      (((uint16_t)(a) <<  8) | (b))
+#define CONCAT_3BIN(a, b, c)           (((uint16_t)(a) << 16) | ((uint16_t)(b) << 8) | (c))
+#define CONCAT_4BIN(a, b, c, d)                (((uint32_t) (a) << 24) | ((uint32_t)(b) << 16) | ((uint32_t)(c) << 8) | (d))
+
+#define BIT_GET(a, b)                          (((((uint8_t*)a)[(b)/8]) >> ((b)%8)) & 0x01)
+#define BIT_SET(a, b, c)                       ((((c) & 0x01) == 0x01) ? ((((uint8_t*)a)[(b)/8]) |= (0x01 << ((b)%8))) : \
+                                                                       ((((uint8_t*)a)[(b)/8]) &= ~(0x01 << ((b)%8))))
+
+
+/*[ Definition of Public API ]*/
+int SLMP_MakePacketStream ( uint32_t ulFrameType, const SLMP_INFO *p, uint8_t *pucStream );
+int SLMP_GetSlmpInfo ( SLMP_INFO *p, const uint8_t *pucStream );
+int SLMP_MakeErrorData ( const SLMP_INFO *p, uint8_t *pucStream, uint16_t *pusDataSize );
+uint8_t local_itoa( uint8_t ucInt );
+uint8_t local_atoi( uint8_t ucInt );
+
+#endif
 /*EOF*/
\ No newline at end of file
index f0de50a7399fade9baaa74b2d96588667f45efdc..8214af4fe6a8bd4649dad1fbaf5732b4fa8323e8 100644 (file)
-/*\r
- * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
- * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/\r
- * \r
- * \r
- *  Redistribution and use in source and binary forms, with or without \r
- *  modification, are permitted provided that the following conditions \r
- *  are met:\r
- *\r
- *    Redistributions of source code must retain the above copyright \r
- *    notice, this list of conditions and the following disclaimer.\r
- *\r
- *    Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the \r
- *    documentation and/or other materials provided with the   \r
- *    distribution.\r
- *\r
- *    Neither the name of Texas Instruments Incorporated nor the names of\r
- *    its contributors may be used to endorse or promote products derived\r
- *    from this software without specific prior written permission.\r
- *\r
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
-*/\r
-\r
-#include "SLMP.h"\r
-#include <stdint.h>\r
-#include "string.h"\r
-\r
-static unsigned int uiHeaderLength[]           = {  6,  2,  6,  2, 12,  4, 12,  4};\r
-static unsigned int uiDataAddr[]                       = { 15, 11, 19, 15, 30, 22, 38, 30};\r
-\r
-/* A Function for making packet stream from the SLMP_Info structure */\r
-int SLMP_MakePacketStream ( uint32_t ulFrameType, const SLMP_INFO *p, uint8_t *pucStream )\r
-{\r
-       int i = 0;\r
-       int iLength = 0;\r
-       int iIndex = 0;\r
-\r
-       if ( (p == NULL) || (pucStream == NULL) )\r
-       {\r
-               return SLMP_ERR_NG;\r
-       }\r
-\r
-       /*[ Request : Binary Mode, Single Transmission Type ]*/\r
-       if( (uint16_t)ulFrameType == SLMP_FTYPE_BIN_REQ_ST )\r
-       {\r
-               iIndex = SLMP_FTYPE_BIN_REQ_ST_INDEX;\r
-               iLength = (p->usDataLength)-uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               pucStream[ 0] = SHIFT_R8(SLMP_FTYPE_BIN_REQ_ST);\r
-               pucStream[ 1] = SHIFT_R0(SLMP_FTYPE_BIN_REQ_ST);\r
-               pucStream[ 2] = SHIFT_R0(p->usNetNumber);\r
-               pucStream[ 3] = SHIFT_R0(p->usNodeNumber);\r
-               pucStream[ 4] = SHIFT_R0(p->usProcNumber);\r
-               pucStream[ 5] = SHIFT_R8(p->usProcNumber);\r
-               pucStream[ 6] = 0x00;\r
-               pucStream[ 7] = SHIFT_R0(p->usDataLength);\r
-               pucStream[ 8] = SHIFT_R8(p->usDataLength);\r
-               pucStream[ 9] = SHIFT_R0(p->usTimer);\r
-               pucStream[10] = SHIFT_R8(p->usTimer);\r
-               pucStream[11] = SHIFT_R0(p->usCommand);\r
-               pucStream[12] = SHIFT_R8(p->usCommand);\r
-               pucStream[13] = SHIFT_R0(p->usSubCommand);\r
-               pucStream[14] = SHIFT_R8(p->usSubCommand);\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];\r
-               }\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Response : Binary Mode, Single Transmission Type ]*/\r
-       else if( (uint16_t)ulFrameType == SLMP_FTYPE_BIN_RES_ST )\r
-       {\r
-               iIndex = SLMP_FTYPE_BIN_RES_ST_INDEX;\r
-               iLength = (p->usDataLength)-uiHeaderLength[iIndex]+2;\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               pucStream[ 0] = SHIFT_R8(SLMP_FTYPE_BIN_RES_ST);\r
-               pucStream[ 1] = SHIFT_R0(SLMP_FTYPE_BIN_RES_ST);\r
-               pucStream[ 2] = SHIFT_R0(p->usNetNumber);\r
-               pucStream[ 3] = SHIFT_R0(p->usNodeNumber);\r
-               pucStream[ 4] = SHIFT_R0(p->usProcNumber);\r
-               pucStream[ 5] = SHIFT_R8(p->usProcNumber);\r
-               pucStream[ 6] = 0x00;\r
-               pucStream[ 7] = SHIFT_R0(p->usDataLength+2);\r
-               pucStream[ 8] = SHIFT_R8(p->usDataLength+2);\r
-               pucStream[ 9] = SHIFT_R0(p->usEndCode);\r
-               pucStream[10] = SHIFT_R8(p->usEndCode);\r
-\r
-               for( i=0; i<iLength+2; i++ )\r
-               {\r
-                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];\r
-               }\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Request : Binary Mode, Multiple Transmission Type ]*/\r
-       else if( (uint16_t)ulFrameType == SLMP_FTYPE_BIN_REQ_MT )\r
-       {\r
-               iIndex = SLMP_FTYPE_BIN_REQ_MT_INDEX;\r
-               iLength = (p->usDataLength)-uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               pucStream[ 0] = SHIFT_R8(SLMP_FTYPE_BIN_REQ_MT);\r
-               pucStream[ 1] = SHIFT_R0(SLMP_FTYPE_BIN_REQ_MT);\r
-               pucStream[ 2] = SHIFT_R0(p->usSerialNumber);\r
-               pucStream[ 3] = SHIFT_R8(p->usSerialNumber);\r
-               pucStream[ 4] = 0x00;\r
-               pucStream[ 5] = 0x00;\r
-               pucStream[ 6] = SHIFT_R0(p->usNetNumber);\r
-               pucStream[ 7] = SHIFT_R0(p->usNodeNumber);\r
-               pucStream[ 8] = SHIFT_R0(p->usProcNumber);\r
-               pucStream[ 9] = SHIFT_R8(p->usProcNumber);\r
-               pucStream[10] = 0x00;\r
-               pucStream[11] = SHIFT_R0(p->usDataLength);\r
-               pucStream[12] = SHIFT_R8(p->usDataLength);\r
-               pucStream[13] = SHIFT_R0(p->usTimer);\r
-               pucStream[14] = SHIFT_R8(p->usTimer);\r
-               pucStream[15] = SHIFT_R0(p->usCommand);\r
-               pucStream[16] = SHIFT_R8(p->usCommand);\r
-               pucStream[17] = SHIFT_R0(p->usSubCommand);\r
-               pucStream[18] = SHIFT_R8(p->usSubCommand);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];\r
-               }\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Response : Binary Mode, Multiple Transmission Type ]*/\r
-       else if( (uint16_t)ulFrameType == SLMP_FTYPE_BIN_RES_MT )\r
-       {\r
-               iIndex = SLMP_FTYPE_BIN_RES_MT_INDEX;\r
-               iLength = (p->usDataLength)-uiHeaderLength[iIndex]+2;\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               pucStream[ 0] = SHIFT_R8(SLMP_FTYPE_BIN_RES_MT);\r
-               pucStream[ 1] = SHIFT_R0(SLMP_FTYPE_BIN_RES_MT);\r
-               pucStream[ 2] = SHIFT_R0(p->usSerialNumber);\r
-               pucStream[ 3] = SHIFT_R8(p->usSerialNumber);\r
-               pucStream[ 4] = 0x00;\r
-               pucStream[ 5] = 0x00;\r
-               pucStream[ 6] = SHIFT_R0(p->usNetNumber);\r
-               pucStream[ 7] = SHIFT_R0(p->usNodeNumber);\r
-               pucStream[ 8] = SHIFT_R0(p->usProcNumber);\r
-               pucStream[ 9] = SHIFT_R8(p->usProcNumber);\r
-               pucStream[10] = 0x00;\r
-               pucStream[11] = SHIFT_R0(p->usDataLength+2);\r
-               pucStream[12] = SHIFT_R8(p->usDataLength+2);\r
-               pucStream[13] = SHIFT_R0(p->usEndCode);\r
-               pucStream[14] = SHIFT_R8(p->usEndCode);\r
-\r
-               for( i=0; i<iLength+2; i++ )\r
-               {\r
-                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];\r
-               }\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Request : ASCII Mode, Single Transmission Type ]*/\r
-       else if( ulFrameType == SLMP_FTYPE_ASCII_REQ_ST )\r
-       {\r
-               iIndex = SLMP_FTYPE_ASCII_REQ_ST_INDEX;\r
-               iLength = (p->usDataLength)-uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               pucStream[ 0] = SHIFT_R24(SLMP_FTYPE_ASCII_REQ_ST);\r
-               pucStream[ 1] = SHIFT_R16(SLMP_FTYPE_ASCII_REQ_ST);\r
-               pucStream[ 2] = SHIFT_R8 (SLMP_FTYPE_ASCII_REQ_ST);\r
-               pucStream[ 3] = SHIFT_R0 (SLMP_FTYPE_ASCII_REQ_ST);\r
-               pucStream[ 4] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 5] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 6] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 7] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 8] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 9] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[10] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[11] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[12] = local_itoa(0x00);\r
-               pucStream[13] = local_itoa(0x00);\r
-               pucStream[14] = local_itoa(SHIFT_R12(p->usDataLength) & MASK_LOWER4BIT);\r
-               pucStream[15] = local_itoa(SHIFT_R8 (p->usDataLength) & MASK_LOWER4BIT);\r
-               pucStream[16] = local_itoa(SHIFT_R4 (p->usDataLength) & MASK_LOWER4BIT);\r
-               pucStream[17] = local_itoa(SHIFT_R0 (p->usDataLength) & MASK_LOWER4BIT);\r
-               pucStream[18] = local_itoa(SHIFT_R12(p->usTimer) & MASK_LOWER4BIT);\r
-               pucStream[19] = local_itoa(SHIFT_R8 (p->usTimer) & MASK_LOWER4BIT);\r
-               pucStream[20] = local_itoa(SHIFT_R4 (p->usTimer) & MASK_LOWER4BIT);\r
-               pucStream[21] = local_itoa(SHIFT_R0 (p->usTimer) & MASK_LOWER4BIT);\r
-               pucStream[22] = local_itoa(SHIFT_R12(p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[23] = local_itoa(SHIFT_R8 (p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[24] = local_itoa(SHIFT_R4 (p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[25] = local_itoa(SHIFT_R0 (p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[26] = local_itoa(SHIFT_R12(p->usSubCommand) & MASK_LOWER4BIT);\r
-               pucStream[27] = local_itoa(SHIFT_R8 (p->usSubCommand) & MASK_LOWER4BIT);\r
-               pucStream[28] = local_itoa(SHIFT_R4 (p->usSubCommand) & MASK_LOWER4BIT);\r
-               pucStream[29] = local_itoa(SHIFT_R0 (p->usSubCommand) & MASK_LOWER4BIT);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];\r
-               }\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Response : ASCII Mode, Single Transmission Type ]*/\r
-       else if( ulFrameType == SLMP_FTYPE_ASCII_RES_ST )\r
-       {\r
-               iIndex = SLMP_FTYPE_ASCII_RES_ST_INDEX;\r
-               iLength = (p->usDataLength)-uiHeaderLength[iIndex]+4;\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               pucStream[ 0] = SHIFT_R24(SLMP_FTYPE_ASCII_RES_ST);\r
-               pucStream[ 1] = SHIFT_R16(SLMP_FTYPE_ASCII_RES_ST);\r
-               pucStream[ 2] = SHIFT_R8 (SLMP_FTYPE_ASCII_RES_ST);\r
-               pucStream[ 3] = SHIFT_R0 (SLMP_FTYPE_ASCII_RES_ST);\r
-               pucStream[ 4] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 5] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 6] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 7] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 8] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 9] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[10] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[11] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[12] = local_itoa(0x00);\r
-               pucStream[13] = local_itoa(0x00);\r
-               pucStream[14] = local_itoa(SHIFT_R12(p->usDataLength+4) & MASK_LOWER4BIT);\r
-               pucStream[15] = local_itoa(SHIFT_R8 (p->usDataLength+4) & MASK_LOWER4BIT);\r
-               pucStream[16] = local_itoa(SHIFT_R4 (p->usDataLength+4) & MASK_LOWER4BIT);\r
-               pucStream[17] = local_itoa(SHIFT_R0 (p->usDataLength+4) & MASK_LOWER4BIT);\r
-               pucStream[18] = local_itoa(SHIFT_R12(p->usEndCode) & MASK_LOWER4BIT);\r
-               pucStream[19] = local_itoa(SHIFT_R8 (p->usEndCode) & MASK_LOWER4BIT);\r
-               pucStream[20] = local_itoa(SHIFT_R4 (p->usEndCode) & MASK_LOWER4BIT);\r
-               pucStream[21] = local_itoa(SHIFT_R0 (p->usEndCode) & MASK_LOWER4BIT);\r
-\r
-               for( i=0; i<iLength+4; i++ )\r
-               {\r
-                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];\r
-               }\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Request : ASCII Mode, Multiple Transmission Type ]*/\r
-       else if( ulFrameType == SLMP_FTYPE_ASCII_REQ_MT )\r
-       {\r
-               iIndex = SLMP_FTYPE_ASCII_REQ_MT_INDEX;\r
-               iLength = (p->usDataLength)-uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               pucStream[ 0] = SHIFT_R24(SLMP_FTYPE_ASCII_REQ_MT);\r
-               pucStream[ 1] = SHIFT_R16(SLMP_FTYPE_ASCII_REQ_MT);\r
-               pucStream[ 2] = SHIFT_R8 (SLMP_FTYPE_ASCII_REQ_MT);\r
-               pucStream[ 3] = SHIFT_R0 (SLMP_FTYPE_ASCII_REQ_MT);\r
-               pucStream[ 4] = local_itoa(SHIFT_R12(p->usSerialNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 5] = local_itoa(SHIFT_R8 (p->usSerialNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 6] = local_itoa(SHIFT_R4 (p->usSerialNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 7] = local_itoa(SHIFT_R0 (p->usSerialNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 8] = local_itoa(0x00);\r
-               pucStream[ 9] = local_itoa(0x00);\r
-               pucStream[10] = local_itoa(0x00);\r
-               pucStream[11] = local_itoa(0x00);\r
-               pucStream[12] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[13] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[14] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[15] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[16] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[17] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[18] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[19] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[20] = local_itoa(0x00);\r
-               pucStream[21] = local_itoa(0x00);\r
-               pucStream[22] = local_itoa(SHIFT_R12(p->usDataLength) & MASK_LOWER4BIT);\r
-               pucStream[23] = local_itoa(SHIFT_R8 (p->usDataLength) & MASK_LOWER4BIT);\r
-               pucStream[24] = local_itoa(SHIFT_R4 (p->usDataLength) & MASK_LOWER4BIT);\r
-               pucStream[25] = local_itoa(SHIFT_R0 (p->usDataLength) & MASK_LOWER4BIT);\r
-               pucStream[26] = local_itoa(SHIFT_R12(p->usTimer) & MASK_LOWER4BIT);\r
-               pucStream[27] = local_itoa(SHIFT_R8 (p->usTimer) & MASK_LOWER4BIT);\r
-               pucStream[28] = local_itoa(SHIFT_R4 (p->usTimer) & MASK_LOWER4BIT);\r
-               pucStream[29] = local_itoa(SHIFT_R0 (p->usTimer) & MASK_LOWER4BIT);\r
-               pucStream[30] = local_itoa(SHIFT_R12(p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[31] = local_itoa(SHIFT_R8 (p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[32] = local_itoa(SHIFT_R4 (p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[33] = local_itoa(SHIFT_R0 (p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[34] = local_itoa(SHIFT_R12(p->usSubCommand) & MASK_LOWER4BIT);\r
-               pucStream[35] = local_itoa(SHIFT_R8 (p->usSubCommand) & MASK_LOWER4BIT);\r
-               pucStream[36] = local_itoa(SHIFT_R4 (p->usSubCommand) & MASK_LOWER4BIT);\r
-               pucStream[37] = local_itoa(SHIFT_R0 (p->usSubCommand) & MASK_LOWER4BIT);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];\r
-               }\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Response : ASCII Mode, Multiple Transmission Type ]*/\r
-       else if( ulFrameType == SLMP_FTYPE_ASCII_RES_MT )\r
-       {\r
-               iIndex = SLMP_FTYPE_ASCII_RES_MT_INDEX;\r
-               iLength = (p->usDataLength)-uiHeaderLength[iIndex]+4;\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               pucStream[ 0] = SHIFT_R24(SLMP_FTYPE_ASCII_RES_MT);\r
-               pucStream[ 1] = SHIFT_R16(SLMP_FTYPE_ASCII_RES_MT);\r
-               pucStream[ 2] = SHIFT_R8 (SLMP_FTYPE_ASCII_RES_MT);\r
-               pucStream[ 3] = SHIFT_R0 (SLMP_FTYPE_ASCII_RES_MT);\r
-               pucStream[ 4] = local_itoa(SHIFT_R12(p->usSerialNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 5] = local_itoa(SHIFT_R8 (p->usSerialNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 6] = local_itoa(SHIFT_R4 (p->usSerialNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 7] = local_itoa(SHIFT_R0 (p->usSerialNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 8] = local_itoa(0x00);\r
-               pucStream[ 9] = local_itoa(0x00);\r
-               pucStream[10] = local_itoa(0x00);\r
-               pucStream[11] = local_itoa(0x00);\r
-               pucStream[12] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[13] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[14] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[15] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[16] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[17] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[18] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[19] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[20] = local_itoa(0x00);\r
-               pucStream[21] = local_itoa(0x00);\r
-               pucStream[22] = local_itoa(SHIFT_R12(p->usDataLength+4) & MASK_LOWER4BIT);\r
-               pucStream[23] = local_itoa(SHIFT_R8 (p->usDataLength+4) & MASK_LOWER4BIT);\r
-               pucStream[24] = local_itoa(SHIFT_R4 (p->usDataLength+4) & MASK_LOWER4BIT);\r
-               pucStream[25] = local_itoa(SHIFT_R0 (p->usDataLength+4) & MASK_LOWER4BIT);\r
-               pucStream[26] = local_itoa(SHIFT_R12(p->usEndCode) & MASK_LOWER4BIT);\r
-               pucStream[27] = local_itoa(SHIFT_R8 (p->usEndCode) & MASK_LOWER4BIT);\r
-               pucStream[28] = local_itoa(SHIFT_R4 (p->usEndCode) & MASK_LOWER4BIT);\r
-               pucStream[29] = local_itoa(SHIFT_R0 (p->usEndCode) & MASK_LOWER4BIT);\r
-\r
-               for( i=0; i<iLength+4; i++ )\r
-               {\r
-                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];\r
-               }\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       return SLMP_ERR_NG;\r
-}\r
-\r
-/* A Function for getting SLMP_Info from packet stream */\r
-int SLMP_GetSlmpInfo ( SLMP_INFO *p, const uint8_t *pucStream )\r
-{\r
-       int i = 0;\r
-       int iIndex = 0;\r
-       int iLength = 0;\r
-       unsigned int uiTempLength = 0;\r
-       unsigned int uiTemp0 = 0, uiTemp1 = 0, uiTemp2 = 0, uiTemp3 = 0;\r
-       uint16_t        usFrameType = 0;\r
-       uint32_t        ulFrameType = 0;\r
-\r
-       if ( (p == NULL) || (pucStream == NULL) )\r
-       {\r
-               return SLMP_ERR_NG;\r
-       }\r
-\r
-       usFrameType = CONCAT_2BIN(pucStream[0], pucStream[1]);\r
-\r
-       (p->ulFrameType) = usFrameType;\r
-\r
-       /*[ Request : Binary Mode, Single Transmission Type ]*/\r
-       if( usFrameType == SLMP_FTYPE_BIN_REQ_ST )\r
-       {\r
-               iIndex = SLMP_FTYPE_BIN_REQ_ST_INDEX;\r
-               uiTempLength = CONCAT_2BIN(pucStream[ 8], pucStream[ 7]);\r
-\r
-               iLength = uiTempLength - uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               (p->usNetNumber)        = pucStream[2];\r
-               (p->usNodeNumber)       = pucStream[3];\r
-               (p->usProcNumber)       = CONCAT_2BIN(pucStream[ 5], pucStream[ 4]);\r
-               (p->usDataLength)       = (uint16_t)uiTempLength;\r
-               (p->usTimer)            = CONCAT_2BIN(pucStream[10], pucStream[ 9]);\r
-               (p->usCommand)          = CONCAT_2BIN(pucStream[12], pucStream[11]);\r
-               (p->usSubCommand)       = CONCAT_2BIN(pucStream[14], pucStream[13]);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];\r
-               }\r
-\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Response : Binary Mode, Single Transmission Type ]*/\r
-       else if( usFrameType == SLMP_FTYPE_BIN_RES_ST )\r
-       {\r
-               iIndex = SLMP_FTYPE_BIN_RES_ST_INDEX;\r
-               uiTempLength = CONCAT_2BIN(pucStream[ 8], pucStream[ 7]);\r
-\r
-               iLength = uiTempLength - uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               (p->usNetNumber)        = pucStream[2];\r
-               (p->usNodeNumber)       = pucStream[3];\r
-               (p->usProcNumber)       = CONCAT_2BIN(pucStream[ 5], pucStream[ 4]);\r
-               (p->usDataLength)       = (uint16_t)uiTempLength;\r
-               (p->usEndCode)          = CONCAT_2BIN(pucStream[10], pucStream[ 9]);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];\r
-               }\r
-\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Request : Binary Mode, Multiple Transmission Type ]*/\r
-       else if( usFrameType == SLMP_FTYPE_BIN_REQ_MT )\r
-       {\r
-               iIndex = SLMP_FTYPE_BIN_REQ_MT_INDEX;\r
-               uiTempLength = CONCAT_2BIN(pucStream[12], pucStream[11]);\r
-\r
-               iLength = uiTempLength - uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               (p->usSerialNumber)     = CONCAT_2BIN(pucStream[3], pucStream[2]);\r
-               (p->usNetNumber)        = pucStream[6];\r
-               (p->usNodeNumber)       = pucStream[7];\r
-               (p->usProcNumber)       = CONCAT_2BIN(pucStream[ 9], pucStream[ 8]);\r
-               (p->usDataLength)       = (uint16_t)uiTempLength;\r
-               (p->usTimer)            = CONCAT_2BIN(pucStream[14], pucStream[13]);\r
-               (p->usCommand)          = CONCAT_2BIN(pucStream[16], pucStream[15]);\r
-               (p->usSubCommand)       = CONCAT_2BIN(pucStream[18], pucStream[17]);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];\r
-               }\r
-\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Response : Binary Mode, Multiple Transmission Type ]*/\r
-       else if( usFrameType == SLMP_FTYPE_BIN_RES_MT )\r
-       {\r
-               iIndex = SLMP_FTYPE_BIN_RES_MT_INDEX;\r
-               uiTempLength = CONCAT_2BIN(pucStream[12], pucStream[11]);\r
-\r
-               iLength = uiTempLength - uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               (p->usSerialNumber)     = CONCAT_2BIN(pucStream[3], pucStream[2]);\r
-               (p->usNetNumber)        = pucStream[6];\r
-               (p->usNodeNumber)       = pucStream[7];\r
-               (p->usProcNumber)       = CONCAT_2BIN(pucStream[ 9], pucStream[ 8]);\r
-               (p->usDataLength)       = (uint16_t)uiTempLength;\r
-               (p->usEndCode)          = CONCAT_2BIN(pucStream[14], pucStream[13]);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];\r
-               }\r
-\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       ulFrameType = CONCAT_4BIN(pucStream[0], pucStream[1], pucStream[2], pucStream[3]);\r
-\r
-       (p->ulFrameType) = ulFrameType;\r
-\r
-       /*[ Request : ASCII Mode, Single Transmission Type ]*/\r
-       if( ulFrameType == SLMP_FTYPE_ASCII_REQ_ST )\r
-       {\r
-               iIndex = SLMP_FTYPE_ASCII_REQ_ST_INDEX;\r
-               uiTemp0 = local_atoi(pucStream[14]);\r
-               uiTemp1 = local_atoi(pucStream[15]);\r
-               uiTemp2 = local_atoi(pucStream[16]);\r
-               uiTemp3 = local_atoi(pucStream[17]);\r
-               uiTempLength = CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               iLength = uiTempLength - uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               uiTemp0 = local_atoi(pucStream[ 4]);\r
-               uiTemp1 = local_atoi(pucStream[ 5]);\r
-               (p->usNetNumber)        = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);\r
-\r
-               uiTemp0 = local_atoi(pucStream[ 6]);\r
-               uiTemp1 = local_atoi(pucStream[ 7]);\r
-               (p->usNodeNumber)       = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);\r
-\r
-               uiTemp0 = local_atoi(pucStream[ 8]);\r
-               uiTemp1 = local_atoi(pucStream[ 9]);\r
-               uiTemp2 = local_atoi(pucStream[10]);\r
-               uiTemp3 = local_atoi(pucStream[11]);\r
-               (p->usProcNumber)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               (p->usDataLength)       = (uint16_t)uiTempLength;\r
-\r
-               uiTemp0 = local_atoi(pucStream[18]);\r
-               uiTemp1 = local_atoi(pucStream[19]);\r
-               uiTemp2 = local_atoi(pucStream[20]);\r
-               uiTemp3 = local_atoi(pucStream[21]);\r
-               (p->usTimer)            = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               uiTemp0 = local_atoi(pucStream[22]);\r
-               uiTemp1 = local_atoi(pucStream[23]);\r
-               uiTemp2 = local_atoi(pucStream[24]);\r
-               uiTemp3 = local_atoi(pucStream[25]);\r
-               (p->usCommand)          = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               uiTemp0 = local_atoi(pucStream[26]);\r
-               uiTemp1 = local_atoi(pucStream[27]);\r
-               uiTemp2 = local_atoi(pucStream[28]);\r
-               uiTemp3 = local_atoi(pucStream[29]);\r
-               (p->usSubCommand)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];\r
-               }\r
-\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Response : ASCII Mode, Single Transmission Type ]*/\r
-       else if( ulFrameType == SLMP_FTYPE_ASCII_RES_ST )\r
-       {\r
-               iIndex = SLMP_FTYPE_ASCII_RES_ST_INDEX;\r
-               uiTemp0 = local_atoi(pucStream[14]);\r
-               uiTemp1 = local_atoi(pucStream[15]);\r
-               uiTemp2 = local_atoi(pucStream[16]);\r
-               uiTemp3 = local_atoi(pucStream[17]);\r
-               uiTempLength = CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               iLength = uiTempLength - uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               uiTemp0 = local_atoi(pucStream[ 4]);\r
-               uiTemp1 = local_atoi(pucStream[ 5]);\r
-               (p->usNetNumber)        = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);\r
-\r
-               uiTemp0 = local_atoi(pucStream[ 6]);\r
-               uiTemp1 = local_atoi(pucStream[ 7]);\r
-               (p->usNodeNumber)       = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);\r
-\r
-               uiTemp0 = local_atoi(pucStream[ 8]);\r
-               uiTemp1 = local_atoi(pucStream[ 9]);\r
-               uiTemp2 = local_atoi(pucStream[10]);\r
-               uiTemp3 = local_atoi(pucStream[11]);\r
-               (p->usProcNumber)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               (p->usDataLength)       = (uint16_t)uiTempLength;\r
-\r
-               uiTemp0 = local_atoi(pucStream[18]);\r
-               uiTemp1 = local_atoi(pucStream[19]);\r
-               uiTemp2 = local_atoi(pucStream[20]);\r
-               uiTemp3 = local_atoi(pucStream[21]);\r
-               (p->usEndCode)          = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];\r
-               }\r
-\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Request : ASCII Mode, Multiple Transmission Type ]*/\r
-       else if( ulFrameType == SLMP_FTYPE_ASCII_REQ_MT )\r
-       {\r
-               iIndex = SLMP_FTYPE_ASCII_REQ_MT_INDEX;\r
-               uiTemp0 = local_atoi(pucStream[22]);\r
-               uiTemp1 = local_atoi(pucStream[23]);\r
-               uiTemp2 = local_atoi(pucStream[24]);\r
-               uiTemp3 = local_atoi(pucStream[25]);\r
-               uiTempLength = CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               iLength = uiTempLength - uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               uiTemp0 = local_atoi(pucStream[ 4]);\r
-               uiTemp1 = local_atoi(pucStream[ 5]);\r
-               uiTemp2 = local_atoi(pucStream[ 6]);\r
-               uiTemp3 = local_atoi(pucStream[ 7]);\r
-               (p->usSerialNumber)     = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               uiTemp0 = local_atoi(pucStream[12]);\r
-               uiTemp1 = local_atoi(pucStream[13]);\r
-               (p->usNetNumber)        = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);\r
-\r
-               uiTemp0 = local_atoi(pucStream[14]);\r
-               uiTemp1 = local_atoi(pucStream[15]);\r
-               (p->usNodeNumber)       = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);\r
-\r
-               uiTemp0 = local_atoi(pucStream[16]);\r
-               uiTemp1 = local_atoi(pucStream[17]);\r
-               uiTemp2 = local_atoi(pucStream[18]);\r
-               uiTemp3 = local_atoi(pucStream[19]);\r
-               (p->usProcNumber)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               (p->usDataLength)       = (uint16_t)uiTempLength;\r
-\r
-               uiTemp0 = local_atoi(pucStream[26]);\r
-               uiTemp1 = local_atoi(pucStream[27]);\r
-               uiTemp2 = local_atoi(pucStream[28]);\r
-               uiTemp3 = local_atoi(pucStream[29]);\r
-               (p->usTimer)            = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               uiTemp0 = local_atoi(pucStream[30]);\r
-               uiTemp1 = local_atoi(pucStream[31]);\r
-               uiTemp2 = local_atoi(pucStream[32]);\r
-               uiTemp3 = local_atoi(pucStream[33]);\r
-               (p->usCommand)          = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               uiTemp0 = local_atoi(pucStream[34]);\r
-               uiTemp1 = local_atoi(pucStream[35]);\r
-               uiTemp2 = local_atoi(pucStream[36]);\r
-               uiTemp3 = local_atoi(pucStream[37]);\r
-               (p->usSubCommand)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];\r
-               }\r
-\r
-               return SLMP_ERR_OK;\r
-       }\r
-\r
-       /*[ Response : ASCII Mode, Multiple Transmission Type ]*/\r
-       else if( ulFrameType == SLMP_FTYPE_ASCII_RES_MT )\r
-       {\r
-               iIndex = SLMP_FTYPE_ASCII_RES_MT_INDEX;\r
-               uiTemp0 = local_atoi(pucStream[22]);\r
-               uiTemp1 = local_atoi(pucStream[23]);\r
-               uiTemp2 = local_atoi(pucStream[24]);\r
-               uiTemp3 = local_atoi(pucStream[25]);\r
-               uiTempLength = CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-               \r
-               iLength = uiTempLength - uiHeaderLength[iIndex];\r
-               if ( iLength < 0 )\r
-               {\r
-                       return SLMP_ERR_NG;\r
-               }\r
-               else if ( iLength > 0 )\r
-               {\r
-                       if ( p->pucData == NULL )\r
-                       {\r
-                               return SLMP_ERR_NG;\r
-                       }\r
-               }\r
-\r
-               uiTemp0 = local_atoi(pucStream[ 4]);\r
-               uiTemp1 = local_atoi(pucStream[ 5]);\r
-               uiTemp2 = local_atoi(pucStream[ 6]);\r
-               uiTemp3 = local_atoi(pucStream[ 7]);\r
-               (p->usSerialNumber)     = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               uiTemp0 = local_atoi(pucStream[12]);\r
-               uiTemp1 = local_atoi(pucStream[13]);\r
-               (p->usNetNumber)        = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);\r
-\r
-               uiTemp0 = local_atoi(pucStream[14]);\r
-               uiTemp1 = local_atoi(pucStream[15]);\r
-               (p->usNodeNumber)       = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);\r
-\r
-               uiTemp0 = local_atoi(pucStream[16]);\r
-               uiTemp1 = local_atoi(pucStream[17]);\r
-               uiTemp2 = local_atoi(pucStream[18]);\r
-               uiTemp3 = local_atoi(pucStream[19]);\r
-               (p->usProcNumber)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               (p->usDataLength)       = (uint16_t)uiTempLength;\r
-\r
-               uiTemp0 = local_atoi(pucStream[26]);\r
-               uiTemp1 = local_atoi(pucStream[27]);\r
-               uiTemp2 = local_atoi(pucStream[28]);\r
-               uiTemp3 = local_atoi(pucStream[29]);\r
-               (p->usEndCode)          = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);\r
-\r
-               for( i=0; i<iLength; i++ )\r
-               {\r
-                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];\r
-               }\r
-\r
-               return SLMP_ERR_OK;\r
-       }\r
-       return SLMP_ERR_NG;\r
-}\r
-\r
-/*[ translating from integer to ascii ]*/\r
-uint8_t local_itoa( uint8_t ucInt){\r
-       unsigned char ucTable[] = {     '0','1','2','3','4','5','6','7','8','9',\r
-                                               'A','B','C','D','E','F'};\r
-       return ucTable[ucInt];\r
-}\r
-\r
-/*[ translating from ascii to integer ]*/\r
-uint8_t local_atoi( uint8_t ucInt){\r
-       switch(ucInt)\r
-       {\r
-               case 'A' :\r
-                       return 0x0A;\r
-               case 'B' :\r
-                       return 0x0B;\r
-               case 'C' :\r
-                       return 0x0C;\r
-               case 'D' :\r
-                       return 0x0D;\r
-               case 'E' :\r
-                       return 0x0E;\r
-               case 'F' :\r
-                       return 0x0F;\r
-               default :\r
-                       return (ucInt-'0');\r
-       }\r
-}\r
-\r
-/* A Function for making error response data from the SLMP_Info structure */\r
-int SLMP_MakeErrorData ( const SLMP_INFO *p, uint8_t *pucStream, uint16_t *pusDataSize )\r
-{\r
-       if ( (p == NULL) || (pucStream == NULL) )\r
-       {\r
-               return SLMP_ERR_NG;\r
-       }\r
-\r
-       /*[ Binary Mode ]*/\r
-       if ( SLMP_DATA_CODE(p->ulFrameType) == SLMP_DATA_CODE_BIN )\r
-       {\r
-               pucStream[ 0] = SHIFT_R0(p->usNetNumber);\r
-               pucStream[ 1] = SHIFT_R0(p->usNodeNumber);\r
-               pucStream[ 2] = SHIFT_R0(p->usProcNumber);\r
-               pucStream[ 3] = SHIFT_R8(p->usProcNumber);\r
-               pucStream[ 4] = 0x00;\r
-               pucStream[ 5] = SHIFT_R0(p->usCommand);\r
-               pucStream[ 6] = SHIFT_R8(p->usCommand);\r
-               pucStream[ 7] = SHIFT_R0(p->usSubCommand);\r
-               pucStream[ 8] = SHIFT_R8(p->usSubCommand);\r
-               (*pusDataSize) = 0x0009;\r
-       }\r
-\r
-       /*[ ASCII Mode ]*/\r
-       else if ( SLMP_DATA_CODE(p->ulFrameType) == SLMP_DATA_CODE_ASCII )\r
-       {\r
-               pucStream[ 0] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 1] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 2] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 3] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 4] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 5] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 6] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 7] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);\r
-               pucStream[ 8] = local_itoa(0x00);\r
-               pucStream[ 9] = local_itoa(0x00);\r
-               pucStream[10] = local_itoa(SHIFT_R12(p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[11] = local_itoa(SHIFT_R8 (p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[12] = local_itoa(SHIFT_R4 (p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[13] = local_itoa(SHIFT_R0 (p->usCommand) & MASK_LOWER4BIT);\r
-               pucStream[14] = local_itoa(SHIFT_R12(p->usSubCommand) & MASK_LOWER4BIT);\r
-               pucStream[15] = local_itoa(SHIFT_R8 (p->usSubCommand) & MASK_LOWER4BIT);\r
-               pucStream[16] = local_itoa(SHIFT_R4 (p->usSubCommand) & MASK_LOWER4BIT);\r
-               pucStream[17] = local_itoa(SHIFT_R0 (p->usSubCommand) & MASK_LOWER4BIT);\r
-               (*pusDataSize) = 0x0012;\r
-       }\r
-\r
-       /*[ Data Code Error ]*/\r
-       else\r
-       {\r
-               return SLMP_ERR_NG;\r
-       }\r
-\r
-       return SLMP_ERR_OK;\r
-}\r
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/
+ * 
+ * 
+ *  Redistribution and use in source and binary forms, with or without 
+ *  modification, are permitted provided that the following conditions 
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the   
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#include "SLMP.h"
+#include <stdint.h>
+#include "string.h"
+
+static unsigned int uiHeaderLength[]           = {  6,  2,  6,  2, 12,  4, 12,  4};
+static unsigned int uiDataAddr[]                       = { 15, 11, 19, 15, 30, 22, 38, 30};
+
+/* A Function for making packet stream from the SLMP_Info structure */
+int SLMP_MakePacketStream ( uint32_t ulFrameType, const SLMP_INFO *p, uint8_t *pucStream )
+{
+       int i = 0;
+       int iLength = 0;
+       int iIndex = 0;
+
+       if ( (p == NULL) || (pucStream == NULL) )
+       {
+               return SLMP_ERR_NG;
+       }
+
+       /*[ Request : Binary Mode, Single Transmission Type ]*/
+       if( (uint16_t)ulFrameType == SLMP_FTYPE_BIN_REQ_ST )
+       {
+               iIndex = SLMP_FTYPE_BIN_REQ_ST_INDEX;
+               iLength = (p->usDataLength)-uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               pucStream[ 0] = SHIFT_R8(SLMP_FTYPE_BIN_REQ_ST);
+               pucStream[ 1] = SHIFT_R0(SLMP_FTYPE_BIN_REQ_ST);
+               pucStream[ 2] = SHIFT_R0(p->usNetNumber);
+               pucStream[ 3] = SHIFT_R0(p->usNodeNumber);
+               pucStream[ 4] = SHIFT_R0(p->usProcNumber);
+               pucStream[ 5] = SHIFT_R8(p->usProcNumber);
+               pucStream[ 6] = 0x00;
+               pucStream[ 7] = SHIFT_R0(p->usDataLength);
+               pucStream[ 8] = SHIFT_R8(p->usDataLength);
+               pucStream[ 9] = SHIFT_R0(p->usTimer);
+               pucStream[10] = SHIFT_R8(p->usTimer);
+               pucStream[11] = SHIFT_R0(p->usCommand);
+               pucStream[12] = SHIFT_R8(p->usCommand);
+               pucStream[13] = SHIFT_R0(p->usSubCommand);
+               pucStream[14] = SHIFT_R8(p->usSubCommand);
+               for( i=0; i<iLength; i++ )
+               {
+                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];
+               }
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Response : Binary Mode, Single Transmission Type ]*/
+       else if( (uint16_t)ulFrameType == SLMP_FTYPE_BIN_RES_ST )
+       {
+               iIndex = SLMP_FTYPE_BIN_RES_ST_INDEX;
+               iLength = (p->usDataLength)-uiHeaderLength[iIndex]+2;
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               pucStream[ 0] = SHIFT_R8(SLMP_FTYPE_BIN_RES_ST);
+               pucStream[ 1] = SHIFT_R0(SLMP_FTYPE_BIN_RES_ST);
+               pucStream[ 2] = SHIFT_R0(p->usNetNumber);
+               pucStream[ 3] = SHIFT_R0(p->usNodeNumber);
+               pucStream[ 4] = SHIFT_R0(p->usProcNumber);
+               pucStream[ 5] = SHIFT_R8(p->usProcNumber);
+               pucStream[ 6] = 0x00;
+               pucStream[ 7] = SHIFT_R0(p->usDataLength+2);
+               pucStream[ 8] = SHIFT_R8(p->usDataLength+2);
+               pucStream[ 9] = SHIFT_R0(p->usEndCode);
+               pucStream[10] = SHIFT_R8(p->usEndCode);
+
+               for( i=0; i<iLength+2; i++ )
+               {
+                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];
+               }
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Request : Binary Mode, Multiple Transmission Type ]*/
+       else if( (uint16_t)ulFrameType == SLMP_FTYPE_BIN_REQ_MT )
+       {
+               iIndex = SLMP_FTYPE_BIN_REQ_MT_INDEX;
+               iLength = (p->usDataLength)-uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               pucStream[ 0] = SHIFT_R8(SLMP_FTYPE_BIN_REQ_MT);
+               pucStream[ 1] = SHIFT_R0(SLMP_FTYPE_BIN_REQ_MT);
+               pucStream[ 2] = SHIFT_R0(p->usSerialNumber);
+               pucStream[ 3] = SHIFT_R8(p->usSerialNumber);
+               pucStream[ 4] = 0x00;
+               pucStream[ 5] = 0x00;
+               pucStream[ 6] = SHIFT_R0(p->usNetNumber);
+               pucStream[ 7] = SHIFT_R0(p->usNodeNumber);
+               pucStream[ 8] = SHIFT_R0(p->usProcNumber);
+               pucStream[ 9] = SHIFT_R8(p->usProcNumber);
+               pucStream[10] = 0x00;
+               pucStream[11] = SHIFT_R0(p->usDataLength);
+               pucStream[12] = SHIFT_R8(p->usDataLength);
+               pucStream[13] = SHIFT_R0(p->usTimer);
+               pucStream[14] = SHIFT_R8(p->usTimer);
+               pucStream[15] = SHIFT_R0(p->usCommand);
+               pucStream[16] = SHIFT_R8(p->usCommand);
+               pucStream[17] = SHIFT_R0(p->usSubCommand);
+               pucStream[18] = SHIFT_R8(p->usSubCommand);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];
+               }
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Response : Binary Mode, Multiple Transmission Type ]*/
+       else if( (uint16_t)ulFrameType == SLMP_FTYPE_BIN_RES_MT )
+       {
+               iIndex = SLMP_FTYPE_BIN_RES_MT_INDEX;
+               iLength = (p->usDataLength)-uiHeaderLength[iIndex]+2;
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               pucStream[ 0] = SHIFT_R8(SLMP_FTYPE_BIN_RES_MT);
+               pucStream[ 1] = SHIFT_R0(SLMP_FTYPE_BIN_RES_MT);
+               pucStream[ 2] = SHIFT_R0(p->usSerialNumber);
+               pucStream[ 3] = SHIFT_R8(p->usSerialNumber);
+               pucStream[ 4] = 0x00;
+               pucStream[ 5] = 0x00;
+               pucStream[ 6] = SHIFT_R0(p->usNetNumber);
+               pucStream[ 7] = SHIFT_R0(p->usNodeNumber);
+               pucStream[ 8] = SHIFT_R0(p->usProcNumber);
+               pucStream[ 9] = SHIFT_R8(p->usProcNumber);
+               pucStream[10] = 0x00;
+               pucStream[11] = SHIFT_R0(p->usDataLength+2);
+               pucStream[12] = SHIFT_R8(p->usDataLength+2);
+               pucStream[13] = SHIFT_R0(p->usEndCode);
+               pucStream[14] = SHIFT_R8(p->usEndCode);
+
+               for( i=0; i<iLength+2; i++ )
+               {
+                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];
+               }
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Request : ASCII Mode, Single Transmission Type ]*/
+       else if( ulFrameType == SLMP_FTYPE_ASCII_REQ_ST )
+       {
+               iIndex = SLMP_FTYPE_ASCII_REQ_ST_INDEX;
+               iLength = (p->usDataLength)-uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               pucStream[ 0] = SHIFT_R24(SLMP_FTYPE_ASCII_REQ_ST);
+               pucStream[ 1] = SHIFT_R16(SLMP_FTYPE_ASCII_REQ_ST);
+               pucStream[ 2] = SHIFT_R8 (SLMP_FTYPE_ASCII_REQ_ST);
+               pucStream[ 3] = SHIFT_R0 (SLMP_FTYPE_ASCII_REQ_ST);
+               pucStream[ 4] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[ 5] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[ 6] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[ 7] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[ 8] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[ 9] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[10] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[11] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[12] = local_itoa(0x00);
+               pucStream[13] = local_itoa(0x00);
+               pucStream[14] = local_itoa(SHIFT_R12(p->usDataLength) & MASK_LOWER4BIT);
+               pucStream[15] = local_itoa(SHIFT_R8 (p->usDataLength) & MASK_LOWER4BIT);
+               pucStream[16] = local_itoa(SHIFT_R4 (p->usDataLength) & MASK_LOWER4BIT);
+               pucStream[17] = local_itoa(SHIFT_R0 (p->usDataLength) & MASK_LOWER4BIT);
+               pucStream[18] = local_itoa(SHIFT_R12(p->usTimer) & MASK_LOWER4BIT);
+               pucStream[19] = local_itoa(SHIFT_R8 (p->usTimer) & MASK_LOWER4BIT);
+               pucStream[20] = local_itoa(SHIFT_R4 (p->usTimer) & MASK_LOWER4BIT);
+               pucStream[21] = local_itoa(SHIFT_R0 (p->usTimer) & MASK_LOWER4BIT);
+               pucStream[22] = local_itoa(SHIFT_R12(p->usCommand) & MASK_LOWER4BIT);
+               pucStream[23] = local_itoa(SHIFT_R8 (p->usCommand) & MASK_LOWER4BIT);
+               pucStream[24] = local_itoa(SHIFT_R4 (p->usCommand) & MASK_LOWER4BIT);
+               pucStream[25] = local_itoa(SHIFT_R0 (p->usCommand) & MASK_LOWER4BIT);
+               pucStream[26] = local_itoa(SHIFT_R12(p->usSubCommand) & MASK_LOWER4BIT);
+               pucStream[27] = local_itoa(SHIFT_R8 (p->usSubCommand) & MASK_LOWER4BIT);
+               pucStream[28] = local_itoa(SHIFT_R4 (p->usSubCommand) & MASK_LOWER4BIT);
+               pucStream[29] = local_itoa(SHIFT_R0 (p->usSubCommand) & MASK_LOWER4BIT);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];
+               }
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Response : ASCII Mode, Single Transmission Type ]*/
+       else if( ulFrameType == SLMP_FTYPE_ASCII_RES_ST )
+       {
+               iIndex = SLMP_FTYPE_ASCII_RES_ST_INDEX;
+               iLength = (p->usDataLength)-uiHeaderLength[iIndex]+4;
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               pucStream[ 0] = SHIFT_R24(SLMP_FTYPE_ASCII_RES_ST);
+               pucStream[ 1] = SHIFT_R16(SLMP_FTYPE_ASCII_RES_ST);
+               pucStream[ 2] = SHIFT_R8 (SLMP_FTYPE_ASCII_RES_ST);
+               pucStream[ 3] = SHIFT_R0 (SLMP_FTYPE_ASCII_RES_ST);
+               pucStream[ 4] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[ 5] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[ 6] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[ 7] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[ 8] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[ 9] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[10] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[11] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[12] = local_itoa(0x00);
+               pucStream[13] = local_itoa(0x00);
+               pucStream[14] = local_itoa(SHIFT_R12(p->usDataLength+4) & MASK_LOWER4BIT);
+               pucStream[15] = local_itoa(SHIFT_R8 (p->usDataLength+4) & MASK_LOWER4BIT);
+               pucStream[16] = local_itoa(SHIFT_R4 (p->usDataLength+4) & MASK_LOWER4BIT);
+               pucStream[17] = local_itoa(SHIFT_R0 (p->usDataLength+4) & MASK_LOWER4BIT);
+               pucStream[18] = local_itoa(SHIFT_R12(p->usEndCode) & MASK_LOWER4BIT);
+               pucStream[19] = local_itoa(SHIFT_R8 (p->usEndCode) & MASK_LOWER4BIT);
+               pucStream[20] = local_itoa(SHIFT_R4 (p->usEndCode) & MASK_LOWER4BIT);
+               pucStream[21] = local_itoa(SHIFT_R0 (p->usEndCode) & MASK_LOWER4BIT);
+
+               for( i=0; i<iLength+4; i++ )
+               {
+                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];
+               }
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Request : ASCII Mode, Multiple Transmission Type ]*/
+       else if( ulFrameType == SLMP_FTYPE_ASCII_REQ_MT )
+       {
+               iIndex = SLMP_FTYPE_ASCII_REQ_MT_INDEX;
+               iLength = (p->usDataLength)-uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               pucStream[ 0] = SHIFT_R24(SLMP_FTYPE_ASCII_REQ_MT);
+               pucStream[ 1] = SHIFT_R16(SLMP_FTYPE_ASCII_REQ_MT);
+               pucStream[ 2] = SHIFT_R8 (SLMP_FTYPE_ASCII_REQ_MT);
+               pucStream[ 3] = SHIFT_R0 (SLMP_FTYPE_ASCII_REQ_MT);
+               pucStream[ 4] = local_itoa(SHIFT_R12(p->usSerialNumber) & MASK_LOWER4BIT);
+               pucStream[ 5] = local_itoa(SHIFT_R8 (p->usSerialNumber) & MASK_LOWER4BIT);
+               pucStream[ 6] = local_itoa(SHIFT_R4 (p->usSerialNumber) & MASK_LOWER4BIT);
+               pucStream[ 7] = local_itoa(SHIFT_R0 (p->usSerialNumber) & MASK_LOWER4BIT);
+               pucStream[ 8] = local_itoa(0x00);
+               pucStream[ 9] = local_itoa(0x00);
+               pucStream[10] = local_itoa(0x00);
+               pucStream[11] = local_itoa(0x00);
+               pucStream[12] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[13] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[14] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[15] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[16] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[17] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[18] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[19] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[20] = local_itoa(0x00);
+               pucStream[21] = local_itoa(0x00);
+               pucStream[22] = local_itoa(SHIFT_R12(p->usDataLength) & MASK_LOWER4BIT);
+               pucStream[23] = local_itoa(SHIFT_R8 (p->usDataLength) & MASK_LOWER4BIT);
+               pucStream[24] = local_itoa(SHIFT_R4 (p->usDataLength) & MASK_LOWER4BIT);
+               pucStream[25] = local_itoa(SHIFT_R0 (p->usDataLength) & MASK_LOWER4BIT);
+               pucStream[26] = local_itoa(SHIFT_R12(p->usTimer) & MASK_LOWER4BIT);
+               pucStream[27] = local_itoa(SHIFT_R8 (p->usTimer) & MASK_LOWER4BIT);
+               pucStream[28] = local_itoa(SHIFT_R4 (p->usTimer) & MASK_LOWER4BIT);
+               pucStream[29] = local_itoa(SHIFT_R0 (p->usTimer) & MASK_LOWER4BIT);
+               pucStream[30] = local_itoa(SHIFT_R12(p->usCommand) & MASK_LOWER4BIT);
+               pucStream[31] = local_itoa(SHIFT_R8 (p->usCommand) & MASK_LOWER4BIT);
+               pucStream[32] = local_itoa(SHIFT_R4 (p->usCommand) & MASK_LOWER4BIT);
+               pucStream[33] = local_itoa(SHIFT_R0 (p->usCommand) & MASK_LOWER4BIT);
+               pucStream[34] = local_itoa(SHIFT_R12(p->usSubCommand) & MASK_LOWER4BIT);
+               pucStream[35] = local_itoa(SHIFT_R8 (p->usSubCommand) & MASK_LOWER4BIT);
+               pucStream[36] = local_itoa(SHIFT_R4 (p->usSubCommand) & MASK_LOWER4BIT);
+               pucStream[37] = local_itoa(SHIFT_R0 (p->usSubCommand) & MASK_LOWER4BIT);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];
+               }
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Response : ASCII Mode, Multiple Transmission Type ]*/
+       else if( ulFrameType == SLMP_FTYPE_ASCII_RES_MT )
+       {
+               iIndex = SLMP_FTYPE_ASCII_RES_MT_INDEX;
+               iLength = (p->usDataLength)-uiHeaderLength[iIndex]+4;
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               pucStream[ 0] = SHIFT_R24(SLMP_FTYPE_ASCII_RES_MT);
+               pucStream[ 1] = SHIFT_R16(SLMP_FTYPE_ASCII_RES_MT);
+               pucStream[ 2] = SHIFT_R8 (SLMP_FTYPE_ASCII_RES_MT);
+               pucStream[ 3] = SHIFT_R0 (SLMP_FTYPE_ASCII_RES_MT);
+               pucStream[ 4] = local_itoa(SHIFT_R12(p->usSerialNumber) & MASK_LOWER4BIT);
+               pucStream[ 5] = local_itoa(SHIFT_R8 (p->usSerialNumber) & MASK_LOWER4BIT);
+               pucStream[ 6] = local_itoa(SHIFT_R4 (p->usSerialNumber) & MASK_LOWER4BIT);
+               pucStream[ 7] = local_itoa(SHIFT_R0 (p->usSerialNumber) & MASK_LOWER4BIT);
+               pucStream[ 8] = local_itoa(0x00);
+               pucStream[ 9] = local_itoa(0x00);
+               pucStream[10] = local_itoa(0x00);
+               pucStream[11] = local_itoa(0x00);
+               pucStream[12] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[13] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[14] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[15] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[16] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[17] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[18] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[19] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[20] = local_itoa(0x00);
+               pucStream[21] = local_itoa(0x00);
+               pucStream[22] = local_itoa(SHIFT_R12(p->usDataLength+4) & MASK_LOWER4BIT);
+               pucStream[23] = local_itoa(SHIFT_R8 (p->usDataLength+4) & MASK_LOWER4BIT);
+               pucStream[24] = local_itoa(SHIFT_R4 (p->usDataLength+4) & MASK_LOWER4BIT);
+               pucStream[25] = local_itoa(SHIFT_R0 (p->usDataLength+4) & MASK_LOWER4BIT);
+               pucStream[26] = local_itoa(SHIFT_R12(p->usEndCode) & MASK_LOWER4BIT);
+               pucStream[27] = local_itoa(SHIFT_R8 (p->usEndCode) & MASK_LOWER4BIT);
+               pucStream[28] = local_itoa(SHIFT_R4 (p->usEndCode) & MASK_LOWER4BIT);
+               pucStream[29] = local_itoa(SHIFT_R0 (p->usEndCode) & MASK_LOWER4BIT);
+
+               for( i=0; i<iLength+4; i++ )
+               {
+                       pucStream[uiDataAddr[iIndex]+i] = p->pucData[i];
+               }
+               return SLMP_ERR_OK;
+       }
+
+       return SLMP_ERR_NG;
+}
+
+/* A Function for getting SLMP_Info from packet stream */
+int SLMP_GetSlmpInfo ( SLMP_INFO *p, const uint8_t *pucStream )
+{
+       int i = 0;
+       int iIndex = 0;
+       int iLength = 0;
+       unsigned int uiTempLength = 0;
+       unsigned int uiTemp0 = 0, uiTemp1 = 0, uiTemp2 = 0, uiTemp3 = 0;
+       uint16_t        usFrameType = 0;
+       uint32_t        ulFrameType = 0;
+
+       if ( (p == NULL) || (pucStream == NULL) )
+       {
+               return SLMP_ERR_NG;
+       }
+
+       usFrameType = CONCAT_2BIN(pucStream[0], pucStream[1]);
+
+       (p->ulFrameType) = usFrameType;
+
+       /*[ Request : Binary Mode, Single Transmission Type ]*/
+       if( usFrameType == SLMP_FTYPE_BIN_REQ_ST )
+       {
+               iIndex = SLMP_FTYPE_BIN_REQ_ST_INDEX;
+               uiTempLength = CONCAT_2BIN(pucStream[ 8], pucStream[ 7]);
+
+               iLength = uiTempLength - uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               (p->usNetNumber)        = pucStream[2];
+               (p->usNodeNumber)       = pucStream[3];
+               (p->usProcNumber)       = CONCAT_2BIN(pucStream[ 5], pucStream[ 4]);
+               (p->usDataLength)       = (uint16_t)uiTempLength;
+               (p->usTimer)            = CONCAT_2BIN(pucStream[10], pucStream[ 9]);
+               (p->usCommand)          = CONCAT_2BIN(pucStream[12], pucStream[11]);
+               (p->usSubCommand)       = CONCAT_2BIN(pucStream[14], pucStream[13]);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];
+               }
+
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Response : Binary Mode, Single Transmission Type ]*/
+       else if( usFrameType == SLMP_FTYPE_BIN_RES_ST )
+       {
+               iIndex = SLMP_FTYPE_BIN_RES_ST_INDEX;
+               uiTempLength = CONCAT_2BIN(pucStream[ 8], pucStream[ 7]);
+
+               iLength = uiTempLength - uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               (p->usNetNumber)        = pucStream[2];
+               (p->usNodeNumber)       = pucStream[3];
+               (p->usProcNumber)       = CONCAT_2BIN(pucStream[ 5], pucStream[ 4]);
+               (p->usDataLength)       = (uint16_t)uiTempLength;
+               (p->usEndCode)          = CONCAT_2BIN(pucStream[10], pucStream[ 9]);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];
+               }
+
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Request : Binary Mode, Multiple Transmission Type ]*/
+       else if( usFrameType == SLMP_FTYPE_BIN_REQ_MT )
+       {
+               iIndex = SLMP_FTYPE_BIN_REQ_MT_INDEX;
+               uiTempLength = CONCAT_2BIN(pucStream[12], pucStream[11]);
+
+               iLength = uiTempLength - uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               (p->usSerialNumber)     = CONCAT_2BIN(pucStream[3], pucStream[2]);
+               (p->usNetNumber)        = pucStream[6];
+               (p->usNodeNumber)       = pucStream[7];
+               (p->usProcNumber)       = CONCAT_2BIN(pucStream[ 9], pucStream[ 8]);
+               (p->usDataLength)       = (uint16_t)uiTempLength;
+               (p->usTimer)            = CONCAT_2BIN(pucStream[14], pucStream[13]);
+               (p->usCommand)          = CONCAT_2BIN(pucStream[16], pucStream[15]);
+               (p->usSubCommand)       = CONCAT_2BIN(pucStream[18], pucStream[17]);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];
+               }
+
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Response : Binary Mode, Multiple Transmission Type ]*/
+       else if( usFrameType == SLMP_FTYPE_BIN_RES_MT )
+       {
+               iIndex = SLMP_FTYPE_BIN_RES_MT_INDEX;
+               uiTempLength = CONCAT_2BIN(pucStream[12], pucStream[11]);
+
+               iLength = uiTempLength - uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               (p->usSerialNumber)     = CONCAT_2BIN(pucStream[3], pucStream[2]);
+               (p->usNetNumber)        = pucStream[6];
+               (p->usNodeNumber)       = pucStream[7];
+               (p->usProcNumber)       = CONCAT_2BIN(pucStream[ 9], pucStream[ 8]);
+               (p->usDataLength)       = (uint16_t)uiTempLength;
+               (p->usEndCode)          = CONCAT_2BIN(pucStream[14], pucStream[13]);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];
+               }
+
+               return SLMP_ERR_OK;
+       }
+
+       ulFrameType = CONCAT_4BIN(pucStream[0], pucStream[1], pucStream[2], pucStream[3]);
+
+       (p->ulFrameType) = ulFrameType;
+
+       /*[ Request : ASCII Mode, Single Transmission Type ]*/
+       if( ulFrameType == SLMP_FTYPE_ASCII_REQ_ST )
+       {
+               iIndex = SLMP_FTYPE_ASCII_REQ_ST_INDEX;
+               uiTemp0 = local_atoi(pucStream[14]);
+               uiTemp1 = local_atoi(pucStream[15]);
+               uiTemp2 = local_atoi(pucStream[16]);
+               uiTemp3 = local_atoi(pucStream[17]);
+               uiTempLength = CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               iLength = uiTempLength - uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               uiTemp0 = local_atoi(pucStream[ 4]);
+               uiTemp1 = local_atoi(pucStream[ 5]);
+               (p->usNetNumber)        = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);
+
+               uiTemp0 = local_atoi(pucStream[ 6]);
+               uiTemp1 = local_atoi(pucStream[ 7]);
+               (p->usNodeNumber)       = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);
+
+               uiTemp0 = local_atoi(pucStream[ 8]);
+               uiTemp1 = local_atoi(pucStream[ 9]);
+               uiTemp2 = local_atoi(pucStream[10]);
+               uiTemp3 = local_atoi(pucStream[11]);
+               (p->usProcNumber)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               (p->usDataLength)       = (uint16_t)uiTempLength;
+
+               uiTemp0 = local_atoi(pucStream[18]);
+               uiTemp1 = local_atoi(pucStream[19]);
+               uiTemp2 = local_atoi(pucStream[20]);
+               uiTemp3 = local_atoi(pucStream[21]);
+               (p->usTimer)            = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               uiTemp0 = local_atoi(pucStream[22]);
+               uiTemp1 = local_atoi(pucStream[23]);
+               uiTemp2 = local_atoi(pucStream[24]);
+               uiTemp3 = local_atoi(pucStream[25]);
+               (p->usCommand)          = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               uiTemp0 = local_atoi(pucStream[26]);
+               uiTemp1 = local_atoi(pucStream[27]);
+               uiTemp2 = local_atoi(pucStream[28]);
+               uiTemp3 = local_atoi(pucStream[29]);
+               (p->usSubCommand)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];
+               }
+
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Response : ASCII Mode, Single Transmission Type ]*/
+       else if( ulFrameType == SLMP_FTYPE_ASCII_RES_ST )
+       {
+               iIndex = SLMP_FTYPE_ASCII_RES_ST_INDEX;
+               uiTemp0 = local_atoi(pucStream[14]);
+               uiTemp1 = local_atoi(pucStream[15]);
+               uiTemp2 = local_atoi(pucStream[16]);
+               uiTemp3 = local_atoi(pucStream[17]);
+               uiTempLength = CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               iLength = uiTempLength - uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               uiTemp0 = local_atoi(pucStream[ 4]);
+               uiTemp1 = local_atoi(pucStream[ 5]);
+               (p->usNetNumber)        = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);
+
+               uiTemp0 = local_atoi(pucStream[ 6]);
+               uiTemp1 = local_atoi(pucStream[ 7]);
+               (p->usNodeNumber)       = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);
+
+               uiTemp0 = local_atoi(pucStream[ 8]);
+               uiTemp1 = local_atoi(pucStream[ 9]);
+               uiTemp2 = local_atoi(pucStream[10]);
+               uiTemp3 = local_atoi(pucStream[11]);
+               (p->usProcNumber)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               (p->usDataLength)       = (uint16_t)uiTempLength;
+
+               uiTemp0 = local_atoi(pucStream[18]);
+               uiTemp1 = local_atoi(pucStream[19]);
+               uiTemp2 = local_atoi(pucStream[20]);
+               uiTemp3 = local_atoi(pucStream[21]);
+               (p->usEndCode)          = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];
+               }
+
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Request : ASCII Mode, Multiple Transmission Type ]*/
+       else if( ulFrameType == SLMP_FTYPE_ASCII_REQ_MT )
+       {
+               iIndex = SLMP_FTYPE_ASCII_REQ_MT_INDEX;
+               uiTemp0 = local_atoi(pucStream[22]);
+               uiTemp1 = local_atoi(pucStream[23]);
+               uiTemp2 = local_atoi(pucStream[24]);
+               uiTemp3 = local_atoi(pucStream[25]);
+               uiTempLength = CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               iLength = uiTempLength - uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               uiTemp0 = local_atoi(pucStream[ 4]);
+               uiTemp1 = local_atoi(pucStream[ 5]);
+               uiTemp2 = local_atoi(pucStream[ 6]);
+               uiTemp3 = local_atoi(pucStream[ 7]);
+               (p->usSerialNumber)     = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               uiTemp0 = local_atoi(pucStream[12]);
+               uiTemp1 = local_atoi(pucStream[13]);
+               (p->usNetNumber)        = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);
+
+               uiTemp0 = local_atoi(pucStream[14]);
+               uiTemp1 = local_atoi(pucStream[15]);
+               (p->usNodeNumber)       = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);
+
+               uiTemp0 = local_atoi(pucStream[16]);
+               uiTemp1 = local_atoi(pucStream[17]);
+               uiTemp2 = local_atoi(pucStream[18]);
+               uiTemp3 = local_atoi(pucStream[19]);
+               (p->usProcNumber)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               (p->usDataLength)       = (uint16_t)uiTempLength;
+
+               uiTemp0 = local_atoi(pucStream[26]);
+               uiTemp1 = local_atoi(pucStream[27]);
+               uiTemp2 = local_atoi(pucStream[28]);
+               uiTemp3 = local_atoi(pucStream[29]);
+               (p->usTimer)            = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               uiTemp0 = local_atoi(pucStream[30]);
+               uiTemp1 = local_atoi(pucStream[31]);
+               uiTemp2 = local_atoi(pucStream[32]);
+               uiTemp3 = local_atoi(pucStream[33]);
+               (p->usCommand)          = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               uiTemp0 = local_atoi(pucStream[34]);
+               uiTemp1 = local_atoi(pucStream[35]);
+               uiTemp2 = local_atoi(pucStream[36]);
+               uiTemp3 = local_atoi(pucStream[37]);
+               (p->usSubCommand)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];
+               }
+
+               return SLMP_ERR_OK;
+       }
+
+       /*[ Response : ASCII Mode, Multiple Transmission Type ]*/
+       else if( ulFrameType == SLMP_FTYPE_ASCII_RES_MT )
+       {
+               iIndex = SLMP_FTYPE_ASCII_RES_MT_INDEX;
+               uiTemp0 = local_atoi(pucStream[22]);
+               uiTemp1 = local_atoi(pucStream[23]);
+               uiTemp2 = local_atoi(pucStream[24]);
+               uiTemp3 = local_atoi(pucStream[25]);
+               uiTempLength = CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+               
+               iLength = uiTempLength - uiHeaderLength[iIndex];
+               if ( iLength < 0 )
+               {
+                       return SLMP_ERR_NG;
+               }
+               else if ( iLength > 0 )
+               {
+                       if ( p->pucData == NULL )
+                       {
+                               return SLMP_ERR_NG;
+                       }
+               }
+
+               uiTemp0 = local_atoi(pucStream[ 4]);
+               uiTemp1 = local_atoi(pucStream[ 5]);
+               uiTemp2 = local_atoi(pucStream[ 6]);
+               uiTemp3 = local_atoi(pucStream[ 7]);
+               (p->usSerialNumber)     = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               uiTemp0 = local_atoi(pucStream[12]);
+               uiTemp1 = local_atoi(pucStream[13]);
+               (p->usNetNumber)        = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);
+
+               uiTemp0 = local_atoi(pucStream[14]);
+               uiTemp1 = local_atoi(pucStream[15]);
+               (p->usNodeNumber)       = (uint16_t)CONCAT_2ASCII(uiTemp0, uiTemp1);
+
+               uiTemp0 = local_atoi(pucStream[16]);
+               uiTemp1 = local_atoi(pucStream[17]);
+               uiTemp2 = local_atoi(pucStream[18]);
+               uiTemp3 = local_atoi(pucStream[19]);
+               (p->usProcNumber)       = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               (p->usDataLength)       = (uint16_t)uiTempLength;
+
+               uiTemp0 = local_atoi(pucStream[26]);
+               uiTemp1 = local_atoi(pucStream[27]);
+               uiTemp2 = local_atoi(pucStream[28]);
+               uiTemp3 = local_atoi(pucStream[29]);
+               (p->usEndCode)          = (uint16_t)CONCAT_4ASCII(uiTemp0, uiTemp1, uiTemp2, uiTemp3);
+
+               for( i=0; i<iLength; i++ )
+               {
+                       p->pucData[i] = pucStream[uiDataAddr[iIndex]+i];
+               }
+
+               return SLMP_ERR_OK;
+       }
+       return SLMP_ERR_NG;
+}
+
+/*[ translating from integer to ascii ]*/
+uint8_t local_itoa( uint8_t ucInt){
+       unsigned char ucTable[] = {     '0','1','2','3','4','5','6','7','8','9',
+                                               'A','B','C','D','E','F'};
+       return ucTable[ucInt];
+}
+
+/*[ translating from ascii to integer ]*/
+uint8_t local_atoi( uint8_t ucInt){
+       switch(ucInt)
+       {
+               case 'A' :
+                       return 0x0A;
+               case 'B' :
+                       return 0x0B;
+               case 'C' :
+                       return 0x0C;
+               case 'D' :
+                       return 0x0D;
+               case 'E' :
+                       return 0x0E;
+               case 'F' :
+                       return 0x0F;
+               default :
+                       return (ucInt-'0');
+       }
+}
+
+/* A Function for making error response data from the SLMP_Info structure */
+int SLMP_MakeErrorData ( const SLMP_INFO *p, uint8_t *pucStream, uint16_t *pusDataSize )
+{
+       if ( (p == NULL) || (pucStream == NULL) )
+       {
+               return SLMP_ERR_NG;
+       }
+
+       /*[ Binary Mode ]*/
+       if ( SLMP_DATA_CODE(p->ulFrameType) == SLMP_DATA_CODE_BIN )
+       {
+               pucStream[ 0] = SHIFT_R0(p->usNetNumber);
+               pucStream[ 1] = SHIFT_R0(p->usNodeNumber);
+               pucStream[ 2] = SHIFT_R0(p->usProcNumber);
+               pucStream[ 3] = SHIFT_R8(p->usProcNumber);
+               pucStream[ 4] = 0x00;
+               pucStream[ 5] = SHIFT_R0(p->usCommand);
+               pucStream[ 6] = SHIFT_R8(p->usCommand);
+               pucStream[ 7] = SHIFT_R0(p->usSubCommand);
+               pucStream[ 8] = SHIFT_R8(p->usSubCommand);
+               (*pusDataSize) = 0x0009;
+       }
+
+       /*[ ASCII Mode ]*/
+       else if ( SLMP_DATA_CODE(p->ulFrameType) == SLMP_DATA_CODE_ASCII )
+       {
+               pucStream[ 0] = local_itoa(SHIFT_R4(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[ 1] = local_itoa(SHIFT_R0(p->usNetNumber) & MASK_LOWER4BIT);
+               pucStream[ 2] = local_itoa(SHIFT_R4(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[ 3] = local_itoa(SHIFT_R0(p->usNodeNumber) & MASK_LOWER4BIT);
+               pucStream[ 4] = local_itoa(SHIFT_R12(p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[ 5] = local_itoa(SHIFT_R8 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[ 6] = local_itoa(SHIFT_R4 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[ 7] = local_itoa(SHIFT_R0 (p->usProcNumber) & MASK_LOWER4BIT);
+               pucStream[ 8] = local_itoa(0x00);
+               pucStream[ 9] = local_itoa(0x00);
+               pucStream[10] = local_itoa(SHIFT_R12(p->usCommand) & MASK_LOWER4BIT);
+               pucStream[11] = local_itoa(SHIFT_R8 (p->usCommand) & MASK_LOWER4BIT);
+               pucStream[12] = local_itoa(SHIFT_R4 (p->usCommand) & MASK_LOWER4BIT);
+               pucStream[13] = local_itoa(SHIFT_R0 (p->usCommand) & MASK_LOWER4BIT);
+               pucStream[14] = local_itoa(SHIFT_R12(p->usSubCommand) & MASK_LOWER4BIT);
+               pucStream[15] = local_itoa(SHIFT_R8 (p->usSubCommand) & MASK_LOWER4BIT);
+               pucStream[16] = local_itoa(SHIFT_R4 (p->usSubCommand) & MASK_LOWER4BIT);
+               pucStream[17] = local_itoa(SHIFT_R0 (p->usSubCommand) & MASK_LOWER4BIT);
+               (*pusDataSize) = 0x0012;
+       }
+
+       /*[ Data Code Error ]*/
+       else
+       {
+               return SLMP_ERR_NG;
+       }
+
+       return SLMP_ERR_OK;
+}
index 3c1f57890b73c95e56c2c90ab2c874b89932c3d0..979b4489d1f0e6f260c6bf9be1efe9522ce14188 100644 (file)
@@ -1,22 +1,22 @@
----------------------------------------------------------------------\r
-CC-Link IE Field Network Basic Master Application sample code\r
-\r
-readme.txt\r
-\r
----------------------------------------------------------------------\r
-\r
-Contents.\r
-\r
-root  -+-  library  -+-  include  ... SLMP library code header file\r
-       |             +-  src      ... SLMP library code file\r
-       |\r
-       +-  sample   -+-  include  ... user sample program header file\r
-       |             +-  src      ... user sample program code file\r
-       |\r
-       +-  build    -+-  linux    ... Makefile for Linux\r
-       |\r
-       |\r
-       +-  manual   ---  User manual\r
-       |\r
-       |\r
-       +-  version.txt --- Version information\r
+---------------------------------------------------------------------
+CC-Link IE Field Network Basic Master Application sample code
+
+readme.txt
+
+---------------------------------------------------------------------
+
+Contents.
+
+root  -+-  library  -+-  include  ... SLMP library code header file
+       |             +-  src      ... SLMP library code file
+       |
+       +-  sample   -+-  include  ... user sample program header file
+       |             +-  src      ... user sample program code file
+       |
+       +-  build    -+-  linux    ... Makefile for Linux
+       |
+       |
+       +-  manual   ---  User manual
+       |
+       |
+       +-  version.txt --- Version information
index c9d5b760e2ce0f9b97d149e7297e13b974aa001f..ea9214e171d549baf3295ac8a98fe365468a244a 100644 (file)
@@ -1,17 +1,17 @@
-,,\r
-CCIEF-BASIC Master Sample Parameter,,\r
-,,\r
-Group,,\r
-ID,DATA,COMMENT\r
-1,1,Total number of group\r
-2,1,Number of group\r
-3,100,Group1 Cyclic transmission timeout\r
-4,2,Group1 Count of cyclic transmission timeout\r
-5,0,Group1 Constant link scan time\r
-,,\r
-Slave,,\r
-ID,DATA,COMMENT\r
-1,1,Total number of slave\r
-2,192.168.3.1,Slave1 IP address\r
-3,1,Slave1 Number of occupied stations\r
+,,
+CCIEF-BASIC Master Sample Parameter,,
+,,
+Group,,
+ID,DATA,COMMENT
+1,1,Total number of group
+2,1,Number of group
+3,100,Group1 Cyclic transmission timeout
+4,2,Group1 Count of cyclic transmission timeout
+5,0,Group1 Constant link scan time
+,,
+Slave,,
+ID,DATA,COMMENT
+1,1,Total number of slave
+2,192.168.3.1,Slave1 IP address
+3,1,Slave1 Number of occupied stations
 4,1,Slave1 Number of group
\ No newline at end of file
index da02f9d7cbf6b481fdebbb9af63784328a33a2fc..e4fe54b35473c795c3528c2c04dfa2f48ecdbd22 100644 (file)
-/*\r
- * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
- * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/\r
- * \r
- * \r
- *  Redistribution and use in source and binary forms, with or without \r
- *  modification, are permitted provided that the following conditions \r
- *  are met:\r
- *\r
- *    Redistributions of source code must retain the above copyright \r
- *    notice, this list of conditions and the following disclaimer.\r
- *\r
- *    Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the \r
- *    documentation and/or other materials provided with the   \r
- *    distribution.\r
- *\r
- *    Neither the name of Texas Instruments Incorporated nor the names of\r
- *    its contributors may be used to endorse or promote products derived\r
- *    from this software without specific prior written permission.\r
- *\r
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
-*/\r
-\r
-#ifndef                __CCIEF_BASIC_MASTER_H__\r
-#define                __CCIEF_BASIC_MASTER_H__\r
-\r
-#include <stdint.h>\r
-\r
-/*[ Definition for sample code ]*/\r
-#define        CCIEF_BASIC_MASTER_ERR_OK                                                       0\r
-#define        CCIEF_BASIC_MASTER_ERR_NG                                                       (-1)\r
-#define CCIEF_BASIC_MASTER_ERR_DEVICE_RANGE                                    (-100)\r
-#define CCIEF_BASIC_MASTER_ERR_MASTER_DUPLICATION                      (-200)\r
-#define CCIEF_BASIC_MASTER_ERR_SLAVE_DUPLICATION                       (-300)\r
-\r
-/*[ Definition for CCIEF-BASIC environment ]*/\r
-#define        CCIEF_BASIC_PROTCOL_VERSION                                                     1                       /* Protocol Version */\r
-#define        CCIEF_BASIC_PORT_NUMBER_CYCLIC                                          61450           /* Port number of Cyclic */\r
-#define        CCIEF_BASIC_MAX_FRAME_SIZE                                                      6000            /* Size of MAX Packet [byte] */\r
-#define        CCIEF_BASIC_RX_RY_SIZE                                                          8                       /* Size of RX/RY [byte] */\r
-#define        CCIEF_BASIC_RWW_RWR_SIZE                                                        64                      /* Size of RWw/RWr [byte] */\r
-#define        CCIEF_BASIC_MAX_SLAVE_NUMBER                                            64                      /* Number of MAX slaves */\r
-#define        CCIEF_BASIC_MAX_GROUP_NUMBER                                            64                      /* Number of MAX groups */\r
-#define        CCIEF_BASIC_MAX_NUMBER_OF_OCCUPIED_STATIONS_GROUP       16                      /* Number of MAX occupied stations for group */\r
-#define        CCIEF_BASIC_SLMP_COMMAND_CYCLIC_DATA                            0x0E70          /* Cyclic Data(0E70h) of SLMP Command */\r
-#define        CCIEF_BASIC_MASTER_PERSUASION_TIME                                      2500            /* Master persuasion time(2500ms) [ms] */\r
-#define        CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT                         500                     /* Default cyclic transmission timeout [ms] */\r
-#define        CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT_COUNT           3                       /* Default count of cyclic transmission timeout */\r
-#define        CCIEF_BASIC_MAX_CONSTANT_LINK_SCAN_TIME                         2000            /* Constant link scan time MAX [ms] */\r
-#define        CCIEF_BASIC_UNIT_INFO_APPLICATION_STOP                          0x0000          /* Stopping application for setting the unit info */\r
-#define        CCIEF_BASIC_UNIT_INFO_APPLICATION_RUNNING                       0x0001          /* Running application for setting the unit info */\r
-\r
-/*[ Definition for CCIEF-BASIC End Code ]*/\r
-#define        CCIEF_BASIC_END_OK                                                                      0x0000          /* Processing success. */\r
-#define        CCIEF_BASIC_END_DUPLICATE_MASTER                                        0xCFE0          /* Duplicate of the master. */\r
-#define        CCIEF_BASIC_END_NUMBER_OF_OCCUPIED_STATIONS                     0xCFE1          /* Invalid number of occupied stations. */\r
-#define        CCIEF_BASIC_END_SLAVE                                                           0xCFF0          /* Error of the slave. */\r
-#define CCIEF_BASIC_END_DISCONNECTED_REQUEST                           0xCFFF          /* Disconnected request from Slave. */\r
-\r
-/*[ Definition for CCIEF-BASIC sample code ]*/\r
-#define        CCIEF_BASIC_BIT_ON                                                                      1                       /* Bit ON */\r
-#define        CCIEF_BASIC_BIT_OFF                                                                     0                       /* Bit OFF */\r
-#define        CCIEF_BASIC_CYCLIC_STATE_OFF                                            0                       /* Cyclic state OFF. */\r
-#define        CCIEF_BASIC_CYCLIC_STATE_ON                                                     1                       /* Cyclic state ON. */\r
-#define        CCIEF_BASIC_CYCLIC_START                                                        1                       /* Start the cyclic of the slave. */\r
-#define        CCIEF_BASIC_CYCLIC_STOP                                                         0                       /* Stop the cyclic of the slave. */\r
-#define        CCIEF_BASIC_SLAVE_ID_OCCUPIED_STATIONS                          0xFFFFFFFF      /* Slave Id of occupied stations. */\r
-#define        CCIEF_BASIC_CONSTANT_LINK_SCAN_NOT_USE                          0                       /* Not using the constant link scan. */\r
-#define        CCIEF_BASIC_CONSTANT_LINK_SCAN_USE                                      1                       /* Using the constant link scan. */\r
-#define        CCIEF_BASIC_DEVICE_TYPE_RX                                                      1                       /* Type of device for RX. */\r
-#define        CCIEF_BASIC_DEVICE_TYPE_RY                                                      2                       /* Type of device for RY. */\r
-#define        CCIEF_BASIC_DEVICE_TYPE_RWW                                                     3                       /* Type of device for RWw. */\r
-#define        CCIEF_BASIC_DEVICE_TYPE_RWR                                                     4                       /* Type of device for RWr. */\r
-#define        CCIEF_BASIC_SLAVE_DUPLICATION_NOT_DETECT                        0                       /* Slave dupsication not detect. */\r
-#define        CCIEF_BASIC_SLAVE_DUPLICATION_DETECT                            1                       /* Slave dupsication detect. */\r
-#define        CCIEF_BASIC_SLAVE_RESPONSE_NOT_RECEIVED                         0                       /* Response not receive. */\r
-#define        CCIEF_BASIC_SLAVE_RESPONSE_RECEIVED                                     1                       /* Response receive. */\r
-\r
-/*[ Definition for CCIEF-BASIC state ]*/\r
-/* Master */\r
-#define        CCIEF_BASIC_STATE_MASTER_INITAL                                         0                       /* Initialization of the master. */\r
-#define        CCIEF_BASIC_STATE_MASTER_WAITING                                        1                       /* Waiting for the cyclic operation. */\r
-#define        CCIEF_BASIC_STATE_MASTER_PERSUASION                                     2                       /* Persuasion of the master. */\r
-#define        CCIEF_BASIC_STATE_MASTER_LINK_SCAN_END                          3                       /* End of the link scan. */\r
-#define        CCIEF_BASIC_STATE_MASTER_LINK_SCAN                                      4                       /* Running the link scan. */\r
-/* Slave */\r
-#define        CCIEF_BASIC_STATE_SLAVE_INITAL                                          0                       /* Initialization of the slave. */\r
-#define        CCIEF_BASIC_STATE_SLAVE_DISCONNECT                                      1                       /* Disconnection of the cyclic network. */\r
-#define        CCIEF_BASIC_STATE_SLAVE_CONNECTING                                      2                       /* Connecting for the cyclic network. */\r
-#define        CCIEF_BASIC_STATE_SLAVE_CYCLIC_STOP                                     3                       /* Stop the cyclic operation. */\r
-#define        CCIEF_BASIC_STATE_SLAVE_CYCLIC_END                                      4                       /* End of the cyclic operation. */\r
-#define        CCIEF_BASIC_STATE_SLAVE_CYCLIC                                          5                       /* Running the cyclic operation. */\r
-\r
-/*[ Definition for CCIEF-BASIC event ]*/\r
-/* Master */\r
-#define        CCIEF_BASIC_EVENT_MASTER_INITAL                                         0                       /* Initialization of the master. */\r
-#define        CCIEF_BASIC_EVENT_MASTER_PARAMETER_GET                          1                       /* Getting the parameter. */\r
-#define        CCIEF_BASIC_EVENT_MASTER_PARAMETER_CHANGE                       2                       /* Changing the parameter. */\r
-#define        CCIEF_BASIC_EVENT_MASTER_PERSUASION_TIMEOUT                     3                       /* Timeout of monitoring the persuasion frame. */\r
-#define        CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_START                        4                       /* Starting the link scan. */\r
-#define        CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_END                          5                       /* End of the link scan. */\r
-#define        CCIEF_BASIC_EVENT_MASTER_CYCLIC_DATA_RECV                       6                       /* Receiving the cyclic data from the master. */\r
-#define        CCIEF_BASIC_EVENT_MASTER_DUPLICATION_ERR_RECV           7                       /* Receiving the error of the duplication master from the slave. */\r
-/* Slave */\r
-#define        CCIEF_BASIC_EVENT_SLAVE_INITAL                                          0                       /* Initialization of the slave. */\r
-#define        CCIEF_BASIC_EVENT_SLAVE_PARAMETER_CHANGE                        1                       /* Changing the parameter. */\r
-#define        CCIEF_BASIC_EVENT_SLAVE_LINK_SCAN_START                         2                       /* Starting the link scan. */\r
-#define        CCIEF_BASIC_EVENT_SLAVE_CYCLIC_DATA_RECV                        3                       /* Receiving the cyclic data from the slave. */\r
-#define        CCIEF_BASIC_EVENT_SLAVE_CYCLIC_DATA_TIMEOUT                     4                       /* Timeout the response of the cyclic data. */\r
-#define        CCIEF_BASIC_EVENT_SLAVE_CYCLIC_END                                      5                       /* The end of the cyclic data of all slaves. */\r
-#define        CCIEF_BASIC_EVENT_SLAVE_DUPLICATION_MASTER_ERR          6                       /* Receiving the error of the duplication master from the slave. */\r
-\r
-/*[ Structure for sample code ]*/\r
-typedef struct \r
-{\r
-       uint8_t         ucGroupNumber;                                          /* Group number */\r
-       uint16_t        usCyclicTransmissionTimeout;            /* Cyclic transmission timeout */\r
-       uint16_t        usCyclicTransmissionTimeoutCount;       /* Count of cyclic transmission timeout */\r
-       uint16_t        usConstantLinkScanTime;                         /* Constant link scan time */\r
-} CCIEF_BASIC_GROUP_PARAMETER;\r
-\r
-typedef struct \r
-{\r
-       uint32_t        ulIpAddress;                            /* Slave ip address */\r
-       uint16_t        usOccupiedStationNumber;        /* Number of occupied stations */\r
-       uint8_t         ucGroupNumber;                          /* Group number */\r
-} CCIEF_BASIC_SLAVE_PARAMETER;\r
-\r
-typedef struct \r
-{\r
-       int                                                     iTotalGroupNumber;                                              /* Total number of the groups */\r
-       CCIEF_BASIC_GROUP_PARAMETER     Group[CCIEF_BASIC_MAX_GROUP_NUMBER];    /* Parameter of the groups */\r
-       int                                                     iTotalSlaveNumber;                                              /* Total number of the slaves */\r
-       CCIEF_BASIC_SLAVE_PARAMETER     Slave[CCIEF_BASIC_MAX_SLAVE_NUMBER];    /* Parameter of the slaves */\r
-} CCIEF_BASIC_MASTER_PARAMETER;\r
-\r
-typedef struct \r
-{\r
-       uint16_t        usVenderCode;           /* Vender code */\r
-       uint16_t        usReserve1;                     /* Reserve */\r
-       uint32_t        ulModelCode;            /* Model code */\r
-       uint16_t        usMachineVersion;       /* Machine version */\r
-       uint16_t        usReserve2;                     /* Reserve */\r
-       uint16_t        usUnitInfo;                     /* Information of the unit */\r
-       uint16_t        usErrCode;                      /* Error code */\r
-       uint32_t        ulUnitData;                     /* Data of the unit */\r
-} CCIEF_BASIC_SLAVE_NOTIFY_INFO;\r
-\r
-typedef struct \r
-{\r
-       uint16_t                                                usProtocolVersion;                      /* Protocol version */\r
-       uint16_t                                                usEndCode;                                      /* Error code of the slave */\r
-       uint32_t                                                ulId;                                           /* Id of the slave */\r
-       uint8_t                                                 ucGroupNumber;                          /* Group number of the slave */\r
-       uint16_t                                                usFrameSequenceNumber;          /* Frame sequence number */\r
-       int                                                             usOccupiedStationNumber;        /* Number of occupied stations */\r
-       int                                                             iState;                                         /* State of the slave */\r
-       CCIEF_BASIC_SLAVE_NOTIFY_INFO   NotifyInfo;                                     /* Notify information from the slave */\r
-       int                                                             iCyclicState;                           /* Cyclic state */\r
-       int                                                             iStationNumber;                         /* Number of stations */\r
-} CCIEF_BASIC_SLAVE_INFO;\r
-\r
-typedef struct \r
-{\r
-       uint16_t        usProtocolVersion;                              /* Protocol version */\r
-       uint32_t        ulId;                                                   /* Id of the master */\r
-       uint8_t         ucGroupNumber;                                  /* Group number of the slave */\r
-       int                     iTotalSlaveNumber;                              /* Total number of the slaves */\r
-       int                     usTotalOccupiedStationNumber;   /* Total number of occupied stations */\r
-       int                     iState;                                                 /* State of Master */\r
-       uint16_t        usUnitInfo;                                             /* Information of the unit */\r
-       uint16_t        usFrameSequenceNumber;                  /* Frame sequence number */\r
-       uint16_t        usParameterId;                                  /* Parameter id */\r
-       int64_t         llTimeData;                                             /* Data of time */\r
-       int64_t         llLinkScanTimeCurrent;                  /* Current link scan time[us] */\r
-       int64_t         llLinkScanTimeMinimum;                  /* Minimum link scan time[us] */\r
-       int64_t         llLinkScanTimeMaximum;                  /* Maximum link scan time[us] */\r
-} CCIEF_BASIC_GROUP_INFO;\r
-\r
-/*[ Definition of callback function ]*/\r
-typedef void(*CCIEF_BASIC_MASTER_CALLBACK_CYCLIC_LINK_SCAN_END)( uint8_t ucGroupNumber );\r
-\r
-/* Definition of function of sample program */\r
-extern int ccief_basic_master_initialize( uint32_t ulIpAddress, uint32_t ulSubnetMask, CCIEF_BASIC_MASTER_PARAMETER *pParameter,\r
-                                                                               CCIEF_BASIC_MASTER_CALLBACK_CYCLIC_LINK_SCAN_END pCyclicLinkScanEndFunc );\r
-extern void ccief_basic_master_terminate( void );\r
-extern int ccief_basic_master_main( void );\r
-extern int ccief_basic_master_start_cyclic( int iSlaveNumber );\r
-extern int ccief_basic_master_stop_cyclic( int iSlaveNumber );\r
-extern int ccief_basic_master_get_rx( int iNumber, int *piValue );\r
-extern int ccief_basic_master_set_ry( int iNumber, int iValue );\r
-extern int ccief_basic_master_set_rww( int iNumber, uint16_t usValue );\r
-extern int ccief_basic_master_get_rwr( int iNumber, uint16_t *pusValue );\r
-extern uint16_t *ccief_basic_master_get_pointer( int iDeviceType );\r
-extern void ccief_basic_master_set_unit_info( uint16_t usUnitInfo );\r
-extern int ccief_basic_master_get_slave_info( int iSlaveNumber, CCIEF_BASIC_SLAVE_INFO *pSlaveInfo );\r
-extern int ccief_basic_master_get_group_info( int iGroupNumber, CCIEF_BASIC_GROUP_INFO *pGroupInfo );\r
-\r
-#endif\r
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/
+ * 
+ * 
+ *  Redistribution and use in source and binary forms, with or without 
+ *  modification, are permitted provided that the following conditions 
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the   
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#ifndef                __CCIEF_BASIC_MASTER_H__
+#define                __CCIEF_BASIC_MASTER_H__
+
+#include <stdint.h>
+
+/*[ Definition for sample code ]*/
+#define        CCIEF_BASIC_MASTER_ERR_OK                                                       0
+#define        CCIEF_BASIC_MASTER_ERR_NG                                                       (-1)
+#define CCIEF_BASIC_MASTER_ERR_DEVICE_RANGE                                    (-100)
+#define CCIEF_BASIC_MASTER_ERR_MASTER_DUPLICATION                      (-200)
+#define CCIEF_BASIC_MASTER_ERR_SLAVE_DUPLICATION                       (-300)
+
+/*[ Definition for CCIEF-BASIC environment ]*/
+#define        CCIEF_BASIC_PROTCOL_VERSION                                                     1                       /* Protocol Version */
+#define        CCIEF_BASIC_PORT_NUMBER_CYCLIC                                          61450           /* Port number of Cyclic */
+#define        CCIEF_BASIC_MAX_FRAME_SIZE                                                      6000            /* Size of MAX Packet [byte] */
+#define        CCIEF_BASIC_RX_RY_SIZE                                                          8                       /* Size of RX/RY [byte] */
+#define        CCIEF_BASIC_RWW_RWR_SIZE                                                        64                      /* Size of RWw/RWr [byte] */
+#define        CCIEF_BASIC_MAX_SLAVE_NUMBER                                            64                      /* Number of MAX slaves */
+#define        CCIEF_BASIC_MAX_GROUP_NUMBER                                            64                      /* Number of MAX groups */
+#define        CCIEF_BASIC_MAX_NUMBER_OF_OCCUPIED_STATIONS_GROUP       16                      /* Number of MAX occupied stations for group */
+#define        CCIEF_BASIC_SLMP_COMMAND_CYCLIC_DATA                            0x0E70          /* Cyclic Data(0E70h) of SLMP Command */
+#define        CCIEF_BASIC_MASTER_PERSUASION_TIME                                      2500            /* Master persuasion time(2500ms) [ms] */
+#define        CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT                         500                     /* Default cyclic transmission timeout [ms] */
+#define        CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT_COUNT           3                       /* Default count of cyclic transmission timeout */
+#define        CCIEF_BASIC_MAX_CONSTANT_LINK_SCAN_TIME                         2000            /* Constant link scan time MAX [ms] */
+#define        CCIEF_BASIC_UNIT_INFO_APPLICATION_STOP                          0x0000          /* Stopping application for setting the unit info */
+#define        CCIEF_BASIC_UNIT_INFO_APPLICATION_RUNNING                       0x0001          /* Running application for setting the unit info */
+
+/*[ Definition for CCIEF-BASIC End Code ]*/
+#define        CCIEF_BASIC_END_OK                                                                      0x0000          /* Processing success. */
+#define        CCIEF_BASIC_END_DUPLICATE_MASTER                                        0xCFE0          /* Duplicate of the master. */
+#define        CCIEF_BASIC_END_NUMBER_OF_OCCUPIED_STATIONS                     0xCFE1          /* Invalid number of occupied stations. */
+#define        CCIEF_BASIC_END_SLAVE                                                           0xCFF0          /* Error of the slave. */
+#define CCIEF_BASIC_END_DISCONNECTED_REQUEST                           0xCFFF          /* Disconnected request from Slave. */
+
+/*[ Definition for CCIEF-BASIC sample code ]*/
+#define        CCIEF_BASIC_BIT_ON                                                                      1                       /* Bit ON */
+#define        CCIEF_BASIC_BIT_OFF                                                                     0                       /* Bit OFF */
+#define        CCIEF_BASIC_CYCLIC_STATE_OFF                                            0                       /* Cyclic state OFF. */
+#define        CCIEF_BASIC_CYCLIC_STATE_ON                                                     1                       /* Cyclic state ON. */
+#define        CCIEF_BASIC_CYCLIC_START                                                        1                       /* Start the cyclic of the slave. */
+#define        CCIEF_BASIC_CYCLIC_STOP                                                         0                       /* Stop the cyclic of the slave. */
+#define        CCIEF_BASIC_SLAVE_ID_OCCUPIED_STATIONS                          0xFFFFFFFF      /* Slave Id of occupied stations. */
+#define        CCIEF_BASIC_CONSTANT_LINK_SCAN_NOT_USE                          0                       /* Not using the constant link scan. */
+#define        CCIEF_BASIC_CONSTANT_LINK_SCAN_USE                                      1                       /* Using the constant link scan. */
+#define        CCIEF_BASIC_DEVICE_TYPE_RX                                                      1                       /* Type of device for RX. */
+#define        CCIEF_BASIC_DEVICE_TYPE_RY                                                      2                       /* Type of device for RY. */
+#define        CCIEF_BASIC_DEVICE_TYPE_RWW                                                     3                       /* Type of device for RWw. */
+#define        CCIEF_BASIC_DEVICE_TYPE_RWR                                                     4                       /* Type of device for RWr. */
+#define        CCIEF_BASIC_SLAVE_DUPLICATION_NOT_DETECT                        0                       /* Slave dupsication not detect. */
+#define        CCIEF_BASIC_SLAVE_DUPLICATION_DETECT                            1                       /* Slave dupsication detect. */
+#define        CCIEF_BASIC_SLAVE_RESPONSE_NOT_RECEIVED                         0                       /* Response not receive. */
+#define        CCIEF_BASIC_SLAVE_RESPONSE_RECEIVED                                     1                       /* Response receive. */
+
+/*[ Definition for CCIEF-BASIC state ]*/
+/* Master */
+#define        CCIEF_BASIC_STATE_MASTER_INITAL                                         0                       /* Initialization of the master. */
+#define        CCIEF_BASIC_STATE_MASTER_WAITING                                        1                       /* Waiting for the cyclic operation. */
+#define        CCIEF_BASIC_STATE_MASTER_PERSUASION                                     2                       /* Persuasion of the master. */
+#define        CCIEF_BASIC_STATE_MASTER_LINK_SCAN_END                          3                       /* End of the link scan. */
+#define        CCIEF_BASIC_STATE_MASTER_LINK_SCAN                                      4                       /* Running the link scan. */
+/* Slave */
+#define        CCIEF_BASIC_STATE_SLAVE_INITAL                                          0                       /* Initialization of the slave. */
+#define        CCIEF_BASIC_STATE_SLAVE_DISCONNECT                                      1                       /* Disconnection of the cyclic network. */
+#define        CCIEF_BASIC_STATE_SLAVE_CONNECTING                                      2                       /* Connecting for the cyclic network. */
+#define        CCIEF_BASIC_STATE_SLAVE_CYCLIC_STOP                                     3                       /* Stop the cyclic operation. */
+#define        CCIEF_BASIC_STATE_SLAVE_CYCLIC_END                                      4                       /* End of the cyclic operation. */
+#define        CCIEF_BASIC_STATE_SLAVE_CYCLIC                                          5                       /* Running the cyclic operation. */
+
+/*[ Definition for CCIEF-BASIC event ]*/
+/* Master */
+#define        CCIEF_BASIC_EVENT_MASTER_INITAL                                         0                       /* Initialization of the master. */
+#define        CCIEF_BASIC_EVENT_MASTER_PARAMETER_GET                          1                       /* Getting the parameter. */
+#define        CCIEF_BASIC_EVENT_MASTER_PARAMETER_CHANGE                       2                       /* Changing the parameter. */
+#define        CCIEF_BASIC_EVENT_MASTER_PERSUASION_TIMEOUT                     3                       /* Timeout of monitoring the persuasion frame. */
+#define        CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_START                        4                       /* Starting the link scan. */
+#define        CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_END                          5                       /* End of the link scan. */
+#define        CCIEF_BASIC_EVENT_MASTER_CYCLIC_DATA_RECV                       6                       /* Receiving the cyclic data from the master. */
+#define        CCIEF_BASIC_EVENT_MASTER_DUPLICATION_ERR_RECV           7                       /* Receiving the error of the duplication master from the slave. */
+/* Slave */
+#define        CCIEF_BASIC_EVENT_SLAVE_INITAL                                          0                       /* Initialization of the slave. */
+#define        CCIEF_BASIC_EVENT_SLAVE_PARAMETER_CHANGE                        1                       /* Changing the parameter. */
+#define        CCIEF_BASIC_EVENT_SLAVE_LINK_SCAN_START                         2                       /* Starting the link scan. */
+#define        CCIEF_BASIC_EVENT_SLAVE_CYCLIC_DATA_RECV                        3                       /* Receiving the cyclic data from the slave. */
+#define        CCIEF_BASIC_EVENT_SLAVE_CYCLIC_DATA_TIMEOUT                     4                       /* Timeout the response of the cyclic data. */
+#define        CCIEF_BASIC_EVENT_SLAVE_CYCLIC_END                                      5                       /* The end of the cyclic data of all slaves. */
+#define        CCIEF_BASIC_EVENT_SLAVE_DUPLICATION_MASTER_ERR          6                       /* Receiving the error of the duplication master from the slave. */
+
+/*[ Structure for sample code ]*/
+typedef struct 
+{
+       uint8_t         ucGroupNumber;                                          /* Group number */
+       uint16_t        usCyclicTransmissionTimeout;            /* Cyclic transmission timeout */
+       uint16_t        usCyclicTransmissionTimeoutCount;       /* Count of cyclic transmission timeout */
+       uint16_t        usConstantLinkScanTime;                         /* Constant link scan time */
+} CCIEF_BASIC_GROUP_PARAMETER;
+
+typedef struct 
+{
+       uint32_t        ulIpAddress;                            /* Slave ip address */
+       uint16_t        usOccupiedStationNumber;        /* Number of occupied stations */
+       uint8_t         ucGroupNumber;                          /* Group number */
+} CCIEF_BASIC_SLAVE_PARAMETER;
+
+typedef struct 
+{
+       int                                                     iTotalGroupNumber;                                              /* Total number of the groups */
+       CCIEF_BASIC_GROUP_PARAMETER     Group[CCIEF_BASIC_MAX_GROUP_NUMBER];    /* Parameter of the groups */
+       int                                                     iTotalSlaveNumber;                                              /* Total number of the slaves */
+       CCIEF_BASIC_SLAVE_PARAMETER     Slave[CCIEF_BASIC_MAX_SLAVE_NUMBER];    /* Parameter of the slaves */
+} CCIEF_BASIC_MASTER_PARAMETER;
+
+typedef struct 
+{
+       uint16_t        usVenderCode;           /* Vender code */
+       uint16_t        usReserve1;                     /* Reserve */
+       uint32_t        ulModelCode;            /* Model code */
+       uint16_t        usMachineVersion;       /* Machine version */
+       uint16_t        usReserve2;                     /* Reserve */
+       uint16_t        usUnitInfo;                     /* Information of the unit */
+       uint16_t        usErrCode;                      /* Error code */
+       uint32_t        ulUnitData;                     /* Data of the unit */
+} CCIEF_BASIC_SLAVE_NOTIFY_INFO;
+
+typedef struct 
+{
+       uint16_t                                                usProtocolVersion;                      /* Protocol version */
+       uint16_t                                                usEndCode;                                      /* Error code of the slave */
+       uint32_t                                                ulId;                                           /* Id of the slave */
+       uint8_t                                                 ucGroupNumber;                          /* Group number of the slave */
+       uint16_t                                                usFrameSequenceNumber;          /* Frame sequence number */
+       int                                                             usOccupiedStationNumber;        /* Number of occupied stations */
+       int                                                             iState;                                         /* State of the slave */
+       CCIEF_BASIC_SLAVE_NOTIFY_INFO   NotifyInfo;                                     /* Notify information from the slave */
+       int                                                             iCyclicState;                           /* Cyclic state */
+       int                                                             iStationNumber;                         /* Number of stations */
+} CCIEF_BASIC_SLAVE_INFO;
+
+typedef struct 
+{
+       uint16_t        usProtocolVersion;                              /* Protocol version */
+       uint32_t        ulId;                                                   /* Id of the master */
+       uint8_t         ucGroupNumber;                                  /* Group number of the slave */
+       int                     iTotalSlaveNumber;                              /* Total number of the slaves */
+       int                     usTotalOccupiedStationNumber;   /* Total number of occupied stations */
+       int                     iState;                                                 /* State of Master */
+       uint16_t        usUnitInfo;                                             /* Information of the unit */
+       uint16_t        usFrameSequenceNumber;                  /* Frame sequence number */
+       uint16_t        usParameterId;                                  /* Parameter id */
+       int64_t         llTimeData;                                             /* Data of time */
+       int64_t         llLinkScanTimeCurrent;                  /* Current link scan time[us] */
+       int64_t         llLinkScanTimeMinimum;                  /* Minimum link scan time[us] */
+       int64_t         llLinkScanTimeMaximum;                  /* Maximum link scan time[us] */
+} CCIEF_BASIC_GROUP_INFO;
+
+/*[ Definition of callback function ]*/
+typedef void(*CCIEF_BASIC_MASTER_CALLBACK_CYCLIC_LINK_SCAN_END)( uint8_t ucGroupNumber );
+
+/* Definition of function of sample program */
+extern int ccief_basic_master_initialize( uint32_t ulIpAddress, uint32_t ulSubnetMask, CCIEF_BASIC_MASTER_PARAMETER *pParameter,
+                                                                               CCIEF_BASIC_MASTER_CALLBACK_CYCLIC_LINK_SCAN_END pCyclicLinkScanEndFunc );
+extern void ccief_basic_master_terminate( void );
+extern int ccief_basic_master_main( void );
+extern int ccief_basic_master_start_cyclic( int iSlaveNumber );
+extern int ccief_basic_master_stop_cyclic( int iSlaveNumber );
+extern int ccief_basic_master_get_rx( int iNumber, int *piValue );
+extern int ccief_basic_master_set_ry( int iNumber, int iValue );
+extern int ccief_basic_master_set_rww( int iNumber, uint16_t usValue );
+extern int ccief_basic_master_get_rwr( int iNumber, uint16_t *pusValue );
+extern uint16_t *ccief_basic_master_get_pointer( int iDeviceType );
+extern void ccief_basic_master_set_unit_info( uint16_t usUnitInfo );
+extern int ccief_basic_master_get_slave_info( int iSlaveNumber, CCIEF_BASIC_SLAVE_INFO *pSlaveInfo );
+extern int ccief_basic_master_get_group_info( int iGroupNumber, CCIEF_BASIC_GROUP_INFO *pGroupInfo );
+
+#endif
 /*EOF*/
\ No newline at end of file
index eb16578584e1a8f03f5e7d681bbd6b68240d9b86..076b9aba23d795477946367b08602238e974e65d 100644 (file)
@@ -1,81 +1,81 @@
-/*\r
- * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
- * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/\r
- * \r
- * \r
- *  Redistribution and use in source and binary forms, with or without \r
- *  modification, are permitted provided that the following conditions \r
- *  are met:\r
- *\r
- *    Redistributions of source code must retain the above copyright \r
- *    notice, this list of conditions and the following disclaimer.\r
- *\r
- *    Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the \r
- *    documentation and/or other materials provided with the   \r
- *    distribution.\r
- *\r
- *    Neither the name of Texas Instruments Incorporated nor the names of\r
- *    its contributors may be used to endorse or promote products derived\r
- *    from this software without specific prior written permission.\r
- *\r
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
-*/\r
-\r
-#ifndef                __CCIEF_BASIC_SLAVES_H__\r
-#define                __CCIEF_BASIC_SLAVES_H__\r
-\r
-#include <stdint.h>\r
-#include "CCIEF_BASIC_MASTER.h"\r
-\r
-/*[ Definition for CCIEF-BASIC Slaves ]*/\r
-#define        CCIEF_BASIC_CYCLIC_STATE_SET_CYCLIC_STOP                0                       /* Setting the cyclic state of stop cyclic. */\r
-#define        CCIEF_BASIC_CYCLIC_STATE_SET_CONNECTING                 1                       /* Setting the cyclic state of connecting. */\r
-#define        CCIEF_BASIC_CYCLIC_STATE_SET_CYCLIC                             2                       /* Setting the cyclic state of cyclic. */\r
-\r
-/*[ Structure for CCIEF-BASIC Slaves ]*/\r
-typedef struct\r
-{\r
-       CCIEF_BASIC_SLAVE_PARAMETER             *pParameter;                                            /* Parameter */\r
-       int                                                             iNumber;                                                        /* Slave Number */\r
-       uint32_t                                                ulId;                                                           /* Id number */\r
-       int                                                             iStationNumber;                                         /* Number of stations */\r
-       int                                                             iGroupStationNumber;                            /* Number of stations for the group */\r
-       int                                                             iCyclicStart;                                           /* Start cyclic of the user operation */\r
-       int                                                             iState;                                                         /* State of Slave */\r
-       int                                                             iCyclicState;                                           /* Cyclic state */\r
-       int                                                             iCyclicStateSet;                                        /* Setting of the cyclic state */\r
-       int                                                             iReceiveComplete;                                       /* State of response receive */\r
-       int                                                             iDuplicateState;                                        /* State of slave duplication */\r
-       uint16_t                                                *pusFrameSequenceNumber;                        /* Frame sequence number of the master */\r
-       uint16_t                                                usProtocolVersion;                                      /* Protocol version of the slave */\r
-       uint16_t                                                usEndCode;                                                      /* End code of the slave */\r
-       uint16_t                                                usFrameSequenceNumber;                          /* Frame sequence number of the slave */\r
-       CCIEF_BASIC_SLAVE_NOTIFY_INFO   NotifyInfo;                                                     /* Notification information of the slave */\r
-       uint16_t                                                usCyclicTransmissionTimeoutCount;       /* Count of cyclic transmission timeout */\r
-       uint16_t                                                usTimeoutCount;                                         /* Counter of timeout for the cyclic transmission timeout */\r
-       uint16_t                                                *pusRWw;                                                        /* Pointer of RWw for the packet */\r
-       uint16_t                                                *pusRY;                                                         /* Pointer of RY for the packet */\r
-       uint16_t                                                *pusRWr;                                                        /* Pointer of RWr for the packet */\r
-       uint16_t                                                *pusRX;                                                         /* Pointer of RX for the packet */\r
-       uint16_t                                                *pusSlaveRWr;                                           /* Pointer of RWr for the slave */\r
-       uint16_t                                                *pusSlaveRX;                                            /* Pointer of RX for the slave */\r
-} CCIEF_BASIC_SLAVES_CYCLIC_DATA_INFO;\r
-\r
-/* Definition of function of sample program */\r
-extern void ccief_basic_slaves_initialize( CCIEF_BASIC_SLAVES_CYCLIC_DATA_INFO *pSlave );\r
-extern void ccief_basic_slaves_execute_state( CCIEF_BASIC_SLAVES_CYCLIC_DATA_INFO *pSlave, int iEvent );\r
-\r
-#endif\r
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/
+ * 
+ * 
+ *  Redistribution and use in source and binary forms, with or without 
+ *  modification, are permitted provided that the following conditions 
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the   
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#ifndef                __CCIEF_BASIC_SLAVES_H__
+#define                __CCIEF_BASIC_SLAVES_H__
+
+#include <stdint.h>
+#include "CCIEF_BASIC_MASTER.h"
+
+/*[ Definition for CCIEF-BASIC Slaves ]*/
+#define        CCIEF_BASIC_CYCLIC_STATE_SET_CYCLIC_STOP                0                       /* Setting the cyclic state of stop cyclic. */
+#define        CCIEF_BASIC_CYCLIC_STATE_SET_CONNECTING                 1                       /* Setting the cyclic state of connecting. */
+#define        CCIEF_BASIC_CYCLIC_STATE_SET_CYCLIC                             2                       /* Setting the cyclic state of cyclic. */
+
+/*[ Structure for CCIEF-BASIC Slaves ]*/
+typedef struct
+{
+       CCIEF_BASIC_SLAVE_PARAMETER             *pParameter;                                            /* Parameter */
+       int                                                             iNumber;                                                        /* Slave Number */
+       uint32_t                                                ulId;                                                           /* Id number */
+       int                                                             iStationNumber;                                         /* Number of stations */
+       int                                                             iGroupStationNumber;                            /* Number of stations for the group */
+       int                                                             iCyclicStart;                                           /* Start cyclic of the user operation */
+       int                                                             iState;                                                         /* State of Slave */
+       int                                                             iCyclicState;                                           /* Cyclic state */
+       int                                                             iCyclicStateSet;                                        /* Setting of the cyclic state */
+       int                                                             iReceiveComplete;                                       /* State of response receive */
+       int                                                             iDuplicateState;                                        /* State of slave duplication */
+       uint16_t                                                *pusFrameSequenceNumber;                        /* Frame sequence number of the master */
+       uint16_t                                                usProtocolVersion;                                      /* Protocol version of the slave */
+       uint16_t                                                usEndCode;                                                      /* End code of the slave */
+       uint16_t                                                usFrameSequenceNumber;                          /* Frame sequence number of the slave */
+       CCIEF_BASIC_SLAVE_NOTIFY_INFO   NotifyInfo;                                                     /* Notification information of the slave */
+       uint16_t                                                usCyclicTransmissionTimeoutCount;       /* Count of cyclic transmission timeout */
+       uint16_t                                                usTimeoutCount;                                         /* Counter of timeout for the cyclic transmission timeout */
+       uint16_t                                                *pusRWw;                                                        /* Pointer of RWw for the packet */
+       uint16_t                                                *pusRY;                                                         /* Pointer of RY for the packet */
+       uint16_t                                                *pusRWr;                                                        /* Pointer of RWr for the packet */
+       uint16_t                                                *pusRX;                                                         /* Pointer of RX for the packet */
+       uint16_t                                                *pusSlaveRWr;                                           /* Pointer of RWr for the slave */
+       uint16_t                                                *pusSlaveRX;                                            /* Pointer of RX for the slave */
+} CCIEF_BASIC_SLAVES_CYCLIC_DATA_INFO;
+
+/* Definition of function of sample program */
+extern void ccief_basic_slaves_initialize( CCIEF_BASIC_SLAVES_CYCLIC_DATA_INFO *pSlave );
+extern void ccief_basic_slaves_execute_state( CCIEF_BASIC_SLAVES_CYCLIC_DATA_INFO *pSlave, int iEvent );
+
+#endif
 /*EOF*/
\ No newline at end of file
index 6966ebb49983541653c96f10b1ddc253922b8514..e8676345a25acaec91161691a05a95bb92e29f49 100644 (file)
@@ -1,67 +1,67 @@
-/*\r
- * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
- * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/\r
- * \r
- * \r
- *  Redistribution and use in source and binary forms, with or without \r
- *  modification, are permitted provided that the following conditions \r
- *  are met:\r
- *\r
- *    Redistributions of source code must retain the above copyright \r
- *    notice, this list of conditions and the following disclaimer.\r
- *\r
- *    Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the \r
- *    documentation and/or other materials provided with the   \r
- *    distribution.\r
- *\r
- *    Neither the name of Texas Instruments Incorporated nor the names of\r
- *    its contributors may be used to endorse or promote products derived\r
- *    from this software without specific prior written permission.\r
- *\r
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
-*/\r
-\r
-#ifndef                __SOCKET_H__\r
-#define                __SOCKET_H__\r
-\r
-#include <stdint.h>\r
-#ifdef _WIN32\r
-#include <winsock2.h>\r
-#elif __linux__\r
-#include <sys/socket.h>\r
-#endif\r
-\r
-/*[ Definition for sample code ]*/\r
-#define        SOCKET_ERR_OK                                                   0\r
-#define        SOCKET_ERR_SOCKET                                               (-100)\r
-#define        SOCKET_ERR_RECV                                                 (-103)\r
-#define        SOCKET_ERR_SEND                                                 (-104)\r
-#define        SOCKET_ERR_NO_RECEIVABLE                                (-200)\r
-\r
-/* Definition of function of sample code */\r
-#ifdef _WIN32\r
-extern int socket_initialize( SOCKET *sock, uint32_t ulIpAddress, uint16_t usPortNumber );\r
-extern void socket_terminate( SOCKET sock );\r
-extern int socket_recv( SOCKET sock, uint8_t *pucStream, int iLength, uint32_t *pulRecvAddr, uint16_t *pusRecvPortNumber );\r
-extern int socket_send( SOCKET sock, uint8_t *pucStream, int iLength, uint32_t ulSendAddr, uint16_t usSendPortNumber );\r
-#elif __linux__\r
-extern int socket_initialize( int *sock, uint32_t ulIpAddress, uint16_t usPortNumber );\r
-extern void socket_terminate( int sock );\r
-extern int socket_recv( int sock, uint8_t *pucStream, int iLength, uint32_t *pulRecvAddr, uint16_t *pusRecvPortNumber );\r
-extern int socket_send( int sock, uint8_t *pucStream, int iLength, uint32_t ulSendAddr, uint16_t usSendPortNumber );\r
-#endif\r
-\r
-#endif\r
-/*EOF*/\r
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/
+ * 
+ * 
+ *  Redistribution and use in source and binary forms, with or without 
+ *  modification, are permitted provided that the following conditions 
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the   
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#ifndef                __SOCKET_H__
+#define                __SOCKET_H__
+
+#include <stdint.h>
+#ifdef _WIN32
+#include <winsock2.h>
+#elif __linux__
+#include <sys/socket.h>
+#endif
+
+/*[ Definition for sample code ]*/
+#define        SOCKET_ERR_OK                                                   0
+#define        SOCKET_ERR_SOCKET                                               (-100)
+#define        SOCKET_ERR_RECV                                                 (-103)
+#define        SOCKET_ERR_SEND                                                 (-104)
+#define        SOCKET_ERR_NO_RECEIVABLE                                (-200)
+
+/* Definition of function of sample code */
+#ifdef _WIN32
+extern int socket_initialize( SOCKET *sock, uint32_t ulIpAddress, uint16_t usPortNumber );
+extern void socket_terminate( SOCKET sock );
+extern int socket_recv( SOCKET sock, uint8_t *pucStream, int iLength, uint32_t *pulRecvAddr, uint16_t *pusRecvPortNumber );
+extern int socket_send( SOCKET sock, uint8_t *pucStream, int iLength, uint32_t ulSendAddr, uint16_t usSendPortNumber );
+#elif __linux__
+extern int socket_initialize( int *sock, uint32_t ulIpAddress, uint16_t usPortNumber );
+extern void socket_terminate( int sock );
+extern int socket_recv( int sock, uint8_t *pucStream, int iLength, uint32_t *pulRecvAddr, uint16_t *pusRecvPortNumber );
+extern int socket_send( int sock, uint8_t *pucStream, int iLength, uint32_t ulSendAddr, uint16_t usSendPortNumber );
+#endif
+
+#endif
+/*EOF*/
index 93a2b58ae37df7f61f9ab88ba24646bad61ceb8f..14d35299030439bf84900ba8049eb340de232bcf 100644 (file)
@@ -1,72 +1,72 @@
-/*\r
- * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
- * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/\r
- * \r
- * \r
- *  Redistribution and use in source and binary forms, with or without \r
- *  modification, are permitted provided that the following conditions \r
- *  are met:\r
- *\r
- *    Redistributions of source code must retain the above copyright \r
- *    notice, this list of conditions and the following disclaimer.\r
- *\r
- *    Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the \r
- *    documentation and/or other materials provided with the   \r
- *    distribution.\r
- *\r
- *    Neither the name of Texas Instruments Incorporated nor the names of\r
- *    its contributors may be used to endorse or promote products derived\r
- *    from this software without specific prior written permission.\r
- *\r
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
-*/\r
-\r
-#ifndef                __TIMER_H__\r
-#define                __TIMER_H__\r
-\r
-#include <stdint.h>\r
-\r
-/*[ Definition for timer ]*/\r
-#define        TIMER_OK                                0\r
-#define        TIMER_RESOURCE_NONE             (-1)\r
-#define        TIMER_MAX                               100             /* Number of timer MAX */\r
-\r
-/*[ Structure for sample code ]*/\r
-typedef struct \r
-{\r
-       uint16_t        usYear;                         /* Year */\r
-       uint16_t        usMonth;                        /* Month */\r
-       uint16_t        usDay;                          /* Day */\r
-       uint16_t        usHour;                         /* Hour */\r
-       uint16_t        usMinute;                       /* Minute */\r
-       uint16_t        usSecond;                       /* Second */\r
-       uint16_t        usMilliseconds;         /* Milliseconds */\r
-} TIMER_TIME_DATA;\r
-\r
-/*[ Definition of callback function ]*/\r
-typedef void (*TIMER_CALLBACK)( int iId, void *pCallbackArg );\r
-\r
-/* Definition of function of the timer */\r
-extern void timer_initialize( void );\r
-extern void timer_terminate( void );\r
-extern void timer_main( void );\r
-extern int timer_start( long lTime, int *piId, TIMER_CALLBACK pCallbackFunc, void *pCallbackArg );\r
-extern void timer_stop( int iId );\r
-extern int64_t timer_get_time( void );\r
-extern int64_t timer_calculate_time_data( void );\r
-extern void timer_analyze_time_data( int64_t ullTime, TIMER_TIME_DATA *pTimeData );\r
-\r
-#endif\r
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/
+ * 
+ * 
+ *  Redistribution and use in source and binary forms, with or without 
+ *  modification, are permitted provided that the following conditions 
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the   
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#ifndef                __TIMER_H__
+#define                __TIMER_H__
+
+#include <stdint.h>
+
+/*[ Definition for timer ]*/
+#define        TIMER_OK                                0
+#define        TIMER_RESOURCE_NONE             (-1)
+#define        TIMER_MAX                               100             /* Number of timer MAX */
+
+/*[ Structure for sample code ]*/
+typedef struct 
+{
+       uint16_t        usYear;                         /* Year */
+       uint16_t        usMonth;                        /* Month */
+       uint16_t        usDay;                          /* Day */
+       uint16_t        usHour;                         /* Hour */
+       uint16_t        usMinute;                       /* Minute */
+       uint16_t        usSecond;                       /* Second */
+       uint16_t        usMilliseconds;         /* Milliseconds */
+} TIMER_TIME_DATA;
+
+/*[ Definition of callback function ]*/
+typedef void (*TIMER_CALLBACK)( int iId, void *pCallbackArg );
+
+/* Definition of function of the timer */
+extern void timer_initialize( void );
+extern void timer_terminate( void );
+extern void timer_main( void );
+extern int timer_start( long lTime, int *piId, TIMER_CALLBACK pCallbackFunc, void *pCallbackArg );
+extern void timer_stop( int iId );
+extern int64_t timer_get_time( void );
+extern int64_t timer_calculate_time_data( void );
+extern void timer_analyze_time_data( int64_t ullTime, TIMER_TIME_DATA *pTimeData );
+
+#endif
 /*EOF*/
\ No newline at end of file
index fa5f30d13e09bcc9f219c31369ed17870d41f8fa..db3e143b85959620b0265e6fa3904bfd42ff02f9 100644 (file)
@@ -1,65 +1,65 @@
-/*\r
- * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
- * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/\r
- * \r
- * \r
- *  Redistribution and use in source and binary forms, with or without \r
- *  modification, are permitted provided that the following conditions \r
- *  are met:\r
- *\r
- *    Redistributions of source code must retain the above copyright \r
- *    notice, this list of conditions and the following disclaimer.\r
- *\r
- *    Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the \r
- *    documentation and/or other materials provided with the   \r
- *    distribution.\r
- *\r
- *    Neither the name of Texas Instruments Incorporated nor the names of\r
- *    its contributors may be used to endorse or promote products derived\r
- *    from this software without specific prior written permission.\r
- *\r
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
-*/\r
-\r
-#ifndef                __USER_SAMPLE_H__\r
-#define                __USER_SAMPLE_H__\r
-\r
-#include <stdint.h>\r
-\r
-/*[ Definition of profile of the CCIEF-BASIC Slave (Please rewrite for user environment) ]*/\r
-#define        USER_PROFILE_VENDOR_CODE                                        0x1234\r
-#define        USER_PROFILE_MODEL_CODE                                         0x00000001\r
-#define        USER_PROFILE_MACHINE_VERSION                            0x0001\r
-\r
-/*[ Definition for user environment ]*/\r
-#define        USER_ERR_OK                                                             0\r
-#define        USER_ERR_NG                                                             (-1)\r
-#define        USER_EXIT                                                               1\r
-\r
-/*[ Definition of prameter for sample code (Please rewrite for user environment) ]*/\r
-/* Group */\r
-#define        USER_PARAMETER_GROUP_ID_TOTAL_NUMBER                                            1\r
-#define        USER_PARAMETER_GROUP_ID_GROUP_NUMBER                                            2\r
-#define        USER_PARAMETER_GROUP_ID_DISCONNECTION_DETECT_TIME                       3\r
-#define        USER_PARAMETER_GROUP_ID_DISCONNECTION_DETECT_TIME_COUNT         4\r
-#define        USER_PARAMETER_GROUP_ID_CONSTANT_LINK_SCAN_TIME                         5\r
-/* Parameter */\r
-#define        USER_PARAMETER_SLAVE_ID_TOTAL_NUMBER                                            1\r
-#define        USER_PARAMETER_SLAVE_ID_IP_ADDRESS                                                      2\r
-#define        USER_PARAMETER_SLAVE_ID_OCCUPIED_STATION_NUMBER                         3\r
-#define        USER_PARAMETER_SLAVE_ID_GROUP_NUMBER                                            4\r
-\r
-#endif\r
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/
+ * 
+ * 
+ *  Redistribution and use in source and binary forms, with or without 
+ *  modification, are permitted provided that the following conditions 
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the   
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#ifndef                __USER_SAMPLE_H__
+#define                __USER_SAMPLE_H__
+
+#include <stdint.h>
+
+/*[ Definition of profile of the CCIEF-BASIC Slave (Please rewrite for user environment) ]*/
+#define        USER_PROFILE_VENDOR_CODE                                        0x1234
+#define        USER_PROFILE_MODEL_CODE                                         0x00000001
+#define        USER_PROFILE_MACHINE_VERSION                            0x0001
+
+/*[ Definition for user environment ]*/
+#define        USER_ERR_OK                                                             0
+#define        USER_ERR_NG                                                             (-1)
+#define        USER_EXIT                                                               1
+
+/*[ Definition of prameter for sample code (Please rewrite for user environment) ]*/
+/* Group */
+#define        USER_PARAMETER_GROUP_ID_TOTAL_NUMBER                                            1
+#define        USER_PARAMETER_GROUP_ID_GROUP_NUMBER                                            2
+#define        USER_PARAMETER_GROUP_ID_DISCONNECTION_DETECT_TIME                       3
+#define        USER_PARAMETER_GROUP_ID_DISCONNECTION_DETECT_TIME_COUNT         4
+#define        USER_PARAMETER_GROUP_ID_CONSTANT_LINK_SCAN_TIME                         5
+/* Parameter */
+#define        USER_PARAMETER_SLAVE_ID_TOTAL_NUMBER                                            1
+#define        USER_PARAMETER_SLAVE_ID_IP_ADDRESS                                                      2
+#define        USER_PARAMETER_SLAVE_ID_OCCUPIED_STATION_NUMBER                         3
+#define        USER_PARAMETER_SLAVE_ID_GROUP_NUMBER                                            4
+
+#endif
 /*EOF*/
\ No newline at end of file
index df78cfbd3061643a0bd914d6d5e35873de2617fd..a0ef65db3760e237b772bbecd88bc7e179972338 100644 (file)
-/*\r
- * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
- * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/\r
- * \r
- * \r
- *  Redistribution and use in source and binary forms, with or without \r
- *  modification, are permitted provided that the following conditions \r
- *  are met:\r
- *\r
- *    Redistributions of source code must retain the above copyright \r
- *    notice, this list of conditions and the following disclaimer.\r
- *\r
- *    Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the \r
- *    documentation and/or other materials provided with the   \r
- *    distribution.\r
- *\r
- *    Neither the name of Texas Instruments Incorporated nor the names of\r
- *    its contributors may be used to endorse or promote products derived\r
- *    from this software without specific prior written permission.\r
- *\r
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
-*/\r
-\r
-#include "SLMP.h"\r
-#include "CCIEF_BASIC_MASTER.h"\r
-#include "CCIEF_BASIC_SLAVES.h"\r
-#include "SOCKET.h"\r
-#include "TIMER.h"\r
-\r
-/************************************************************************************/\r
-/* The following is an user defined main program. This main program is one of a                */\r
-/* sample in the Windows OS and Intel x86 CPU. Please rewrite if necessary.                    */\r
-/* This main program is one of a sample in the Linux. Please rewrite if necessary.     */\r
-/*                                                                                                                                                                     */\r
-/* This sample program for CCIEF-BASIC Slave Application.                                                      */\r
-/*                                                                                                                                                                     */\r
-/************************************************************************************/\r
-\r
-#ifdef _WIN32\r
-#include <WinSock2.h>\r
-#include <Ws2tcpip.h>\r
-#include <windows.h>\r
-#elif __linux__\r
-#include <sys/socket.h>\r
-#include <netinet/in.h>\r
-#include <string.h>\r
-#endif\r
-#include <stdio.h>\r
-#include <time.h>\r
-\r
-#ifdef _WIN32\r
-#elif __linux__\r
-#define INVALID_SOCKET         -1\r
-#endif\r
-\r
-/*[ Structure for Information of the CCIEF-BASIC Master ]*/\r
-typedef struct \r
-{\r
-       uint8_t                                                         ucGroupNumber;                                                          /* Group number */\r
-       int                                                                     iTotalSlaveNumber;                                                      /* Total number of the slaves */\r
-       int                                                                     iOccupiedStationNumberTotal;                            /* Total number of the occupied station number */\r
-       int                                                                     iState;                                                                         /* State of Master */\r
-       CCIEF_BASIC_GROUP_PARAMETER                     *pGroupParameter;                                                       /* Pointer of the group parameter */\r
-       CCIEF_BASIC_SLAVES_CYCLIC_DATA_INFO     *pSlave[CCIEF_BASIC_MAX_SLAVE_NUMBER];          /* Pointer of information of the slaves */\r
-       uint16_t                                                        usFrameSequenceNumber;                                          /* Frame sequence number */\r
-       int                                                                     iPersuasionTimerId;                                                     /* Timer id for persuasion */\r
-       int                                                                     iCyclicTimerId;                                                         /* Timer id for cyclic time */\r
-       uint8_t                                                         aucCyclicData[CCIEF_BASIC_MAX_FRAME_SIZE];      /* Data for sending cyclic data */\r
-       int                                                                     iCyclicDataSize;                                                        /* Size of data for sending cyclic data */\r
-       int                                                                     iConstantLinkScanUse;                                           /* Using the constant link scan */\r
-       uint32_t                                                        ulResponseWaitTime;                                                     /* Time of waiting response[ms] */\r
-       int64_t                                                         llTimeData;                                                                     /* Time data of the sending latest cyclic data */\r
-       int64_t                                                         llLinkScanTimeStart;                                            /* Start time of link scan[us] */\r
-       int64_t                                                         llLinkScanTimeCurrent;                                          /* Current the link scan time[us] */\r
-       int64_t                                                         llLinkScanTimeMinimum;                                          /* Minimum the link scan time[us] */\r
-       int64_t                                                         llLinkScanTimeMaximum;                                          /* Maximum the link scan time[us] */\r
-} CCIEF_BASIC_MASTER_GROUP_INFO;\r
-\r
-#ifdef _WIN32\r
-typedef struct \r
-{\r
-       uint32_t                                                ulIpAddress;                                                    /* Ip address */\r
-       CCIEF_BASIC_MASTER_PARAMETER    Parameter;                                                              /* Parameter */\r
-       int                                                             iGroupTotalNumber;                                              /* Total number of the groups */\r
-       CCIEF_BASIC_MASTER_GROUP_INFO   *pGroup[CCIEF_BASIC_MAX_GROUP_NUMBER];  /* Pointer of information of the groups */\r
-       uint32_t                                                ulId;                                                                   /* Id number */\r
-       uint32_t                                                ulDirectedIpAddress;                                    /* Directed broadcast ip address */\r
-       int                                                             iOccupiedStationNumberTotal;                    /* Total number of the occupied station number */\r
-       uint16_t                                                usParameterId;                                                  /* Parameter id */\r
-       uint16_t                                                usUnitInfo;                                                             /* Information of the unit */\r
-       int                                                             iErrCode;                                                               /* Error code of the master */\r
-} CCIEF_BASIC_MASTER_CYCLIC_DATA_INFO;\r
-#elif __linux__\r
-typedef struct \r
-{\r
-       uint32_t                                                ulIpAddress;                                                    /* Ip address */\r
-       uint32_t                                                ulSubnetMask;                                                   /* Slave subnet mask */\r
-       CCIEF_BASIC_MASTER_PARAMETER    Parameter;                                                              /* Parameter */\r
-       int                                                             iGroupTotalNumber;                                              /* Total number of the groups */\r
-       CCIEF_BASIC_MASTER_GROUP_INFO   *pGroup[CCIEF_BASIC_MAX_GROUP_NUMBER];  /* Pointer of information of the groups */\r
-       uint32_t                                                ulId;                                                                   /* Id number */\r
-       uint32_t                                                ulDirectedIpAddress;                                    /* Directed broadcast ip address */\r
-       int                                                             iOccupiedStationNumberTotal;                    /* Total number of the occupied station number */\r
-       uint16_t                                                usParameterId;                                                  /* Parameter id */\r
-       uint16_t                                                usUnitInfo;                                                             /* Information of the unit */\r
-       int                                                             iErrCode;                                                               /* Error code of the master */\r
-} CCIEF_BASIC_MASTER_CYCLIC_DATA_INFO;\r
-#endif\r
-\r
-/* Definition of external variable of sample program */\r
-#ifdef _WIN32\r
-static SOCKET sock;            /* sokect of CCIEF-BASIC Master */\r
-#elif __linux__\r
-static int sock;               /* sokect of CCIEF-BASIC Master */\r
-#endif\r
-\r
-static unsigned char   aucSendData[CCIEF_BASIC_MAX_FRAME_SIZE];        /* Data for sending packet */\r
-static unsigned char   aucRecvData[CCIEF_BASIC_MAX_FRAME_SIZE];        /* Data for receiving packet */\r
-static unsigned char   aucSendPacket[CCIEF_BASIC_MAX_FRAME_SIZE];      /* Buffer for sending packet */\r
-static unsigned char   aucRecvPacket[CCIEF_BASIC_MAX_FRAME_SIZE];      /* Buffer for receiving packet */\r
-\r
-static unsigned short  ausRX[(CCIEF_BASIC_RX_RY_SIZE / sizeof( uint16_t )) * CCIEF_BASIC_MAX_SLAVE_NUMBER];    /* RX for the master */\r
-static unsigned short  ausRY[(CCIEF_BASIC_RX_RY_SIZE / sizeof( uint16_t )) * CCIEF_BASIC_MAX_SLAVE_NUMBER];    /* RY for the master */\r
-static unsigned short  ausRWw[(CCIEF_BASIC_RWW_RWR_SIZE / sizeof( uint16_t )) * CCIEF_BASIC_MAX_SLAVE_NUMBER]; /* RWw for the master */\r
-static unsigned short  ausRWr[(CCIEF_BASIC_RWW_RWR_SIZE / sizeof( uint16_t )) * CCIEF_BASIC_MAX_SLAVE_NUMBER]; /* RWr for the master */\r
-\r
-static CCIEF_BASIC_MASTER_CALLBACK_CYCLIC_LINK_SCAN_END        pUserLinkScanEndFunc = NULL;    /* Callback function for end of the link scan */\r
-\r
-static CCIEF_BASIC_MASTER_CYCLIC_DATA_INFO     Master;                                                                 /* Information of the master */\r
-static CCIEF_BASIC_MASTER_GROUP_INFO           Group[CCIEF_BASIC_MAX_GROUP_NUMBER];    /* Information of the groups */\r
-static CCIEF_BASIC_SLAVES_CYCLIC_DATA_INFO     Slave[CCIEF_BASIC_MAX_SLAVE_NUMBER];    /* Information of the slaves cyclic data */\r
-\r
-/* Definition of function of sample program */\r
-static int ccief_basic_master_check_parameter( CCIEF_BASIC_MASTER_PARAMETER *pParameter );\r
-static int ccief_basic_master_recv( void );\r
-static int ccief_basic_master_polling( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup );\r
-static void ccief_basic_master_execute_state( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent );\r
-static void ccief_basic_master_execute_state_wait_cyclic( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent );\r
-static void ccief_basic_master_execute_state_persuasion( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent );\r
-static void ccief_basic_master_execute_state_linkscan_end( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent );\r
-static void ccief_basic_master_execute_state_linkscan( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent );\r
-static void ccief_basic_master_persuasion_timer_timeout( int iId, void *pCallbackArg );\r
-static void ccief_basic_master_cyclic_timer_timeout( int iId, void *pCallbackArg );\r
-static int ccief_basic_master_make_cyclic_data( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup );\r
-static int ccief_basic_master_send_cyclic_data( uint32_t ulIpAddress, uint8_t *pucData, int iDataSize );\r
-static void ccief_basic_master_recv_cyclic_data_response( uint8_t *pucData );\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for initialization of CCIEF-BASIC Master.                  */\r
-/************************************************************************************/\r
-int ccief_basic_master_initialize( uint32_t ulIpAddress, uint32_t ulSubnetMask, CCIEF_BASIC_MASTER_PARAMETER *pParameter,\r
-                                                                CCIEF_BASIC_MASTER_CALLBACK_CYCLIC_LINK_SCAN_END pCyclicLinkScanEndFunc )\r
-{\r
-       CCIEF_BASIC_MASTER_GROUP_INFO           *pGroup;\r
-       CCIEF_BASIC_SLAVES_CYCLIC_DATA_INFO *pSlave;\r
-       uint8_t ucGroupNumber;\r
-       int i, j, iGroupCheck;\r
-       int iErrCode;\r
-\r
-       /* Initialize of the master */\r
-       memset( &Master, 0, sizeof( Master ) );\r
-       memset( &Group, 0, sizeof( Group ) );\r
-       pGroup = (CCIEF_BASIC_MASTER_GROUP_INFO*)NULL;\r
-\r
-       /* Getting the parameter */\r
-       memcpy( &Master.Parameter, pParameter, sizeof( Master.Parameter ) );\r
-\r
-       /* User callback function */\r
-       pUserLinkScanEndFunc = pCyclicLinkScanEndFunc;\r
-\r
-       /* Setting the master information */\r
-       Master.ulIpAddress = ulIpAddress;\r
-       Master.ulId = ulIpAddress;\r
-#ifdef _WIN32\r
-#elif __linux__\r
-       Master.ulSubnetMask = ulSubnetMask;\r
-#endif\r
-       Master.ulDirectedIpAddress = ((ulIpAddress & ulSubnetMask) | ~ulSubnetMask);\r
-\r
-       /* Check the Parameter */\r
-       iErrCode = ccief_basic_master_check_parameter( pParameter );\r
-       if ( iErrCode != CCIEF_BASIC_MASTER_ERR_OK )\r
-       {\r
-               return iErrCode;\r
-       }\r
-\r
-       for ( i = 0; i < pParameter->iTotalSlaveNumber; i ++ )\r
-       {\r
-               ucGroupNumber = pParameter->Slave[i].ucGroupNumber;\r
-               iGroupCheck = CCIEF_BASIC_MASTER_ERR_NG;\r
-               for ( j = 0; j < Master.iGroupTotalNumber; j ++ )\r
-               {\r
-                       if ( ucGroupNumber == Master.pGroup[j]->ucGroupNumber )\r
-                       {\r
-                               pGroup = Master.pGroup[j];\r
-                               iGroupCheck = CCIEF_BASIC_MASTER_ERR_OK;\r
-                               break;\r
-                       }\r
-               }\r
-               if ( iGroupCheck == CCIEF_BASIC_MASTER_ERR_NG )\r
-               {\r
-                       pGroup = &Group[Master.iGroupTotalNumber];\r
-                       pGroup->ucGroupNumber = ucGroupNumber;\r
-                       for ( j = 0; j < pParameter->iTotalGroupNumber; j ++ )\r
-                       {\r
-                               if ( ucGroupNumber == pParameter->Group[j].ucGroupNumber )\r
-                               {\r
-                                       break;\r
-                               }\r
-                       }\r
-                       pGroup->pGroupParameter = &pParameter->Group[j];\r
-                       Master.pGroup[Master.iGroupTotalNumber] = pGroup;\r
-                       Master.iGroupTotalNumber ++;\r
-               }\r
-               pSlave = &Slave[i];\r
-               pSlave->iNumber = i;\r
-               pSlave->pParameter = &Master.Parameter.Slave[i];\r
-               pSlave->ulId = pParameter->Slave[i].ulIpAddress;\r
-               if ( pGroup->pGroupParameter->usCyclicTransmissionTimeoutCount == 0 )\r
-               {\r
-                       pSlave->usCyclicTransmissionTimeoutCount = CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT_COUNT;\r
-               }\r
-               else\r
-               {\r
-                       pSlave->usCyclicTransmissionTimeoutCount = pGroup->pGroupParameter->usCyclicTransmissionTimeoutCount;\r
-               }\r
-               pSlave->iStationNumber = Master.iOccupiedStationNumberTotal;\r
-               pSlave->iGroupStationNumber = pGroup->iOccupiedStationNumberTotal;\r
-               pSlave->iReceiveComplete = CCIEF_BASIC_SLAVE_RESPONSE_NOT_RECEIVED;\r
-               pSlave->iDuplicateState = CCIEF_BASIC_SLAVE_DUPLICATION_NOT_DETECT;\r
-               pSlave->pusRWw = &ausRWw[pSlave->iStationNumber * ( CCIEF_BASIC_RWW_RWR_SIZE / sizeof( uint16_t ) )];\r
-               pSlave->pusRY = &ausRY[pSlave->iStationNumber * ( CCIEF_BASIC_RX_RY_SIZE / sizeof( uint16_t ) )];\r
-               pSlave->pusRWr = &ausRWr[pSlave->iStationNumber * ( CCIEF_BASIC_RWW_RWR_SIZE / sizeof( uint16_t ) )];\r
-               pSlave->pusRX = &ausRX[pSlave->iStationNumber * ( CCIEF_BASIC_RX_RY_SIZE / sizeof( uint16_t ) )];\r
-               pSlave->pusFrameSequenceNumber = &pGroup->usFrameSequenceNumber;\r
-               pGroup->pSlave[pGroup->iTotalSlaveNumber] = pSlave;\r
-               pGroup->iTotalSlaveNumber ++;\r
-               pGroup->iOccupiedStationNumberTotal += pParameter->Slave[i].usOccupiedStationNumber;\r
-               Master.iOccupiedStationNumberTotal += pParameter->Slave[i].usOccupiedStationNumber;\r
-       }\r
-\r
-       /* Calucurate of the parameter id */\r
-       srand( (unsigned)time( NULL ) );\r
-       Master.usParameterId = (uint16_t)rand();\r
-\r
-       /* Initialize a socket */\r
-       sock = INVALID_SOCKET;\r
-\r
-       /* Initialize of the slaves */\r
-       for ( i = 0; i < Master.Parameter.iTotalSlaveNumber; i ++ )\r
-       {\r
-               ccief_basic_slaves_initialize( &Slave[i] );\r
-       }\r
-\r
-       for ( i = 0; i < Master.iGroupTotalNumber; i ++ )\r
-       {\r
-               /* Set the master state */\r
-               Master.pGroup[i]->iState = CCIEF_BASIC_STATE_MASTER_WAITING;\r
-\r
-               /* Execute the state of the master */\r
-               ccief_basic_master_execute_state( Master.pGroup[i], CCIEF_BASIC_EVENT_MASTER_PARAMETER_GET );\r
-       }\r
-\r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for termination of CCIEF-BASIC Master.                     */\r
-/************************************************************************************/\r
-void ccief_basic_master_terminate( void )\r
-{\r
-       /* Termination of socket */\r
-       socket_terminate( sock );\r
-\r
-       return;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for main function of CCIEF-BASIC Master.                   */\r
-/************************************************************************************/\r
-int ccief_basic_master_main( void )\r
-{\r
-       int i, iErrCode = 0;\r
-\r
-       /* Receive data */\r
-       iErrCode = ccief_basic_master_recv();\r
-       if ( iErrCode != CCIEF_BASIC_MASTER_ERR_OK )\r
-       {\r
-               return iErrCode;\r
-       }\r
-\r
-       /* Execute the state of the master */\r
-       for ( i = 0; i < Master.iGroupTotalNumber; i ++ )\r
-       {\r
-               (void)ccief_basic_master_polling( Master.pGroup[i] );\r
-       }\r
-\r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for set of the start cyclic of the slave.          */\r
-/************************************************************************************/\r
-int ccief_basic_master_start_cyclic( int iSlaveNumber )\r
-{\r
-       if (( iSlaveNumber < 0 ) || ( Master.Parameter.iTotalSlaveNumber <= iSlaveNumber ))\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_NG;\r
-       }\r
-\r
-       /* Start cyclic from user operation. */\r
-       Slave[iSlaveNumber].iCyclicStart = CCIEF_BASIC_CYCLIC_START;\r
-\r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for set of the stop cyclic of the slave.           */\r
-/************************************************************************************/\r
-int ccief_basic_master_stop_cyclic( int iSlaveNumber )\r
-{\r
-       if (( iSlaveNumber < 0 ) || ( Master.Parameter.iTotalSlaveNumber <= iSlaveNumber ))\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_NG;\r
-       }\r
-\r
-       /* Stop cyclic from user operation. */\r
-       Slave[iSlaveNumber].iCyclicStart = CCIEF_BASIC_CYCLIC_STOP;\r
-\r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for getting the RX.                                                                */\r
-/************************************************************************************/\r
-int ccief_basic_master_get_rx( int iNumber, int *piValue )\r
-{\r
-       unsigned short usTemp;\r
-\r
-       /* Check the number of device */\r
-       if (( iNumber < 0 ) || ( sizeof( ausRX ) * 8 ) <= iNumber )\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_DEVICE_RANGE;\r
-       }\r
-\r
-       usTemp = ausRX[iNumber / 16];\r
-       if (( usTemp & ( 1 << ( iNumber % 16 ))) == CCIEF_BASIC_BIT_OFF )\r
-       {\r
-               *piValue = CCIEF_BASIC_BIT_OFF;\r
-       }\r
-       else\r
-       {\r
-               *piValue = CCIEF_BASIC_BIT_ON;\r
-       }\r
-       \r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for setting the RY.                                                                */\r
-/************************************************************************************/\r
-int ccief_basic_master_set_ry( int iNumber, int iValue )\r
-{\r
-       unsigned short usTemp;\r
-\r
-       /* Check the number of device */\r
-       if (( iNumber < 0 ) || ( sizeof( ausRY ) * 8 ) <= iNumber )\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_DEVICE_RANGE;\r
-       }\r
-\r
-       /* Check the value */\r
-       if (( iValue == CCIEF_BASIC_BIT_OFF ) || ( iValue == CCIEF_BASIC_BIT_ON ))\r
-       {\r
-               usTemp = ausRY[( iNumber / 16 )];\r
-               usTemp = (uint16_t)(( usTemp & ~( 1 << ( iNumber % 16 ))) | ( iValue << ( iNumber % 16 )));\r
-               ausRY[( iNumber / 16 )] = usTemp;\r
-       }\r
-       else\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_NG;\r
-       }\r
-\r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for setting the RWw.                                                       */\r
-/************************************************************************************/\r
-int ccief_basic_master_set_rww( int iNumber, uint16_t usValue )\r
-{\r
-       int iMaxNumber;\r
-\r
-       /* Check the number of device */\r
-       iMaxNumber = sizeof( ausRWw ) / sizeof( uint16_t );\r
-       if (( iNumber < 0 ) || (iMaxNumber <= iNumber ))\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_DEVICE_RANGE;\r
-       }\r
-\r
-       ausRWw[iNumber] = usValue;\r
-       \r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for getting the RWr.                                                       */\r
-/************************************************************************************/\r
-int ccief_basic_master_get_rwr( int iNumber, uint16_t *pusValue )\r
-{\r
-       int iMaxNumber;\r
-\r
-       /* Check the number of device */\r
-       iMaxNumber = sizeof( ausRWr ) / sizeof( uint16_t );\r
-       if (( iNumber < 0 ) || (iMaxNumber <= iNumber ))\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_DEVICE_RANGE;\r
-       }\r
-\r
-       *pusValue = ausRWr[iNumber];\r
-       \r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for getting the device start pointer.                      */\r
-/************************************************************************************/\r
-uint16_t *ccief_basic_master_get_pointer( int iDeviceType )\r
-{\r
-       uint16_t *pusStartPointer;\r
-\r
-       /* Getting the device start pointer */\r
-\r
-       /* Check the device type */\r
-       switch ( iDeviceType )\r
-       {\r
-               /* RX */\r
-               case CCIEF_BASIC_DEVICE_TYPE_RX:\r
-                       pusStartPointer = ausRX;\r
-                       break;\r
-               /* RY */\r
-               case CCIEF_BASIC_DEVICE_TYPE_RY:\r
-                       pusStartPointer = ausRY;\r
-                       break;\r
-               /* RWw */\r
-               case CCIEF_BASIC_DEVICE_TYPE_RWW:\r
-                       pusStartPointer = ausRWw;\r
-                       break;\r
-               /* RWr */\r
-               case CCIEF_BASIC_DEVICE_TYPE_RWR:\r
-                       pusStartPointer = ausRWr;\r
-                       break;\r
-               /* Error of argument */\r
-               default:\r
-                       pusStartPointer = NULL;\r
-                       break;\r
-       }\r
-       \r
-       return pusStartPointer;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for setting the unit info.                                         */\r
-/************************************************************************************/\r
-void ccief_basic_master_set_unit_info( uint16_t usUnitInfo )\r
-{\r
-       Master.usUnitInfo = usUnitInfo;\r
-\r
-       return;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for getting information of the slave.                      */\r
-/************************************************************************************/\r
-int ccief_basic_master_get_slave_info( int iSlaveNumber, CCIEF_BASIC_SLAVE_INFO *pSlaveInfo )\r
-{\r
-\r
-       if (( iSlaveNumber < 0 ) || ( Master.Parameter.iTotalSlaveNumber <= iSlaveNumber ))\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_NG;\r
-       }\r
-\r
-       if ( pSlaveInfo == NULL )\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_NG;\r
-       }\r
-\r
-       /* Getting information of the slave */\r
-       pSlaveInfo->usProtocolVersion = Slave[iSlaveNumber].usProtocolVersion;\r
-       pSlaveInfo->usEndCode = Slave[iSlaveNumber].usEndCode;\r
-       pSlaveInfo->ucGroupNumber = Slave[iSlaveNumber].pParameter->ucGroupNumber;\r
-       pSlaveInfo->ulId = Slave[iSlaveNumber].ulId;\r
-       pSlaveInfo->usFrameSequenceNumber = Slave[iSlaveNumber].usFrameSequenceNumber;\r
-       pSlaveInfo->usOccupiedStationNumber = Slave[iSlaveNumber].pParameter->usOccupiedStationNumber;\r
-       pSlaveInfo->iState = Slave[iSlaveNumber].iState;\r
-       memcpy( &pSlaveInfo->NotifyInfo, &Slave[iSlaveNumber].NotifyInfo, sizeof( pSlaveInfo->NotifyInfo ) );\r
-       pSlaveInfo->iCyclicState = Slave[iSlaveNumber].iCyclicState;\r
-       pSlaveInfo->iStationNumber = Slave[iSlaveNumber].iStationNumber;\r
-\r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for getting information of the master.                     */\r
-/************************************************************************************/\r
-int ccief_basic_master_get_group_info( int iGroupNumber, CCIEF_BASIC_GROUP_INFO *pGroupInfo )\r
-{\r
-\r
-       if ( pGroupInfo == NULL )\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_NG;\r
-       }\r
-\r
-       /* Getting information of the master */\r
-       pGroupInfo->usProtocolVersion = CCIEF_BASIC_PROTCOL_VERSION;\r
-       pGroupInfo->ulId = Master.ulId;\r
-       pGroupInfo->ucGroupNumber = Group[iGroupNumber].ucGroupNumber;\r
-       pGroupInfo->iTotalSlaveNumber = Group[iGroupNumber].iTotalSlaveNumber;\r
-       pGroupInfo->usTotalOccupiedStationNumber = Group[iGroupNumber].iOccupiedStationNumberTotal;\r
-       pGroupInfo->iState = Group[iGroupNumber].iState;\r
-       pGroupInfo->usUnitInfo = Master.usUnitInfo;\r
-       pGroupInfo->usFrameSequenceNumber = Group[iGroupNumber].usFrameSequenceNumber;\r
-       pGroupInfo->usParameterId = Master.usParameterId;\r
-       pGroupInfo->llTimeData = Group[iGroupNumber].llTimeData;\r
-       pGroupInfo->llLinkScanTimeCurrent = Group[iGroupNumber].llLinkScanTimeCurrent;\r
-       pGroupInfo->llLinkScanTimeMinimum = Group[iGroupNumber].llLinkScanTimeMinimum;\r
-       pGroupInfo->llLinkScanTimeMaximum = Group[iGroupNumber].llLinkScanTimeMaximum;\r
-\r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for check the parameter of CCIEF-BASIC Master.     */\r
-/************************************************************************************/\r
-int ccief_basic_master_check_parameter( CCIEF_BASIC_MASTER_PARAMETER *pParameter )\r
-{\r
-       int     i, j, iOccupiedStationNumberTotal;\r
-       struct in_addr addr;\r
-       char Ipaddr[16];\r
-\r
-       /* Check the master ip address */\r
-       for ( i = 0; i < pParameter->iTotalSlaveNumber; i ++ )\r
-       {\r
-               if ( Master.ulIpAddress == pParameter->Slave[i].ulIpAddress )\r
-               {\r
-                       printf( "Parameter Error: Duplicate master ip address in slaves!\n" );\r
-                       return CCIEF_BASIC_MASTER_ERR_NG;\r
-               }\r
-       }\r
-\r
-       /* Check the total number of the slaves */\r
-       if (( pParameter->iTotalSlaveNumber == 0 ) || ( CCIEF_BASIC_MAX_SLAVE_NUMBER < pParameter->iTotalSlaveNumber )) {\r
-               printf( "Parameter Error: Out of range of total slave number! %d (range: 1-64)\n", pParameter->iTotalSlaveNumber );\r
-               return CCIEF_BASIC_MASTER_ERR_NG;\r
-       }\r
-       \r
-       /* Check the total number of occupied stations */\r
-       iOccupiedStationNumberTotal = 0;\r
-       for ( i = 0; i < pParameter->iTotalSlaveNumber; i ++ )\r
-       {\r
-               if (( pParameter->Slave[i].usOccupiedStationNumber < 1 ) || ( CCIEF_BASIC_MAX_NUMBER_OF_OCCUPIED_STATIONS_GROUP < pParameter->Slave[i].usOccupiedStationNumber )) {\r
-                       printf( "Parameter Error: Invalid number of occupied stations! %d(No.%d) (range: 1-16)\n", pParameter->Slave[i].usOccupiedStationNumber, i+1 );\r
-                       return CCIEF_BASIC_MASTER_ERR_NG;\r
-               }\r
-               iOccupiedStationNumberTotal += pParameter->Slave[i].usOccupiedStationNumber;\r
-\r
-       }\r
-       if ( CCIEF_BASIC_MAX_SLAVE_NUMBER < iOccupiedStationNumberTotal )\r
-       {\r
-               printf( "Parameter Error: Invalid total number of occupied stations! %d (range: 1-64)\n", iOccupiedStationNumberTotal );\r
-               return CCIEF_BASIC_MASTER_ERR_NG;\r
-       }\r
-\r
-       /* Check the total number of occupied stations(for group) */\r
-       for ( i = 0; i < CCIEF_BASIC_MAX_GROUP_NUMBER; i ++ )\r
-       {\r
-               iOccupiedStationNumberTotal = 0;\r
-               for ( j = 0; j < pParameter->iTotalSlaveNumber; j ++ )\r
-               {\r
-                       if (( i + 1 ) == pParameter->Slave[j].ucGroupNumber )\r
-                       {\r
-                               iOccupiedStationNumberTotal += pParameter->Slave[j].usOccupiedStationNumber;\r
-                       }\r
-               }\r
-               if ( CCIEF_BASIC_MAX_NUMBER_OF_OCCUPIED_STATIONS_GROUP < iOccupiedStationNumberTotal )\r
-               {\r
-                       printf( "Parameter Error: Invalid total number of occupied stations! (Group Number %d)\n", ( i + 1 ));\r
-                       return CCIEF_BASIC_MASTER_ERR_NG;\r
-               }\r
-       }\r
-\r
-       /* Check the slave ip address */\r
-       for ( i = 0; i < pParameter->iTotalSlaveNumber; i ++ )\r
-       {\r
-               for ( j = 0; j < pParameter->iTotalSlaveNumber; j ++ )\r
-               {\r
-                       if (( i != j ) && ( pParameter->Slave[i].ulIpAddress == pParameter->Slave[j].ulIpAddress ))\r
-                       {\r
-#ifdef _WIN32\r
-                               addr.S_un.S_addr = htonl(pParameter->Slave[j].ulIpAddress);\r
-#elif __linux__\r
-                               addr.s_addr = htonl(pParameter->Slave[j].ulIpAddress);  \r
-#endif\r
-                               inet_ntop(AF_INET, &addr, Ipaddr, sizeof(Ipaddr) );\r
-                               printf( "Parameter Error: Duplicate slaves ip address %s!\n", Ipaddr );\r
-                               return CCIEF_BASIC_MASTER_ERR_NG;\r
-                       }\r
-               }\r
-       }\r
-\r
-       /* Check the total number of the group */\r
-       if (( pParameter->iTotalGroupNumber == 0 ) || ( CCIEF_BASIC_MAX_GROUP_NUMBER < pParameter->iTotalGroupNumber )) {\r
-               printf( "Parameter Error: Out of range of total group number! %d (range: 1-64)\n", pParameter->iTotalGroupNumber );\r
-               return CCIEF_BASIC_MASTER_ERR_NG;\r
-       }\r
-\r
-       /* Check the group number */\r
-       for ( i = 0; i < pParameter->iTotalSlaveNumber; i ++ )\r
-       {\r
-               if (( pParameter->Slave[i].ucGroupNumber == 0) || ( CCIEF_BASIC_MAX_GROUP_NUMBER < pParameter->Slave[i].ucGroupNumber ))\r
-               {\r
-                       printf( "Parameter Error: Invalid group number at the slave No.%d! (range: 1-64)\n", ( i + 1 ));\r
-                       return CCIEF_BASIC_MASTER_ERR_NG;\r
-               }\r
-       }\r
-       for ( i = 0; i < pParameter->iTotalSlaveNumber; i ++ )\r
-       {\r
-               for ( j = 0; j < pParameter->iTotalGroupNumber; j ++ )\r
-               {\r
-                       if ( pParameter->Slave[i].ucGroupNumber == pParameter->Group[j].ucGroupNumber )\r
-                       {\r
-                               break;\r
-                       }\r
-               }\r
-               if ( j == pParameter->iTotalGroupNumber )\r
-               {\r
-                       printf( "Parameter Error: Not found the parameter of group number %d!\n", pParameter->Slave[i].ucGroupNumber );\r
-                       return CCIEF_BASIC_MASTER_ERR_NG;\r
-               }\r
-       }\r
-\r
-       /* Check the constant link scan time */\r
-       for ( i = 0; i < pParameter->iTotalGroupNumber; i ++ )\r
-       {\r
-               if ( CCIEF_BASIC_MAX_CONSTANT_LINK_SCAN_TIME < pParameter->Group[i].usConstantLinkScanTime )\r
-               {\r
-                       printf( "Parameter Error: Invalid constant link scan time! %d (range: 0-2000)\n", pParameter->Group[i].usConstantLinkScanTime );\r
-                       printf( "(0:no use)\n" );\r
-                       return CCIEF_BASIC_MASTER_ERR_NG;\r
-               }\r
-       }\r
-\r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for receiving packet. The following is one of a    */\r
-/* sample in the Windows OS. Please rewrite if necessary.                                                      */\r
-/* The following is one of a sample in the Linux. Please rewrite if necessary.         */\r
-/************************************************************************************/\r
-int ccief_basic_master_recv( void )\r
-{\r
-       uint32_t                ulRecvAddr;\r
-       uint16_t                usRecvPortNumber;\r
-       struct in_addr  addr;\r
-       SLMP_INFO               source = { 0 }; /* SLMP Infomation for received packet */\r
-       int                             iErrCode = 0;\r
-       int                             i;\r
-       char                    Ipaddr[16];\r
-#ifdef _WIN32\r
-#elif __linux__\r
-       uint32_t                ulMyNetAddress;\r
-       uint32_t                ulOtherNetAddress;\r
-#endif\r
-\r
-       /* Check the socket */\r
-       if ( sock == INVALID_SOCKET ) {\r
-               return CCIEF_BASIC_MASTER_ERR_OK;\r
-       }\r
-\r
-       /* Packet receiving */\r
-       iErrCode = socket_recv( sock, aucRecvPacket, sizeof( aucRecvPacket ), &ulRecvAddr, &usRecvPortNumber );\r
-       if ( iErrCode != SOCKET_ERR_OK )\r
-       {\r
-               if ( iErrCode == SOCKET_ERR_NO_RECEIVABLE )\r
-               {\r
-                       return CCIEF_BASIC_MASTER_ERR_OK;\r
-               }\r
-               else\r
-               {\r
-                       return iErrCode;\r
-               }\r
-       }\r
-\r
-#ifdef _WIN32\r
-#elif __linux__\r
-       ulMyNetAddress = ( Master.ulIpAddress & Master.ulSubnetMask );\r
-       ulOtherNetAddress = ( ulRecvAddr & Master.ulSubnetMask );\r
-\r
-       /* Other network broadcast break*/\r
-       if( ulMyNetAddress != ulOtherNetAddress )\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_OK;\r
-       }\r
-#endif\r
-\r
-\r
-       /* Sets the SLMP Information for receiving. */\r
-       source.pucData = aucRecvData;\r
-\r
-       /* Get the SLMP Information from the request packet using the SLMP library. */\r
-       iErrCode = SLMP_GetSlmpInfo( &source, aucRecvPacket );\r
-       if ( iErrCode != SLMP_ERR_OK )\r
-       {\r
-               /* Invalid SLMP Frame. */\r
-               printf( "ERR : Invalid SLMP frame received!\n" );\r
-               return CCIEF_BASIC_MASTER_ERR_OK;\r
-       }\r
-\r
-       /* Check the SLMP frame. */\r
-       if ( source.ulFrameType == SLMP_FTYPE_BIN_RES_ST )\r
-       {\r
-               /* Response of the SLMP frame */\r
-               if ( source.usEndCode == SLMP_ERR_OK )\r
-               {\r
-                       /* Receiving response of the cyclic data. */\r
-                       ccief_basic_master_recv_cyclic_data_response( source.pucData );\r
-               }\r
-               else\r
-               {\r
-#ifdef _WIN32\r
-                       addr.S_un.S_addr = htonl(ulRecvAddr);\r
-#elif __linux__\r
-                       addr.s_addr = htonl(ulRecvAddr);        \r
-#endif\r
-                       inet_ntop(AF_INET, &addr, Ipaddr, sizeof(Ipaddr) );\r
-                       printf( "ERR : EndCode %04X from %s!\n", source.usEndCode, Ipaddr );\r
-               }\r
-       }\r
-       else\r
-       {\r
-               /* Request of the SLMP frame */\r
-               if ( source.usCommand == SLMP_COMMAND_CYCLIC_DATA )\r
-               {\r
-                       /* Cyclic Data(0E70h) */\r
-                       for ( i = 0; i < Master.iGroupTotalNumber; i ++ )\r
-                       {\r
-                               /* Execute the state of the master */\r
-                               ccief_basic_master_execute_state( Master.pGroup[i], CCIEF_BASIC_EVENT_MASTER_CYCLIC_DATA_RECV );\r
-                       }\r
-               }\r
-       }\r
-\r
-       /* Check the error code of the master duplication */\r
-       if ( Master.iErrCode == CCIEF_BASIC_MASTER_ERR_MASTER_DUPLICATION )\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_MASTER_DUPLICATION;\r
-       }\r
-       \r
-       /* Check the error code of the slave duplication */\r
-       if ( Master.iErrCode == CCIEF_BASIC_MASTER_ERR_SLAVE_DUPLICATION )\r
-       {\r
-               return CCIEF_BASIC_MASTER_ERR_SLAVE_DUPLICATION;\r
-       }\r
-\r
-       return CCIEF_BASIC_MASTER_ERR_OK;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for polling operation.                                                     */\r
-/************************************************************************************/\r
-int ccief_basic_master_polling( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup )\r
-{\r
-       int     i;\r
-       int iSlaveCyclicStateOffNumber, iSlaveCyclicStateOffCyclicEndNumber;\r
-       int iSlaveCyclicStateOnNumber, iSlaveCyclicStateOnCyclicEndNumber;\r
-       int iErrCode = CCIEF_BASIC_MASTER_ERR_OK;\r
-\r
-       /* Check the state of the master */\r
-       if ( pGroup->iState == CCIEF_BASIC_STATE_MASTER_LINK_SCAN )\r
-       {\r
-               /* Check using the constant link scan */\r
-               if ( pGroup->iConstantLinkScanUse == CCIEF_BASIC_CONSTANT_LINK_SCAN_NOT_USE )\r
-               {\r
-                       /* Check the cyclic end of the slave */\r
-                       iSlaveCyclicStateOffNumber = 0;\r
-                       iSlaveCyclicStateOffCyclicEndNumber = 0;\r
-                       iSlaveCyclicStateOnNumber = 0;\r
-                       iSlaveCyclicStateOnCyclicEndNumber = 0;\r
-                       for ( i = 0; i < pGroup->iTotalSlaveNumber; i ++ )\r
-                       {\r
-                               if ( pGroup->pSlave[i]->iCyclicState == CCIEF_BASIC_CYCLIC_STATE_OFF )\r
-                               {\r
-                                       /* OFF the slave cyclic state */\r
-                                       iSlaveCyclicStateOffNumber ++;\r
-                                       if ( pGroup->pSlave[i]->iState == CCIEF_BASIC_STATE_SLAVE_CYCLIC_END )\r
-                                       {\r
-                                               iSlaveCyclicStateOffCyclicEndNumber ++;\r
-                                       }\r
-                               }\r
-                               else\r
-                               {\r
-                                       /* ON the slave cyclic state */\r
-                                       iSlaveCyclicStateOnNumber ++;\r
-                                       if ( pGroup->pSlave[i]->iState == CCIEF_BASIC_STATE_SLAVE_CYCLIC_END )\r
-                                       {\r
-                                               iSlaveCyclicStateOnCyclicEndNumber ++;\r
-                                       }\r
-                               }\r
-                       }\r
-                       if ((( 0 < iSlaveCyclicStateOnNumber ) && ( iSlaveCyclicStateOnNumber == iSlaveCyclicStateOnCyclicEndNumber ))\r
-                        || (( 0 == iSlaveCyclicStateOnNumber ) && ( iSlaveCyclicStateOffNumber == iSlaveCyclicStateOffCyclicEndNumber )))\r
-                       {\r
-                               /* End of the cyclic */\r
-                               /* Execute the state of the slave */\r
-                               for ( i = 0; i < pGroup->iTotalSlaveNumber; i ++ )\r
-                               {\r
-                                       ccief_basic_slaves_execute_state( pGroup->pSlave[i], CCIEF_BASIC_EVENT_SLAVE_CYCLIC_END );\r
-                               }\r
-                               /* Execute the state of the master */\r
-                               ccief_basic_master_execute_state( pGroup, CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_END );\r
-                       }\r
-               }\r
-       }\r
-\r
-       return iErrCode;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for executed according to the state                                */\r
-/* of the master.                                                                                                                                      */\r
-/************************************************************************************/\r
-void ccief_basic_master_execute_state( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent )\r
-{\r
-       /* Execute the state of the master */\r
-       switch ( pGroup->iState )\r
-       {\r
-               /* Waiting for the cyclic operation. */\r
-               case CCIEF_BASIC_STATE_MASTER_WAITING:\r
-                       ccief_basic_master_execute_state_wait_cyclic( pGroup, iEvent );\r
-                       break;\r
-               /* Persuasion of the master. */\r
-               case CCIEF_BASIC_STATE_MASTER_PERSUASION:\r
-                       ccief_basic_master_execute_state_persuasion( pGroup, iEvent );\r
-                       break;\r
-               /* End of the link scan. */\r
-               case CCIEF_BASIC_STATE_MASTER_LINK_SCAN_END:\r
-                       ccief_basic_master_execute_state_linkscan_end( pGroup, iEvent );\r
-                       break;\r
-               /* Running the link scan. */\r
-               case CCIEF_BASIC_STATE_MASTER_LINK_SCAN:\r
-                       ccief_basic_master_execute_state_linkscan( pGroup, iEvent );\r
-                       break;\r
-               default:\r
-                       break;\r
-       }\r
-\r
-       return;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for state of waiting of the cyclic operation.      */\r
-/************************************************************************************/\r
-void ccief_basic_master_execute_state_wait_cyclic( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent )\r
-{\r
-       /* Check the event */\r
-       switch ( iEvent )\r
-       {\r
-               /* Getting the parameter */\r
-               case CCIEF_BASIC_EVENT_MASTER_PARAMETER_GET:\r
-                       /* Initialization of the socket */\r
-                       if ( sock == INVALID_SOCKET )\r
-                       {\r
-                               Master.iErrCode = socket_initialize( &sock, Master.ulIpAddress, CCIEF_BASIC_PORT_NUMBER_CYCLIC );\r
-                               if( Master.iErrCode != CCIEF_BASIC_MASTER_ERR_OK )\r
-                               {\r
-                                       return;\r
-                               }\r
-                       }\r
-                       /* Check constant link scan */\r
-                       pGroup->iConstantLinkScanUse = CCIEF_BASIC_CONSTANT_LINK_SCAN_NOT_USE;\r
-                       if ( pGroup->pGroupParameter->usConstantLinkScanTime != 0 )\r
-                       {\r
-                               /* Set waiting of the end of constant link scan */\r
-                               pGroup->iConstantLinkScanUse = CCIEF_BASIC_CONSTANT_LINK_SCAN_USE;\r
-                       }\r
-                       /* Start the master persuasion timer*/\r
-                       timer_start( CCIEF_BASIC_MASTER_PERSUASION_TIME, &pGroup->iPersuasionTimerId,\r
-                                                &ccief_basic_master_persuasion_timer_timeout, (void *)pGroup );\r
-                       /* Set the master state */\r
-                       pGroup->iState = CCIEF_BASIC_STATE_MASTER_PERSUASION;\r
-                       break;\r
-               /* Changing the parameter */\r
-               case CCIEF_BASIC_EVENT_MASTER_PARAMETER_CHANGE:\r
-                       /* Nothing */\r
-                       break;\r
-               default:\r
-                       break;\r
-       }\r
-\r
-       return;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for state of persuasion of the master.                     */\r
-/************************************************************************************/\r
-void ccief_basic_master_execute_state_persuasion( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent )\r
-{\r
-       int     i;\r
-\r
-       /* Check the event */\r
-       switch ( iEvent )\r
-       {\r
-               /* Changing the parameter */\r
-               case CCIEF_BASIC_EVENT_MASTER_PARAMETER_CHANGE:\r
-                       /* Execute the state of the slave */\r
-                       for ( i = 0; i < pGroup->iTotalSlaveNumber; i ++ )\r
-                       {\r
-                               ccief_basic_slaves_execute_state( pGroup->pSlave[i], CCIEF_BASIC_EVENT_SLAVE_PARAMETER_CHANGE );\r
-                       }\r
-                       /* Stop the master persuasion timer*/\r
-                       timer_stop( pGroup->iPersuasionTimerId );\r
-                       /* Termination of socket */\r
-                       socket_terminate( sock );\r
-                       /* Set the master state */\r
-                       pGroup->iState = CCIEF_BASIC_STATE_MASTER_WAITING;\r
-                       break;\r
-               /* Timeout of monitoring the persuasion frame */\r
-               case CCIEF_BASIC_EVENT_MASTER_PERSUASION_TIMEOUT:\r
-                       /* Check the constant link scan time */\r
-                       if ( pGroup->pGroupParameter->usConstantLinkScanTime != 0 )\r
-                       {\r
-                               /* Set the constant link scan time */\r
-                               pGroup->ulResponseWaitTime = pGroup->pGroupParameter->usConstantLinkScanTime;\r
-                       }\r
-                       else\r
-                       {\r
-                               /* Set the cyclic transmission timeout */\r
-                               pGroup->ulResponseWaitTime = pGroup->pGroupParameter->usCyclicTransmissionTimeout;\r
-                       }\r
-                       if ( pGroup->ulResponseWaitTime == 0 )\r
-                       {\r
-                               pGroup->ulResponseWaitTime = CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT;\r
-                       }\r
-                       /* Set the master state */\r
-                       pGroup->iState = CCIEF_BASIC_STATE_MASTER_LINK_SCAN_END;\r
-                       /* Initialization of the frame sequence number */\r
-                       pGroup->usFrameSequenceNumber = 0;\r
-                       /* Execute the state of the master */\r
-                       ccief_basic_master_execute_state( pGroup, CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_START );\r
-                       break;\r
-               /* Receiving the cyclic data from the master */\r
-               case CCIEF_BASIC_EVENT_MASTER_CYCLIC_DATA_RECV:\r
-                       /* Stop the master persuasion timer*/\r
-                       timer_stop( pGroup->iPersuasionTimerId );\r
-                       /* Termination of socket */\r
-                       socket_terminate( sock );\r
-                       /* Set the master state */\r
-                       pGroup->iState = CCIEF_BASIC_STATE_MASTER_WAITING;\r
-                       /* Set the error code of the master duplication */\r
-                       Master.iErrCode = CCIEF_BASIC_MASTER_ERR_MASTER_DUPLICATION;\r
-                       return;\r
-               default:\r
-                       break;\r
-       }\r
-\r
-       return;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for state of end of the link scan.                         */\r
-/************************************************************************************/\r
-void ccief_basic_master_execute_state_linkscan_end( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent )\r
-{\r
-       int     i;\r
-\r
-       /* Check the event */\r
-       switch ( iEvent )\r
-       {\r
-               /* Changing the parameter */\r
-               case CCIEF_BASIC_EVENT_MASTER_PARAMETER_CHANGE:\r
-                       /* Execute the state of the slave */\r
-                       for ( i = 0; i < pGroup->iTotalSlaveNumber; i ++ )\r
-                       {\r
-                               ccief_basic_slaves_execute_state( pGroup->pSlave[i], CCIEF_BASIC_EVENT_SLAVE_PARAMETER_CHANGE );\r
-                       }\r
-                       /* Termination of socket */\r
-                       socket_terminate( sock );\r
-                       /* Set the master state */\r
-                       pGroup->iState = CCIEF_BASIC_STATE_MASTER_WAITING;\r
-                       break;\r
-               /* Starting the link scan */\r
-               case CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_START:\r
-                       /* Execute the state of the slave */\r
-                       for ( i = 0; i < pGroup->iTotalSlaveNumber; i ++ )\r
-                       {\r
-                               /* Reset the receive complete flag */\r
-                               pGroup->pSlave[i]->iReceiveComplete = CCIEF_BASIC_SLAVE_RESPONSE_NOT_RECEIVED;\r
-                               \r
-                               ccief_basic_slaves_execute_state( pGroup->pSlave[i], CCIEF_BASIC_EVENT_SLAVE_LINK_SCAN_START );\r
-                       }\r
-                       /* Callback function for notification of end of the link scan to user operation */\r
-                       if ( pUserLinkScanEndFunc != NULL )\r
-                       {\r
-                               pUserLinkScanEndFunc( pGroup->ucGroupNumber );\r
-                       }\r
-                       /* Make the request data of Cyclic Data */\r
-                       pGroup->iCyclicDataSize = ccief_basic_master_make_cyclic_data( pGroup );\r
-                       /* Start the link scan time */\r
-                       pGroup->llLinkScanTimeStart = timer_get_time();\r
-                       /* Sending Cyclic Data */\r
-                       ccief_basic_master_send_cyclic_data( Master.ulDirectedIpAddress, pGroup->aucCyclicData, pGroup->iCyclicDataSize );\r
-                       /* Start the timer for cyclic time */\r
-                       timer_start( pGroup->ulResponseWaitTime, &pGroup->iCyclicTimerId, &ccief_basic_master_cyclic_timer_timeout, (void *)pGroup );\r
-                       /* Set the master state */\r
-                       pGroup->iState = CCIEF_BASIC_STATE_MASTER_LINK_SCAN;\r
-                       break;\r
-               /* Receiving the cyclic data from the master */\r
-               case CCIEF_BASIC_EVENT_MASTER_CYCLIC_DATA_RECV:\r
-                       /* Nothing */\r
-                       break;\r
-               /* Receiving the error of the duplication master from the slave */\r
-               case CCIEF_BASIC_EVENT_MASTER_DUPLICATION_ERR_RECV:\r
-                       /* Execute the state of the slave */\r
-                       for ( i = 0; i < pGroup->iTotalSlaveNumber; i ++ )\r
-                       {\r
-                               ccief_basic_slaves_execute_state( pGroup->pSlave[i], CCIEF_BASIC_EVENT_SLAVE_DUPLICATION_MASTER_ERR );\r
-                       }\r
-                       /* Termination of socket */\r
-                       socket_terminate( sock );\r
-                       /* Set the master state */\r
-                       pGroup->iState = CCIEF_BASIC_STATE_MASTER_WAITING;\r
-                       /* Set the error code of the master duplication */\r
-                       Master.iErrCode = CCIEF_BASIC_MASTER_ERR_MASTER_DUPLICATION;\r
-                       return;\r
-               default:\r
-                       break;\r
-       }\r
-\r
-       return;\r
-}\r
-\r
-/************************************************************************************/\r
-/* This is an user defined function for state of running the link scan.                                */\r
-/************************************************************************************/\r
-void ccief_basic_master_execute_state_linkscan( CCIEF_BASIC_MASTER_GROUP_INFO *pGroup, int iEvent )\r
-{\r
-       int     i;\r
-       int64_t llLinkScanTimeEnd;\r
-\r
-       /* Check the event */\r
-       switch ( iEvent )\r
-       {\r
-               /* Changing the parameter */\r
-               case CCIEF_BASIC_EVENT_MASTER_PARAMETER_CHANGE:\r
-                       /* Execute the state of the slave */\r
-                       for ( i = 0; i < pGroup->iTotalSlaveNumber; i ++ )\r
-                       {\r
-                               ccief_basic_slaves_execute_state( pGroup->pSlave[i], CCIEF_BASIC_EVENT_SLAVE_PARAMETER_CHANGE );\r
-                       }\r
-                       /* Stop the cyclic timer*/\r
-                       timer_stop( pGroup->iCyclicTimerId );\r
-                       /* Termination of socket */\r
-                       socket_terminate( sock );\r
-                       /* Set the master state */\r
-                       pGroup->iState = CCIEF_BASIC_STATE_MASTER_WAITING;\r
-                       break;\r
-               /* End of the link scan */\r
-               case CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_END:\r
-                       /* Stop the cyclic timer*/\r
-                       timer_stop( pGroup->iCyclicTimerId );\r
-                       /* Stop the link scan time */\r
-                       llLinkScanTimeEnd = timer_get_time();\r
-                       pGroup->llLinkScanTimeCurrent = llLinkScanTimeEnd - pGroup->llLinkScanTimeStart;\r
-                       if (( pGroup->llLinkScanTimeMinimum == 0 ) || ( pGroup->llLinkScanTimeCurrent < pGroup->llLinkScanTimeMinimum ))\r
-                       {\r
-                               pGroup->llLinkScanTimeMinimum = pGroup->llLinkScanTimeCurrent;\r
-                       }\r
-                       if ( pGroup->llLinkScanTimeMaximum < pGroup->llLinkScanTimeCurrent )\r
-                       {\r
-                               pGroup->llLinkScanTimeMaximum = pGroup->llLinkScanTimeCurrent;\r
-                       }\r
-                       pGroup->llLinkScanTimeStart = llLinkScanTimeEnd;\r
-                       /* Set the master state */\r
-                       pGroup->iState = CCIEF_BASIC_STATE_MASTER_LINK_SCAN_END;\r
-                       /* Increasing of th frame sequence number */\r
-                       pGroup->usFrameSequenceNumber ++;\r
-                       if ( pGroup->usFrameSequenceNumber == 0 )\r
-                       {\r
-                               pGroup->usFrameSequenceNumber = 1;\r