╤сюЁър 1901301502

This commit is contained in:
Иван Мокротоваров 2019-01-30 15:02:44 +03:00
parent 4e0861bec1
commit 126ea01dd6
13 changed files with 278 additions and 54 deletions

View File

@ -4,7 +4,7 @@ platform=TPP2W(G2)
src_lib_ver=2_01_00
name=KSM-Line-2.0
output=KSM-Line-2.0.tpc
debug=on
debug=off
defines= /dLCD_TYPE=SOLOMON_SSD1963 /dOBJECT_LCD=LCD_ENABLED /dOBJECT_FD=FD_ENABLED /dOBJECT_KP=KP_ENABLED /dOBJECT_WLN=WLN_ENABLED
transport=udp_broadcast
[address1]
@ -163,3 +163,17 @@ format=65001
condition=
locked=no
location=project
[file21]
path=common.th
type=cheader
format=65001
condition=
locked=no
location=project
[file22]
path=common.tc
type=c
format=65001
condition=
locked=no
location=project

View File

@ -1,33 +1,33 @@
[project]
watch=works[i].Count, portVector, works[i].WorkPort
watch=works[i].Count, portVector, works[i].WorkPort, len(port), pinState, z, works[i], EncoderCfg.reinitInterval, works
[file1]
line=105
cursor=1677
line=85
cursor=2097
opened=yes
breakpoints=
[file2]
line=78
cursor=409
line=44
cursor=1179
opened=yes
breakpoints=
[file3]
line=0
cursor=248
opened=active
cursor=327
opened=no
breakpoints=
[file4]
line=0
cursor=125
opened=yes
opened=no
breakpoints=
[file5]
line=0
cursor=161
opened=yes
opened=no
breakpoints=
[file6]
line=18
cursor=422
line=5
cursor=1461
opened=yes
breakpoints=
[file7]
@ -45,9 +45,9 @@ line=0
cursor=0
opened=no
[file10]
line=4
cursor=1099
opened=no
line=76
cursor=5043
opened=yes
breakpoints=
[file11]
line=0
@ -57,12 +57,12 @@ breakpoints=
[file12]
line=0
cursor=360
opened=yes
opened=no
breakpoints=
[file13]
line=0
cursor=55
opened=yes
opened=no
breakpoints=
[file14]
line=0
@ -70,8 +70,8 @@ cursor=93
opened=no
breakpoints=
[file15]
line=12
cursor=541
line=0
cursor=294
opened=yes
breakpoints=
[file16]
@ -82,7 +82,7 @@ breakpoints=
[file17]
line=0
cursor=20
opened=yes
opened=no
breakpoints=
[file18]
line=0
@ -91,11 +91,21 @@ opened=yes
breakpoints=
[file19]
line=0
cursor=101
cursor=93
opened=yes
breakpoints=
[file20]
line=18
cursor=2430
line=156
cursor=3777
opened=active
breakpoints=
[file21]
line=0
cursor=0
opened=yes
breakpoints=24
breakpoints=
[file22]
line=18
cursor=0
opened=yes
breakpoints=

Binary file not shown.

Binary file not shown.

View File

@ -47,13 +47,49 @@ void on_sock_inband() // обработка поступивших команд
}
void cmd_replay(string message){
sock.setsendinband(chr(sock.escchar)+" "+message+chr(sock.endchar));
sock.setsendinband(chr(sock.escchar)+" "+message+chr(sock.endchar)+chr(13)+chr(10));
}
string cmd_setencoder(string params){
return "Запущен режим калибровки энкодера";
string message;
// setencoder=encoderpin,mode,interval,sensorspinoverdot
// setencoder=4,1,50,1.2
d("params: "+params);
unsigned char n, p, num ;
unsigned long t;
string vals = "";
n = 1;
p = instr(1,params,",",1);
while (p>0){
vals+=chr(val(mid(params,n,n-p)));
n = p+1;
p = instr(n,params,",",1);
}
string port = mid(params,n,len(params)-n+1);
d("port: "+port);
string ports;
n = 1;
p = instr(1,port,".",1);
while (p>0){
ports+=chr(val(mid(port,n,n-p)));
n = p+1;
p = instr(n,port,".",1);
}
ports += chr(val(mid(port,n,len(port)-n+1)));
config.EncoderCfg.encoderPort = vals[0];
config.EncoderCfg.encoderMode = vals[1];
config.EncoderCfg.encoderInterval = vals[2];
config.EncoderCfg.workedPorts = ports;
message = "Энкодер настроен: Порт: "+str(vals[0])+ ", Режим: "+str(vals[1])+ ", Интервал: "+str(vals[2])+ ", Рабочие порты: "+port;
encoder_init();
return message;
}
string cmd_enc_calibre(string params){
int mode = val(left(params,1));
enc_calibrate_mode(mode);
if (mode >0){
return "Запушена калибровка энкодера в режиме "+str(mode);
}
return "Остановлен режим калибровки энкодера. Среднее значение: " + str(enc_calibrate_result());
}
string cmd_systeminfo(){

View File

@ -189,9 +189,11 @@ void config_create(){
config.BRAKERS[1] = c;
config.BRAKERS[2] = c;
config.EncoderCfg.encoderPort = 4;
config.EncoderCfg.encoderMode = 1;
config.EncoderCfg.encoderInterval = 10;
config.EncoderCfg.workedPorts = "12";
config.EncoderCfg.encoderPort = 0;
config.EncoderCfg.encoderMode = 0;
config.EncoderCfg.encoderInterval = 0;
config.EncoderCfg.windowWidth= 40;
config.EncoderCfg.reinitInterval = 3;
config.EncoderCfg.workedPorts = "";
}

View File

@ -1,23 +1,31 @@
#include "global.th";
#include "sensors.th";
#include "command.th"
#define ENCWORKER 5
EncoderProcess works[ENCWORKER];
string vector[4];
char portVector[SENSORS];
int calibrate_mode = 0;
unsigned long calibrate_buff[ENCWORKER][10];
unsigned long calibrate_count[ENCWORKER];
char z[ENCWORKER];
bool inited = false;
int center;
void encoder_init(){
for (int i = 0; i< SENSORS;i++){
portVector[i]=-1;
}
int intnum = ((int)(config.EncoderCfg.encoderPort/4));
center = config.EncoderCfg.encoderInterval/2;
for (char i = 0; i < ENCWORKER; i++){
works[i].Enabled = false;
works[i].config = &config.EncoderCfg;
works[i].State = false;
works[i].Inited = false;
works[i].Count = config.EncoderCfg.encoderInterval/2;
works[i].Point = config.EncoderCfg.encoderInterval/2;
works[i].WorkPort=0;
string ports = config.EncoderCfg.workedPorts;
if (i<len(ports)){
@ -27,6 +35,7 @@ void encoder_init(){
vector[intnum-1]+=chr(i);
}
}
inited = true;
#if PLATFORM_ID != SIMULATOR
io.intnum = intnum-1;
io.intenabled = YES;
@ -34,7 +43,14 @@ void encoder_init(){
}
bool inEncCalibrate(){
return calibrate_mode>0;
}
bool getEncEnabled(unsigned char port,bool value){
if (!inited) return true;
if (calibrate_mode>0) // в режиме калибровки не слать состояние портов
return false;
if (port == config.EncoderCfg.encoderPort)
return false;
if (portVector[port]==-1)
@ -42,32 +58,81 @@ bool getEncEnabled(unsigned char port,bool value){
if (works[portVector[port]].Enabled && works[portVector[port]].State == false && value){
long interval = works[portVector[port]].config->encoderInterval;
long diff = interval /5;
long diff = interval * config.EncoderCfg.windowWidth / 200;
if (works[portVector[port]].Inited == false){
works[portVector[port]].Count = interval/2;
works[portVector[port]].Inited =true;
d(str(port)+" выравнивание по первой ");
z[portVector[port]]=0;
}
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));
works[portVector[port]].Point = (works[portVector[port]].Point + works[portVector[port]].Count) /2;
int sdvig = center - works[portVector[port]].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);
}
}else{
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));
}
return false;
}
}
void on_io_int(unsigned char linestate){
string workers = vector[linestate-1];
for (int i = 0; i < len(workers);i++){
if (works[i].Enabled){
works[i].Count++;
if (works[i].Count>works[i].config->encoderInterval)
if(calibrate_mode>0){
for (int i=0;i<len(config.EncoderCfg.workedPorts);i++){
unsigned char port = config.EncoderCfg.workedPorts[i];
if (pinChange(port) && getPinStateS(port,true)==true)
{
works[i].Count = 0;
works[i].State = false;
if (z[i]>=0)
{
calibrate_buff[i][z[i]]=calibrate_count[i];
cmd_replay("Калибровка энкодера "+str(port)+":"+str(calibrate_count[i]));
d("Калибровка энкодера "+str(port)+":"+str(calibrate_count[i]));
}
z[i]++;
calibrate_count[i]=0;
if (z[i]>9)
z[i]=0;
}
else
calibrate_count[i]++;
}
return;
}
else{
for (int i = 0; i < ENCWORKER;i++){
if (works[i].Enabled){
works[i].Count++;
if (works[i].Count>works[i].config->encoderInterval)
{
z[i] = (works[i].State? 0: z[i]+1);
//d("z["+str(i)+"] = "+ str(z[i])+" | "+str(config.EncoderCfg.reinitInterval));
if (z[i] >= config.EncoderCfg.reinitInterval)
works[i].Inited = false;
works[i].Count = 0;
works[i].State = false;
}
//d("count ["+str(i)+"] :"+str(works[i].Count));
}
d("count ["+str(i)+"] :"+str(works[i].Count));
}
}
}
/// Блок калибровки
@ -88,11 +153,32 @@ void enc_calibrate_mode(int mode){
d("Установка режима калибровки энкодера - неверный режим: "+ str(mode));
break;
}
if (calibrate_mode>0){
for (int i=0;i<len(config.EncoderCfg.workedPorts);i++){
z[i]=-1;
calibrate_count[i]=0;
for (int x=0;x<10;x++){
calibrate_buff[i][x]=0;
}
}
}
}
int enc_calibrate_result(){
return 0;
int o = 0;
for (int i=0;i<len(config.EncoderCfg.workedPorts);i++){
int c = 0;
int s = 0;
for (int x=0;x<10;x++){
if (calibrate_buff[i][x]>0){
c++;
s+=calibrate_buff[i][x];
}
}
o += s/c;
if (o > s/c)
o = o/2;
}
return o;
}

View File

@ -1,3 +1,5 @@
void encoder_init();
bool getEncEnabled(unsigned char port,bool value);
bool inEncCalibrate();
void enc_calibrate_mode(int mode);
int enc_calibrate_result();

View File

@ -61,14 +61,18 @@ typedef struct EncoderConfig{
unsigned char encoderPort;
unsigned char encoderMode;
unsigned long encoderInterval;
unsigned char reinitInterval;
unsigned char windowWidth;
string workedPorts;
};
typedef struct EncoderProcess{
bool Enabled;
EncoderConfig *config;
bool Inited;
bool State;
unsigned long Count;
unsigned long Point;
unsigned char WorkPort;
};
typedef struct Configuration{

25
main.tc
View File

@ -23,7 +23,7 @@ void d(string mess){
void on_sys_init(){
pat.play("R-R---~",PL_PAT_CANINT);
pat.play("RG~",PL_PAT_CANINT);
config_init();
net_init();
@ -68,12 +68,13 @@ pat.play("R-R---~",PL_PAT_CANINT);
d("sys.freebuffpages: "+str(sys.freebuffpages));
d("config.IP="+config.IP);
// unsigned int day,min;
// unsigned char second;
// if (rtc.running){
// unsigned int day,min;
// unsigned char second;
// rtc.getdata(day,min,second);
// if (day == 0)
// rtc.setdata(daycount(18,10,25),mincount(19,58),1);
//// if (day == 0)
//// rtc.setdata(daycount(18,10,25),mincount(19,58),1);
// }
sys.onsystimerperiod = 1 ;
net_start();
@ -84,14 +85,14 @@ pat.play("R-R---~",PL_PAT_CANINT);
io.enabled=YES;
io.num=PL_IO_NUM_48;
io.enabled=YES;
pat.play("G-R-R---~",PL_PAT_CANINT);
pat.play("---G-R-R~",PL_PAT_CANINT);
}
void on_sys_timer()
{
if (!inEncCalibrate()){
for (int i=1; i<=3; i++){
braker_proc(i);
}
@ -99,11 +100,17 @@ void on_sys_timer()
for (int i=1; i <= SENSORS; i++){
if (pinChange(i)){
bool state = getPinStateS(i,true);
//if (getEncEnabled(i,state))
if (getEncEnabled(i,state))
send_sensor(i,state);
}
}
}
unsigned int day,min;
unsigned char second;
if (rtc.running){
rtc.getdata(day,min,second);
}
#if PLATFORM_ID != SIMULATOR
sock.num = 0;
@ -123,7 +130,7 @@ void on_sys_timer()
io.lineset(PL_IO_NUM_48,sock.statesimple != PL_SSTS_EST);
io.state=LOW;
io.state=HIGH;
io.lineset(PL_IO_NUM_48,HIGH);
io.lineset(PL_IO_NUM_48,inEncCalibrate() ? second % 2: 1);
io.state=LOW;
io.state=HIGH;
#endif

11
make.cmd Normal file
View File

@ -0,0 +1,11 @@
node premake.js
set dat=%date:~8,2%%date:~3,2%%date:~0,2%%time:~0,2%%time:~3,2%
git commit -a -m "Ñáîðêà %dat%"
git push
"C:\Program Files (x86)\Tibbo\TIDE\Bin\tmake.exe" -r -p "C:\Program Files (x86)\Tibbo\TIDE\Platforms" KSM-Line-2.2_tpp2.tpr
rem ren KSM-Line-2.0.tpc KSM-Line-2.0.tpp2.%dat%.tpc
rem copy KSM-Line-2.0.tpp2.%dat%.tpc up\KSM-Line-2.0.tpp2.%dat%.tpc.zip
"C:\Program Files (x86)\Tibbo\TIDE\Bin\tmake.exe" -r -p "C:\Program Files (x86)\Tibbo\TIDE\Platforms" KSM-Line-2.2_tpp3.tpr
rem ren KSM-Line-2.0.tpc KSM-Line-2.0.tpp3.%dat%.tpc
rem copy KSM-Line-2.0.tpp3.%dat%.tpc up\KSM-Line-2.0.tpp3.%dat%.tpc.zip
call postmake.cmd

2
net.tc
View File

@ -43,7 +43,7 @@ void net_start(){
net_openSocket(0,1000,false);//, &net_sensor_handle); // sensors
net_openSocket(1,999,false);//, &net_relay_handle); // relay
net_openSocket(2,998,false);//, &net_diag_handle); // diag
net_openSocket(2,998,true);//, &net_diag_handle); // diag
net_openSocket(3,997,true);//, &net_config_handle); // config
}

52
premake.js Normal file
View File

@ -0,0 +1,52 @@
const fs = require('fs');
function getFile(path){
return fs.readFileSync(path);
}
var date = new Date();
var dt = (''+date.getFullYear()).slice(-2) + ('0' + (date.getMonth() + 1)).slice(-2) + ('0' + date.getDate()).slice(-2)+('0' + date.getHours()).slice(-2)+('0' + date.getMinutes()).slice(-2);
var file = getFile("KSM-Line-2.2.tpr");
var out1 = "";
var out2 = "";
var lines = file.toString().split("\n")
for (line in lines){
var l = lines[line];
var o1 = l;
var o2 = l;
var sect = "";
if (l.startsWith("[")){
sect = l;
console.log(l);
}
if (sect.trim().localeCompare("[project]")){
if (l.startsWith("platform=")){
o1 = "platform=TPP2W(G2)";
o2 = "platform=TPP3W(G2)";
console.log(o1);
}else if (l.startsWith("name=")){
o1 = "name=KSM-Line-2.0_"+dt
o1 = "name=KSM-Line-2.0_"+dt
console.log(o1);
}else if (l.startsWith("output=")){
o1 = "output=KSM-Line-2.0.tpp2."+dt+".tpc";
o2 = "output=KSM-Line-2.0.tpp3."+dt+".tpc";
console.log(o1);
}
}
out1 += o1 +"\n";
out2 += o2 +"\n";
}
fs.writeFile("KSM-Line-2.2_tpp2.tpr", out1 , function(err){ console.log("tpp2")});
fs.writeFile("KSM-Line-2.2_tpp3.tpr", out2 , function(err){ console.log("tpp3")});
var postmake = "";
postmake += "copy KSM-Line-2.0.tpp2."+dt+".tpc up\\KSM-Line-2.0.tpp2."+dt+".tpc.zip\r\n";
postmake += "copy KSM-Line-2.0.tpp3."+dt+".tpc up\\KSM-Line-2.0.tpp3."+dt+".tpc.zip\r\n";
postmake += "move KSM-Line-2.0.tpp2."+dt+".tpc bin\\KSM-Line-2.0.tpp2."+dt+".tpc\r\n";
postmake += "move KSM-Line-2.0.tpp3."+dt+".tpc bin\\KSM-Line-2.0.tpp3."+dt+".tpc\r\n";
postmake += "echo wget -c -O ./KSM-Line-2.0.tpp2."+dt+".tpc http://available-we.azurewebsites.net/tibbo/KSM-Line-2.0.tpp2."+dt+".tpc.zip >up\\app.sh\r\n";
postmake += "echo wget -c -O ./KSM-Line-2.0.tpp3."+dt+".tpc http://available-we.azurewebsites.net/tibbo/KSM-Line-2.0.tpp3."+dt+".tpc.zip >>up\\app.sh\r\n";
fs.writeFile("postmake.cmd", postmake , function(err){ console.log("postmake")});