/**
*******************************************************************************
* @file modbus_devid.c
* @brief Реализация идентификаторов устройства Modbus
*******************************************************************************
* @details
Модуль обработки запросов идентификации устройства через MEI-тип 0x0E:
- Формирование иерархии объектов идентификации
- Поддержка потоковой передачи при большом количестве объектов
- Автоматический расчет MoreFollows флагов

@section stream Потоковая передача:
При большом количестве объектов идентификация разбивается на несколько
сообщений с установкой флага MoreFollows и указанием NextObjId для
продолжения чтения в следующем запросе.
******************************************************************************/
#include "modbus_devid.h"

#ifdef MODBUS_ENABLE_DEVICE_IDENTIFICATIONS

MB_DeviceIdentificationsTypeDef MB_DEVID;  ///< Глобальная структура идентификаторов устройства



  
/**
  * @brief    Записать Один Объект Идентификатора в массив данных
  * @param    mbdata  Указатель на массив данных в структуре RS_MsgTypeDef.
  * @return   obj     Объект для записи.
  */
void MB_WriteSingleObjectToMessage(char *mbdata, unsigned *ind, MB_DeviceObjectTypeDef *obj)
{
  mbdata[(*ind)++] = obj->length;
  for (int i = 0; i < obj->length; i++)
  {
    mbdata[(*ind)++] = obj->name[i];
  }
}


/**
  * @brief    Записать Массив Объектов Идентификатора в массив данных
  * @param    mbdata  Указатель на массив данных в структуре RS_MsgTypeDef.
  * @return   obj     Объект для записи.
  */
void MB_WriteObjectsToMessage(RS_MsgTypeDef *modbus_msg, unsigned maxidofobj)
{
  MB_DeviceObjectTypeDef *obj = (MB_DeviceObjectTypeDef *)&MB_DEVID;
  unsigned objidtmp = modbus_msg->DevId.NextObjId;
  modbus_msg->Except_Code = ET_NO_ERRORS;

  /* Define number of object in one message */
  unsigned lastobjid = 0;
  for(int i = 0; i < DATA_SIZE*2;)
  {
    /* Если объект за пределами допутимого - выходим из цикла */
    if(objidtmp >= 0xFF + MODBUS_NUMB_OF_USEROBJECTS)
      break;

    i += 2;
    i += obj[objidtmp].length;
    /* Если все еще помещается в массив переходим на следующий объект */
    if(i < DATA_SIZE*2)
    {
      objidtmp++;
    }
    
    /* Если объекты для записи закончились - выходим из цикла*/
    if(objidtmp > maxidofobj)
      break;
  }
  lastobjid = objidtmp-1;
  
  
  /* Fill message with objects data */
  char *mbdata = (char *)&modbus_msg->MbData;
  unsigned ind = 0;
  unsigned objid = modbus_msg->DevId.NextObjId;
  for(; objid <= lastobjid; objid++)
  {
    mbdata[ind++] = objid;
    MB_WriteSingleObjectToMessage(mbdata, &ind, &obj[objid]);
  }
  objid--;

  if(modbus_msg->ByteCnt != 0)
  {
    modbus_msg->ByteCnt = ind;
    modbus_msg->DevId.NextObjId = lastobjid+1;
    if(objid == maxidofobj)
    {
      modbus_msg->DevId.MoreFollows = 0;
    }
    else
    {
      modbus_msg->DevId.MoreFollows = 0xFF;
    }
  }
  else
  {
    modbus_msg->Except_Code = ET_ILLEGAL_DATA_VALUE;
  }
}


/**
  * @brief    Обработать функцию Read Device Identifications (43/14 - 0x2B/0E).
  * @param    modbus_msg        Указатель на структуру собщения modbus.
  * @return   fMessageHandled   Статус о результате обработки комманды.
  * @details  Обработка команды Write Single Register.
  */
uint8_t MB_Process_Read_Device_Identifications(RS_MsgTypeDef *modbus_msg)
{  
  modbus_msg->DevId.Conformity = MODBUS_DEVICE_CONFORMITY;

  switch(modbus_msg->DevId.ReadDevId)
  { 
    case RID_BASIC_IDENTIFICATIONS:
      if (modbus_msg->DevId.NextObjId == 0)
      {
        modbus_msg->DevId.NextObjId = 0;
      }
      
      MB_WriteObjectsToMessage(modbus_msg, 2);
      modbus_msg->DevId.NumbOfObj = 3;
      break;
      
    case RID_REGULAR_IDENTIFICATIONS:
      if (modbus_msg->DevId.NextObjId == 0)
      {
        modbus_msg->DevId.NextObjId = 3;
      }
      
      MB_WriteObjectsToMessage(modbus_msg, 6);
      modbus_msg->DevId.NumbOfObj = 4;
      break;
      
    case RID_EXTENDED_IDENTIFICATIONS:
      if(MODBUS_NUMB_OF_USEROBJECTS <= 0 || MODBUS_NUMB_OF_USEROBJECTS > 128)
      {
        modbus_msg->Except_Code = ET_ILLEGAL_DATA_VALUE;
        break;
      }
    
      if (modbus_msg->DevId.NextObjId == 0)
      {
        modbus_msg->DevId.NextObjId = 0x80;
      }

      MB_WriteObjectsToMessage(modbus_msg, 0x80+MODBUS_NUMB_OF_USEROBJECTS);
      modbus_msg->DevId.NumbOfObj = MODBUS_NUMB_OF_USEROBJECTS;
      break;
      
    case RID_SPEDIFIC_IDENTIFICATIONS:      
      MB_WriteObjectsToMessage(modbus_msg, modbus_msg->DevId.NextObjId);
      modbus_msg->DevId.NumbOfObj = 1;
      break;
    default:
      return 0;
  }  

  if(modbus_msg->Except_Code != ET_NO_ERRORS)
  {
    return 0;
  }
  else
  {
    return 1;
  }
}



/**
  * @brief    Инициализация идентификаторов.
  */
void MB_DeviceInentificationInit(void)
{
  MB_ObjectInit(&MB_DEVID.VendorName,          MODBUS_VENDOR_NAME);
  MB_ObjectInit(&MB_DEVID.ProductCode,         MODBUS_PRODUCT_CODE);
  MB_ObjectInit(&MB_DEVID.Revision,            MODBUS_REVISION);
  MB_ObjectInit(&MB_DEVID.VendorUrl,           MODBUS_VENDOR_URL);
  MB_ObjectInit(&MB_DEVID.ProductName,         MODBUS_PRODUCT_NAME);
  MB_ObjectInit(&MB_DEVID.ModelName,           MODBUS_MODEL_NAME);
  
#if defined(MODBUS_USEROBJECT_0_NAME) && MODBUS_NUMB_OF_USEROBJECTS>0
  MB_ObjectInit(&MB_DEVID.User[0],   MODBUS_USEROBJECT_0_NAME);
#endif
#if defined(MODBUS_USEROBJECT_1_NAME) && MODBUS_NUMB_OF_USEROBJECTS>1
  MB_ObjectInit(&MB_DEVID.User[1],   MODBUS_USEROBJECT_1_NAME);
#endif
#if defined(MODBUS_USEROBJECT_2_NAME) && MODBUS_NUMB_OF_USEROBJECTS>2
  MB_ObjectInit(&MB_DEVID.User[2],   MODBUS_USEROBJECT_2_NAME);
#endif
#if defined(MODBUS_USEROBJECT_3_NAME) && MODBUS_NUMB_OF_USEROBJECTS>3
  MB_ObjectInit(&MB_DEVID.User[3],   MODBUS_USEROBJECT_3_NAME);
#endif
#if defined(MODBUS_USEROBJECT_4_NAME) && MODBUS_NUMB_OF_USEROBJECTS>4
  MB_ObjectInit(&MB_DEVID.User[4],   MODBUS_USEROBJECT_4_NAME);
#endif
#if defined(MODBUS_USEROBJECT_5_NAME) && MODBUS_NUMB_OF_USEROBJECTS>5
  MB_ObjectInit(&MB_DEVID.User[5],   MODBUS_USEROBJECT_5_NAME);
#endif
#if defined(MODBUS_USEROBJECT_6_NAME) && MODBUS_NUMB_OF_USEROBJECTS>6
  MB_ObjectInit(&MB_DEVID.User[6],   MODBUS_USEROBJECT_6_NAME);
#endif
#if defined(MODBUS_USEROBJECT_7_NAME) && MODBUS_NUMB_OF_USEROBJECTS>7
  MB_ObjectInit(&MB_DEVID.User[7],   MODBUS_USEROBJECT_7_NAME);
#endif
#if defined(MODBUS_USEROBJECT_8_NAME) && MODBUS_NUMB_OF_USEROBJECTS>8
  MB_ObjectInit(&MB_DEVID.User[8],   MODBUS_USEROBJECT_8_NAME);
#endif
#if defined(MODBUS_USEROBJECT_9_NAME) && MODBUS_NUMB_OF_USEROBJECTS>9
  MB_ObjectInit(&MB_DEVID.User[9],   MODBUS_USEROBJECT_9_NAME);
#endif
#if defined(MODBUS_USEROBJECT_10_NAME) && MODBUS_NUMB_OF_USEROBJECTS>10
  MB_ObjectInit(&MB_DEVID.User[10],   MODBUS_USEROBJECT_10_NAME);
#endif
#if defined(MODBUS_USEROBJECT_11_NAME) && MODBUS_NUMB_OF_USEROBJECTS>11
  MB_ObjectInit(&MB_DEVID.User[11],   MODBUS_USEROBJECT_11_NAME);
#endif
#if defined(MODBUS_USEROBJECT_12_NAME) && MODBUS_NUMB_OF_USEROBJECTS>12
  MB_ObjectInit(&MB_DEVID.User[12],   MODBUS_USEROBJECT_12_NAME);
#endif
#if defined(MODBUS_USEROBJECT_13_NAME) && MODBUS_NUMB_OF_USEROBJECTS>13
  MB_ObjectInit(&MB_DEVID.User[13],   MODBUS_USEROBJECT_13_NAME);
#endif
#if defined(MODBUS_USEROBJECT_14_NAME) && MODBUS_NUMB_OF_USEROBJECTS>14
  MB_ObjectInit(&MB_DEVID.User[14],   MODBUS_USEROBJECT_14_NAME);
#endif
#if defined(MODBUS_USEROBJECT_15_NAME) && MODBUS_NUMB_OF_USEROBJECTS>15
  MB_ObjectInit(&MB_DEVID.User[15],   MODBUS_USEROBJECT_15_NAME);
#endif
#if defined(MODBUS_USEROBJECT_16_NAME) && MODBUS_NUMB_OF_USEROBJECTS>16
  MB_ObjectInit(&MB_DEVID.User[16],   MODBUS_USEROBJECT_16_NAME);
#endif
#if defined(MODBUS_USEROBJECT_17_NAME) && MODBUS_NUMB_OF_USEROBJECTS>17
  MB_ObjectInit(&MB_DEVID.User[17],   MODBUS_USEROBJECT_17_NAME);
#endif
#if defined(MODBUS_USEROBJECT_18_NAME) && MODBUS_NUMB_OF_USEROBJECTS>18
  MB_ObjectInit(&MB_DEVID.User[18],   MODBUS_USEROBJECT_18_NAME);
#endif
#if defined(MODBUS_USEROBJECT_19_NAME) && MODBUS_NUMB_OF_USEROBJECTS>19
  MB_ObjectInit(&MB_DEVID.User[19],   MODBUS_USEROBJECT_19_NAME);
#endif
#if defined(MODBUS_USEROBJECT_20_NAME) && MODBUS_NUMB_OF_USEROBJECTS>20
  MB_ObjectInit(&MB_DEVID.User[20],   MODBUS_USEROBJECT_20_NAME);
#endif
#if defined(MODBUS_USEROBJECT_21_NAME) && MODBUS_NUMB_OF_USEROBJECTS>21
  MB_ObjectInit(&MB_DEVID.User[21],   MODBUS_USEROBJECT_21_NAME);
#endif
#if defined(MODBUS_USEROBJECT_22_NAME) && MODBUS_NUMB_OF_USEROBJECTS>22
  MB_ObjectInit(&MB_DEVID.User[22],   MODBUS_USEROBJECT_22_NAME);
#endif
#if defined(MODBUS_USEROBJECT_23_NAME) && MODBUS_NUMB_OF_USEROBJECTS>23
  MB_ObjectInit(&MB_DEVID.User[23],   MODBUS_USEROBJECT_23_NAME);
#endif
#if defined(MODBUS_USEROBJECT_24_NAME) && MODBUS_NUMB_OF_USEROBJECTS>24
  MB_ObjectInit(&MB_DEVID.User[24],   MODBUS_USEROBJECT_24_NAME);
#endif
#if defined(MODBUS_USEROBJECT_25_NAME) && MODBUS_NUMB_OF_USEROBJECTS>25
  MB_ObjectInit(&MB_DEVID.User[25],   MODBUS_USEROBJECT_25_NAME);
#endif
#if defined(MODBUS_USEROBJECT_26_NAME) && MODBUS_NUMB_OF_USEROBJECTS>26
  MB_ObjectInit(&MB_DEVID.User[26],   MODBUS_USEROBJECT_26_NAME);
#endif
#if defined(MODBUS_USEROBJECT_27_NAME) && MODBUS_NUMB_OF_USEROBJECTS>27
  MB_ObjectInit(&MB_DEVID.User[27],   MODBUS_USEROBJECT_27_NAME);
#endif
#if defined(MODBUS_USEROBJECT_28_NAME) && MODBUS_NUMB_OF_USEROBJECTS>28
  MB_ObjectInit(&MB_DEVID.User[28],   MODBUS_USEROBJECT_28_NAME);
#endif
#if defined(MODBUS_USEROBJECT_29_NAME) && MODBUS_NUMB_OF_USEROBJECTS>29
  MB_ObjectInit(&MB_DEVID.User[29],   MODBUS_USEROBJECT_29_NAME);
#endif
#if defined(MODBUS_USEROBJECT_30_NAME) && MODBUS_NUMB_OF_USEROBJECTS>30
  MB_ObjectInit(&MB_DEVID.User[30],   MODBUS_USEROBJECT_30_NAME);
#endif
#if defined(MODBUS_USEROBJECT_31_NAME) && MODBUS_NUMB_OF_USEROBJECTS>31
  MB_ObjectInit(&MB_DEVID.User[31],   MODBUS_USEROBJECT_31_NAME);
#endif
#if defined(MODBUS_USEROBJECT_32_NAME) && MODBUS_NUMB_OF_USEROBJECTS>32
  MB_ObjectInit(&MB_DEVID.User[32],   MODBUS_USEROBJECT_32_NAME);
#endif
#if defined(MODBUS_USEROBJECT_33_NAME) && MODBUS_NUMB_OF_USEROBJECTS>33
  MB_ObjectInit(&MB_DEVID.User[33],   MODBUS_USEROBJECT_33_NAME);
#endif
#if defined(MODBUS_USEROBJECT_34_NAME) && MODBUS_NUMB_OF_USEROBJECTS>34
  MB_ObjectInit(&MB_DEVID.User[34],   MODBUS_USEROBJECT_34_NAME);
#endif
#if defined(MODBUS_USEROBJECT_35_NAME) && MODBUS_NUMB_OF_USEROBJECTS>35
  MB_ObjectInit(&MB_DEVID.User[35],   MODBUS_USEROBJECT_35_NAME);
#endif
#if defined(MODBUS_USEROBJECT_36_NAME) && MODBUS_NUMB_OF_USEROBJECTS>36
  MB_ObjectInit(&MB_DEVID.User[36],   MODBUS_USEROBJECT_36_NAME);
#endif
#if defined(MODBUS_USEROBJECT_37_NAME) && MODBUS_NUMB_OF_USEROBJECTS>37
  MB_ObjectInit(&MB_DEVID.User[37],   MODBUS_USEROBJECT_37_NAME);
#endif
#if defined(MODBUS_USEROBJECT_38_NAME) && MODBUS_NUMB_OF_USEROBJECTS>38
  MB_ObjectInit(&MB_DEVID.User[38],   MODBUS_USEROBJECT_38_NAME);
#endif
#if defined(MODBUS_USEROBJECT_39_NAME) && MODBUS_NUMB_OF_USEROBJECTS>39
  MB_ObjectInit(&MB_DEVID.User[39],   MODBUS_USEROBJECT_39_NAME);
#endif
#if defined(MODBUS_USEROBJECT_40_NAME) && MODBUS_NUMB_OF_USEROBJECTS>40
  MB_ObjectInit(&MB_DEVID.User[40],   MODBUS_USEROBJECT_40_NAME);
#endif
#if defined(MODBUS_USEROBJECT_41_NAME) && MODBUS_NUMB_OF_USEROBJECTS>41
  MB_ObjectInit(&MB_DEVID.User[41],   MODBUS_USEROBJECT_41_NAME);
#endif
#if defined(MODBUS_USEROBJECT_42_NAME) && MODBUS_NUMB_OF_USEROBJECTS>42
  MB_ObjectInit(&MB_DEVID.User[42],   MODBUS_USEROBJECT_42_NAME);
#endif
#if defined(MODBUS_USEROBJECT_43_NAME) && MODBUS_NUMB_OF_USEROBJECTS>43
  MB_ObjectInit(&MB_DEVID.User[43],   MODBUS_USEROBJECT_43_NAME);
#endif
#if defined(MODBUS_USEROBJECT_44_NAME) && MODBUS_NUMB_OF_USEROBJECTS>44
  MB_ObjectInit(&MB_DEVID.User[44],   MODBUS_USEROBJECT_44_NAME);
#endif
#if defined(MODBUS_USEROBJECT_45_NAME) && MODBUS_NUMB_OF_USEROBJECTS>45
  MB_ObjectInit(&MB_DEVID.User[45],   MODBUS_USEROBJECT_45_NAME);
#endif
#if defined(MODBUS_USEROBJECT_46_NAME) && MODBUS_NUMB_OF_USEROBJECTS>46
  MB_ObjectInit(&MB_DEVID.User[46],   MODBUS_USEROBJECT_46_NAME);
#endif
#if defined(MODBUS_USEROBJECT_47_NAME) && MODBUS_NUMB_OF_USEROBJECTS>47
  MB_ObjectInit(&MB_DEVID.User[47],   MODBUS_USEROBJECT_47_NAME);
#endif
#if defined(MODBUS_USEROBJECT_48_NAME) && MODBUS_NUMB_OF_USEROBJECTS>48
  MB_ObjectInit(&MB_DEVID.User[48],   MODBUS_USEROBJECT_48_NAME);
#endif
#if defined(MODBUS_USEROBJECT_49_NAME) && MODBUS_NUMB_OF_USEROBJECTS>49
  MB_ObjectInit(&MB_DEVID.User[49],   MODBUS_USEROBJECT_49_NAME);
#endif
#if defined(MODBUS_USEROBJECT_50_NAME) && MODBUS_NUMB_OF_USEROBJECTS>50
  MB_ObjectInit(&MB_DEVID.User[50],   MODBUS_USEROBJECT_50_NAME);
#endif
#if defined(MODBUS_USEROBJECT_51_NAME) && MODBUS_NUMB_OF_USEROBJECTS>51
  MB_ObjectInit(&MB_DEVID.User[51],   MODBUS_USEROBJECT_51_NAME);
#endif
#if defined(MODBUS_USEROBJECT_52_NAME) && MODBUS_NUMB_OF_USEROBJECTS>52
  MB_ObjectInit(&MB_DEVID.User[52],   MODBUS_USEROBJECT_52_NAME);
#endif
#if defined(MODBUS_USEROBJECT_53_NAME) && MODBUS_NUMB_OF_USEROBJECTS>53
  MB_ObjectInit(&MB_DEVID.User[53],   MODBUS_USEROBJECT_53_NAME);
#endif
#if defined(MODBUS_USEROBJECT_54_NAME) && MODBUS_NUMB_OF_USEROBJECTS>54
  MB_ObjectInit(&MB_DEVID.User[54],   MODBUS_USEROBJECT_54_NAME);
#endif
#if defined(MODBUS_USEROBJECT_55_NAME) && MODBUS_NUMB_OF_USEROBJECTS>55
  MB_ObjectInit(&MB_DEVID.User[55],   MODBUS_USEROBJECT_55_NAME);
#endif
#if defined(MODBUS_USEROBJECT_56_NAME) && MODBUS_NUMB_OF_USEROBJECTS>56
  MB_ObjectInit(&MB_DEVID.User[56],   MODBUS_USEROBJECT_56_NAME);
#endif
#if defined(MODBUS_USEROBJECT_57_NAME) && MODBUS_NUMB_OF_USEROBJECTS>57
  MB_ObjectInit(&MB_DEVID.User[57],   MODBUS_USEROBJECT_57_NAME);
#endif
#if defined(MODBUS_USEROBJECT_58_NAME) && MODBUS_NUMB_OF_USEROBJECTS>58
  MB_ObjectInit(&MB_DEVID.User[58],   MODBUS_USEROBJECT_58_NAME);
#endif
#if defined(MODBUS_USEROBJECT_59_NAME) && MODBUS_NUMB_OF_USEROBJECTS>59
  MB_ObjectInit(&MB_DEVID.User[59],   MODBUS_USEROBJECT_59_NAME);
#endif
#if defined(MODBUS_USEROBJECT_60_NAME) && MODBUS_NUMB_OF_USEROBJECTS>60
  MB_ObjectInit(&MB_DEVID.User[60],   MODBUS_USEROBJECT_60_NAME);
#endif
#if defined(MODBUS_USEROBJECT_61_NAME) && MODBUS_NUMB_OF_USEROBJECTS>61
  MB_ObjectInit(&MB_DEVID.User[61],   MODBUS_USEROBJECT_61_NAME);
#endif
#if defined(MODBUS_USEROBJECT_62_NAME) && MODBUS_NUMB_OF_USEROBJECTS>62
  MB_ObjectInit(&MB_DEVID.User[62],   MODBUS_USEROBJECT_62_NAME);
#endif
#if defined(MODBUS_USEROBJECT_63_NAME) && MODBUS_NUMB_OF_USEROBJECTS>63
  MB_ObjectInit(&MB_DEVID.User[63],   MODBUS_USEROBJECT_63_NAME);
#endif
#if defined(MODBUS_USEROBJECT_64_NAME) && MODBUS_NUMB_OF_USEROBJECTS>64
  MB_ObjectInit(&MB_DEVID.User[64],   MODBUS_USEROBJECT_64_NAME);
#endif
#if defined(MODBUS_USEROBJECT_65_NAME) && MODBUS_NUMB_OF_USEROBJECTS>65
  MB_ObjectInit(&MB_DEVID.User[65],   MODBUS_USEROBJECT_65_NAME);
#endif
#if defined(MODBUS_USEROBJECT_66_NAME) && MODBUS_NUMB_OF_USEROBJECTS>66
  MB_ObjectInit(&MB_DEVID.User[66],   MODBUS_USEROBJECT_66_NAME);
#endif
#if defined(MODBUS_USEROBJECT_67_NAME) && MODBUS_NUMB_OF_USEROBJECTS>67
  MB_ObjectInit(&MB_DEVID.User[67],   MODBUS_USEROBJECT_67_NAME);
#endif
#if defined(MODBUS_USEROBJECT_68_NAME) && MODBUS_NUMB_OF_USEROBJECTS>68
  MB_ObjectInit(&MB_DEVID.User[68],   MODBUS_USEROBJECT_68_NAME);
#endif
#if defined(MODBUS_USEROBJECT_69_NAME) && MODBUS_NUMB_OF_USEROBJECTS>69
  MB_ObjectInit(&MB_DEVID.User[69],   MODBUS_USEROBJECT_69_NAME);
#endif
#if defined(MODBUS_USEROBJECT_70_NAME) && MODBUS_NUMB_OF_USEROBJECTS>70
  MB_ObjectInit(&MB_DEVID.User[70],   MODBUS_USEROBJECT_70_NAME);
#endif
#if defined(MODBUS_USEROBJECT_71_NAME) && MODBUS_NUMB_OF_USEROBJECTS>71
  MB_ObjectInit(&MB_DEVID.User[71],   MODBUS_USEROBJECT_71_NAME);
#endif
#if defined(MODBUS_USEROBJECT_72_NAME) && MODBUS_NUMB_OF_USEROBJECTS>72
  MB_ObjectInit(&MB_DEVID.User[72],   MODBUS_USEROBJECT_72_NAME);
#endif
#if defined(MODBUS_USEROBJECT_73_NAME) && MODBUS_NUMB_OF_USEROBJECTS>73
  MB_ObjectInit(&MB_DEVID.User[73],   MODBUS_USEROBJECT_73_NAME);
#endif
#if defined(MODBUS_USEROBJECT_74_NAME) && MODBUS_NUMB_OF_USEROBJECTS>74
  MB_ObjectInit(&MB_DEVID.User[74],   MODBUS_USEROBJECT_74_NAME);
#endif
#if defined(MODBUS_USEROBJECT_75_NAME) && MODBUS_NUMB_OF_USEROBJECTS>75
  MB_ObjectInit(&MB_DEVID.User[75],   MODBUS_USEROBJECT_75_NAME);
#endif
#if defined(MODBUS_USEROBJECT_76_NAME) && MODBUS_NUMB_OF_USEROBJECTS>76
  MB_ObjectInit(&MB_DEVID.User[76],   MODBUS_USEROBJECT_76_NAME);
#endif
#if defined(MODBUS_USEROBJECT_77_NAME) && MODBUS_NUMB_OF_USEROBJECTS>77
  MB_ObjectInit(&MB_DEVID.User[77],   MODBUS_USEROBJECT_77_NAME);
#endif
#if defined(MODBUS_USEROBJECT_78_NAME) && MODBUS_NUMB_OF_USEROBJECTS>78
  MB_ObjectInit(&MB_DEVID.User[78],   MODBUS_USEROBJECT_78_NAME);
#endif
#if defined(MODBUS_USEROBJECT_79_NAME) && MODBUS_NUMB_OF_USEROBJECTS>79
  MB_ObjectInit(&MB_DEVID.User[79],   MODBUS_USEROBJECT_79_NAME);
#endif
#if defined(MODBUS_USEROBJECT_80_NAME) && MODBUS_NUMB_OF_USEROBJECTS>80
  MB_ObjectInit(&MB_DEVID.User[80],   MODBUS_USEROBJECT_80_NAME);
#endif
#if defined(MODBUS_USEROBJECT_81_NAME) && MODBUS_NUMB_OF_USEROBJECTS>81
  MB_ObjectInit(&MB_DEVID.User[81],   MODBUS_USEROBJECT_81_NAME);
#endif
#if defined(MODBUS_USEROBJECT_82_NAME) && MODBUS_NUMB_OF_USEROBJECTS>82
  MB_ObjectInit(&MB_DEVID.User[82],   MODBUS_USEROBJECT_82_NAME);
#endif
#if defined(MODBUS_USEROBJECT_83_NAME) && MODBUS_NUMB_OF_USEROBJECTS>83
  MB_ObjectInit(&MB_DEVID.User[83],   MODBUS_USEROBJECT_83_NAME);
#endif
#if defined(MODBUS_USEROBJECT_84_NAME) && MODBUS_NUMB_OF_USEROBJECTS>84
  MB_ObjectInit(&MB_DEVID.User[84],   MODBUS_USEROBJECT_84_NAME);
#endif
#if defined(MODBUS_USEROBJECT_85_NAME) && MODBUS_NUMB_OF_USEROBJECTS>85
  MB_ObjectInit(&MB_DEVID.User[85],   MODBUS_USEROBJECT_85_NAME);
#endif
#if defined(MODBUS_USEROBJECT_86_NAME) && MODBUS_NUMB_OF_USEROBJECTS>86
  MB_ObjectInit(&MB_DEVID.User[86],   MODBUS_USEROBJECT_86_NAME);
#endif
#if defined(MODBUS_USEROBJECT_87_NAME) && MODBUS_NUMB_OF_USEROBJECTS>87
  MB_ObjectInit(&MB_DEVID.User[87],   MODBUS_USEROBJECT_87_NAME);
#endif
#if defined(MODBUS_USEROBJECT_88_NAME) && MODBUS_NUMB_OF_USEROBJECTS>88
  MB_ObjectInit(&MB_DEVID.User[88],   MODBUS_USEROBJECT_88_NAME);
#endif
#if defined(MODBUS_USEROBJECT_89_NAME) && MODBUS_NUMB_OF_USEROBJECTS>89
  MB_ObjectInit(&MB_DEVID.User[89],   MODBUS_USEROBJECT_89_NAME);
#endif
#if defined(MODBUS_USEROBJECT_90_NAME) && MODBUS_NUMB_OF_USEROBJECTS>90
  MB_ObjectInit(&MB_DEVID.User[90],   MODBUS_USEROBJECT_90_NAME);
#endif
#if defined(MODBUS_USEROBJECT_91_NAME) && MODBUS_NUMB_OF_USEROBJECTS>91
  MB_ObjectInit(&MB_DEVID.User[91],   MODBUS_USEROBJECT_91_NAME);
#endif
#if defined(MODBUS_USEROBJECT_92_NAME) && MODBUS_NUMB_OF_USEROBJECTS>92
  MB_ObjectInit(&MB_DEVID.User[92],   MODBUS_USEROBJECT_92_NAME);
#endif
#if defined(MODBUS_USEROBJECT_93_NAME) && MODBUS_NUMB_OF_USEROBJECTS>93
  MB_ObjectInit(&MB_DEVID.User[93],   MODBUS_USEROBJECT_93_NAME);
#endif
#if defined(MODBUS_USEROBJECT_94_NAME) && MODBUS_NUMB_OF_USEROBJECTS>94
  MB_ObjectInit(&MB_DEVID.User[94],   MODBUS_USEROBJECT_94_NAME);
#endif
#if defined(MODBUS_USEROBJECT_95_NAME) && MODBUS_NUMB_OF_USEROBJECTS>95
  MB_ObjectInit(&MB_DEVID.User[95],   MODBUS_USEROBJECT_95_NAME);
#endif
#if defined(MODBUS_USEROBJECT_96_NAME) && MODBUS_NUMB_OF_USEROBJECTS>96
  MB_ObjectInit(&MB_DEVID.User[96],   MODBUS_USEROBJECT_96_NAME);
#endif
#if defined(MODBUS_USEROBJECT_97_NAME) && MODBUS_NUMB_OF_USEROBJECTS>97
  MB_ObjectInit(&MB_DEVID.User[97],   MODBUS_USEROBJECT_97_NAME);
#endif
#if defined(MODBUS_USEROBJECT_98_NAME) && MODBUS_NUMB_OF_USEROBJECTS>98
  MB_ObjectInit(&MB_DEVID.User[98],   MODBUS_USEROBJECT_98_NAME);
#endif
#if defined(MODBUS_USEROBJECT_99_NAME) && MODBUS_NUMB_OF_USEROBJECTS>99
  MB_ObjectInit(&MB_DEVID.User[99],   MODBUS_USEROBJECT_99_NAME);
#endif
#if defined(MODBUS_USEROBJECT_100_NAME) && MODBUS_NUMB_OF_USEROBJECTS>100
  MB_ObjectInit(&MB_DEVID.User[100],   MODBUS_USEROBJECT_100_NAME);
#endif
#if defined(MODBUS_USEROBJECT_101_NAME) && MODBUS_NUMB_OF_USEROBJECTS>101
  MB_ObjectInit(&MB_DEVID.User[101],   MODBUS_USEROBJECT_101_NAME);
#endif
#if defined(MODBUS_USEROBJECT_102_NAME) && MODBUS_NUMB_OF_USEROBJECTS>102
  MB_ObjectInit(&MB_DEVID.User[102],   MODBUS_USEROBJECT_102_NAME);
#endif
#if defined(MODBUS_USEROBJECT_103_NAME) && MODBUS_NUMB_OF_USEROBJECTS>103
  MB_ObjectInit(&MB_DEVID.User[103],   MODBUS_USEROBJECT_103_NAME);
#endif
#if defined(MODBUS_USEROBJECT_104_NAME) && MODBUS_NUMB_OF_USEROBJECTS>104
  MB_ObjectInit(&MB_DEVID.User[104],   MODBUS_USEROBJECT_104_NAME);
#endif
#if defined(MODBUS_USEROBJECT_105_NAME) && MODBUS_NUMB_OF_USEROBJECTS>105
  MB_ObjectInit(&MB_DEVID.User[105],   MODBUS_USEROBJECT_105_NAME);
#endif
#if defined(MODBUS_USEROBJECT_106_NAME) && MODBUS_NUMB_OF_USEROBJECTS>106
  MB_ObjectInit(&MB_DEVID.User[106],   MODBUS_USEROBJECT_106_NAME);
#endif
#if defined(MODBUS_USEROBJECT_107_NAME) && MODBUS_NUMB_OF_USEROBJECTS>107
  MB_ObjectInit(&MB_DEVID.User[107],   MODBUS_USEROBJECT_107_NAME);
#endif
#if defined(MODBUS_USEROBJECT_108_NAME) && MODBUS_NUMB_OF_USEROBJECTS>108
  MB_ObjectInit(&MB_DEVID.User[108],   MODBUS_USEROBJECT_108_NAME);
#endif
#if defined(MODBUS_USEROBJECT_109_NAME) && MODBUS_NUMB_OF_USEROBJECTS>109
  MB_ObjectInit(&MB_DEVID.User[109],   MODBUS_USEROBJECT_109_NAME);
#endif
#if defined(MODBUS_USEROBJECT_110_NAME) && MODBUS_NUMB_OF_USEROBJECTS>110
  MB_ObjectInit(&MB_DEVID.User[110],   MODBUS_USEROBJECT_110_NAME);
#endif
#if defined(MODBUS_USEROBJECT_111_NAME) && MODBUS_NUMB_OF_USEROBJECTS>111
  MB_ObjectInit(&MB_DEVID.User[111],   MODBUS_USEROBJECT_111_NAME);
#endif
#if defined(MODBUS_USEROBJECT_112_NAME) && MODBUS_NUMB_OF_USEROBJECTS>112
  MB_ObjectInit(&MB_DEVID.User[112],   MODBUS_USEROBJECT_112_NAME);
#endif
#if defined(MODBUS_USEROBJECT_113_NAME) && MODBUS_NUMB_OF_USEROBJECTS>113
  MB_ObjectInit(&MB_DEVID.User[113],   MODBUS_USEROBJECT_113_NAME);
#endif
#if defined(MODBUS_USEROBJECT_114_NAME) && MODBUS_NUMB_OF_USEROBJECTS>114
  MB_ObjectInit(&MB_DEVID.User[114],   MODBUS_USEROBJECT_114_NAME);
#endif
#if defined(MODBUS_USEROBJECT_115_NAME) && MODBUS_NUMB_OF_USEROBJECTS>115
  MB_ObjectInit(&MB_DEVID.User[115],   MODBUS_USEROBJECT_115_NAME);
#endif
#if defined(MODBUS_USEROBJECT_116_NAME) && MODBUS_NUMB_OF_USEROBJECTS>116
  MB_ObjectInit(&MB_DEVID.User[116],   MODBUS_USEROBJECT_116_NAME);
#endif
#if defined(MODBUS_USEROBJECT_117_NAME) && MODBUS_NUMB_OF_USEROBJECTS>117
  MB_ObjectInit(&MB_DEVID.User[117],   MODBUS_USEROBJECT_117_NAME);
#endif
#if defined(MODBUS_USEROBJECT_118_NAME) && MODBUS_NUMB_OF_USEROBJECTS>118
  MB_ObjectInit(&MB_DEVID.User[118],   MODBUS_USEROBJECT_118_NAME);
#endif
#if defined(MODBUS_USEROBJECT_119_NAME) && MODBUS_NUMB_OF_USEROBJECTS>119
  MB_ObjectInit(&MB_DEVID.User[119],   MODBUS_USEROBJECT_119_NAME);
#endif
#if defined(MODBUS_USEROBJECT_120_NAME) && MODBUS_NUMB_OF_USEROBJECTS>120
  MB_ObjectInit(&MB_DEVID.User[120],   MODBUS_USEROBJECT_120_NAME);
#endif
#if defined(MODBUS_USEROBJECT_121_NAME) && MODBUS_NUMB_OF_USEROBJECTS>121
  MB_ObjectInit(&MB_DEVID.User[121],   MODBUS_USEROBJECT_121_NAME);
#endif
#if defined(MODBUS_USEROBJECT_122_NAME) && MODBUS_NUMB_OF_USEROBJECTS>122
  MB_ObjectInit(&MB_DEVID.User[122],   MODBUS_USEROBJECT_122_NAME);
#endif
#if defined(MODBUS_USEROBJECT_123_NAME) && MODBUS_NUMB_OF_USEROBJECTS>123
  MB_ObjectInit(&MB_DEVID.User[123],   MODBUS_USEROBJECT_123_NAME);
#endif
#if defined(MODBUS_USEROBJECT_124_NAME) && MODBUS_NUMB_OF_USEROBJECTS>124
  MB_ObjectInit(&MB_DEVID.User[124],   MODBUS_USEROBJECT_124_NAME);
#endif
#if defined(MODBUS_USEROBJECT_125_NAME) && MODBUS_NUMB_OF_USEROBJECTS>125
  MB_ObjectInit(&MB_DEVID.User[125],   MODBUS_USEROBJECT_125_NAME);
#endif
#if defined(MODBUS_USEROBJECT_126_NAME) && MODBUS_NUMB_OF_USEROBJECTS>126
  MB_ObjectInit(&MB_DEVID.User[126],   MODBUS_USEROBJECT_126_NAME);
#endif
#if defined(MODBUS_USEROBJECT_127_NAME) && MODBUS_NUMB_OF_USEROBJECTS>127
  MB_ObjectInit(&MB_DEVID.User[127],   MODBUS_USEROBJECT_127_NAME);
#endif

}

#endif //MODBUS_ENABLE_DEVICE_IDENTIFICATIONS
