int segments_intersect(point p1, point p2, point p3, point p4)
{
    int d1, d2, d3, d4;
    int x_lb, x_ub, y_lb, y_ub;
    d1 = DIRECTION(p3, p4, p1);
    d2 = DIRECTION(p3, p4, p2);
    d3 = DIRECTION(p1, p2, p3);
    d4 = DIRECTION(p1, p2, p4);

    if (d1 * d2 < 0 && d3 * d4 < 0)
    {
        return 1;
    }

    x_lb = MIN(p3.x, p4.x);
    x_ub = MAX(p3.x, p4.x);
    y_lb = MIN(p3.y, p4.y);
    y_ub = MAX(p3.y, p4.y);

    if (d1 == 0 && IS_IN_RECT(x_lb, x_ub, y_lb, y_ub, p1.x, p1.y))
        return 1;
    if (d2 == 0 && IS_IN_RECT(x_lb, x_ub, y_lb, y_ub, p2.x, p2.y))
        return 1;
    if (d3 == 0 && IS_IN_RECT(p1.x, p2.x, p1.y, p2.y, p3.x, p3.y))
        return 1;
    if (d4 == 0 && IS_IN_RECT(p1.x, p2.x, p1.y, p2.y, p4.x, p4.y))
        return 1;

    return 0;
}
/* return 0 on success, 1 in case of error */
static int ct_seq_real_show(const struct ip_conntrack_tuple_hash *hash,
			    struct seq_file *s)
{
	struct ip_conntrack *conntrack = hash->ctrack;
	struct ip_conntrack_protocol *proto;

	MUST_BE_READ_LOCKED(&ip_conntrack_lock);

	IP_NF_ASSERT(conntrack);

	/* we only want to print DIR_ORIGINAL */
	if (DIRECTION(hash))
		return 0;

	proto = ip_ct_find_proto(conntrack->tuplehash[IP_CT_DIR_ORIGINAL]
			       .tuple.dst.protonum);
	IP_NF_ASSERT(proto);

	if (seq_printf(s, "%-8s %u %lu ",
		      proto->name,
		      conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum,
		      timer_pending(&conntrack->timeout)
		      ? (conntrack->timeout.expires - jiffies)/HZ : 0) != 0)
		return 1;

	if (proto->print_conntrack(s, conntrack))
		return 1;
  
	if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
			proto))
		return 1;

 	if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
		return 1;

	if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
		if (seq_printf(s, "[UNREPLIED] "))
			return 1;

	if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
			proto))
		return 1;

 	if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
		return 1;

	if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
		if (seq_printf(s, "[ASSURED] "))
			return 1;

#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
	if (seq_printf(s, "mark=%ld ", conntrack->mark))
		return 1;
#endif

	if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
		return 1;

	return 0;
}
CRemoteControlLinkData::CRemoteControlLinkData(const wxString& callsign, wxInt32 protocol, wxInt32 linked, wxInt32 direction, wxInt32 dongle) :
m_callsign(callsign),
m_protocol(PROTOCOL(protocol)),
m_linked(false),
m_direction(DIRECTION(direction)),
m_dongle(false)
{
	m_linked = linked == 1;
	m_dongle = dongle == 1;
}
예제 #4
0
enum imx233_i2c_error_t imx233_i2c_add(bool start, bool transmit, void *buffer, unsigned size, bool stop)
{
    if(i2c_nr_stages == I2C_NR_STAGES)
        return I2C_ERROR;
    /* align buffer end on cache boundary */
    uint32_t start_off = CACHEALIGN_UP(i2c_buffer_end);
    uint32_t end_off = start_off + size;
    if(end_off > I2C_BUFFER_SIZE)
    {
        panicf("die");
        return I2C_BUFFER_FULL;
    }
    i2c_buffer_end = end_off;
    if(transmit)
    {
        /* copy data to buffer */
        memcpy(i2c_buffer + start_off, buffer, size);
    }
    else
    {
        /* record pointers for finalization */
        i2c_stage[i2c_nr_stages].src = i2c_buffer + start_off;
        i2c_stage[i2c_nr_stages].dst = buffer;
    }
    
    if(i2c_nr_stages > 0)
    {
        i2c_stage[i2c_nr_stages - 1].dma.next = &i2c_stage[i2c_nr_stages].dma;
        i2c_stage[i2c_nr_stages - 1].dma.cmd |= BM_APB_CHx_CMD_CHAIN;
        if(!start)
            i2c_stage[i2c_nr_stages - 1].ctrl0 |= BM_I2C_CTRL0_RETAIN_CLOCK;
    }
    i2c_stage[i2c_nr_stages].dma.buffer = i2c_buffer + start_off;
    i2c_stage[i2c_nr_stages].dma.next = NULL;
    i2c_stage[i2c_nr_stages].dma.cmd = BF_OR4(APB_CHx_CMD,
        COMMAND(transmit ? BV_APB_CHx_CMD_COMMAND__READ : BV_APB_CHx_CMD_COMMAND__WRITE),
        WAIT4ENDCMD(1), CMDWORDS(1), XFER_COUNT(size));
    /* assume that any read is final (send nak on last) */
    i2c_stage[i2c_nr_stages].ctrl0 = BF_OR6(I2C_CTRL0,
        XFER_COUNT(size), DIRECTION(transmit), SEND_NAK_ON_LAST(!transmit),
        PRE_SEND_START(start), POST_SEND_STOP(stop), MASTER_MODE(1));
    i2c_nr_stages++;
    return I2C_SUCCESS;
}
예제 #5
0
void Room::InitializeWalls()
{
	//Initialisation des pivots et murs contours
	int x = 0;
	int y = 0;
	int row = 1;
	for (int i = 0; i < NB_PIVOTS_CONTOUR; i++)
	{
		pivotsContour[i] = new Wall(x, y);
		if (i < 5 || (i>=10 && i<15))
		{
			if (i!= 2 && i!=12)
				pivotsContour[i]->InitializeAttachedWall(x + TAILLE_PIVOT, y, EAST, true);
		}
		else if (i >= 5 && i < 8)
		{
			pivotsContour[i]->InitializeAttachedWall(x, y - 220, NORTH, true);
			x = LARGEUR - COLONNE_POINTAGE_LARGEUR - TAILLE_PIVOT;
		}
		else if (i >= 8 && i < 10)
		{
			pivotsContour[i]->InitializeAttachedWall(x, y + TAILLE_PIVOT , SOUTH, true);
		}

		if (i == 5 || i==7 || i==9)
		{
			x = 0;
			y += 220 + TAILLE_PIVOT;
		}
		else if (i == 6 || i==8)
		{
			x = LARGEUR - COLONNE_POINTAGE_LARGEUR - TAILLE_PIVOT;
		}
		else 
		{
			x += 220 + TAILLE_PIVOT;
		}
	}
	x = 220+TAILLE_PIVOT;
	y = 220+TAILLE_PIVOT;
	int dir = 0;
	// Initialisation des pivots et murs centraux
	for (int j = 0; j < NB_PIVOTS_CENTRE; j++)
	{
		pivotsCentre[j] = new Wall(x, y);
		dir = rand() % 8;
		pivotsCentre[j]->InitializeAttachedWall(x, y, DIRECTION(dir), false);
		for (int i = 0; i < j; i++)
		{
			if (pivotsCentre[j]->GetRectWall().intersects(pivotsCentre[i]->GetRectWall()))
			{
				while (pivotsCentre[j]->GetRectWall().intersects(pivotsCentre[i]->GetRectWall()))
				{
					pivotsCentre[j]->InitializeAttachedWall(x, y, DIRECTION(rand()%8), false);
				}
			}
		}
		x += 220 + TAILLE_PIVOT;
		if (x+(TAILLE_PIVOT*2) >= LARGEUR - COLONNE_POINTAGE_LARGEUR - TAILLE_PIVOT)
		{
			x = 220+TAILLE_PIVOT;
			y += 220 + TAILLE_PIVOT;
		}
	}
}
예제 #6
0
u_int
_token_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
{
	const struct token_header *trp;
	u_short extracted_ethertype;
	struct ether_header ehdr;
	u_int route_len = 0, hdr_len = TOKEN_HDRLEN;
	int seg;

	trp = (const struct token_header *)p;

	if (caplen < TOKEN_HDRLEN) {
		ND_PRINT((ndo, "%s", tstr));
		return hdr_len;
	}

	/*
	 * Get the TR addresses into a canonical form
	 */
	extract_token_addrs(trp, (char*)ESRC(&ehdr), (char*)EDST(&ehdr));

	/* Adjust for source routing information in the MAC header */
	if (IS_SOURCE_ROUTED(trp)) {
		/* Clear source-routed bit */
		*ESRC(&ehdr) &= 0x7f;

		if (ndo->ndo_eflag)
			token_hdr_print(ndo, trp, length, ESRC(&ehdr), EDST(&ehdr));

		if (caplen < TOKEN_HDRLEN + 2) {
			ND_PRINT((ndo, "%s", tstr));
			return hdr_len;
		}
		route_len = RIF_LENGTH(trp);
		hdr_len += route_len;
		if (caplen < hdr_len) {
			ND_PRINT((ndo, "%s", tstr));
			return hdr_len;
		}
		if (ndo->ndo_vflag) {
			ND_PRINT((ndo, "%s ", broadcast_indicator[BROADCAST(trp)]));
			ND_PRINT((ndo, "%s", direction[DIRECTION(trp)]));

			for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
				ND_PRINT((ndo, " [%d:%d]", RING_NUMBER(trp, seg),
				    BRIDGE_NUMBER(trp, seg)));
		} else {
			ND_PRINT((ndo, "rt = %x", EXTRACT_16BITS(&trp->token_rcf)));

			for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
				ND_PRINT((ndo, ":%x", EXTRACT_16BITS(&trp->token_rseg[seg])));
		}
		ND_PRINT((ndo, " (%s) ", largest_frame[LARGEST_FRAME(trp)]));
	} else {
		if (ndo->ndo_eflag)
			token_hdr_print(ndo, trp, length, ESRC(&ehdr), EDST(&ehdr));
	}

	/* Skip over token ring MAC header and routing information */
	length -= hdr_len;
	p += hdr_len;
	caplen -= hdr_len;

	/* Frame Control field determines interpretation of packet */
	if (FRAME_TYPE(trp) == TOKEN_FC_LLC) {
		/* Try to print the LLC-layer header & higher layers */
		if (llc_print(ndo, p, length, caplen, ESRC(&ehdr), EDST(&ehdr),
		    &extracted_ethertype) == 0) {
			/* ether_type not known, print raw packet */
			if (!ndo->ndo_eflag)
				token_hdr_print(ndo, trp,
				    length + TOKEN_HDRLEN + route_len,
				    ESRC(&ehdr), EDST(&ehdr));
			if (extracted_ethertype) {
				ND_PRINT((ndo, "(LLC %s) ",
			etherproto_string(htons(extracted_ethertype))));
			}
			if (!ndo->ndo_suppress_default_print)
				ND_DEFAULTPRINT(p, caplen);
		}
	} else {
		/* Some kinds of TR packet we cannot handle intelligently */
		/* XXX - dissect MAC packets if frame type is 0 */
		if (!ndo->ndo_eflag)
			token_hdr_print(ndo, trp, length + TOKEN_HDRLEN + route_len,
			    ESRC(&ehdr), EDST(&ehdr));
		if (!ndo->ndo_suppress_default_print)
			ND_DEFAULTPRINT(p, caplen);
	}
	return (hdr_len);
}
예제 #7
0
//
// The algo just checks the y=mx+b of the line
// and depending on the location of the vertex, etc
// it is in the triangle or not
// - no clipping
//
bool CheckSight(DriverBotPtr bot, DriverBotPtr nme)
{
	float rad;
	float tmp_heading;
	float tmp_x2;
	float tmp_y2;
	float tmp_x3;
	float tmp_y3;
	float a1, b1, a2, b2, a3, b3, a4, b4;
	float m1, m2, m3;
	float bb1, bb2, bb3;
	float center_x, center_y;
	int direction;
	bool AB_vert;
	bool BC_vert;
	bool CA_vert;
	int inside = 0;

	AB_vert = BC_vert = CA_vert = false;

	// now the next point of the triangle
	// shift by 45 degrees
	tmp_heading = bot->heading + 125.0f;
	if (tmp_heading > 360.0f)
		tmp_heading -= 360.0f;
	
	rad = tmp_heading / RAD_TO_DEG;

	tmp_x2 = LINE_OF_SIGHT * (float)cos(rad);
	tmp_y2 = LINE_OF_SIGHT * (float)sin(rad);

	tmp_x2 = tmp_x2 + bot->x;
	tmp_y2 = (-tmp_y2) + bot->y;

	// Now the final point
	tmp_heading = bot->heading + 55.0f;
	if (tmp_heading > 360.0f)
		tmp_heading -= 360.0f;

	rad = tmp_heading / RAD_TO_DEG;

	tmp_x3 = LINE_OF_SIGHT * (float)cos(rad);
	tmp_y3 = LINE_OF_SIGHT * (float)sin(rad);

	tmp_x3 = tmp_x3 + bot->x;
	tmp_y3 = (-tmp_y3) + bot->y;

	
	a1 = tmp_x2;
	b1 = tmp_y2;

	a2 = tmp_x3;
	b2 = tmp_y3;
	
	a3 = bot->x;
	b3 = bot->y;

	a4 = nme->x;
	b4 = nme->y;


	// find the slope of the different lines
	// have to check for divide by zero also
	if ((a2 - a1) != 0)
	{
		m1 = (b2 - b1) / (a2 - a1);		// a->b
		bb1 = (b1)-(m1 * a1);
	} else if ((a2 - a1) == 0) {
		AB_vert = true;
	} // end of the if-else

	// y = mx + b
	if ((a3 - a2) != 0)
	{
		m2 = (b3 - b2) / (a3 - a2);
		bb2 = (b2)-(m2 * a2);
	} else if ((a3 - a2) == 0) {
		BC_vert = true;
	} // end of if-else

	// y = mx + b
	if ((a1 - a3) != 0) 
	{
		m3 = (b1 - b3) / (a1 - a3);
		bb3 = (b3) - (m3 * a3);
	} else if ((a3 - a2) == 0) {
		CA_vert = true;
	} // end of the if-else

	center_x = (a1 + a2 + a3) / 3.0f;
	center_y = (b1 + b2 + b3) / 3.0f;

	// a->b
	if (((m1 * center_x) + bb1) >= center_y)
		DIRECTION(direction, UP);
	else
		DIRECTION(direction, DOWN);

	if (AB_vert == true) {
		if ((a1 < a4) && (a1 < center_x)) 
			inside++;
		else if ((a1 > a4) && (a1 > center_x)) 
			inside++;

	} else {
		if (direction == UP) {
			if (b4 <= ((m1 * a4) + bb1))
				inside++;
		} else if (direction == DOWN) {
			if (b4 >= ((m1 * a4) + bb1))
				inside++;
		} // end of if-else

	} // end of the if - else

	// b->c
	if (((m2 * center_x)+bb2) >= center_y)
		DIRECTION(direction,UP);
	else
		DIRECTION(direction, DOWN);

	if (BC_vert == true) {
		if (( a2 < a4) && (a2 < center_x))
			inside++;
		else if ((a2 > a4) && (a2 > center_x))
			inside++;

	} else {
		if (direction == UP) {
			if (b4 <= ((m2 * a4) + bb2))
				inside++;

		} else if (direction == DOWN) {

			if (b4 >= ((m2 * a4) + bb2))
				inside++;

		} // end of the if-else

	} // end of the if-else

	// c->a
	if (((m3 * center_x) + bb3) >= center_y)
		DIRECTION(direction, UP);
	else
		DIRECTION(direction, DOWN);

	if (CA_vert == true) {
		if ((a3 < a4) && (a3 < center_x))
			inside++;
		else if ((a3 > a4) && (a3 > center_x))
			inside++;
	} else {

		if (direction == UP) {
			if (b4 <= ((m3 * a4) + bb3))
				inside++;

		} else if (direction == DOWN) {
			if (b4 >= ((m3 * a4) + bb3))
				inside++;
		} // end of the if-else

	} // end of the if-else

#if DRAW_LINE_SIGHT
	//DrawLineOfSight(bot->x, bot->y, tmp_x, tmp_y);
	DrawLineOfSight(tmp_x2, tmp_y2, tmp_x3, tmp_y3);
	DrawLineOfSight(bot->x, bot->y, tmp_x2, tmp_y2);
	DrawLineOfSight(bot->x, bot->y, tmp_x3, tmp_y3);
#endif

	// check if point lies inside
	if (inside == 3) {

		return true;

	} else {
		return false;
	} // end of if-else

} // end of the function
예제 #8
0
DIRECTION Record::Direction()
{
	return DIRECTION(_dir);
}
static int
icmp_error_message(struct sk_buff *skb,
		   enum ip_conntrack_info *ctinfo,
		   unsigned int hooknum)
{
	struct ip_conntrack_tuple innertuple, origtuple;
	struct {
		struct icmphdr icmp;
		struct iphdr ip;
	} _in, *inside;
	struct ip_conntrack_protocol *innerproto;
	struct ip_conntrack_tuple_hash *h;
	int dataoff;

	IP_NF_ASSERT(skb->nfct == NULL);

	/* Not enough header? */
	inside = skb_header_pointer(skb, skb->nh.iph->ihl*4, sizeof(_in), &_in);
	if (inside == NULL)
		return -NF_ACCEPT;

	/* Ignore ICMP's containing fragments (shouldn't happen) */
	if (inside->ip.frag_off & htons(IP_OFFSET)) {
		DEBUGP("icmp_error_track: fragment of proto %u\n",
		       inside->ip.protocol);
		return -NF_ACCEPT;
	}

	innerproto = ip_conntrack_proto_find_get(inside->ip.protocol);
	dataoff = skb->nh.iph->ihl*4 + sizeof(inside->icmp) + inside->ip.ihl*4;
	/* Are they talking about one of our connections? */
	if (!ip_ct_get_tuple(&inside->ip, skb, dataoff, &origtuple, innerproto)) {
		DEBUGP("icmp_error: ! get_tuple p=%u", inside->ip.protocol);
		ip_conntrack_proto_put(innerproto);
		return -NF_ACCEPT;
	}

	/* Ordinarily, we'd expect the inverted tupleproto, but it's
	   been preserved inside the ICMP. */
	if (!ip_ct_invert_tuple(&innertuple, &origtuple, innerproto)) {
		DEBUGP("icmp_error_track: Can't invert tuple\n");
		ip_conntrack_proto_put(innerproto);
		return -NF_ACCEPT;
	}
	ip_conntrack_proto_put(innerproto);

	*ctinfo = IP_CT_RELATED;

	h = ip_conntrack_find_get(&innertuple, NULL);
	if (!h) {
		/* Locally generated ICMPs will match inverted if they
		   haven't been SNAT'ed yet */
		/* FIXME: NAT code has to handle half-done double NAT --RR */
		if (hooknum == NF_IP_LOCAL_OUT)
			h = ip_conntrack_find_get(&origtuple, NULL);

		if (!h) {
			DEBUGP("icmp_error_track: no match\n");
			return -NF_ACCEPT;
		}
		/* Reverse direction from that found */
		if (DIRECTION(h) != IP_CT_DIR_REPLY)
			*ctinfo += IP_CT_IS_REPLY;
	} else {
		if (DIRECTION(h) == IP_CT_DIR_REPLY)
			*ctinfo += IP_CT_IS_REPLY;
	}

	/* Update skb to refer to this connection */
	skb->nfct = &tuplehash_to_ctrack(h)->ct_general;
	skb->nfctinfo = *ctinfo;
	return -NF_ACCEPT;
}
예제 #10
0
u_int
token_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
{
	const struct token_header *trp;
	int llc_hdrlen;
	nd_mac_addr srcmac, dstmac;
	struct lladdr_info src, dst;
	u_int route_len = 0, hdr_len = TOKEN_HDRLEN;
	int seg;

	ndo->ndo_protocol = "token";
	trp = (const struct token_header *)p;

	if (caplen < TOKEN_HDRLEN) {
		nd_print_trunc(ndo);
		return hdr_len;
	}

	/*
	 * Get the TR addresses into a canonical form
	 */
	extract_token_addrs(trp, (char*)srcmac, (char*)dstmac);

	/* Adjust for source routing information in the MAC header */
	if (IS_SOURCE_ROUTED(trp)) {
		/* Clear source-routed bit */
		srcmac[0] &= 0x7f;

		if (ndo->ndo_eflag)
			token_hdr_print(ndo, trp, length, srcmac, dstmac);

		if (caplen < TOKEN_HDRLEN + 2) {
			nd_print_trunc(ndo);
			return hdr_len;
		}
		route_len = RIF_LENGTH(trp);
		hdr_len += route_len;
		if (caplen < hdr_len) {
			nd_print_trunc(ndo);
			return hdr_len;
		}
		if (ndo->ndo_vflag) {
			ND_PRINT("%s ", broadcast_indicator[BROADCAST(trp)]);
			ND_PRINT("%s", direction[DIRECTION(trp)]);

			for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
				ND_PRINT(" [%u:%u]", RING_NUMBER(trp, seg),
				    BRIDGE_NUMBER(trp, seg));
		} else {
			ND_PRINT("rt = %x", EXTRACT_BE_U_2(trp->token_rcf));

			for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
				ND_PRINT(":%x", EXTRACT_BE_U_2(trp->token_rseg[seg]));
		}
		ND_PRINT(" (%s) ", largest_frame[LARGEST_FRAME(trp)]);
	} else {
		if (ndo->ndo_eflag)
			token_hdr_print(ndo, trp, length, srcmac, dstmac);
	}

	src.addr = srcmac;
	src.addr_string = etheraddr_string;
	dst.addr = dstmac;
	dst.addr_string = etheraddr_string;

	/* Skip over token ring MAC header and routing information */
	length -= hdr_len;
	p += hdr_len;
	caplen -= hdr_len;

	/* Frame Control field determines interpretation of packet */
	if (FRAME_TYPE(trp) == TOKEN_FC_LLC) {
		/* Try to print the LLC-layer header & higher layers */
		llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst);
		if (llc_hdrlen < 0) {
			/* packet type not known, print raw packet */
			if (!ndo->ndo_suppress_default_print)
				ND_DEFAULTPRINT(p, caplen);
			llc_hdrlen = -llc_hdrlen;
		}
		hdr_len += llc_hdrlen;
	} else {
		/* Some kinds of TR packet we cannot handle intelligently */
		/* XXX - dissect MAC packets if frame type is 0 */
		if (!ndo->ndo_eflag)
			token_hdr_print(ndo, trp, length + TOKEN_HDRLEN + route_len,
			    srcmac, dstmac);
		if (!ndo->ndo_suppress_default_print)
			ND_DEFAULTPRINT(p, caplen);
	}
	return (hdr_len);
}