void FrobitInterface::on_nmea(const msgs::nmea::ConstPtr& msg)
{
	// Sort out messages according to NMEA identifier

	if(msg->valid)
	{
		if(msg->type == "PFBHI")
		{
			if(msg->data.size() == PFBHI_DATA_LENGTH)
				handle_startup_message(msg);
			else
				handle_corrupt_data(msg);
		}
		else if(msg->type == "PFBST")
		{
			if(msg->data.size() == PFBST_DATA_LENGTH)
				handle_status_message(msg);
			else
				handle_corrupt_data(msg);
		}
		else if(msg->type == "PFDAT")
		{
			handle_data_message(msg);
		}
		else
			handle_unknown_type(msg);
	}
	else
		handle_invalid_message(msg);
}
Exemple #2
0
static void
handle_message(struct peer_connection *pc, char *buffer, size_t length, uint32_t ppid, uint16_t i_stream)
{
	struct rtcweb_datachannel_open_request *req;
	struct rtcweb_datachannel_open_response *rsp;
	struct rtcweb_datachannel_ack *ack, *msg;

	switch (ppid) {
	case DATA_CHANNEL_PPID_CONTROL:
		if (length < sizeof(struct rtcweb_datachannel_ack)) {
			return;
		}
		msg = (struct rtcweb_datachannel_ack *)buffer;
		switch (msg->msg_type) {
		case DATA_CHANNEL_OPEN_REQUEST:
			if (length < sizeof(struct rtcweb_datachannel_open_request)) {
				/* XXX: error handling? */
				return;
			}
			req = (struct rtcweb_datachannel_open_request *)buffer;
			handle_open_request_message(pc, req, length, i_stream);
			break;
		case DATA_CHANNEL_OPEN_RESPONSE:
			if (length < sizeof(struct rtcweb_datachannel_open_response)) {
				/* XXX: error handling? */
				return;
			}
			rsp = (struct rtcweb_datachannel_open_response *)buffer;
			handle_open_response_message(pc, rsp, length, i_stream);
			break;
		case DATA_CHANNEL_ACK:
			if (length < sizeof(struct rtcweb_datachannel_ack)) {
				/* XXX: error handling? */
				return;
			}
			ack = (struct rtcweb_datachannel_ack *)buffer;
			handle_open_ack_message(pc, ack, length, i_stream);
			break;
		default:
			handle_unknown_message(buffer, length, i_stream);
			break;
		}
		break;
	case DATA_CHANNEL_PPID_DOMSTRING:
	case DATA_CHANNEL_PPID_BINARY:
		handle_data_message(pc, buffer, length, i_stream);
		break;
	default:
		printf("Message of length %zu, PPID %u on stream %u received.\n",
		       length, ppid, i_stream);
		break;
	}
}