⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connector_app.c

📁 用于以太网开发
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************                      
 *
 *      Copyright (C) 2003 Freescale Semiconductor, Inc. 
 *           and 2000-2002 Viola Systems Ltd.
 *       All Rights Reserved
 *
 * File Name      : Connector_App.c
 * Project Name   : Connector_App.mcp
 * Description    : This file contains the application code using UDP 
 *                    protocol functions on the MC9S12NE64. It calls 
 *                    implementation code in udp.c.
 *
 * Version : 1.0
 * Date    : 10.10.2002
 *
 ***************************************************************************/
 
/*
 *Redistribution and use in source and binary forms, with or without 
 *modification, are permitted provided that the following conditions 
 *are met:
 *
 *1. Redistributions of source code must retain the above copyright 
 *notice, this list of conditions and the following disclaimer.
 *
 *2. Redistributions in binary form must reproduce the above copyright 
 *notice, this list of conditions and the following disclaimer in the 
 *documentation and/or other materials provided with the distribution.
 *
 *3. The end-user documentation included with the redistribution, if 
 *any, must include the following acknowledgment:
 *	"This product includes software developed by Viola 
 *	Systems (http://www.violasystems.com/)."
 *
 *Alternately, this acknowledgment may appear in the software itself, 
 *if and wherever such third-party acknowledgments normally appear.
 *
 *4. The names "OpenTCP" and "Viola Systems" must not be used to 
 *endorse or promote products derived from this software without prior 
 *written permission. For written permission, please contact 
 *opentcp@opentcp.org.
 *
 *5. Products derived from this software may not be called "OpenTCP", 
 *nor may "OpenTCP" appear in their name, without prior written 
 *permission of the Viola Systems Ltd.
 *
 *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 
 *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE 
 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *====================================================================
 *
 *OpenTCP is the unified open source TCP/IP stack available on a series 
 *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>.
 *
 *For more information on how to network-enable your devices, or how to 
 *obtain commercial technical support for OpenTCP, please see 
 *<http://www.violasystems.com/>.
 */
 

#include <debug.h>
#include <datatypes.h>
#include <globalvariables.h>
#include <system.h>
#include <tcp_ip.h>

#include <string.h>
#include "MOTTYPES.h"

static unsigned char data_buffer [64];

/* The applications that use UDP must implement following function stubs			*/
/* void application_name_init (void) - call once when processor starts				*/
/* void application_name_run (void) - call periodically on main loop				*/
/* INT32 application_name_eventlistener (INT8, UINT8, UINT32, UINT16, UINT16, UINT16)	*/
/* - called by TCP input process to inform arriving data, errors etc 				*/

/* These will probably go to some include file */
void udp_demo_init(void);
void udp_demo_run(void);
INT32 udp_demo_eventlistener(INT8 , UINT8 , UINT32 , UINT16 , UINT16 , UINT16 );

/** \brief Socket handle holder for this application
 *
 * This variable holds the assigned socket handle. Note that this application 
 * will reserve one UDP socket immediately and will not release it. For
 * saving resources, UDP sockets can also be allocated/deallocated 
 * dynamically.
 */
UINT8 udp_demo_soch;

UINT8 udp_demo_senddata; /**< Used to trigger data sending */

#define UDP_DEMO_PORT	2001 /**< UDP_DEMO_RMTHOST_PRT number on which we'll work */

#define UDP_DEMO_RMTHOST_IP	0xC0A80201	/**< Remote IP address this application will send data to*/

#define UDP_DEMO_RMTHOST_PRT	2000	/**< UDP_DEMO_RMTHOST_PRT number on remote server we'll send data to */

/* Internal function used for sending data to a predefined host */
INT16 udp_demo_send(void);


//============================================================
//============================================================
#define GAMEMODE  1
#define DEMOBOARD 1

extern tU16 Pot;
extern tU16 OldPot;
extern tU08 OldSwitchValue;
extern tU08 OldB1;
extern tU08 OldB2;

signed char cvt[16]={ '0','1','2','3','4','5','6','7','8','9',
                      'A','B','C','D','E','F' };
signed char cvtd[10]={ '0','1','2','3','4','5','6','7','8','9'};

//============================================================
//============================================================
void ctoh (signed char * s, unsigned char c)  {
  *s= cvt[c / 16];
  s++;
  *s= cvt[c % 16];
}

//============================================================
	//NEED TO MAKE THIS GENERIC FOR ANY SIZE DEC DIGIT
//============================================================
signed char* xxxxDEC_TO_ASCII(UINT16 c)	{
				
  signed char s[5];
  UINT16 divider = 1000;
  UINT8 leaddigit;
  UINT8 foundmsd;
  UINT8	 j;

  j = 0;
  foundmsd = FALSE;
  //div 1000 
  leaddigit = c / divider;
  if  (leaddigit == 0) {
    divider = divider/10;
  }
  else {
    s[j] = cvtd[leaddigit];
    c = c - leaddigit * divider;
    divider = divider/10;
    j=j+1;
    foundmsd = TRUE;
  }
  //div 100 
  leaddigit = c / divider;
  if  ((leaddigit == 0) && (!foundmsd)) {
    divider = divider/10;	 
  }
  else {
    s[j] = cvtd[leaddigit];
    c = c - leaddigit * divider;
    divider = divider/10;
    j=j+1;
    foundmsd = TRUE;
  }
  //div 10 
  leaddigit = c / divider;
  if  ((leaddigit == 0) && (!foundmsd)) {
    divider = divider/10;
  }
  else {
    s[j] = cvtd[leaddigit];
    c = c - leaddigit * divider;
    divider = divider/10;
    j=j+1;
    foundmsd = TRUE;
  }
  //div 1 
  leaddigit = c / divider;
  s[j] = cvtd[leaddigit];
  j=j+1;
  s[j]=0;
  return s;

}

//============================================================
// Poll ATD and send new values via UDP
//============================================================
UINT8 get_a2d(char channel)			{

    UINT16 temp;
 		UINT16	i, datalen;
    signed char* s;

	  if (ATDSTAT0_SCF == 1)  {  
	  	temp =   ATDDR0;// 10-bit					
	  	Pot = temp >> 6;
		  ATDCTL5 = channel | ATDCTL5_SCAN; 
#if !(DEMOBOARD)        
      Pot = 1023-Pot;          
#endif
		  if (Pot > OldPot)
		    temp = Pot - OldPot;
		  else
		    temp = OldPot - Pot;
      if ((Pot !=  OldPot) && (temp > 8))	 {
              OldPot = Pot;
              i = 0;       net_buf[UDP_APP_OFFSET+i]='c';
              i = 1;       net_buf[UDP_APP_OFFSET+i]='o';
              i = 2;       net_buf[UDP_APP_OFFSET+i]='m';
              i = 3;       net_buf[UDP_APP_OFFSET+i]='m';
              i = 4;       net_buf[UDP_APP_OFFSET+i]='D';
              i = 5;       net_buf[UDP_APP_OFFSET+i]='I';
              i = 6;       net_buf[UDP_APP_OFFSET+i]='A';
              i = 7;       net_buf[UDP_APP_OFFSET+i]='@';
              i = 8;       net_buf[UDP_APP_OFFSET+i]='e';
              i = 9;       net_buf[UDP_APP_OFFSET+i]='q';
              i = 10;      net_buf[UDP_APP_OFFSET+i]='@';
             	s = xxxxDEC_TO_ASCII(Pot);
              while (*s != 0) {
                 i = i + 1;
                 net_buf[UDP_APP_OFFSET+i]=*s;
                 s++;
              }		 
              datalen = i+1;       
             	udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,datalen);
         			return Pot;
        }
	}
	return Pot;
}

//============================================================
//============================================================
void check_switch() {

 		UINT8	temp, i;
		UINT16 myctr, datalen;

			datalen=13;
      i = 0;       net_buf[UDP_APP_OFFSET+i]='c';
      i = 1;       net_buf[UDP_APP_OFFSET+i]='o';
      i = 2;       net_buf[UDP_APP_OFFSET+i]='m';
      i = 3;       net_buf[UDP_APP_OFFSET+i]='m';
      i = 4;       net_buf[UDP_APP_OFFSET+i]='R';
      i = 5;       net_buf[UDP_APP_OFFSET+i]='C';
      i = 6;       net_buf[UDP_APP_OFFSET+i]='V';
      i = 7;       net_buf[UDP_APP_OFFSET+i]='@';
      i = 8;       net_buf[UDP_APP_OFFSET+i]='e';
      i = 9;       net_buf[UDP_APP_OFFSET+i]='q';
      i = 10;      net_buf[UDP_APP_OFFSET+i]='@';
      i = 11;			 net_buf[UDP_APP_OFFSET+i]='s';
      i = 12;
      if (PTG_PTG4 == 0) {
            net_buf[UDP_APP_OFFSET+i]='0';
      			temp = FALSE;
      }
      else {
            net_buf[UDP_APP_OFFSET+i]='1';
      			temp = TRUE;
      }
		  if (OldSwitchValue !=  temp)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -