╤сюЁър 1901301648

This commit is contained in:
Иван Мокротоваров 2019-01-30 16:48:38 +03:00
parent 39d899aca1
commit 659bcc8ed4
6 changed files with 61 additions and 36 deletions

View File

@ -1,13 +1,13 @@
[project]
watch=works[i].Count, portVector, works[i].WorkPort, len(port), pinState, z, works[i], EncoderCfg.reinitInterval, works
[file1]
line=0
cursor=263
opened=active
line=60
cursor=465
opened=yes
breakpoints=
[file2]
line=62
cursor=1455
line=68
cursor=1100
opened=yes
breakpoints=
[file3]
@ -26,13 +26,13 @@ cursor=161
opened=no
breakpoints=
[file6]
line=0
cursor=190
line=108
cursor=1395
opened=yes
breakpoints=
[file7]
line=100
cursor=2644
line=0
cursor=2450
opened=yes
breakpoints=
[file8]
@ -45,8 +45,8 @@ line=0
cursor=0
opened=no
[file10]
line=22
cursor=5043
line=168
cursor=5269
opened=yes
breakpoints=
[file11]
@ -70,8 +70,8 @@ cursor=93
opened=no
breakpoints=
[file15]
line=0
cursor=294
line=7
cursor=20
opened=yes
breakpoints=
[file16]
@ -86,7 +86,7 @@ opened=no
breakpoints=
[file18]
line=0
cursor=334
cursor=295
opened=yes
breakpoints=
[file19]
@ -95,9 +95,9 @@ cursor=93
opened=yes
breakpoints=
[file20]
line=0
cursor=2782
opened=yes
line=48
cursor=2344
opened=active
breakpoints=
[file21]
line=0

View File

@ -21,15 +21,13 @@ void on_sock_inband() // обработка поступивших команд
cmdlen = instr(1,cmdline,chr('&'),1);
string cmd = left(cmdline,cmdlen-1);
string params = mid(cmdline,cmdlen+1,position-cmdlen-1);
d("{cmd}: "+cmd);
d("{cmd}.params: "+params);
// d("{cmd}: "+cmd);
// d("{cmd}.params: "+params);
if (cmd =="systeminfo"){
cmd_replay(cmd_systeminfo());
}else if (cmd == "reset" || cmd == "reboot"){
// cmd_replay(cmd_reset());
cmd_replay("{cmd} Rebooting...");
cmd_reset();
}else if (cmd == "ip"){
cmd_replay(cmd_ip(params));
}else if (cmd == "setbraker"){
@ -38,6 +36,10 @@ void on_sock_inband() // обработка поступивших команд
cmd_replay(cmd_setencoder(params));
}else if (cmd == "enc_calibrate_start"){
cmd_replay(cmd_enc_calibre(params));
}else if (cmd == "enc_set_windows"){
cmd_replay(cmd_enc_set_windows(params));
}else if (cmd == "debug_enc_level"){
cmd_replay(cmd_debug_enc_level(params));
}else if (cmd == "debug_sensors"){
cmd_replay(cmd_debug_sensors(params));
}else if (cmd == "debug_showtime"){
@ -55,15 +57,28 @@ void on_sock_inband() // обработка поступивших команд
string cmd_debug_sensors(string params){
getParams(params);
config.debug.SensorsLook = val(pars[0])>0;
return "Debug sensors SET="+config.debug.SensorsLook? "TRUE":"FALSE";
return "Debug sensors SET="+(config.debug.SensorsLook? "TRUE":"FALSE");
}
string cmd_debug_enc_level(string params){
getParams(params);
config.debug.EncoderDebug= val(pars[0]);
return "Debug encoder level SET="+str(config.debug.EncoderDebug);
}
string cmd_debug_showtime(string params){
getParams(params);
config.debug.ShowTime = val(pars[0])>0;
return "Debug show time SET="+config.debug.ShowTime? "TRUE":"FALSE";
return "Debug show time SET="+(config.debug.ShowTime? "TRUE":"FALSE");
}
string cmd_enc_set_windows(string params){
getParams(params);
config.EncoderCfg.windowWidth = val(pars[0]);
return "Encoder window SET="+str(config.EncoderCfg.windowWidth);
}
void cmd_replay(string message){
d(message);
sock.setsendinband(chr(sock.escchar)+" "+message+chr(sock.endchar)+chr(13)+chr(10));
}

View File

@ -6,6 +6,8 @@ string cmd_ip(string params);
string cmd_setbraker(string params);
string cmd_setencoder(string params);
string cmd_enc_calibre(string params);
string cmd_enc_set_windows(string params);
string cmd_debug_enc_level(string params);
string cmd_debug_sensors(string params);
string cmd_debug_showtime(string params);
void getParams(string params);

View File

@ -195,5 +195,7 @@ void config_create(){
config.EncoderCfg.windowWidth= 40;
config.EncoderCfg.reinitInterval = 3;
config.EncoderCfg.workedPorts = "";
config.debug.EncoderDebug=0;
}

View File

@ -62,30 +62,35 @@ bool getEncEnabled(unsigned char port,bool value){
if (works[portVector[port]].Inited == false){
works[portVector[port]].Count = interval/2;
works[portVector[port]].Inited =true;
d(str(port)+" выравнивание по первой ");
if (config.debug.EncoderDebug>0) d(str(port)+" выравнивание по первой ");
z[portVector[port]]=0;
}
int point = (works[portVector[port]].Point + works[portVector[port]].Count) /2;
int sdvig = center - point;
if (config.debug.EncoderDebug>3) d(str(port)+ " count:"+str(works[portVector[port]].Count)+" center:"+str(center)+" point:"+str(point)+" diff:"+str(diff)+" sdvig:"+stri(sdvig));
if (works[portVector[port]].Count >= (interval/2 - diff) && works[portVector[port]].Count <= (interval/2+diff)){
works[portVector[port]].State = true;
d(str(port)+" попал о окно "+str(works[portVector[port]].Count));
if (config.debug.EncoderDebug>2) d(str(port)+" попал о окно "+str(works[portVector[port]].Count));
works[portVector[port]].Point = (works[portVector[port]].Point + works[portVector[port]].Count) /2;
int sdvig = center - works[portVector[port]].Point;
//int point = works[portVector[port]].Point;
//int sdvig = center - point;
int d1=diff/2;
if (sdvig > d1 || sdvig < 0-d1 ){
d(str(port)+" "+ str(works[portVector[port]].Count)+" "+str(sdvig)+" "+(sdvig < 0 ? "<<" : ">>"));
works[portVector[port]].Count = works[portVector[port]].Count + (sdvig < 0 ? 0-d1: d1);
int nc = center;
if (config.debug.EncoderDebug>1) d(str(port)+" "+ str(works[portVector[port]].Count)+" "+stri(sdvig)+" "+(sdvig < 0 ? " << " : " >> ")+" new "+str(nc));
works[portVector[port]].Count = nc;
}
}else{
d(str(port)+" не попал о окно "+str(works[portVector[port]].Count));
if (config.debug.EncoderDebug>2) d(str(port)+" не попал о окно "+str(works[portVector[port]].Count));
}
return works[portVector[port]].State;
}
else{
if (works[portVector[port]].Enabled && works[portVector[port]].State == true && value){
d(str(port)+" Повторное срабатывание "+str(works[portVector[port]].Count));
if (config.debug.EncoderDebug>1) d(str(port)+" Повторное срабатывание "+str(works[portVector[port]].Count));
}
return false;
}
@ -103,7 +108,7 @@ void on_io_int(unsigned char linestate){
{
calibrate_buff[i][z[i]]=calibrate_count[i];
cmd_replay("Калибровка энкодера "+str(port)+":"+str(calibrate_count[i]));
d("Калибровка энкодера "+str(port)+":"+str(calibrate_count[i]));
if (config.debug.EncoderDebug>0) d("Калибровка энкодера "+str(port)+":"+str(calibrate_count[i]));
}
z[i]++;
calibrate_count[i]=0;

View File

@ -60,7 +60,7 @@ typedef struct BrakerProcess{
typedef struct EncoderConfig{
unsigned char encoderPort;
unsigned char encoderMode;
unsigned long encoderInterval;
unsigned int encoderInterval;
unsigned char reinitInterval;
unsigned char windowWidth;
string workedPorts;
@ -71,14 +71,15 @@ typedef struct EncoderProcess{
EncoderConfig *config;
bool Inited;
bool State;
unsigned long Count;
unsigned long Point;
unsigned int Count;
unsigned int Point;
unsigned char WorkPort;
};
typedef struct DebugConf{
bool SensorsLook;
bool ShowTime;
int EncoderDebug;
};
typedef struct Configuration{