obcsim/msp_obc_link.c
struct msp_response msp_send_data_frame(msp_link_t *lnk,
                                        unsigned char *data,
                                        unsigned long datalen)
{
	int code;
	struct msp_obc_frame frame;
	unsigned long len;

	if (lnk == NULL || data == NULL || lnk->buffer == NULL)
		return msp_response_error(MSP_OBC_ERR_NULL_POINTER);

	if (lnk->next_action != MSP_LINK_ACTION_TX_DATA) {
		lnk->corrupt_frame_count += 1;
		return msp_response_error(MSP_OBC_ERR_INVALID_ACTION);
	}

	if (datalen != msp_next_data_length(lnk)) {
		lnk->corrupt_frame_count += 1;
		return msp_response_error(MSP_OBC_ERR_INVALID_LENGTH);
	}

	frame.type = MSP_OBC_FRAME_DATA;
	frame.id = lnk->frame_id;
	frame.opcode = MSP_OP_DATA_FRAME;
	frame.data = data;
	frame.datalen = datalen;

	code = msp_obc_encode_frame(lnk, lnk->buffer, &len, frame);
	if (code) {
		lnk->corrupt_frame_count += 1;
		return msp_response_error(code);
	}

	code = msp_i2c_write(lnk->slave_address, lnk->buffer, len);
	if (code) {
		lnk->corrupt_frame_count += 1;
		return msp_response_error(MSP_OBC_ERR_I2C_ERROR);
	}

	/* Increment number of bytes sent */
	lnk->processed_length += datalen;

	/* Read acknowledge of data frame next */
	lnk->next_action = MSP_LINK_ACTION_RX_HEADER;

	return msp_response_ok();
}
/*
 * Blocking (send over I2C)
 *
 * Sends a data frame to the experiment with the data pointed to by the pointer
 * data and length datalen.
 *
 * This function will also update the state of the link.
 *
 * If the link is in an incorrect state or if any of the inputs are invalid
 * then no I2C transmission will be made and an error will be returned.
 */
Blocking (send over I2C)

Sends a data frame to the experiment with the data pointed to by the pointer
data and length datalen.

This function will also update the state of the link.

If the link is in an incorrect state or if any of the inputs are invalid
then no I2C transmission will be made and an error will be returned.
Blocking ( send over I2C ) Sends a data frame to the experiment with the data pointed to by the pointer data and length datalen . This function will also update the state of the link . If the link is in an incorrect state or if any of the inputs are invalid then no I2C transmission will be made and an error will be returned .
struct msp_response msp_send_data_frame(msp_link_t *lnk,
                                        unsigned char *data,
                                        unsigned long datalen)
{
	int code;
	struct msp_obc_frame frame;
	unsigned long len;
	if (lnk == NULL || data == NULL || lnk->buffer == NULL)
		return msp_response_error(MSP_OBC_ERR_NULL_POINTER);
	if (lnk->next_action != MSP_LINK_ACTION_TX_DATA) {
		lnk->corrupt_frame_count += 1;
		return msp_response_error(MSP_OBC_ERR_INVALID_ACTION);
	}
	if (datalen != msp_next_data_length(lnk)) {
		lnk->corrupt_frame_count += 1;
		return msp_response_error(MSP_OBC_ERR_INVALID_LENGTH);
	}
	frame.type = MSP_OBC_FRAME_DATA;
	frame.id = lnk->frame_id;
	frame.opcode = MSP_OP_DATA_FRAME;
	frame.data = data;
	frame.datalen = datalen;
	code = msp_obc_encode_frame(lnk, lnk->buffer, &len, frame);
	if (code) {
		lnk->corrupt_frame_count += 1;
		return msp_response_error(code);
	}
	code = msp_i2c_write(lnk->slave_address, lnk->buffer, len);
	if (code) {
		lnk->corrupt_frame_count += 1;
		return msp_response_error(MSP_OBC_ERR_I2C_ERROR);
	}
	lnk->processed_length += datalen;
	lnk->next_action = MSP_LINK_ACTION_RX_HEADER;
	return msp_response_ok();
}
struct msp_response msp_send_data_frame ( msp_link_t * lnk , unsigned char * data , unsigned long datalen ) { int code ; struct msp_obc_frame frame ; unsigned long len ; if ( lnk == NULL || data == NULL || lnk -> buffer == NULL ) return msp_response_error ( MSP_OBC_ERR_NULL_POINTER ) ; if ( lnk -> next_action != MSP_LINK_ACTION_TX_DATA ) { lnk -> corrupt_frame_count += 1 ; return msp_response_error ( MSP_OBC_ERR_INVALID_ACTION ) ; } if ( datalen != msp_next_data_length ( lnk ) ) { lnk -> corrupt_frame_count += 1 ; return msp_response_error ( MSP_OBC_ERR_INVALID_LENGTH ) ; } frame . type = MSP_OBC_FRAME_DATA ; frame . id = lnk -> frame_id ; frame . opcode = MSP_OP_DATA_FRAME ; frame . data = data ; frame . datalen = datalen ; code = msp_obc_encode_frame ( lnk , lnk -> buffer , & len , frame ) ; if ( code ) { lnk -> corrupt_frame_count += 1 ; return msp_response_error ( code ) ; } code = msp_i2c_write ( lnk -> slave_address , lnk -> buffer , len ) ; if ( code ) { lnk -> corrupt_frame_count += 1 ; return msp_response_error ( MSP_OBC_ERR_I2C_ERROR ) ; } lnk -> processed_length += datalen ; lnk -> next_action = MSP_LINK_ACTION_RX_HEADER ; return msp_response_ok ( ) ; }
Blocking (send over I2C)
Blocking ( send over I2C )
/* Increment number of bytes sent */ /* Read acknowledge of data frame next */