Permalink
Browse files

Added const fixes to headers and generator

  • Loading branch information...
1 parent 68bef8e commit 461d0cd0bdd7a35129c705f2225f7c2c732b6ccf @LorenzMeier LorenzMeier committed Mar 14, 2012
@@ -17,7 +17,7 @@
****************************************************************************/
-#include "testing/mavlink_missionlib_data.h"
+#include "mavlink_missionlib_data.h"
#include "mavlink_parameters.h"
#include "math.h" /* isinf / isnan checks */
@@ -52,7 +52,7 @@ static inline void crc_init(uint16_t* crcAccum)
* @param length length of the byte array
* @return the checksum over the buffer bytes
**/
-static inline uint16_t crc_calculate(uint8_t* pBuffer, uint16_t length)
+static inline uint16_t crc_calculate(const uint8_t* pBuffer, uint16_t length)
{
uint16_t crcTmp;
crc_init(&crcTmp);
@@ -18,6 +18,24 @@ MAVLINK_HELPER mavlink_status_t* mavlink_get_channel_status(uint8_t chan)
return &m_mavlink_status[chan];
}
+/*
+ internal function to give access to the channel buffer for each channel
+ */
+MAVLINK_HELPER mavlink_message_t* mavlink_get_channel_buffer(uint8_t chan)
+{
+
+#if MAVLINK_EXTERNAL_RX_BUFFER
+ // No m_mavlink_message array defined in function,
+ // has to be defined externally
+#ifndef m_mavlink_message
+#error ERROR: IF #define MAVLINK_EXTERNAL_RX_BUFFER IS SET, THE BUFFER HAS TO BE ALLOCATED OUTSIDE OF THIS FUNCTION (mavlink_message_t m_mavlink_buffer[MAVLINK_COMM_NUM_BUFFERS];)
+#endif
+#else
+ static mavlink_message_t m_mavlink_buffer[MAVLINK_COMM_NUM_BUFFERS];
+#endif
+ return &m_mavlink_buffer[chan];
+}
+
/**
* @brief Finalize a MAVLink message with channel assignment
*
@@ -120,7 +138,7 @@ MAVLINK_HELPER void _mav_finalize_message_chan_send(mavlink_channel_t chan, uint
*/
MAVLINK_HELPER uint16_t mavlink_msg_to_send_buffer(uint8_t *buffer, const mavlink_message_t *msg)
{
- memcpy(buffer, (uint8_t *)&msg->magic, MAVLINK_NUM_NON_PAYLOAD_BYTES + (uint16_t)msg->len);
+ memcpy(buffer, (const uint8_t *)&msg->magic, MAVLINK_NUM_NON_PAYLOAD_BYTES + (uint16_t)msg->len);
return MAVLINK_NUM_NON_PAYLOAD_BYTES + (uint16_t)msg->len;
}
@@ -182,8 +200,6 @@ MAVLINK_HELPER void mavlink_update_checksum(mavlink_message_t* msg, uint8_t c)
*/
MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_message_t* r_message, mavlink_status_t* r_mavlink_status)
{
- static mavlink_message_t m_mavlink_message[MAVLINK_COMM_NUM_BUFFERS];
-
/*
default message crc function. You can override this per-system to
put this data in a different memory segment
@@ -195,7 +211,7 @@ MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_messa
#endif
#endif
- mavlink_message_t* rxmsg = &m_mavlink_message[chan]; ///< The currently decoded message
+ mavlink_message_t* rxmsg = mavlink_get_channel_buffer(chan); ///< The currently decoded message
mavlink_status_t* status = mavlink_get_channel_status(chan); ///< The current decode status
int bufferIndex = 0;
@@ -209,6 +225,7 @@ MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_messa
{
status->parse_state = MAVLINK_PARSE_STATE_GOT_STX;
rxmsg->len = 0;
+ rxmsg->magic = c;
mavlink_start_checksum(rxmsg);
}
break;
@@ -269,7 +286,7 @@ MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_messa
break;
case MAVLINK_PARSE_STATE_GOT_MSGID:
- _MAV_PAYLOAD(rxmsg)[status->packet_idx++] = (char)c;
+ _MAV_PAYLOAD_NON_CONST(rxmsg)[status->packet_idx++] = (char)c;
mavlink_update_checksum(rxmsg, c);
if (status->packet_idx == rxmsg->len)
{
@@ -296,6 +313,7 @@ MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_messa
else
{
status->parse_state = MAVLINK_PARSE_STATE_GOT_CRC1;
+ _MAV_PAYLOAD_NON_CONST(rxmsg)[status->packet_idx] = (char)c;
}
break;
@@ -317,6 +335,7 @@ MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_messa
// Successfully got message
status->msg_received = 1;
status->parse_state = MAVLINK_PARSE_STATE_IDLE;
+ _MAV_PAYLOAD_NON_CONST(rxmsg)[status->packet_idx+1] = (char)c;
memcpy(r_message, rxmsg, sizeof(mavlink_message_t));
}
break;
Oops, something went wrong.

0 comments on commit 461d0cd

Please sign in to comment.