tibbo_line/main.tc

182 lines
3.8 KiB
Plaintext

#include "global.th"
#include "sensors.th"
#include "relay.th"
#include "net.th"
#include "encoder.th"
#include "common.th"
static string debug_commands[]= {
"debug_enc_level",
"debug_enc_state",
"debug_relay_reply",
"debug_relay_show",
"debug_sensors",
"debug_showtime",
"" // Разделитель. не удалять
};
//====================================================================
void d(string mess){
if (config.debug.ShowTime)
mess = lstr(sys.timercountms)+":\t"+mess;
sys.debugprint(mess+chr(13));
int c = sock.num;
sock.num = 2;
if (sock.statesimple == PL_SSTS_EST){
sock.setdata(mess+chr(13)+chr(10));
sock.send();
}
sock.num =c;
}
void t(string mess){
mess = lstr(sys.timercountms)+":\t"+mess;
int c = sock.num;
sock.num = 4;
if (sock.statesimple == PL_SSTS_EST){
sock.setdata(mess+chr(13)+chr(10));
sock.send();
}
sock.num =c;
}
#include "config_work.th"
#include "braker.th"
void on_sys_init(){
pat.play("RG~",PL_PAT_CANINT);
d(arrayLength(debug_commands));
// for (int i=0;i<255;i++){
// if (len(debug_commands[i])>0){
// d(str(i)+" - "+debug_commands[i]);
// }else{
// break;
// }
// }
config_init();
net_init();
sensor_init();
relay_init();
brakers_init();
encoder_init();
// fd.filenum = 2;
// fd.open("config");
// fd.setpointer(1);
// string data = fd.getdata(250);
// sys.debugprint(data+chr(13));
// fd.close();
// config.STORE_LOCATON = FLASH;
// config.IP= net.ip;
// config.FLASH_SIZE = 1024;
// config.FLASH_FILES = 10;
// config.STORE_BRAKER = true;
// config.BRAKERS[0].Enable = true;
// config.BRAKERS[0].SensPort = 1;
// config.BRAKERS[0].DropPort = 2;
// config.BRAKERS[0].Relay = 1;
// config.BRAKERS[0].Timeout = 300;
// config_write(config);
d("");
d("Запуск системы");
d("");
d(config.IP);
d("sys.version: "+sys.version);
// if (left(sys.serialnum,1)==chr(255)){
// sys.setserialnum("TEST SERIAL NUMBER SETTING 0123456789-abcdefghijklmnopqrstuvwxyz");
// }
d("sys.serialnum: "+sys.serialnum);
d(PLATFORM );
d("fd.availableflashspace / fd.totalsize: "+str(fd.availableflashspace)+"/"+str(fd.totalsize));
d("sys.totalbuffpages: "+ str(sys.totalbuffpages));
d("sys.freebuffpages: "+str(sys.freebuffpages));
d("config.IP="+config.IP);
// unsigned int day,min;
// unsigned char second;
// if (rtc.running){
// rtc.getdata(day,min,second);
//// if (day == 0)
//// rtc.setdata(daycount(18,10,25),mincount(19,58),1);
// }
sys.onsystimerperiod = 1 ;
net_start();
#if PLATFORM_ID != SIMULATOR
io.num=PL_IO_NUM_46;
io.enabled=YES;
io.num=PL_IO_NUM_47;
io.enabled=YES;
io.num=PL_IO_NUM_48;
io.enabled=YES;
#endif
pat.play("---G-R-R~",PL_PAT_CANINT);
}
void on_sys_timer()
{
t("sys_start");
if (!inEncCalibrate()){
for (int i=1; i<=3; i++){
braker_proc(i);
}
// sensors process
for (int i=1; i <= SENSORS; i++){
if (!isBrakerPort(i) && pinChange(i)){
//bool state = getPinStateS(i,!config.debug.EncoderStateMode);
bool state = getPinStateS(i, !inEncCalibrate());
if (getEncEnabled(i,state)){
// getPinStateS(i,config.debug.EncoderStateMode);
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;
io.num=PL_IO_NUM_47;
io.lineset(PL_IO_NUM_48,sock.statesimple != PL_SSTS_EST);
io.state=LOW;
io.state=HIGH;
sock.num = 1;
io.lineset(PL_IO_NUM_48,sock.statesimple != PL_SSTS_EST);
io.state=LOW;
io.state=HIGH;
sock.num = 2;
io.lineset(PL_IO_NUM_48,sock.statesimple != PL_SSTS_EST);
io.state=LOW;
io.state=HIGH;
sock.num = 3;
io.lineset(PL_IO_NUM_48,sock.statesimple != PL_SSTS_EST);
io.state=LOW;
io.state=HIGH;
io.lineset(PL_IO_NUM_48,inEncCalibrate() ? second % 2: 1);
io.state=LOW;
io.state=HIGH;
#endif
t("sys_end");
}