Ejemplo n.º 1
0
Archivo: userapp.c Proyecto: bbdlg/dust
void procUdpMsg(const char* logicName, const int fd, const char* recvbuf, const int recvlen, void* from)
{
   char sendbuf[1024] = {0};
   int sendlen = 0, len = 0;
   sprintf(sendbuf, "recv <%d> bytes from u.", recvlen);
   sendlen = strlen(sendbuf);

   printf("recv: [%s]\n", recvbuf);
   len = sizeof(struct sockaddr);
   commSend(fd, sendbuf, &sendlen, from);
}
Ejemplo n.º 2
0
void commRevTask(void)
{
		u8	 i,temp;
		if(	fgReceived )
		{
				u8commStatus = 0;
				for(i=0,temp=0;i<(TOTAL_RX_BYTE-1);i++)	temp +=	RxBuf[i];
				if( (temp == RxBuf[TOTAL_RX_BYTE-1])	&& (RxBuf[0] == 0x5a) )
				{
					GetMainBoardInfo();
					delay(30);
					commSend();
				}
				else
				{
					GPIO_Init(TxRxPort, RX, GPIO_MODE_IN_PU_IT);	//开接收中断				
				}
		}
}
Ejemplo n.º 3
0
Archivo: userapp.c Proyecto: bbdlg/dust
/* Periodic Callback Function */
void checkEvent(const struct timeval curTimeval)
{
   char* data = "hallo world!\n";
   char recvdata[1024] = {0};
   int datalen = strlen(data);
   int sum;
   int* pFd = NULL;
   commGetAliveLinks("Udp-2", &sum, &pFd);
   if(pFd && (*pFd > 0)) {
      commSend(*pFd, data, &datalen, NULL);
      DEBUGINFO("send <%d> bytes~", datalen);
   }
#ifdef WIN32
   Sleep(2000);
#else
   sleep(2);
#endif
   
   return;
}
Ejemplo n.º 4
0
int txFrame(int sock, const struct sockaddr_in* destination, int width, int height, txState_t* state, const char* frameBuffer)
{
	if(!frameBuffer) return -1;

	// calculate some values that will be needed later on	
	size_t frameBufferSize = width * height; // size in bytes of the grayscale framebuffer

	if(FIRST_RUN){
		STR_MTU = frameBufferSize;

		while(STR_MTU > 6000){
			STR_MTU >>= 1;
		}

		FIRST_RUN = 0;
	}

	int regions = frameBufferSize / STR_MTU; // number of chunks that the framebuffer will be split up into
	size_t regionBytes = frameBufferSize / regions; // bytes in each chunk
	int regionHeight   = height / regions;          // height in pixels of each region


#ifdef CMP_DEBUG
	printf("Frame: %zu(B)\nRegions: %d\nRegion height: %d\n", 
		frameBufferSize,
		regions,
		regionHeight
	);
#endif

	// for each region, compress, and send
	for(int i = regions; i--;){	
		frameHeader_t header = vidCompressFrame(
			width, height, 
			frameBuffer + (i * regionBytes),
			regionBytes,
			TX_BUF + sizeof(frameHeader_t),
			STR_MTU - sizeof(frameHeader_t) // account for the header
		);

#ifdef CMP_DEBUG
		printf("Compressed region %d\n", i);
#endif

		// update the region information
		header.region.x = 0;
		header.region.y = regionHeight * i;
		header.region.w = width;
		header.region.h = regionHeight;

		// now that we have a header, copy it into the start of the txBuf
		((frameHeader_t*)TX_BUF)[0] = header;

#ifdef CMP_DEBUG
		printf("Region: (%d, %d) - (%d, %d)\n", header.region.x, header.region.y, header.region.w, header.region.h);
#endif

		commSend(MSG_VIDEO, NULL, 0, (struct sockaddr_in*)destination);

		int res = sendto(
			sock,
			TX_BUF,
			sizeof(frameHeader_t),
			0,
			(struct sockaddr*)destination,
			sizeof(*destination)
		);

		res = sendto(
			sock,
			TX_BUF + sizeof(frameHeader_t),
			header.bytes,
			0,
			(struct sockaddr*)destination,
			sizeof(*destination)
		);


#ifdef CMP_DEBUG
		printf("Transmission res %d (errno %d)\n", res, errno);
#endif

		// transmission failed, and we know it was because the 
		// chunk was too damn big
		if(res < 0 && errno == 40){
			errno = 0; // reset
			STR_MTU >>= 1;
			return -2;	
		}
	}