Ejemplo n.º 1
0
// Heart Beat requeset
APP_Error HeartBeat_Request(TLP_Head_Struct *pHeadInfo)
{
	GSM_Error		res;

	uint32_t		timestamp;
	Packet_Struct   Packet;
	uint16_t		crc_resault;
	TLP_Head_Struct	*PacketHead;
	uint8_t			*pData;

	PacketHead = (TLP_Head_Struct *)&(Packet.Data[0]);
	pData      = (uint8_t *)&(Packet.Data[0]) + sizeof(TLP_Head_Struct);
	
	// no need to change
	PacketHead->version = _VERSION;
	PacketHead->length  = sizeof(TLP_Head_Struct);
	PacketHead->type    = _TransmitCtrl;			// device to server
	PacketHead->medium  = _TransmitType;			// UDP
	PacketHead->encrypt = _Encrypt;					// encrypt none
	PacketHead->reserve = _Reserve;			
	
	PacketHead->DEV_IDH = HTONL(_DEV_IDH);
	PacketHead->DEV_IDL = HTONL(_DEV_IDL);
	
	//need to change
	GetTimestamp(&timestamp);
	PacketHead->timestamp = HTONL(timestamp);		// need to fix
	PacketHead->SEQ_num   = HTONL(Get_SEQ());
	
	// send the ack
	*(pData++) = HEART_BEAT;						// command type
	*(pData++) = (uint8_t)(_HeartBeat>>8);
	*(pData++) = (uint8_t)(_HeartBeat);				// action

	Packet.length = pData - ((uint8_t *)&(Packet.Data[0]));

	// get the crc16
	pData         = (uint8_t *)&(Packet.Data[0]) + 2;	
	crc_resault   = Caculate(pData, (Packet.length-2));
	PacketHead->crc16 = HTONS(crc_resault);
	
	// send packet
	res = UDP_SendPacket((char *)&(Packet.Data[0]), Packet.length);
	
	if(res!=ERR_NONE){
		DEBUG("%s : ACK ...Error!\n",__func__);
		return APP_ERR_SEND;
	} else {
		DEBUG("%s : ACK ...OK\n",__func__);
		return APP_ERR_NONE;
	}
}
Ejemplo n.º 2
0
TwoColor::TwoColor(Graph& graph):graph_(graph), is_two_color_(true)
{
	uint32_t size = graph_.V();
	marked_ = new bool[size];
	color_ = new bool[size];

	for(uint32_t i = 0; i<size; ++i) {
		marked_[i] = false;
		color_[i] = false;
	}

	Caculate();
}