LPT
Сообщений 1 страница 15 из 15
Поделиться32011-10-19 14:05:56
Александр, что с мускулом? И что с девайсом?
Поделиться42011-11-02 16:12:27
It`s alive!
#include <string.h>
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#include <sys/types.h>
#include <fcntl.h>
#include <mysql.h>
#include <iostream>
int main()
{
/*int ch;
bool ne=true;
char buffer[256];
initscr(); cbreak(); noecho();
keypad(stdscr, TRUE);
char c;
int n, tem;*/
MYSQL *conn;
MYSQL_RES *result;
MYSQL_ROW row;
int num_fields;
int i, cnt;
if (ioperm(888, 3, 1)) {perror("ioperm"); addstr("error");}
conn = mysql_init(NULL);
mysql_real_connect(conn, "localhost", "root", "111111", "BK", 0, NULL, 0);
while(true)
{
clear();
mysql_query(conn, "SELECT camotor FROM control where id = (select max(id) as id from control)");
result = mysql_store_result(conn);
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
/*for(i = 0; i < num_fields; i++)
{
printf("%s ", row[i] ? row[i] : "NULL");
}
printf("\n");*/
cnt=atoi(row[0]);
}
if(cnt==1)
{
printf("up");
outb(255, 888);
}
else if(cnt==2)
{
printf("down");
outb(255,888);
}
else
{
printf("none");
outb (0, 888);
}
mysql_free_result(result);
}
mysql_close(conn);
}
/*printf("Hit any key to stop\n");
//set permissions to access port
if (ioperm(888, 3, 1)) {perror("ioperm"); addstr("error");}
tem = fcntl(0, F_GETFL, 0);
fcntl (0, F_SETFL, (tem | O_NDELAY));
while (ne)
{
if(ch==27)
{
ne=false;
break;
}
while ( (ch = getch()) == ERR );
//ch= getch();
sprintf(buffer,"key %02i was pressed\n\n", ch);
clear();
addstr(buffer);
if(ch==27)
addstr("press <Enter> to exit.\n\n");
else
addstr("press <Esc> to exit.\n\n");
switch (ch)
{
case 259:
{
outb(255, 888);
break;
}
case 258:
{
outb(0,888);
break;
}
case -1:
{
outb(0,888);
}
}
}
fcntl(0, F_SETFL, tem);
outb(0, 888);
//take away permissions to access port
if (ioperm(888, 3, 0)) {perror("ioperm"); addstr("error");}
while ( (ch = getch()) == ERR );
endwin();
}*/Поделиться52011-11-02 20:13:56
Хорошо, но недостаточно. Остальные пины?
Поделиться62011-11-02 20:24:25
Фигня, допилим как девайс оживёт. Прросто свитч-кейс и пару "иф".
Поделиться72011-11-02 20:32:09
Движок при нажатии кнопки должен делать !!один!! шаг. Двадцать шагов в одну сторону, двадцать в другую. с автоматической инициализацией положения. Как планируете это реализовать? А бортовые огни должны мигать. Как это?
Поделиться82011-11-02 21:25:50
Один шаг - фигня. Там пишем единицу на пин, потом слип и пин обнуляем.
Поделиться92011-11-02 21:26:56
С инициализацией возможны варианты. И моргалку по типу движка запилим.
Поделиться102011-11-03 19:28:14
что думаешь с инициализацией?
Поделиться112011-11-04 10:00:33
Как руль - вертим в любую сторону чтоб упёрлось. Это будет одно крайнее положение. Максимальный угол поворота посчитаем на земле. Вуаля!
Поделиться122011-11-04 10:20:09
уверен что движком не оторвет камеру об ограничитель?
Поделиться132011-11-17 16:15:42
#include <string.h>
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#include <sys/types.h>
#include <fcntl.h>
#include <mysql.h>
#include <iostream>
#include <unistd.h>
#include <math.h>
int quer(int n)
{
char* qer;
MYSQL *conn;
MYSQL_RES *result;
MYSQL_ROW row;
int num_fields, out;
int i, cnt;
//if (ioperm(888, 3, 1)) {perror("ioperm"); addstr("error");}
conn = mysql_init(NULL);
mysql_real_connect(conn, "localhost", "cntrl", "pass", "BK", 0, NULL, 0);
switch (n)
{
case 0:
qer="SELECT camotor FROM control where id = (select max(id) as id from control)";
break;
case 1:
qer="SELECT leftl FROM control where id = (select max(id) as id from control)";
break;
case 2:
qer="SELECT rightl FROM control where id = (select max(id) as id from control)";
break;
case 3:
qer="SELECT taill FROM control where id = (select max(id) as id from control)";
break;
case 4:
qer="SELECT emptyb FROM control where id = (select max(id) as id from control)";
break;
case 5:
qer="SELECT fullb FROM control where id = (select max(id) as id from control)";
break;
case 6:
qer="insert into control (camotor) values (0)";
break;
}
mysql_query(conn, qer);
if(n<6)
{
result = mysql_store_result(conn);
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
cnt=atoi(row[0]);
}
mysql_free_result(result);
mysql_close(conn);
return cnt;
}
else return 0;
}
int powre(int pwr)
{
int val = 1;
for(int i=0; i<pwr+1; i++)
val = val*2;
return val;
}
int main()
{
int q,i, cnt, out, tmp[6], notnull, lght[6];
if (ioperm(888, 3, 1)) {perror("ioperm"); addstr("error");}
for(i=0; i<6; i++)
{
tmp[i]=0;
lght[i]=0;
}
while(true)
{
out=0;
notnull =0;
tmp[0]=0;
q=0;
for(i=0; i<6; i++)
{
q = quer(i);
if((i>0)&&(q>0))
{
if(tmp[i]==0) tmp[i]=powre(i);
else tmp[i]=0;
notnull = 1;
}
if(i==0)
{
tmp[i]=q;
notnull = 1;
}
}
if(notnull)
{ int t = quer(6);
for(i=0; i<6; i++)
out= out+tmp[i];
outb(out, 888);
usleep(200000);
}
//printf("%d\n",out);
}
if (ioperm(888, 3, 0)) {perror("ioperm"); addstr("error");}
}Поделиться142011-11-26 13:24:59
Назовите конкретные сроки готовности системы управления камерой.
Поделиться152011-11-30 14:32:52
Финальная версия.
#include <string.h>
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#include <sys/types.h>
#include <fcntl.h>
#include <mysql.h>
#include <iostream>
#include <unistd.h>
#include <math.h>
int pin(int n)
{
switch (n)
{
case 1:
return 4;
break;
case 2:
return 8;
break;
case 3:
return 16;
break;
}
}
int main()
{
MYSQL *conn;
MYSQL_RES *result;
MYSQL_ROW row;
int num_fields, out;
int i, c;
int notnull, lght[3];
for(i=0; i<3; i++)
{
lght[i]=0;
}
if (ioperm(888, 3, 1)) {perror("ioperm"); addstr("error");}
conn = mysql_init(NULL);
mysql_real_connect(conn, "localhost", "cntrl", "pass", "BK", 0, NULL, 0);
while(true)
{
out=0;
mysql_query(conn, "select camotor, leftl, rightl, taill, emptyb from control where id = (select max(id) as id from control)");
result = mysql_store_result(conn);
num_fields = mysql_num_fields(result);
//if (ioperm(888, 3, 1)) {perror("ioperm"); addstr("error");}
while ((row = mysql_fetch_row(result)))
{
notnull=0;
for(i=0; i<5; i++)
if(atoi(row[i])!=0)
notnull=1;
out=out+atoi(row[0])+(32*atoi(row[4]));
for (i=1; i<4; i++)
{
if(atoi(row[i])==1)
{
if(lght[i-1]==1)
lght[i-1]=0;
else
lght[i-1]=1;
}
}
}
if(c)
{
c=0;
for (i=1; i<4; i++)
{
if(lght[i-1])
out=out+pin(i);
}
}
else
c=1;
printf("%d\n", out);
outb(out, 888);
if(notnull)
mysql_query(conn, "insert into control (camotor) values (0)");
usleep(200000);
//if (ioperm(888, 3, 0)) {perror("ioperm"); addstr("error");}
}
mysql_free_result(result);
mysql_close(conn);
if (ioperm(888, 3, 0)) {perror("ioperm"); addstr("error");}
}
