

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# C-Function API di basso livello
<a name="managedintegrations-sdk-device-api"></a>

Integra il codice specifico del tuo dispositivo con Managed Integrations utilizzando le API di basso livello fornite. C-Function Questa sezione descrive le operazioni API disponibili per ogni cluster nel modello di AWS dati per interazioni efficienti da dispositivo a cloud. Scopri come implementare funzioni di callback, emettere eventi, notificare le modifiche degli attributi e registrare i cluster per gli endpoint dei tuoi dispositivi.

**I componenti chiave dell'API includono:**

1. Strutture di puntatori delle funzioni di callback per attributi e comandi

1. Funzioni di emissione di eventi

1. Funzioni di notifica della modifica degli attributi

1. Funzioni di registrazione del cluster

Implementando queste API, crei un ponte tra le operazioni fisiche del dispositivo e le funzionalità cloud di Managed Integrations, garantendo comunicazioni e controllo senza interruzioni.

[La sezione seguente illustra l'API del cluster. OnOff](https://github.com/project-chip/connectedhomeip/blob/v1.3.0.0/data_model/clusters/OnOff.xml)

## OnOff API del cluster
<a name="managedintegrations-sdk-device-api-onoff"></a>

Il [OnOff.xml](https://github.com/project-chip/connectedhomeip/blob/5bb5c9e23d532cea40476fc0bd1d3008522792ba/data_model/clusters/OnOff.xml)cluster supporta questi attributi e comandi:.
+ Attributi:
  + `OnOff (boolean)`
  + `GlobalSceneControl (boolean)`
  + `OnTime (int16u)`
  + `OffWaitTime (int16u)`
  + `StartUpOnOff (StartUpOnOffEnum)`
+ Comandi:
  + `Off : () -> Status`
  + `On : () -> Status`
  + `Toggle : () -> Status`
  + `OffWithEffect : (EffectIdentifier: EffectIdentifierEnum, EffectVariant: enum8) -> Status`
  + `OnWithRecallGlobalScene : () -> Status`
  + `OnWithTimedOff : (OnOffControl: OnOffControlBitmap, OnTime: int16u, OffWaitTime: int16u) -> Status`

  Per ogni comando, forniamo il puntatore di funzione mappato 1:1 che puoi usare per agganciare la tua implementazione.

Tutti i callback per attributi e comandi sono definiti all'interno di una struttura C che prende il nome dal cluster.

### Esempio di struttura C
<a name="example-c-struct-id"></a>

```
struct iotmiDev_clusterOnOff
{
  /*
    - Each attribute has a getter callback if it's readable
    
    - Each attribute has a setter callback if it's writable
        
    - The type of `value` are derived according to the data type of
      the attribute.
    
    - `user` is the pointer passed during an endpoint setup
    
    - The callback should return iotmiDev_DMStatus to report success or not.

    - For unsupported attributes, just leave them as NULL.
   */
  iotmiDev_DMStatus (*getOnTime)(uint16_t *value, void *user);
  iotmiDev_DMStatus (*setOnTime)(uint16_t value, void *user);
  /*
    - Each command has a command callback

    - If a command takes parameters, the parameters will be defined in a struct
      such as `iotmiDev_OnOff_OnWithTimedOffRequest` below.

    - `user` is the pointer passed during an endpoint setup
    
    - The callback should return iotmiDev_DMStatus to report success or not.

    - For unsupported commands, just leave them as NULL.
   */
  iotmiDev_DMStatus (*cmdOff)(void *user);
  iotmiDev_DMStatus (*cmdOnWithTimedOff)(const iotmiDev_OnOff_OnWithTimedOffRequest *request, void *user);
};
```

Oltre alla struttura C, le funzioni di segnalazione delle modifiche agli attributi sono definite per tutti gli attributi.

```
/* Each attribute has a report function for the customer to report
   an attribute change. An attribute report function is thread-safe. 
   */
void iotmiDev_OnOff_OnTime_report_attr(struct iotmiDev_Endpoint *endpoint, uint16_t newValue, bool immediate);
```

Le funzioni di segnalazione degli eventi sono definite per tutti gli eventi specifici del cluster. Poiché il OnOff cluster non definisce alcun evento, di seguito è riportato un esempio tratto dal `CameraAvStreamManagement` cluster.

```
/* Each event has a report function for the customer to report
   an event. An event report function is thread-safe.
   The iotmiDev_CameraAvStreamManagement_VideoStreamChangedEvent struct is
   derived from the event definition in the cluster.
 */
void iotmiDev_CameraAvStreamManagement_VideoStreamChanged_report_event(struct iotmiDev_Endpoint *endpoint, const iotmiDev_CameraAvStreamManagement_VideoStreamChangedEvent *event, bool immediate);
```

Ogni cluster ha anche una funzione di registro.

```
iotmiDev_DMStatus iotmiDev_OnOffRegisterCluster(struct iotmiDev_Endpoint *endpoint, const struct iotmiDev_clusterOnOff *cluster, void *user);
```

Il puntatore utente passato alla funzione di registro verrà passato alle funzioni di callback.