<commit_before>#include "global.h"
#include "communication.h"
#include "parameter.h"

extern mavlink_message_t received_msg;

mavlink_message_t msg;

void parameter_read_value(void)
{
	AccessRight data_access_right;
	Type data_type;
	int data_int;
	float data_float;
	char *data_name;

	int i, modifiable_data_cnt = 0;
	for(i = 0; i < get_global_data_count(); i++) {

		/* If the access right equal to READ_WRITE, send the data to the ground station */
		get_global_data_access_right(i, &data_access_right);
		if(data_access_right == READ_WRITE) {

			/* Prepare the data */
			get_global_data_type(i, &data_type);
			if(data_type == INTEGER)
				read_global_data_int(i, &data_int);
			else
				read_global_data_float(i, &data_float);

			/* Get the data name*/
			read_global_data_name(i, &data_name);

			/* Send out the data */
			mavlink_msg_param_value_pack(
				1, 0, &msg,
				data_name,   		              /* Data name */ 
				data_type ? data_float : data_int,    /* Data value */
				data_type ? MAV_PARAM_TYPE_REAL32 : MAV_PARAM_TYPE_INT16, /* Data type */
				(uint16_t)get_modifiable_data_count(), /* Data count */
				modifiable_data_cnt		       /* Index */
			);
			send_package(&msg);

			modifiable_data_cnt++;
		}
	}
}

void parameter_read_single_value(void)
{
	mavlink_param_request_read_t mprr;
	mavlink_msg_param_request_read_decode(&received_msg, &mprr);

	AccessRight data_access_right;
	Type data_type;
	int data_int;
	float data_float;
	char *data_name;

	int i;
	for(i = 0; i < get_global_data_count(); i++) {
		/* If the access right equal to READ_WRITE, send the data to the ground station */
		get_global_data_access_right(i, &data_access_right);
		if(data_access_right == READ_ONLY)
			continue;

		/* Get the data name */
		read_global_data_name(i, &data_name);

		if(strcmp(data_name, mprr.param_id) == 0) {
			/* Prepare the data */
			get_global_data_type(i, &data_type);
			if(data_type == INTEGER)
				read_global_data_int(i, &data_int);
			else
				read_global_data_float(i, &data_float);
			
			/* Send out the data */
			mavlink_msg_param_value_pack(
				1, 0, &msg,
				data_name,  		 	       /* Data name */ 
				data_type ? data_float : data_int,     /* Data value */
				data_type ? MAV_PARAM_TYPE_REAL32 : MAV_PARAM_TYPE_INT16, /* Data type */
				(uint16_t)get_modifiable_data_count(), /* Data count */
				mprr.param_index 		       /* Index */
			);
			send_package(&msg);

			break;
		}
	}
}

void parameter_write_value(void)
{
	mavlink_param_set_t mps;	
	mavlink_msg_param_set_decode(&received_msg, &mps);

	Type data_type;
	int data_int;
	float data_float;
	char *data_name;

	int i;
	for(i = 0; i < get_global_data_count(); i++) {
		/* Get the data name */
		read_global_data_name(i, &data_name);

		/* Compare the global data with the parameter id */
		if(strcmp(data_name, mps.param_id) == 0) {
			get_global_data_type(i, &data_type);
			
			/* Update the new value */
			if(data_type == INTEGER) {
				set_global_data_int(i, mps.param_value);
				data_int = mps.param_value;
			} else {
				set_global_data_float(i, mps.param_value);
				data_float = mps.param_value;
			}

			/* Ack message */
			mavlink_msg_param_value_pack(
				1, 0, &msg,
				data_name,   			       /* Data name */ 
				data_type ? data_float : data_int,     /* Data value */
				data_type ? MAV_PARAM_TYPE_REAL32 : MAV_PARAM_TYPE_INT16, /* Data type */
				get_modifiable_data_count(), 	       /* Data count */
				i		 		       /* Index */
			);
			send_package(&msg);

			break;
		}
	}
}<commit_msg>Reconstruct the code of mavlink parameter configuration<commit_after>#include "global.h"
#include "communication.h"
#include "parameter.h"

extern mavlink_message_t received_msg;

mavlink_message_t msg;

void parameter_read_value(void)
{
	AccessRight data_access_right;
	Type data_type;
	Data data;
	char *data_name;

	int i, modifiable_data_cnt = 0;
	for(i = 0; i < get_global_data_count(); i++) {

		/* If the access right equal to READ_WRITE, send the data to the ground station */
		get_global_data_access_right(i, &data_access_right);
		if(data_access_right == READ_WRITE) {

			/* Prepare the data */
			get_global_data_type(i, &data_type);
			read_global_data_value(i, DATA_POINTER_CAST(&data));

			/* Get the data name*/
			read_global_data_name(i, &data_name);

			switch(data_type) {
			    case UINT8:
				/* Send out the data */
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.uint8_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					modifiable_data_cnt		       /* Index */
				);
				break;
			    case INT8:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.int8_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					modifiable_data_cnt		       /* Index */
				);
				break;
			    case UINT16:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.uint16_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					modifiable_data_cnt		       /* Index */
				);
				break;
			    case INT16:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.int16_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					modifiable_data_cnt		       /* Index */
				);
				break;
			    case UINT32:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.uint32_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					modifiable_data_cnt		       /* Index */
				);
				break;
			    case INT32:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.int32_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					modifiable_data_cnt		       /* Index */
				);
				break;
			    case FLOAT:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.float_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					modifiable_data_cnt		       /* Index */
				);
				break;
			}
			send_package(&msg);

			modifiable_data_cnt++;
		}
	}
}

void parameter_read_single_value(void)
{
	mavlink_param_request_read_t mprr;
	mavlink_msg_param_request_read_decode(&received_msg, &mprr);

	AccessRight data_access_right;
	Type data_type;
	Data data;
	char *data_name;

	int i;
	for(i = 0; i < get_global_data_count(); i++) {
		/* If the access right equal to READ_WRITE, send the data to the ground station */
		get_global_data_access_right(i, &data_access_right);
		if(data_access_right == READ_ONLY)
			continue;

		/* Get the data name */
		read_global_data_name(i, &data_name);

		if(strcmp(data_name, mprr.param_id) == 0) {
			/* Prepare the data */
			get_global_data_type(i, &data_type);
			read_global_data_value(i, DATA_POINTER_CAST(&data));

			switch(data_type) {
			    case UINT8:
				/* Send out the data */
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.uint8_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					mprr.param_index		       /* Index */
				);
				break;
			    case INT8:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.int8_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					mprr.param_index		       /* Index */
				);
				break;
			    case UINT16:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.uint16_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					mprr.param_index		       /* Index */
				);
				break;
			    case INT16:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.int16_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					mprr.param_index		       /* Index */
				);
				break;
			    case UINT32:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.uint32_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					mprr.param_index		       /* Index */
				);
				break;
			    case INT32:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.int32_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					mprr.param_index		       /* Index */
				);
				break;
			    case FLOAT:
				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.float_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					mprr.param_index		       /* Index */
				);
				break;
			}
			
			/* Send out the data */
			send_package(&msg);

			break;
		}
	}
}

void parameter_write_value(void)
{
	mavlink_param_set_t mps;	
	mavlink_msg_param_set_decode(&received_msg, &mps);

	Type data_type;
	Data data;
	char *data_name;

	int i;
	for(i = 0; i < get_global_data_count(); i++) {
		/* Get the data name */
		read_global_data_name(i, DATA_POINTER_CAST(&data_name));

		/* Compare the global data with the parameter id */
		if(strcmp(data_name, mps.param_id) == 0) {
			get_global_data_type(i, &data_type);
			
			/* Update the new value */
			set_global_data_value(i, mps.param_type, DATA_CAST(mps.param_value));

			/* Ack message */
			switch(data_type) {
			    case UINT8:
				/* Send out the data */
				data.uint8_value = mps.param_value;

				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.uint8_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					i				       /* Index */
				);
				break;
			    case INT8:
				data.int8_value = mps.param_value;	

				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.int8_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					i				       /* Index */
				);
				break;
			    case UINT16:
				data.uint16_value = mps.param_value;

				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.uint16_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					i				       /* Index */
				);
				break;
			    case INT16:
				data.int16_value = mps.param_value;

				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.int16_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					i				       /* Index */
				);
				break;
			    case UINT32:
				data.uint32_value = mps.param_value;				

				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.uint32_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					i				       /* Index */
				);
				break;
			    case INT32:
				data.int32_value = mps.param_value;

				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.int32_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					i				       /* Index */
				);
				break;
			    case FLOAT:
				data.float_value = mps.param_value;

				mavlink_msg_param_value_pack(
					1, 0, &msg,
					data_name,   		               /* Data name */ 
					data_type,			       /* Data value */
					data.float_value ,		       /* Data type */
					(uint16_t)get_modifiable_data_count(), /* Data count */
					i				       /* Index */
				);
				break;
			}

			send_package(&msg);

			break;
		}
	}
}
{'fraction_non_alphanumeric': 0.11574461608705577, 'fraction_numerical': 0.014306369378281714, 'mean_word_length': 2.071278336059827, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7559950', 'n_tokens_mistral': 5942, 'n_tokens_neox': 4640, 'n_words': 918}