Matter SDK Coverage Report
Current view: top level - app/util - ember-io-storage.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 37.5 % 16 6
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :  *    Copyright (c) 2024 Project CHIP Authors
       3              :  *    All rights reserved.
       4              :  *
       5              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6              :  *    you may not use this file except in compliance with the License.
       7              :  *    You may obtain a copy of the License at
       8              :  *
       9              :  *        http://www.apache.org/licenses/LICENSE-2.0
      10              :  *
      11              :  *    Unless required by applicable law or agreed to in writing, software
      12              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14              :  *    See the License for the specific language governing permissions and
      15              :  *    limitations under the License.
      16              :  */
      17              : #include <app/util/ember-io-storage.h>
      18              : 
      19              : #include <app-common/zap-generated/attribute-type.h>
      20              : #include <zap-generated/endpoint_config.h>
      21              : 
      22              : #include <cstddef>
      23              : 
      24              : namespace chip {
      25              : namespace app {
      26              : namespace Compatibility {
      27              : namespace Internal {
      28              : 
      29              : // On some apps, ATTRIBUTE_LARGEST can as small as 3, making compiler unhappy since data[kAttributeReadBufferSize] cannot hold
      30              : // uint64_t. Make kAttributeReadBufferSize at least 8 so it can fit all basic types.
      31              : constexpr size_t kAttributeReadBufferSize = (ATTRIBUTE_LARGEST >= 8 ? ATTRIBUTE_LARGEST : 8);
      32              : uint8_t attributeIOBuffer[kAttributeReadBufferSize];
      33              : 
      34              : MutableByteSpan gEmberAttributeIOBufferSpan(attributeIOBuffer);
      35              : 
      36          507 : EmberAfAttributeType AttributeBaseType(EmberAfAttributeType type)
      37              : {
      38          507 :     switch (type)
      39              :     {
      40            0 :     case ZCL_ACTION_ID_ATTRIBUTE_TYPE:  // Action Id
      41              :     case ZCL_FABRIC_IDX_ATTRIBUTE_TYPE: // Fabric Index
      42              :     case ZCL_BITMAP8_ATTRIBUTE_TYPE:    // 8-bit bitmap
      43              :     case ZCL_ENUM8_ATTRIBUTE_TYPE:      // 8-bit enumeration
      44              :     case ZCL_STATUS_ATTRIBUTE_TYPE:     // Status Code
      45              :     case ZCL_PERCENT_ATTRIBUTE_TYPE:    // Percentage
      46              :         static_assert(std::is_same<chip::Percent, uint8_t>::value,
      47              :                       "chip::Percent is expected to be uint8_t, change this when necessary");
      48            0 :         return ZCL_INT8U_ATTRIBUTE_TYPE;
      49              : 
      50            6 :     case ZCL_ENDPOINT_NO_ATTRIBUTE_TYPE:   // Endpoint Number
      51              :     case ZCL_GROUP_ID_ATTRIBUTE_TYPE:      // Group Id
      52              :     case ZCL_VENDOR_ID_ATTRIBUTE_TYPE:     // Vendor Id
      53              :     case ZCL_ENUM16_ATTRIBUTE_TYPE:        // 16-bit enumeration
      54              :     case ZCL_BITMAP16_ATTRIBUTE_TYPE:      // 16-bit bitmap
      55              :     case ZCL_PERCENT100THS_ATTRIBUTE_TYPE: // 100ths of a percent
      56              :         static_assert(std::is_same<chip::EndpointId, uint16_t>::value,
      57              :                       "chip::EndpointId is expected to be uint16_t, change this when necessary");
      58              :         static_assert(std::is_same<chip::GroupId, uint16_t>::value,
      59              :                       "chip::GroupId is expected to be uint16_t, change this when necessary");
      60              :         static_assert(std::is_same<chip::Percent100ths, uint16_t>::value,
      61              :                       "chip::Percent100ths is expected to be uint16_t, change this when necessary");
      62            6 :         return ZCL_INT16U_ATTRIBUTE_TYPE;
      63              : 
      64            0 :     case ZCL_CLUSTER_ID_ATTRIBUTE_TYPE: // Cluster Id
      65              :     case ZCL_ATTRIB_ID_ATTRIBUTE_TYPE:  // Attribute Id
      66              :     case ZCL_FIELD_ID_ATTRIBUTE_TYPE:   // Field Id
      67              :     case ZCL_EVENT_ID_ATTRIBUTE_TYPE:   // Event Id
      68              :     case ZCL_COMMAND_ID_ATTRIBUTE_TYPE: // Command Id
      69              :     case ZCL_TRANS_ID_ATTRIBUTE_TYPE:   // Transaction Id
      70              :     case ZCL_DEVTYPE_ID_ATTRIBUTE_TYPE: // Device Type Id
      71              :     case ZCL_DATA_VER_ATTRIBUTE_TYPE:   // Data Version
      72              :     case ZCL_BITMAP32_ATTRIBUTE_TYPE:   // 32-bit bitmap
      73              :     case ZCL_EPOCH_S_ATTRIBUTE_TYPE:    // Epoch Seconds
      74              :     case ZCL_ELAPSED_S_ATTRIBUTE_TYPE:  // Elapsed Seconds
      75              :         static_assert(std::is_same<chip::ClusterId, uint32_t>::value,
      76              :                       "chip::Cluster is expected to be uint32_t, change this when necessary");
      77              :         static_assert(std::is_same<chip::AttributeId, uint32_t>::value,
      78              :                       "chip::AttributeId is expected to be uint32_t, change this when necessary");
      79              :         static_assert(std::is_same<chip::AttributeId, uint32_t>::value,
      80              :                       "chip::AttributeId is expected to be uint32_t, change this when necessary");
      81              :         static_assert(std::is_same<chip::EventId, uint32_t>::value,
      82              :                       "chip::EventId is expected to be uint32_t, change this when necessary");
      83              :         static_assert(std::is_same<chip::CommandId, uint32_t>::value,
      84              :                       "chip::CommandId is expected to be uint32_t, change this when necessary");
      85              :         static_assert(std::is_same<chip::TransactionId, uint32_t>::value,
      86              :                       "chip::TransactionId is expected to be uint32_t, change this when necessary");
      87              :         static_assert(std::is_same<chip::DeviceTypeId, uint32_t>::value,
      88              :                       "chip::DeviceTypeId is expected to be uint32_t, change this when necessary");
      89              :         static_assert(std::is_same<chip::DataVersion, uint32_t>::value,
      90              :                       "chip::DataVersion is expected to be uint32_t, change this when necessary");
      91            0 :         return ZCL_INT32U_ATTRIBUTE_TYPE;
      92              : 
      93            0 :     case ZCL_AMPERAGE_MA_ATTRIBUTE_TYPE: // Amperage milliamps
      94              :     case ZCL_ENERGY_MWH_ATTRIBUTE_TYPE:  // Energy milliwatt-hours
      95              :     case ZCL_POWER_MW_ATTRIBUTE_TYPE:    // Power milliwatts
      96              :     case ZCL_VOLTAGE_MV_ATTRIBUTE_TYPE:  // Voltage millivolts
      97            0 :         return ZCL_INT64S_ATTRIBUTE_TYPE;
      98              : 
      99            0 :     case ZCL_EVENT_NO_ATTRIBUTE_TYPE:   // Event Number
     100              :     case ZCL_FABRIC_ID_ATTRIBUTE_TYPE:  // Fabric Id
     101              :     case ZCL_NODE_ID_ATTRIBUTE_TYPE:    // Node Id
     102              :     case ZCL_BITMAP64_ATTRIBUTE_TYPE:   // 64-bit bitmap
     103              :     case ZCL_EPOCH_US_ATTRIBUTE_TYPE:   // Epoch Microseconds
     104              :     case ZCL_POSIX_MS_ATTRIBUTE_TYPE:   // POSIX Milliseconds
     105              :     case ZCL_SYSTIME_MS_ATTRIBUTE_TYPE: // System time Milliseconds
     106              :     case ZCL_SYSTIME_US_ATTRIBUTE_TYPE: // System time Microseconds
     107              :         static_assert(std::is_same<chip::EventNumber, uint64_t>::value,
     108              :                       "chip::EventNumber is expected to be uint64_t, change this when necessary");
     109              :         static_assert(std::is_same<chip::FabricId, uint64_t>::value,
     110              :                       "chip::FabricId is expected to be uint64_t, change this when necessary");
     111              :         static_assert(std::is_same<chip::NodeId, uint64_t>::value,
     112              :                       "chip::NodeId is expected to be uint64_t, change this when necessary");
     113            0 :         return ZCL_INT64U_ATTRIBUTE_TYPE;
     114              : 
     115            0 :     case ZCL_TEMPERATURE_ATTRIBUTE_TYPE: // Temperature
     116            0 :         return ZCL_INT16S_ATTRIBUTE_TYPE;
     117              : 
     118          501 :     default:
     119          501 :         return type;
     120              :     }
     121              : }
     122              : 
     123              : } // namespace Internal
     124              : } // namespace Compatibility
     125              : } // namespace app
     126              : } // namespace chip
        

Generated by: LCOV version 2.0-1