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

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

#ifdef MODBUS_ENABLE_DEVICE_IDENTIFICATIONS

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


/**
  * @brief    Получить количество объектов в сообщении
  * @param    modbus_msg  Указатель на структуру сообщения
  * @return   int         Количество объектов
  */
int MB_RespGet_NumberOfObjects(RS_MsgTypeDef *modbus_msg)
{
  if(modbus_msg == NULL)
  {
    return 0;
  }
  // Проверяем что ответ связан с диагностикой
  if(modbus_msg->Func_Code != MB_R_DEVICE_INFO)
  {
    return 0;
  }
  
  return modbus_msg->DevId.NumbOfObj;
}

/**
  * @brief    Найти объект по ID в сообщении
  * @param    modbus_msg  Указатель на структуру сообщения
  * @param    obj_id      ID искомого объекта
  * @param    obj_data    Буфер для данных объекта (может быть NULL)
  * @param    obj_length  Указатель для длины объекта
  * @return   int         Найден ли объект (1 - да, 0 - нет)
  */
int MB_RespGet_ObjectById(RS_MsgTypeDef *modbus_msg, uint8_t obj_id, char *obj_data, uint8_t *obj_length)
{
  if((modbus_msg == NULL) || (obj_data == NULL))
    return 0;
  
  // Проверяем что ответ связан с диагностикой
  if(modbus_msg->Func_Code != MB_R_DEVICE_INFO)
  {
    return 0;
  }
  
  uint8_t *data = (uint8_t*)modbus_msg->DATA;
  unsigned ind = 0;
  
  for(int i = 0; i < modbus_msg->DevId.NumbOfObj; i++)
  {
    uint8_t current_id = data[ind++];
    uint8_t current_length = data[ind++];
    
    if(current_id == obj_id)
    {
      if(obj_length) 
        *obj_length = current_length;

      for(int j = 0; j < current_length; j++)
      {
        obj_data[j] = data[ind++];
      }
      obj_data[current_length] = '\0'; // добавляем \0

      return 1;
    }
    else
    {
      // Пропускаем данные этого объекта
      ind += current_length;
    }
  }
  
  return 0;
}

/**
  * @brief    Получить объект по индексу в сообщении
  * @param    modbus_msg  Указатель на структуру сообщения
  * @param    index       Индекс объекта (0..N-1)
  * @param    obj_id      Указатель для ID объекта
  * @param    obj_data    Буфер для данных объекта
  * @param    obj_length  Указатель для длины объекта
  * @return   int         Успешность получения (1 - получен, 0 - не найден)
  */
int MB_RespGet_ObjectByIndex(RS_MsgTypeDef *modbus_msg, int index, uint8_t *obj_id, char *obj_data, uint8_t *obj_length)
{
  if((modbus_msg == NULL) || (obj_data == NULL))
    return 0;
  
  // Проверяем что ответ связан с диагностикой
  if(modbus_msg->Func_Code != MB_R_DEVICE_INFO)
  {
    return 0;
  }
  
  if(index >= modbus_msg->DevId.NumbOfObj) 
    return 0;
  
  uint8_t *data = (uint8_t*)modbus_msg->DATA;
  unsigned ind = 0;
  
  for(int i = 0; i <= index; i++)
  {
    uint8_t current_id = data[ind++];
    uint8_t current_length = data[ind++];
    
    if(obj_id)
      *obj_id = current_id;
    if(obj_length)
      *obj_length = current_length;
    
    if(i == index)
    {
      for(int j = 0; j < current_length; j++)
      {
        obj_data[j] = data[ind++];
      }
      obj_data[current_length] = '\0'; // добавляем \0
      return 1;
    }
    else
    {
      // Пропускаем данные этого объекта
      ind += current_length;
    }
  }
  
  return 0;
}



  
/**
  * @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;
  
  /* Define number of object in one message */
  unsigned lastobjid = 0;
  for(int i = 0; i < DATA_SIZE*2;)
  {
    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->DATA;
  unsigned ind = 0;
  unsigned objid = modbus_msg->DevId.NextObjId;
  for(; objid <= lastobjid; objid++)
  {
    mbdata[ind++] = objid;
    MB_WriteSingleObjectToMessage(mbdata, &ind, &obj[objid]);
  }
  objid--;
  modbus_msg->ByteCnt = ind;
  modbus_msg->DevId.NextObjId = lastobjid+1;
  if(objid == maxidofobj)
  {
    modbus_msg->DevId.MoreFollows = 0;
  }
  else
  {
    modbus_msg->DevId.MoreFollows = 0xFF;
  }
}


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


#else //MODBUS_ENABLE_DEVICE_IDENTIFICATIONS

/* Получить количество объектов в сообщении */
int MB_RespGet_NumberOfObjects(RS_MsgTypeDef *modbus_msg) {return 0;}
int MB_RespGet_ObjectById(RS_MsgTypeDef *modbus_msg, uint8_t obj_id, char *obj_data, uint8_t *obj_length) {return 0;}
int MB_RespGet_ObjectByIndex(RS_MsgTypeDef *modbus_msg, int index, uint8_t *obj_id, char *obj_data, uint8_t *obj_length) {return 0;}
void MB_WriteSingleObjectToMessage(char *mbdata, unsigned *ind, MB_DeviceObjectTypeDef *obj) {}
void MB_WriteObjectsToMessage(RS_MsgTypeDef *modbus_msg, unsigned maxidofobj) {}
uint8_t MB_Process_Read_Device_Identifications(RS_MsgTypeDef *modbus_msg) {return 0;}
void MB_DeviceInentificationInit(void) {}

#endif