host/stream_comm.c
/** Send a packet.
  * \param message_id The message ID of the packet.
  * \param fields Field description array.
  * \param src_struct Field data which will be serialised and sent.
  */
Send a packet.
\param message_id The message ID of the packet.
\param fields Field description array.
\param src_struct Field data which will be serialised and sent.
Send a packet . \ param message_id The message ID of the packet . \ param fields Field description array . \ param src_struct Field data which will be serialised and sent .
static void sendPacket(uint16_t message_id, const pb_field_t fields[], const void *src_struct)
{
	uint8_t buffer[4];
	pb_ostream_t substream;
	assert(payload_length == 0);
	substream.callback = NULL;
	substream.state = NULL;
	substream.max_size = MAX_SEND_SIZE;
	substream.bytes_written = 0;
	if (!pb_encode(&substream, fields, src_struct))
		fatalError();
	printf("Message sent to host:");
	streamPutOneByte('#');
	streamPutOneByte('#');
	streamPutOneByte((uint8_t)(message_id >> 8));
	streamPutOneByte((uint8_t)message_id);
	writeU32BigEndian(buffer, substream.bytes_written);
	writeBytesToStream(buffer, 4);
	main_output_stream.bytes_written = 0;
	main_output_stream.max_size = substream.bytes_written;
	if (!pb_encode(&main_output_stream, fields, src_struct))
		fatalError();
	printf("\n");
}
static void sendPacket ( uint16_t message_id , const pb_field_t fields [ ] , const void * src_struct ) { uint8_t buffer [ 4 ] ; pb_ostream_t substream ; assert ( payload_length == 0 ) ; substream . callback = NULL ; substream . state = NULL ; substream . max_size = MAX_SEND_SIZE ; substream . bytes_written = 0 ; if ( ! pb_encode ( & substream , fields , src_struct ) ) fatalError ( ) ; printf ( " " ) ; streamPutOneByte ( ' ' ) ; streamPutOneByte ( ' ' ) ; streamPutOneByte ( ( uint8_t ) ( message_id >> 8 ) ) ; streamPutOneByte ( ( uint8_t ) message_id ) ; writeU32BigEndian ( buffer , substream . bytes_written ) ; writeBytesToStream ( buffer , 4 ) ; main_output_stream . bytes_written = 0 ; main_output_stream . max_size = substream . bytes_written ; if ( ! pb_encode ( & main_output_stream , fields , src_struct ) ) fatalError ( ) ; printf ( " \n " ) ; }
Send a packet.
Send a packet .
/*
	 * From PROTOCOL, the current received packet must be fully consumed
	 * before any response can be sent.
	 */ /*
	 * Use a non-writing substream to get the length of the message without
	 * storing it anywhere.
	 */ /* Send packet header. */ /* Send actual message. */