转载请注明转自 http://blog.csdn.net/jinatom/article/details/7759589
#include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fs.h>
#include "cardev.h"
#include <errno.h>
int set_car(){
int fd;
fd = open("/dev/cardev", 0);
if (fd < 0) {
fprintf(cgiOut, "open device car erro<BR>\n");
exit(1);
}
fprintf(cgiOut, "open device car success<BR>\n");
if (cgiFormCheckboxSingle("ON") == cgiFormSuccess) {
//handle checkbox
fprintf(cgiOut, "ON!<BR>\n");
ioctl(fd,CAR_CMD_ON,0);
ioctl(fd,CAR_CMD_ON,1);
}
if (cgiFormCheckboxSingle("OFF") == cgiFormSuccess) {
//handle checkbox
fprintf(cgiOut, "OFF!<BR>\n");
ioctl(fd, CAR_CMD_OFF,0);
ioctl(fd, CAR_CMD_OFF,1);
}
if (cgiFormCheckboxSingle("LEFT") == cgiFormSuccess) {
//handle checkbox
fprintf(cgiOut, "LEFT!<BR>\n");
ioctl(fd, CAR_CMD_ON,0);
ioctl(fd, CAR_CMD_OFF,1);
}
if (cgiFormCheckboxSingle("RIGHT") == cgiFormSuccess) {
//handle checkbox
fprintf(cgiOut, "RIGHT!<BR>\n");
ioctl(fd, CAR_CMD_ON,1);
ioctl(fd, CAR_CMD_OFF,0);
}
close(fd);
return 0;
}
void Name() {
char name[81];
cgiFormStringNoNewlines("name", name, 81);
//handle text field containing a string
fprintf(cgiOut, "Name: ");
cgiHtmlEscape(name);
fprintf(cgiOut, "<BR>\n");
}
void ShowForm()
{
fprintf(cgiOut, "<!-- 2.0: multipart/form-data is required for file uploads. -->");
fprintf(cgiOut, "<form name=\"form1\" method=\"POST\" enctype=\"multipart/form-data\" ");
fprintf(cgiOut, " action=\"");
cgiValueEscape(cgiScriptName);
fprintf(cgiOut, "\">\n");
fprintf(cgiOut, "<input type=\"checkbox\" name=\"ON\">ON\n");
fprintf(cgiOut, "<p>\n");
fprintf(cgiOut, "<input type=\"checkbox\" name=\"OFF\" >OFF\n");
fprintf(cgiOut, "<p>\n");
fprintf(cgiOut, "<input type=\"checkbox\" name=\"RIGHT\" >RIGHT\n");
fprintf(cgiOut, "<p>\n");
fprintf(cgiOut, "<input type=\"checkbox\" name=\"LEFT\" >LEFT\n");
fprintf(cgiOut, "<p>\n");
fprintf(cgiOut, "<input type=\"submit\" name=\"testcgic\" value=\"Submit \">\n");
fprintf(cgiOut, "</form>\n");
}
int cgiMain() {
int adc_value;
cgiHeaderContentType("text/html");
fprintf(cgiOut, "<HTML><HEAD>\n");
fprintf(cgiOut, "<TITLE>cgic song1 test</TITLE></HEAD>\n");
fprintf(cgiOut, "<BODY><H1>car control</H1>\n");
set_car();
ShowForm();
fprintf(cgiOut, "</BODY></HTML>\n");
return 0;
}