Esempio n. 1
0
/**
 * Should allocate a pbuf and transfer the bytes of the incoming
 * packet from the interface into the pbuf.
 *
 * @param netif the lwip network interface structure for this ethernetif
 * @return a pbuf filled with the received packet (including MAC header)
 *         NULL on memory error
 */
static struct pbuf *
low_level_input(struct netif *netif)
{
 
  //return NULL;
  return PacketReceive(netif);  
}
Esempio n. 2
0
File: ztcp.c Progetto: chungy/zsnes
int SendData(int dsize,unsigned char *dptr)
{
   int retval;

   if (UDPEnable){
/*      retval = sendto(ugamesocket,dptr,dsize,0,(struct sockaddr *)&ugameaddress,sizeof(ugameaddress));
      if (retval == SOCKET_ERROR)
           {
         closesocket(gamesocket);
         return(-1);
           }
      return(0);  */

     if (((packetnum-packetnumhead) & 0xFF) >= 15){
//        sprintf(message1,"Packet Overflow.");
//        MessageBox (NULL, message1, "Init Error" , MB_ICONERROR );

        // wait for receive packet, call JoyRead while waiting
        while (((packetnum-packetnumhead) & 0xFF) >= 15){
           PacketResend();
           PacketReceive();
           UpdateVFrame();
           while ((packetconfirm[packetnumhead]) && (packetnum!=packetnumhead))
             packetnumhead=(packetnumhead+1) & 0xFF;
        }
     }
     CopyMemory(&(cpacketdata[2]),dptr,dsize);
     CopyMemory(&(packetdata[2048*(packetnum & 0x0F)]),dptr,dsize);
     packetsize[packetnum]=dsize;
     packetconfirm[packetnum]=0;
     cpacketdata[0]=1;
     cpacketdata[1]=(char)packetnum;
     retval = sendto(ugamesocket,cpacketdata,dsize+2,0,(struct sockaddr *)&ugameaddress,sizeof(ugameaddress));
     packettimeleft[packetnum]=60;
     if (dsize>512) packettimeleft[packetnum]=90;
     packetresent[packetnum]=1;
     packetnum=(packetnum+1) & 0xFF;
     if (retval == SOCKET_ERROR)
          {
        closesocket(ugamesocket);
        return(-1);
          }
     return(0);
   }

   /* send data with the socket */
   retval = send(gamesocket,dptr,dsize,0);
   if (retval == SOCKET_ERROR)
	{
      closesocket(gamesocket);
      return(-1);
	}
   return(0);
}
Esempio n. 3
0
/**************************************************************************//**
 * @brief Request AEM (Advanced Energy Monitoring) voltage from board controller.
 *
 * @note Assumes that BSP_Init() has been called with @ref BSP_INIT_STK_BCUART
  *      bitmask.
 *
 * @return
 *   The voltage. Returns 0.0 on board controller communication
 *   error.
 *****************************************************************************/
float BSP_VoltageGet(void)
{
  STK_Packet pkt;
  float      voltage;

  pkt.type          = STK_PACKETTYPE_VOLTAGE_REQ;
  pkt.payloadLength = 0;

  /* Send Request/Get reply */
  PacketSend(&pkt);
  PacketReceive(&pkt);

  /* Process reply */
  if (pkt.type == STK_PACKETTYPE_VOLTAGE_REPLY)
  {
    memcpy(&voltage, pkt.data, sizeof(float));
    return voltage;
  }
  else
  {
    return (float) 0.0;
  }
}
Esempio n. 4
0
/**************************************************************************//**
 * @brief Request AEM (Advanced Energy Monitoring) current from board controller.
 *
 * @note Assumes that BSP_Init() has been called with @ref BSP_INIT_STK_BCUART
 *       bitmask.
 *
 * @return
 *   The current expressed in milliamperes. Returns 0.0 on board controller
 *   communication error.
 *****************************************************************************/
float BSP_CurrentGet(void)
{
  STK_Packet pkt;
  float      current;

  pkt.type          = STK_PACKETTYPE_CURRENT_REQ;
  pkt.payloadLength = 0;

  /* Send Request/Get reply */
  PacketSend(&pkt);
  PacketReceive(&pkt);

  /* Process reply */
  if (pkt.type == STK_PACKETTYPE_CURRENT_REPLY)
  {
    memcpy(&current, pkt.data, sizeof(float));
    return current;
  }
  else
  {
    return (float) 0.0;
  }
}
Esempio n. 5
0
File: ztcp.c Progetto: chungy/zsnes
int GetData(int dsize,unsigned char *dptr)
{
   int retval,i;
   int dataleft;

   retval=0;

      // Temporary UDP routines
   if (UDPEnable) {

     PacketResend();
     PacketReceive();

     i=packetrecvhead;
     if (packetreceived[i]){
       CopyMemory(dptr,&(packetrdata[2048*(i & 0x0F)]),packetreceivesize[i]);
       retval = packetreceivesize[i];
       packetreceived[(i+128) & 0xFF]=0;
       packetrecvhead=(packetrecvhead+1) & 0xFF;
       return(retval);
     }

     i=RecvPtr;
     if ((RecvFlags[i]) && (UDPMode2)){
       CopyMemory(dptr,&(RecvBuffer[32*i]),RecvBufferSize[i]);
       retval = RecvBufferSize[i];
       RecvFlags[(i+128) & 0xFF]=0;
       RecvPtr=(RecvPtr+1) & 0xFF;
       if (!RecvPtr) RecvPtr2=(RecvPtr2+1) & 0xFF;
       CounterA=90;
       return(retval);
     }

     if ((CounterA==0) & (UDPMode2)){
       // Send 16+RecvPtr
       cpacketdata[0]=16;
       cpacketdata[1]=RecvPtr;
       sendto(ugamesocket,cpacketdata,2,0,(struct sockaddr *)&ugameaddress,sizeof(ugameaddress));
       CounterA=90;
       return(0);
     }

     return(0);
   }

   dataleft=GetLeft();
   if(dataleft==0) return(0);

   if(dataleft<dsize)
   {
      dsize=dataleft;
   }
   /* get data with the socket */
   retval = recv(gamesocket,dptr,dsize,0);
   if (retval == SOCKET_ERROR)
	{
      closesocket(gamesocket);
      return(-1);
	}
   return(retval);
}