Skip to content

Commit

Permalink
Merge pull request #479 from Luos-io/feat/service_profile
Browse files Browse the repository at this point in the history
Add a easy to use function allowing to retrieve a profile from a service.
  • Loading branch information
nicolas-rabault authored Mar 12, 2024
2 parents 121a4cd + 224ee04 commit 5c39cf9
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 0 deletions.
19 changes: 19 additions & 0 deletions engine/profiles/motor/profile_motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,22 @@ service_t *ProfileMotor_CreateService(profile_motor_t *profile_motor, SERVICE_CB
// Start service with the linked profile
return ProfileCore_StartService(callback, alias, revision);
}

/******************************************************************************
* @brief Get the profile data from a service pointer
* @param service : service pointer
* @return profile_motor_t pointer
******************************************************************************/
profile_motor_t *ProfileMotor_GetFromService(service_t *service)
{
profile_core_t *profile = ProfileCore_GetFromService(service);
if (profile == 0)
{
return 0;
}
if (profile->type != MOTOR_TYPE)
{
return 0;
}
return (profile_motor_t *)profile->profile_data;
}
1 change: 1 addition & 0 deletions engine/profiles/motor/profile_motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ typedef struct
******************************************************************************/
void ProfileMotor_link(uint8_t, profile_motor_t *);
service_t *ProfileMotor_CreateService(profile_motor_t *, SERVICE_CB, const char *, revision_t);
profile_motor_t *ProfileMotor_GetFromService(service_t *);

#endif /* PROFILE_MOTOR_H_ */
19 changes: 19 additions & 0 deletions engine/profiles/servo_motor/profile_servo_motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,22 @@ service_t *ProfileServo_CreateService(profile_servo_motor_t *profile_servo_motor
// Start service with the linked profile
return ProfileCore_StartService(callback, alias, revision);
}

/******************************************************************************
* @brief Get profile from a service
* @param service : target service
* @return profile pointer
******************************************************************************/
profile_servo_motor_t *ProfileServo_GetFromService(service_t *service)
{
profile_core_t *profile = ProfileCore_GetFromService(service);
if (profile == 0)
{
return 0;
}
if (profile->type != SERVO_MOTOR_TYPE)
{
return 0;
}
return (profile_servo_motor_t *)profile->profile_data;
}
1 change: 1 addition & 0 deletions engine/profiles/servo_motor/profile_servo_motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ typedef struct
******************************************************************************/
void ProfileServo_link(uint8_t, profile_servo_motor_t *);
service_t *ProfileServo_CreateService(profile_servo_motor_t *, SERVICE_CB, const char *, revision_t);
profile_servo_motor_t *ProfileServo_GetFromService(service_t *service);

#endif /* PROFILE_SERVO_MOTOR_H_ */
19 changes: 19 additions & 0 deletions engine/profiles/state/profile_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,22 @@ service_t *ProfileState_CreateService(profile_state_t *profile_state, SERVICE_CB
// Start profile
return ProfileCore_StartService(callback, alias, revision);
}

/******************************************************************************
* @brief Get the profile data from a service pointer
* @param service : Service pointer
* @return profile_state_t pointer
******************************************************************************/
profile_state_t *ProfileState_GetFromService(service_t *service)
{
profile_core_t *profile = ProfileCore_GetFromService(service);
if (profile == 0)
{
return 0;
}
if (profile->type != STATE_TYPE)
{
return 0;
}
return (profile_state_t *)profile->profile_data;
}
1 change: 1 addition & 0 deletions engine/profiles/state/profile_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ typedef struct
******************************************************************************/
void ProfileState_link(uint8_t profile_mode, profile_state_t *profile_state);
service_t *ProfileState_CreateService(profile_state_t *, SERVICE_CB, const char *, revision_t);
profile_state_t *ProfileState_GetFromService(service_t *);

#endif /* PROFILE_STATE_H_ */
19 changes: 19 additions & 0 deletions engine/profiles/voltage/profile_voltage.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,22 @@ service_t *ProfileVoltage_CreateService(profile_voltage_t *profile_voltage, SERV
// Start profile
return ProfileCore_StartService(callback, alias, revision);
}

/******************************************************************************
* @brief Get the profile data from a service pointer
* @param service : Service pointer
* @return profile_voltage_t pointer
******************************************************************************/
profile_voltage_t *ProfileVoltage_GetFromService(service_t *service)
{
profile_core_t *profile = ProfileCore_GetFromService(service);
if (profile == 0)
{
return 0;
}
if (profile->type != VOLTAGE_TYPE)
{
return 0;
}
return (profile_voltage_t *)profile->profile_data;
}
1 change: 1 addition & 0 deletions engine/profiles/voltage/profile_voltage.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ typedef struct
******************************************************************************/
void ProfileVoltage_link(uint8_t, profile_voltage_t *);
service_t *ProfileVoltage_CreateService(profile_voltage_t *, SERVICE_CB, const char *, revision_t);
profile_voltage_t *ProfileVoltage_GetFromService(service_t *);

#endif /* PROFILE_VOLTAGE_H_ */

0 comments on commit 5c39cf9

Please sign in to comment.