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

📄 servlet1.c

📁 picoos源码。The RTOS and the TCP/IP stack will be built automatically.
💻 C
字号:
/*
 *  Copyright (c) 2004, Dennis Kuschel.
 *  All rights reserved. 
 *
 *  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 name of the author may not be used to endorse or promote
 *      products derived from this software without specific prior written
 *      permission. 
 *
 *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 *  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 THE AUTHOR 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.
 *
 */

/**
 * @file    servlet1.c
 * @author  Dennis Kuschel
 * @brief   Simple I/O Switch Servlet.
 *
 * This software is from http://mycpu.mikrocontroller.net.
 * Please send questions and bug reports to dennis_k@freenet.de.
 */

#include "../src/sys.h"
#include "../src/httpd.h"


/* function prototypes */
sint_t  my_switch_servlet(SERVLET_t so);


/*
 *  This is a very simple servlet.
 *  It allows the switching of digital I/O pins on the mcu.
 *  The servlet takes the parameters 'switch=' and 'state=' in the URI.
 *  Examples:
 *
 *    http://127.0.0.1/switch?switch=1&state=on
 *       switches switch 1 on.
 *
 *    http://127.0.0.1/switch?switch=5&state=off
 *       switches switch 5 off.
 */

sint_t  my_switch_servlet(SERVLET_t so)
{
  char *p;
  u32_t sw, st;

  /* read switch parameter from URI */
  p = hsl_getParameterByName(so, "switch");
  if (p == NULL)
  {
    printf("my_switch_servlet: missing parameter 'switch=' in URI\n");
    return SLERR_OK;
  }
  sw = 0;
  sscanf(p, "%u", &sw);

  /* read state parameter from URI */
  p = hsl_getParameterByName(so, "state");
  if (p == NULL)
  {
    printf("my_switch_servlet: missing parameter 'state=' in URI\n");
    return SLERR_OK;
  }
  st = (stricmp(p, "on") == 0) ? 1 : 0;

  /* switch the output (print to console) */
  printf("switch %u: %s\n", sw, (st == 0) ? "off" : "on");

  /* Return. We send an empty data unit to the client. */
  return SLERR_OK;
}

⌨️ 快捷键说明

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