1818#include "ooga_booga.pb.h"
1919#include "pb_decode.h"
2020#include "pb_encode.h"
21+ #include "waypoint.pb.h"
2122
2223#include "cave_talk_link.h"
2324#include "cave_talk_types.h"
@@ -38,6 +39,7 @@ static CaveTalk_Error_t CaveTalk_HandleConfigWheelSpeedControl(const CaveTalk_Ha
3839static CaveTalk_Error_t CaveTalk_HandleConfigSteeringControl (const CaveTalk_Handle_t * const handle , const CaveTalk_Length_t length );
3940static CaveTalk_Error_t CaveTalk_HandleAirQuality (const CaveTalk_Handle_t * const handle , const CaveTalk_Length_t length );
4041static CaveTalk_Error_t CaveTalk_HandleRelativeMove (const CaveTalk_Handle_t * const handle , const CaveTalk_Length_t length );
42+ static CaveTalk_Error_t CaveTalk_HandleWaypoint (const CaveTalk_Handle_t * const handle , const CaveTalk_Length_t length );
4143static bool CaveTalk_EncodeString (pb_ostream_t * stream , const pb_field_t * field , void * const * arg );
4244static bool CaveTalk_DecodeString (pb_istream_t * stream , const pb_field_t * field , void * * arg );
4345
@@ -127,6 +129,9 @@ CaveTalk_Error_t CaveTalk_Hear(CaveTalk_Handle_t *const handle)
127129 case cave_talk_Id_ID_RELATIVE_MOVE :
128130 error = CaveTalk_HandleRelativeMove (handle , length );
129131 break ;
132+ case cave_talk_Id_ID_WAYPOINT :
133+ error = CaveTalk_HandleWaypoint (handle , length );
134+ break ;
130135 default :
131136 error = CAVE_TALK_ERROR_ID ;
132137 break ;
@@ -719,6 +724,36 @@ CaveTalk_Error_t CaveTalk_SpeakRelativeMove(const CaveTalk_Handle_t *const handl
719724 return error ;
720725}
721726
727+ CaveTalk_Error_t CaveTalk_SpeakWaypoint (const CaveTalk_Handle_t * const handle , const cave_talk_WaypointType type , const CaveTalk_Meter_t x , const CaveTalk_Meter_t y , const CaveTalk_Radian_t heading )
728+ {
729+ CaveTalk_Error_t error = CAVE_TALK_ERROR_NULL ;
730+
731+ if ((NULL == handle ) || (NULL == handle -> buffer ) || (NULL == handle -> link_handle .send ))
732+ {
733+ }
734+ else
735+ {
736+ pb_ostream_t ostream = pb_ostream_from_buffer (handle -> buffer , handle -> buffer_size );
737+ cave_talk_Waypoint waypoint_message = cave_talk_Waypoint_init_zero ;
738+
739+ waypoint_message .type = type ;
740+ waypoint_message .x_meters = x ;
741+ waypoint_message .y_meters = y ;
742+ waypoint_message .heading_radians = heading ;
743+
744+ if (!pb_encode (& ostream , cave_talk_Waypoint_fields , & waypoint_message ))
745+ {
746+ error = CAVE_TALK_ERROR_SIZE ;
747+ }
748+ else
749+ {
750+ error = CaveTalk_Speak (& handle -> link_handle , (CaveTalk_Id_t )cave_talk_Id_ID_WAYPOINT , handle -> buffer , ostream .bytes_written );
751+ }
752+ }
753+
754+ return error ;
755+ }
756+
722757static CaveTalk_Error_t CaveTalk_HandleOogaBooga (const CaveTalk_Handle_t * const handle , const CaveTalk_Length_t length )
723758{
724759 CaveTalk_Error_t error = CAVE_TALK_ERROR_NONE ;
@@ -1139,6 +1174,32 @@ static CaveTalk_Error_t CaveTalk_HandleRelativeMove(const CaveTalk_Handle_t *con
11391174 return error ;
11401175}
11411176
1177+ static CaveTalk_Error_t CaveTalk_HandleWaypoint (const CaveTalk_Handle_t * const handle , const CaveTalk_Length_t length )
1178+ {
1179+ CaveTalk_Error_t error = CAVE_TALK_ERROR_NONE ;
1180+
1181+ if ((NULL == handle ) || (NULL == handle -> buffer ))
1182+ {
1183+ error = CAVE_TALK_ERROR_NULL ;
1184+ }
1185+ else
1186+ {
1187+ pb_istream_t istream = pb_istream_from_buffer (handle -> buffer , length );
1188+ cave_talk_Waypoint waypoint_message = cave_talk_Waypoint_init_zero ;
1189+
1190+ if (!pb_decode (& istream , cave_talk_Waypoint_fields , & waypoint_message ))
1191+ {
1192+ error = CAVE_TALK_ERROR_PARSE ;
1193+ }
1194+ else if (NULL != handle -> listen_callbacks .hear_waypoint )
1195+ {
1196+ handle -> listen_callbacks .hear_waypoint (waypoint_message .type , waypoint_message .x_meters , waypoint_message .y_meters , waypoint_message .heading_radians );
1197+ }
1198+ }
1199+
1200+ return error ;
1201+ }
1202+
11421203static bool CaveTalk_EncodeString (pb_ostream_t * stream , const pb_field_t * field , void * const * arg )
11431204{
11441205 bool encoded = false;
0 commit comments