PLC 16 in / 8 rev / an in-out / CAN

Dependencies:   PCAL955x mbed mbed-rtos AT45

Committer:
Oleg_B
Date:
Sun Feb 07 05:08:51 2021 +0000
Revision:
0:d05a7158dbad
Child:
1:3768b56b12e7
main prog for PLC1608

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Oleg_B 0:d05a7158dbad 1
Oleg_B 0:d05a7158dbad 2 /*** PLC F446RE ***/
Oleg_B 0:d05a7158dbad 3 // 512 KB Flash / 128 KB SRAM System / 4 KB SRAM Backup
Oleg_B 0:d05a7158dbad 4
Oleg_B 0:d05a7158dbad 5 #include "mbed.h"
Oleg_B 0:d05a7158dbad 6 #include "rtos.h"
Oleg_B 0:d05a7158dbad 7 #include "AT45.h"
Oleg_B 0:d05a7158dbad 8 #include "PCAL9555.h"
Oleg_B 0:d05a7158dbad 9
Oleg_B 0:d05a7158dbad 10 #include "can.h"
Oleg_B 0:d05a7158dbad 11 #include "config_io.h"
Oleg_B 0:d05a7158dbad 12 #include "ext_vars.h"
Oleg_B 0:d05a7158dbad 13 #include "set_vars.h"
Oleg_B 0:d05a7158dbad 14
Oleg_B 0:d05a7158dbad 15 #include "task_ob.h"
Oleg_B 0:d05a7158dbad 16
Oleg_B 0:d05a7158dbad 17 #define CAN_BAUD 50000 // скорость
Oleg_B 0:d05a7158dbad 18 #define UART_BAUD 9600 // скорость
Oleg_B 0:d05a7158dbad 19 #define MAX_SERL 30 // макс. длинна строки из usb/uart
Oleg_B 0:d05a7158dbad 20
Oleg_B 0:d05a7158dbad 21
Oleg_B 0:d05a7158dbad 22
Oleg_B 0:d05a7158dbad 23
Oleg_B 0:d05a7158dbad 24 /******* создание локальных переменных *************************/
Oleg_B 0:d05a7158dbad 25
Oleg_B 0:d05a7158dbad 26 int busin = 0;
Oleg_B 0:d05a7158dbad 27 int t_sys = 0 ;
Oleg_B 0:d05a7158dbad 28
Oleg_B 0:d05a7158dbad 29 char pc_buffer [MAX_SERL+2];
Oleg_B 0:d05a7158dbad 30 int pc_i=0;
Oleg_B 0:d05a7158dbad 31 int pc_im=0;
Oleg_B 0:d05a7158dbad 32
Oleg_B 0:d05a7158dbad 33 float st_start=0.0;
Oleg_B 0:d05a7158dbad 34 float st_end=0.0;
Oleg_B 0:d05a7158dbad 35 float st_old=0.0;
Oleg_B 0:d05a7158dbad 36 float st_cycl=0.0;
Oleg_B 0:d05a7158dbad 37 float st_task=0.0;
Oleg_B 0:d05a7158dbad 38
Oleg_B 0:d05a7158dbad 39 int new_outs=0;
Oleg_B 0:d05a7158dbad 40
Oleg_B 0:d05a7158dbad 41 /********** прототипы локальных функций **********************/
Oleg_B 0:d05a7158dbad 42 void read_inputs();
Oleg_B 0:d05a7158dbad 43 void write_outs();
Oleg_B 0:d05a7158dbad 44 void save_stat();
Oleg_B 0:d05a7158dbad 45 void logic_tasks();
Oleg_B 0:d05a7158dbad 46 void can_rw();
Oleg_B 0:d05a7158dbad 47 void timers();
Oleg_B 0:d05a7158dbad 48 void pc_rd();
Oleg_B 0:d05a7158dbad 49 int read_val();
Oleg_B 0:d05a7158dbad 50
Oleg_B 0:d05a7158dbad 51 /************** Threads **************************************/
Oleg_B 0:d05a7158dbad 52 Thread read_uart;
Oleg_B 0:d05a7158dbad 53 Thread work_can;
Oleg_B 0:d05a7158dbad 54 RtosTimer t_10msec(&logic_tasks);
Oleg_B 0:d05a7158dbad 55
Oleg_B 0:d05a7158dbad 56
Oleg_B 0:d05a7158dbad 57 /*************** старт программы PLC **************************/
Oleg_B 0:d05a7158dbad 58 int main()
Oleg_B 0:d05a7158dbad 59 {
Oleg_B 0:d05a7158dbad 60 led=1;
Oleg_B 0:d05a7158dbad 61 st.start();
Oleg_B 0:d05a7158dbad 62
Oleg_B 0:d05a7158dbad 63 // ----- настраиваем CAN ------
Oleg_B 0:d05a7158dbad 64 can.frequency(CAN_BAUD);
Oleg_B 0:d05a7158dbad 65
Oleg_B 0:d05a7158dbad 66 //----- настраиваем порт USB ------
Oleg_B 0:d05a7158dbad 67 pc.baud(UART_BAUD);
Oleg_B 0:d05a7158dbad 68 pc.printf( "\r\n> START PLC \r\n");
Oleg_B 0:d05a7158dbad 69 pc.printf(">CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
Oleg_B 0:d05a7158dbad 70
Oleg_B 0:d05a7158dbad 71
Oleg_B 0:d05a7158dbad 72 //------ проверка FLASH ----------
Oleg_B 0:d05a7158dbad 73 pc.printf("> flash size: %d bytes \n", spif.device_size());
Oleg_B 0:d05a7158dbad 74
Oleg_B 0:d05a7158dbad 75
Oleg_B 0:d05a7158dbad 76 //------- запускаем потоки Thread ------
Oleg_B 0:d05a7158dbad 77 work_can.start(can_rw); // обмен информ. по CAN
Oleg_B 0:d05a7158dbad 78 read_uart.start(pc_rd); // чтение UART
Oleg_B 0:d05a7158dbad 79
Oleg_B 0:d05a7158dbad 80
Oleg_B 0:d05a7158dbad 81 //--- запускаем логич.задач по таймеру 10msec ------
Oleg_B 0:d05a7158dbad 82 t_10msec.start(10);
Oleg_B 0:d05a7158dbad 83
Oleg_B 0:d05a7158dbad 84
Oleg_B 0:d05a7158dbad 85 /*** обработка команд по USB ***/
Oleg_B 0:d05a7158dbad 86 while (true) {
Oleg_B 0:d05a7158dbad 87
Oleg_B 0:d05a7158dbad 88 if(t_sys<500){led=1;}else{led=0;}
Oleg_B 0:d05a7158dbad 89 led_r=led;
Oleg_B 0:d05a7158dbad 90
Oleg_B 0:d05a7158dbad 91 // проверяем usb
Oleg_B 0:d05a7158dbad 92 if (pc_i>1 && pc_i==pc_im){
Oleg_B 0:d05a7158dbad 93 pc_i = 0;
Oleg_B 0:d05a7158dbad 94 //pc.printf("usb:%s",pc_buffer);
Oleg_B 0:d05a7158dbad 95 //led = !led;
Oleg_B 0:d05a7158dbad 96
Oleg_B 0:d05a7158dbad 97
Oleg_B 0:d05a7158dbad 98 // --- устанавливаем значение переменных ----
Oleg_B 0:d05a7158dbad 99 if(strstr(pc_buffer,"=")){
Oleg_B 0:d05a7158dbad 100
Oleg_B 0:d05a7158dbad 101 if(strstr (pc_buffer,"vr000")) { vr000=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 102 if(strstr (pc_buffer,"vr001")) { vr001=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 103 if(strstr (pc_buffer,"vr002")) { vr002=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 104 if(strstr (pc_buffer,"vr003")) { vr003=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 105 if(strstr (pc_buffer,"vr004")) { vr004=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 106 if(strstr (pc_buffer,"vr005")) { vr005=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 107 if(strstr (pc_buffer,"vr007")) { vr007=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 108 if(strstr (pc_buffer,"vr008")) { vr008=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 109 if(strstr (pc_buffer,"vr009")) { vr009=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 110 if(strstr (pc_buffer,"vr010")) { vr010=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 111 if(strstr (pc_buffer,"vr011")) { vr011=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 112 if(strstr (pc_buffer,"vr012")) { vr012=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 113 if(strstr (pc_buffer,"vr013")) { vr013=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 114
Oleg_B 0:d05a7158dbad 115 if(strstr (pc_buffer,"al001")) { al001=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 116 if(strstr (pc_buffer,"al002")) { al002=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 117 if(strstr (pc_buffer,"al003")) { al003=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 118 if(strstr (pc_buffer,"al004")) { al004=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 119 if(strstr (pc_buffer,"al005")) { al005=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 120 if(strstr (pc_buffer,"al006")) { al006=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 121 if(strstr (pc_buffer,"al007")) { al007=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 122 if(strstr (pc_buffer,"al008")) { al008=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 123 if(strstr (pc_buffer,"al009")) { al009=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 124 if(strstr (pc_buffer,"al010")) { al010=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 125 if(strstr (pc_buffer,"al011")) { al011=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 126 if(strstr (pc_buffer,"al012")) { al012=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 127 if(strstr (pc_buffer,"al013")) { al013=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 128 if(strstr (pc_buffer,"al014")) { al014=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 129
Oleg_B 0:d05a7158dbad 130 if(strstr (pc_buffer,"pr001")) { pr001=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 131 if(strstr (pc_buffer,"pr002")) { pr002=read_val(); pc.printf( "ok\n"); }
Oleg_B 0:d05a7158dbad 132
Oleg_B 0:d05a7158dbad 133 }
Oleg_B 0:d05a7158dbad 134
Oleg_B 0:d05a7158dbad 135 // --- проверка значения переменных -----
Oleg_B 0:d05a7158dbad 136 if(strstr(pc_buffer,"?")){
Oleg_B 0:d05a7158dbad 137
Oleg_B 0:d05a7158dbad 138 if(strstr (pc_buffer,"vr000")) { pc.printf( "vr000:%d\n", vr000); }
Oleg_B 0:d05a7158dbad 139 if(strstr (pc_buffer,"vr001")) { pc.printf( "vr001:%d\n", vr001); }
Oleg_B 0:d05a7158dbad 140 if(strstr (pc_buffer,"vr002")) { pc.printf( "vr002:%d\n", vr002); }
Oleg_B 0:d05a7158dbad 141 if(strstr (pc_buffer,"vr003")) { pc.printf( "vr003:%d\n", vr003); }
Oleg_B 0:d05a7158dbad 142 if(strstr (pc_buffer,"vr004")) { pc.printf( "vr004:%d\n", vr004); }
Oleg_B 0:d05a7158dbad 143 if(strstr (pc_buffer,"vr005")) { pc.printf( "vr005:%d\n", vr005); }
Oleg_B 0:d05a7158dbad 144 if(strstr (pc_buffer,"vr007")) { pc.printf( "vr007:%d\n", vr007); }
Oleg_B 0:d05a7158dbad 145 if(strstr (pc_buffer,"vr008")) { pc.printf( "vr008:%d\n", vr008); }
Oleg_B 0:d05a7158dbad 146 if(strstr (pc_buffer,"vr009")) { pc.printf( "vr009:%d\n", vr009); }
Oleg_B 0:d05a7158dbad 147 if(strstr (pc_buffer,"vr010")) { pc.printf( "vr010:%d\n", vr010); }
Oleg_B 0:d05a7158dbad 148 if(strstr (pc_buffer,"vr011")) { pc.printf( "vr011:%d\n", vr011); }
Oleg_B 0:d05a7158dbad 149 if(strstr (pc_buffer,"vr012")) { pc.printf( "vr012:%d\n", vr012); }
Oleg_B 0:d05a7158dbad 150 if(strstr (pc_buffer,"vr013")) { pc.printf( "vr013:%d\n", vr013); }
Oleg_B 0:d05a7158dbad 151
Oleg_B 0:d05a7158dbad 152 if(strstr (pc_buffer,"al001")) { pc.printf( "al001:%d\n", al001); }
Oleg_B 0:d05a7158dbad 153 if(strstr (pc_buffer,"al002")) { pc.printf( "al002:%d\n", al002); }
Oleg_B 0:d05a7158dbad 154 if(strstr (pc_buffer,"al003")) { pc.printf( "al003:%d\n", al003); }
Oleg_B 0:d05a7158dbad 155 if(strstr (pc_buffer,"al004")) { pc.printf( "al004:%d\n", al004); }
Oleg_B 0:d05a7158dbad 156 if(strstr (pc_buffer,"al005")) { pc.printf( "al005:%d\n", al005); }
Oleg_B 0:d05a7158dbad 157 if(strstr (pc_buffer,"al006")) { pc.printf( "al006:%d\n", al006); }
Oleg_B 0:d05a7158dbad 158 if(strstr (pc_buffer,"al007")) { pc.printf( "al007:%d\n", al007); }
Oleg_B 0:d05a7158dbad 159 if(strstr (pc_buffer,"al008")) { pc.printf( "al008:%d\n", al008); }
Oleg_B 0:d05a7158dbad 160 if(strstr (pc_buffer,"al009")) { pc.printf( "al009:%d\n", al009); }
Oleg_B 0:d05a7158dbad 161 if(strstr (pc_buffer,"al010")) { pc.printf( "al010:%d\n", al010); }
Oleg_B 0:d05a7158dbad 162 if(strstr (pc_buffer,"al011")) { pc.printf( "al011:%d\n", al011); }
Oleg_B 0:d05a7158dbad 163 if(strstr (pc_buffer,"al012")) { pc.printf( "al012:%d\n", al012); }
Oleg_B 0:d05a7158dbad 164 if(strstr (pc_buffer,"al013")) { pc.printf( "al013:%d\n", al013); }
Oleg_B 0:d05a7158dbad 165 if(strstr (pc_buffer,"al014")) { pc.printf( "al014:%d\n", al014); }
Oleg_B 0:d05a7158dbad 166
Oleg_B 0:d05a7158dbad 167 if(strstr (pc_buffer,"pr001")) { pc.printf( "pr001:%d\n", pr001); }
Oleg_B 0:d05a7158dbad 168 if(strstr (pc_buffer,"pr002")) { pc.printf( "pr002:%d\n", pr002); }
Oleg_B 0:d05a7158dbad 169
Oleg_B 0:d05a7158dbad 170
Oleg_B 0:d05a7158dbad 171 // для контроля состояния
Oleg_B 0:d05a7158dbad 172
Oleg_B 0:d05a7158dbad 173 if(strstr (pc_buffer,"dc_in")) { pc.printf( "\n--- PLC --- \n> inputs:%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d\n", x01,x02,x03,x04,x05,x06,x07,x08,x09,x10,x11,x12,x13,x14,x15,x16); }
Oleg_B 0:d05a7158dbad 174 if(strstr (pc_buffer,"dc_out")) { pc.printf( "\n--- PLC --- \n> outputs:%d%d%d%d%d%d%d%d%\n", y01,y02,y03,y04,y05,y06,y07,y08); }
Oleg_B 0:d05a7158dbad 175 if(strstr (pc_buffer,"an_in")) { pc.printf( "\n--- PLC --- \n> an_in1=%f an_in2=%f an_in3=%f an_in4=%f \n", Vin_1, Vin_2, Vin_3, Vin_4 ); }
Oleg_B 0:d05a7158dbad 176 if(strstr (pc_buffer,"an_out")) { pc.printf( "\n--- PLC --- \n> an_out1=%f an_out2=%f \n", Vout_1, Vout_2 ); }
Oleg_B 0:d05a7158dbad 177 if(strstr (pc_buffer,"stime")) { pc.printf( "\n--- PLC --- \n> work cycle %f / using %f sec \n", st_cycl, st_task ); }
Oleg_B 0:d05a7158dbad 178
Oleg_B 0:d05a7158dbad 179 if(strstr (pc_buffer,"sm-1")){ pc.printf( "\n--- modul SM01 adr=1 --- \n> car position-%d moving-%d alarm-%d \n> inputs %d-%d-%d-%d outputs %d-%d \n", sm1_pos, sm1_mov, sm1_alr, a101, a102, a103, a104, b101, b102 ); }
Oleg_B 0:d05a7158dbad 180 if(strstr (pc_buffer,"sm-2")){ pc.printf( "\n--- modul SM01 adr=2 --- \n> car position-%d moving-%d alarm-%d \n> inputs %d-%d-%d-%d outputs %d-%d \n", sm2_pos, sm2_mov, sm2_alr, a201, a202, a203, a204, b201, b202 ); }
Oleg_B 0:d05a7158dbad 181 if(strstr (pc_buffer,"sm-3")){ pc.printf( "\n--- modul SM01 adr=3 --- \n> car position-%d moving-%d alarm-%d \n> inputs %d-%d-%d-%d outputs %d-%d \n", sm3_pos, sm3_mov, sm3_alr, a301, a302, a303, a304, b301, b302 ); }
Oleg_B 0:d05a7158dbad 182 if(strstr (pc_buffer,"sm-4")){ pc.printf( "\n--- modul SM01 adr=4 --- \n> car position-%d moving-%d alarm-%d \n> inputs %d-%d-%d-%d outputs %d-%d \n", sm4_pos, sm4_mov, sm4_alr, a401, a402, a403, a404, b401, b402 ); }
Oleg_B 0:d05a7158dbad 183
Oleg_B 0:d05a7158dbad 184 if(strstr (pc_buffer,"dm-1")){ pc.printf( "\n--- modul DM0806 adr=1 --- \n> inputs:%d%d%d%d%d%d%d%d% \n> outputs:%d%d%d%d%d%d% \n", x101,x102,x103,x104,x105,x106,x107,x108, y101,y102,y103,y104,y105,y106 ); }
Oleg_B 0:d05a7158dbad 185 if(strstr (pc_buffer,"dm-2")){ pc.printf( "\n--- modul DM0806 adr=2 --- \n> inputs:%d%d%d%d%d%d%d%d% \n> outputs:%d%d%d%d%d%d% \n", x201,x202,x203,x204,x205,x206,x207,x208, y201,y202,y203,y204,y205,y206 ); }
Oleg_B 0:d05a7158dbad 186 if(strstr (pc_buffer,"dm-3")){ pc.printf( "\n--- modul DM0806 adr=3 --- \n> inputs:%d%d%d%d%d%d%d%d% \n> outputs:%d%d%d%d%d%d% \n", x301,x302,x303,x304,x305,x306,x307,x308, y301,y302,y303,y304,y305,y306 ); }
Oleg_B 0:d05a7158dbad 187 if(strstr (pc_buffer,"dm-4")){ pc.printf( "\n--- modul DM0806 adr=4 --- \n> inputs:%d%d%d%d%d%d%d%d% \n> outputs:%d%d%d%d%d%d% \n", x401,x402,x403,x404,x405,x406,x407,x408, y401,y402,y403,y404,y405,y406 ); }
Oleg_B 0:d05a7158dbad 188
Oleg_B 0:d05a7158dbad 189 }
Oleg_B 0:d05a7158dbad 190
Oleg_B 0:d05a7158dbad 191 if(strstr (pc_buffer,"reset")) { NVIC_SystemReset() ; }
Oleg_B 0:d05a7158dbad 192
Oleg_B 0:d05a7158dbad 193
Oleg_B 0:d05a7158dbad 194
Oleg_B 0:d05a7158dbad 195 }
Oleg_B 0:d05a7158dbad 196
Oleg_B 0:d05a7158dbad 197 pc_im=pc_i;
Oleg_B 0:d05a7158dbad 198 Thread::wait(100);
Oleg_B 0:d05a7158dbad 199 }
Oleg_B 0:d05a7158dbad 200
Oleg_B 0:d05a7158dbad 201 }
Oleg_B 0:d05a7158dbad 202
Oleg_B 0:d05a7158dbad 203
Oleg_B 0:d05a7158dbad 204 /**************** дополнительные функции **********************/
Oleg_B 0:d05a7158dbad 205
Oleg_B 0:d05a7158dbad 206 // логические задачи. вызываются для выполнения
Oleg_B 0:d05a7158dbad 207 // каждые 10 мсек
Oleg_B 0:d05a7158dbad 208 void logic_tasks(){
Oleg_B 0:d05a7158dbad 209 // чтение сист.таймера
Oleg_B 0:d05a7158dbad 210 st_start=st.read();
Oleg_B 0:d05a7158dbad 211
Oleg_B 0:d05a7158dbad 212
Oleg_B 0:d05a7158dbad 213 // подготовка входн.информации
Oleg_B 0:d05a7158dbad 214 timers();
Oleg_B 0:d05a7158dbad 215 read_inputs();
Oleg_B 0:d05a7158dbad 216
Oleg_B 0:d05a7158dbad 217 // логичкские задачи
Oleg_B 0:d05a7158dbad 218 task_ob();
Oleg_B 0:d05a7158dbad 219
Oleg_B 0:d05a7158dbad 220 // формирование выходн.информации
Oleg_B 0:d05a7158dbad 221 write_outs();
Oleg_B 0:d05a7158dbad 222 save_stat();
Oleg_B 0:d05a7158dbad 223
Oleg_B 0:d05a7158dbad 224 // определяем реальное время цикла/использ.время
Oleg_B 0:d05a7158dbad 225 st_end=st.read();
Oleg_B 0:d05a7158dbad 226 st_task=st_end-st_start;
Oleg_B 0:d05a7158dbad 227 st_cycl=st_start-st_old;
Oleg_B 0:d05a7158dbad 228 st_old=st_start;
Oleg_B 0:d05a7158dbad 229
Oleg_B 0:d05a7158dbad 230 }
Oleg_B 0:d05a7158dbad 231
Oleg_B 0:d05a7158dbad 232
Oleg_B 0:d05a7158dbad 233 //----------------------------------------
Oleg_B 0:d05a7158dbad 234 // установка выходов контроллера
Oleg_B 0:d05a7158dbad 235 // в соответствии значения преременным
Oleg_B 0:d05a7158dbad 236 void write_outs(){
Oleg_B 0:d05a7158dbad 237 // устанавливаем локальные выходы ПЛК
Oleg_B 0:d05a7158dbad 238 y_1=y01; y_5=y05;
Oleg_B 0:d05a7158dbad 239 y_2=y02; y_6=y06;
Oleg_B 0:d05a7158dbad 240 y_3=y03; y_7=y07;
Oleg_B 0:d05a7158dbad 241 y_4=y04; y_8=y08;
Oleg_B 0:d05a7158dbad 242
Oleg_B 0:d05a7158dbad 243 anout1=Vout_1;
Oleg_B 0:d05a7158dbad 244 anout2=Vout_2;
Oleg_B 0:d05a7158dbad 245
Oleg_B 0:d05a7158dbad 246 // упаковываем выходы для DM0806 ADR=1
Oleg_B 0:d05a7158dbad 247 dm1_outs = 0;
Oleg_B 0:d05a7158dbad 248 if(y106==1){dm1_outs = dm1_outs |1;} // y106
Oleg_B 0:d05a7158dbad 249 dm1_outs = dm1_outs << 1;
Oleg_B 0:d05a7158dbad 250 if(y105==1){dm1_outs = dm1_outs |1;} // y105
Oleg_B 0:d05a7158dbad 251 dm1_outs = dm1_outs << 1;
Oleg_B 0:d05a7158dbad 252 if(y104==1){dm1_outs = dm1_outs |1;} // y104
Oleg_B 0:d05a7158dbad 253 dm1_outs = dm1_outs << 1;
Oleg_B 0:d05a7158dbad 254 if(y103==1){dm1_outs = dm1_outs |1;} // y103
Oleg_B 0:d05a7158dbad 255 dm1_outs = dm1_outs << 1;
Oleg_B 0:d05a7158dbad 256 if(y102==1){dm1_outs = dm1_outs |1;} // y102
Oleg_B 0:d05a7158dbad 257 dm1_outs = dm1_outs << 1;
Oleg_B 0:d05a7158dbad 258 if(y101==1){dm1_outs = dm1_outs |1;} // y101
Oleg_B 0:d05a7158dbad 259
Oleg_B 0:d05a7158dbad 260 // упаковываем выходы для DM0806 ADR=2
Oleg_B 0:d05a7158dbad 261 dm2_outs = 0;
Oleg_B 0:d05a7158dbad 262 if(y206==1){dm2_outs = dm2_outs |1;} // y206
Oleg_B 0:d05a7158dbad 263 dm2_outs = dm2_outs << 1;
Oleg_B 0:d05a7158dbad 264 if(y205==1){dm2_outs = dm2_outs |1;} // y205
Oleg_B 0:d05a7158dbad 265 dm2_outs = dm2_outs << 1;
Oleg_B 0:d05a7158dbad 266 if(y204==1){dm2_outs = dm2_outs |1;} // y204
Oleg_B 0:d05a7158dbad 267 dm2_outs = dm2_outs << 1;
Oleg_B 0:d05a7158dbad 268 if(y203==1){dm2_outs = dm2_outs |1;} // y203
Oleg_B 0:d05a7158dbad 269 dm2_outs = dm2_outs << 1;
Oleg_B 0:d05a7158dbad 270 if(y202==1){dm2_outs = dm2_outs |1;} // y202
Oleg_B 0:d05a7158dbad 271 dm2_outs = dm2_outs << 1;
Oleg_B 0:d05a7158dbad 272 if(y201==1){dm2_outs = dm2_outs |1;} // y201
Oleg_B 0:d05a7158dbad 273
Oleg_B 0:d05a7158dbad 274 // упаковываем выходы для DM0806 ADR=3
Oleg_B 0:d05a7158dbad 275 dm3_outs = 0;
Oleg_B 0:d05a7158dbad 276 if(y306==1){dm3_outs = dm3_outs |1;} // y306
Oleg_B 0:d05a7158dbad 277 dm3_outs = dm3_outs << 1;
Oleg_B 0:d05a7158dbad 278 if(y305==1){dm3_outs = dm3_outs |1;} // y305
Oleg_B 0:d05a7158dbad 279 dm3_outs = dm3_outs << 1;
Oleg_B 0:d05a7158dbad 280 if(y304==1){dm3_outs = dm3_outs |1;} // y304
Oleg_B 0:d05a7158dbad 281 dm3_outs = dm3_outs << 1;
Oleg_B 0:d05a7158dbad 282 if(y303==1){dm3_outs = dm3_outs |1;} // y303
Oleg_B 0:d05a7158dbad 283 dm3_outs = dm3_outs << 1;
Oleg_B 0:d05a7158dbad 284 if(y302==1){dm3_outs = dm3_outs |1;} // y302
Oleg_B 0:d05a7158dbad 285 dm3_outs = dm3_outs << 1;
Oleg_B 0:d05a7158dbad 286 if(y301==1){dm3_outs = dm3_outs |1;} // y301
Oleg_B 0:d05a7158dbad 287
Oleg_B 0:d05a7158dbad 288
Oleg_B 0:d05a7158dbad 289 // упаковываем выходы для DM0806 ADR=4
Oleg_B 0:d05a7158dbad 290 dm4_outs = 0;
Oleg_B 0:d05a7158dbad 291 if(y406==1){dm4_outs = dm4_outs |1;} // y406
Oleg_B 0:d05a7158dbad 292 dm4_outs = dm4_outs << 1;
Oleg_B 0:d05a7158dbad 293 if(y405==1){dm4_outs = dm4_outs |1;} // y405
Oleg_B 0:d05a7158dbad 294 dm4_outs = dm4_outs << 1;
Oleg_B 0:d05a7158dbad 295 if(y404==1){dm4_outs = dm4_outs |1;} // y404
Oleg_B 0:d05a7158dbad 296 dm4_outs = dm4_outs << 1;
Oleg_B 0:d05a7158dbad 297 if(y403==1){dm4_outs = dm4_outs |1;} // y403
Oleg_B 0:d05a7158dbad 298 dm4_outs = dm4_outs << 1;
Oleg_B 0:d05a7158dbad 299 if(y402==1){dm4_outs = dm4_outs |1;} // y402
Oleg_B 0:d05a7158dbad 300 dm4_outs = dm4_outs << 1;
Oleg_B 0:d05a7158dbad 301 if(y401==1){dm4_outs = dm4_outs |1;} // y401
Oleg_B 0:d05a7158dbad 302
Oleg_B 0:d05a7158dbad 303
Oleg_B 0:d05a7158dbad 304 // при изменении по DM0806 посылаем в CAN
Oleg_B 0:d05a7158dbad 305 if(dm1_outs!=mdm1_outs || dm2_outs!=mdm2_outs || dm3_outs!=mdm3_outs || dm4_outs!=mdm4_outs){
Oleg_B 0:d05a7158dbad 306 int _id=50;
Oleg_B 0:d05a7158dbad 307 char _b1= dm1_outs;
Oleg_B 0:d05a7158dbad 308 char _b2= dm2_outs ;
Oleg_B 0:d05a7158dbad 309 char _b3= dm3_outs ;
Oleg_B 0:d05a7158dbad 310 char _b4= dm4_outs ;
Oleg_B 0:d05a7158dbad 311 can_save_wr(_id,_b1,_b2,_b3,_b4);
Oleg_B 0:d05a7158dbad 312 }
Oleg_B 0:d05a7158dbad 313
Oleg_B 0:d05a7158dbad 314
Oleg_B 0:d05a7158dbad 315 // упаковываем выходы для SM01 ADR=1-4
Oleg_B 0:d05a7158dbad 316 sm_outs=0;
Oleg_B 0:d05a7158dbad 317 if(b402==1){sm_outs = sm_outs |1;} // b402
Oleg_B 0:d05a7158dbad 318 sm_outs = sm_outs << 1;
Oleg_B 0:d05a7158dbad 319 if(b401==1){sm_outs = sm_outs |1;} // b401
Oleg_B 0:d05a7158dbad 320 sm_outs = sm_outs << 1;
Oleg_B 0:d05a7158dbad 321 if(b302==1){sm_outs = sm_outs |1;} // b302
Oleg_B 0:d05a7158dbad 322 sm_outs = sm_outs << 1;
Oleg_B 0:d05a7158dbad 323 if(b301==1){sm_outs = sm_outs |1;} // b301
Oleg_B 0:d05a7158dbad 324 sm_outs = sm_outs << 1;
Oleg_B 0:d05a7158dbad 325 if(b202==1){sm_outs = sm_outs |1;} // b202
Oleg_B 0:d05a7158dbad 326 sm_outs = sm_outs << 1;
Oleg_B 0:d05a7158dbad 327 if(b201==1){sm_outs = sm_outs |1;} // b201
Oleg_B 0:d05a7158dbad 328 sm_outs = sm_outs << 1;
Oleg_B 0:d05a7158dbad 329 if(b102==1){sm_outs = sm_outs |1;} // b102
Oleg_B 0:d05a7158dbad 330 sm_outs = sm_outs << 1;
Oleg_B 0:d05a7158dbad 331 if(b101==1){sm_outs = sm_outs |1;} // b101
Oleg_B 0:d05a7158dbad 332
Oleg_B 0:d05a7158dbad 333
Oleg_B 0:d05a7158dbad 334 // при изменении по SM01 посылаем в CAN
Oleg_B 0:d05a7158dbad 335 if(sm_outs != msm_outs || sm_position != msm_position){
Oleg_B 0:d05a7158dbad 336 int _id=60;
Oleg_B 0:d05a7158dbad 337 char _b1=dm1_outs;
Oleg_B 0:d05a7158dbad 338 char _b2= sm_position / 100 ;
Oleg_B 0:d05a7158dbad 339 char _b3= (sm_position - _b2*100) / 10 ;
Oleg_B 0:d05a7158dbad 340 char _b4= (sm_position - _b2*100 - _b3*10) ;
Oleg_B 0:d05a7158dbad 341 can_save_wr(_id,_b1,_b2,_b3,_b4);
Oleg_B 0:d05a7158dbad 342 }
Oleg_B 0:d05a7158dbad 343
Oleg_B 0:d05a7158dbad 344
Oleg_B 0:d05a7158dbad 345 }
Oleg_B 0:d05a7158dbad 346
Oleg_B 0:d05a7158dbad 347
Oleg_B 0:d05a7158dbad 348 //----------------------------------------
Oleg_B 0:d05a7158dbad 349 // формирование значения переменных
Oleg_B 0:d05a7158dbad 350 // в соответствии с сигналами на входах контроллера
Oleg_B 0:d05a7158dbad 351 // и принятой по CAN информацией
Oleg_B 0:d05a7158dbad 352 void read_inputs(){
Oleg_B 0:d05a7158dbad 353 // считываем локальные выходы ПЛК
Oleg_B 0:d05a7158dbad 354 busin=inps;
Oleg_B 0:d05a7158dbad 355 if(busin & 1){ x01=0; }else{ x01=1;}
Oleg_B 0:d05a7158dbad 356 if(busin & 2){ x02=0; }else{ x02=1;}
Oleg_B 0:d05a7158dbad 357 if(busin & 4){ x03=0; }else{ x03=1;}
Oleg_B 0:d05a7158dbad 358 if(busin & 8){ x04=0; }else{ x04=1;}
Oleg_B 0:d05a7158dbad 359 if(busin & 16){ x05=0; }else{ x05=1;}
Oleg_B 0:d05a7158dbad 360 if(busin & 32){ x06=0; }else{ x06=1;}
Oleg_B 0:d05a7158dbad 361 if(busin & 64){ x07=0; }else{ x07=1;}
Oleg_B 0:d05a7158dbad 362 if(busin & 128){ x08=0; }else{ x08=1;}
Oleg_B 0:d05a7158dbad 363 if(busin & 256){ x09=0; }else{ x09=1;}
Oleg_B 0:d05a7158dbad 364 if(busin & 512){ x10=0; }else{ x10=1;}
Oleg_B 0:d05a7158dbad 365 if(busin & 1024){ x11=0; }else{ x11=1;}
Oleg_B 0:d05a7158dbad 366 if(busin & 2048){ x12=0; }else{ x12=1;}
Oleg_B 0:d05a7158dbad 367 if(busin & 4096){ x13=0; }else{ x13=1;}
Oleg_B 0:d05a7158dbad 368 if(busin & 8192){ x14=0; }else{ x14=1;}
Oleg_B 0:d05a7158dbad 369 if(busin & 16384){ x15=0; }else{ x15=1;}
Oleg_B 0:d05a7158dbad 370 if(busin & 32768){ x16=0; }else{ x16=1;}
Oleg_B 0:d05a7158dbad 371
Oleg_B 0:d05a7158dbad 372 Vin_1 = aninp1;
Oleg_B 0:d05a7158dbad 373 Vin_2 = aninp2;
Oleg_B 0:d05a7158dbad 374 Vin_3 = aninp3;
Oleg_B 0:d05a7158dbad 375 Vin_4 = aninp4;
Oleg_B 0:d05a7158dbad 376
Oleg_B 0:d05a7158dbad 377 // проверяем принятые посылки CAN
Oleg_B 0:d05a7158dbad 378 int resalt=1;
Oleg_B 0:d05a7158dbad 379 while(resalt==1){
Oleg_B 0:d05a7158dbad 380 resalt=can_select_rd();
Oleg_B 0:d05a7158dbad 381 if(resalt==1){
Oleg_B 0:d05a7158dbad 382
Oleg_B 0:d05a7158dbad 383 // inps from DM ADR=1
Oleg_B 0:d05a7158dbad 384 if(r_id==51){
Oleg_B 0:d05a7158dbad 385 if( r_b1&1 ){ x101=1; } else { x101=0; }
Oleg_B 0:d05a7158dbad 386 if((r_b1>>1)&1){ x102=1; } else { x102=0; }
Oleg_B 0:d05a7158dbad 387 if((r_b1>>2)&1){ x103=1; } else { x103=0; }
Oleg_B 0:d05a7158dbad 388 if((r_b1>>3)&1){ x104=1; } else { x104=0; }
Oleg_B 0:d05a7158dbad 389 if((r_b1>>4)&1){ x105=1; } else { x105=0; }
Oleg_B 0:d05a7158dbad 390 if((r_b1>>5)&1){ x106=1; } else { x106=0; }
Oleg_B 0:d05a7158dbad 391 if((r_b1>>6)&1){ x107=1; } else { x107=0; }
Oleg_B 0:d05a7158dbad 392 if((r_b1>>7)&1){ x108=1; } else { x108=0; }
Oleg_B 0:d05a7158dbad 393 }
Oleg_B 0:d05a7158dbad 394
Oleg_B 0:d05a7158dbad 395 // inps from DM ADR=2
Oleg_B 0:d05a7158dbad 396 if(r_id==52){
Oleg_B 0:d05a7158dbad 397 if( r_b1&1 ){ x201=1; } else { x201=0; }
Oleg_B 0:d05a7158dbad 398 if((r_b1>>1)&1){ x202=1; } else { x202=0; }
Oleg_B 0:d05a7158dbad 399 if((r_b1>>2)&1){ x203=1; } else { x203=0; }
Oleg_B 0:d05a7158dbad 400 if((r_b1>>3)&1){ x204=1; } else { x204=0; }
Oleg_B 0:d05a7158dbad 401 if((r_b1>>4)&1){ x205=1; } else { x205=0; }
Oleg_B 0:d05a7158dbad 402 if((r_b1>>5)&1){ x206=1; } else { x206=0; }
Oleg_B 0:d05a7158dbad 403 if((r_b1>>6)&1){ x207=1; } else { x207=0; }
Oleg_B 0:d05a7158dbad 404 if((r_b1>>7)&1){ x208=1; } else { x208=0; }
Oleg_B 0:d05a7158dbad 405 }
Oleg_B 0:d05a7158dbad 406
Oleg_B 0:d05a7158dbad 407 // inps from DM ADR=3
Oleg_B 0:d05a7158dbad 408 if(r_id==53){
Oleg_B 0:d05a7158dbad 409 if( r_b1&1 ){ x301=1; } else { x301=0; }
Oleg_B 0:d05a7158dbad 410 if((r_b1>>1)&1){ x302=1; } else { x302=0; }
Oleg_B 0:d05a7158dbad 411 if((r_b1>>2)&1){ x303=1; } else { x303=0; }
Oleg_B 0:d05a7158dbad 412 if((r_b1>>3)&1){ x304=1; } else { x304=0; }
Oleg_B 0:d05a7158dbad 413 if((r_b1>>4)&1){ x305=1; } else { x305=0; }
Oleg_B 0:d05a7158dbad 414 if((r_b1>>5)&1){ x306=1; } else { x306=0; }
Oleg_B 0:d05a7158dbad 415 if((r_b1>>6)&1){ x307=1; } else { x307=0; }
Oleg_B 0:d05a7158dbad 416 if((r_b1>>7)&1){ x308=1; } else { x308=0; }
Oleg_B 0:d05a7158dbad 417 }
Oleg_B 0:d05a7158dbad 418
Oleg_B 0:d05a7158dbad 419 // inps from DM ADR=4
Oleg_B 0:d05a7158dbad 420 if(r_id==54){
Oleg_B 0:d05a7158dbad 421 if( r_b1&1 ){ x401=1; } else { x401=0; }
Oleg_B 0:d05a7158dbad 422 if((r_b1>>1)&1){ x402=1; } else { x402=0; }
Oleg_B 0:d05a7158dbad 423 if((r_b1>>2)&1){ x403=1; } else { x403=0; }
Oleg_B 0:d05a7158dbad 424 if((r_b1>>3)&1){ x404=1; } else { x404=0; }
Oleg_B 0:d05a7158dbad 425 if((r_b1>>4)&1){ x405=1; } else { x405=0; }
Oleg_B 0:d05a7158dbad 426 if((r_b1>>5)&1){ x406=1; } else { x406=0; }
Oleg_B 0:d05a7158dbad 427 if((r_b1>>6)&1){ x407=1; } else { x407=0; }
Oleg_B 0:d05a7158dbad 428 if((r_b1>>7)&1){ x408=1; } else { x408=0; }
Oleg_B 0:d05a7158dbad 429 }
Oleg_B 0:d05a7158dbad 430
Oleg_B 0:d05a7158dbad 431 // inps from SM ADR=1
Oleg_B 0:d05a7158dbad 432 if(r_id==61){
Oleg_B 0:d05a7158dbad 433 if(r_b1 & 4) { a101=1; } else{ a101=0; }
Oleg_B 0:d05a7158dbad 434 if(r_b1 & 8) { a102=1; } else{ a102=0; }
Oleg_B 0:d05a7158dbad 435 if(r_b1 & 16){ a103=1; } else{ a103=0; }
Oleg_B 0:d05a7158dbad 436 if(r_b1 & 32){ a104=1; } else{ a104=0; }
Oleg_B 0:d05a7158dbad 437 if(r_b1 & 64){ sm1_mov=1; } else{ sm1_mov=0; }
Oleg_B 0:d05a7158dbad 438 if(r_b1 & 128){ sm1_alr=1; } else{ sm1_alr=0; }
Oleg_B 0:d05a7158dbad 439 sm1_pos = r_b2*100+r_b3*10+r_b4;
Oleg_B 0:d05a7158dbad 440 }
Oleg_B 0:d05a7158dbad 441
Oleg_B 0:d05a7158dbad 442 // inps from SM ADR=2
Oleg_B 0:d05a7158dbad 443 if(r_id==62){
Oleg_B 0:d05a7158dbad 444 if(r_b1 & 4) { a201=1; } else{ a201=0; }
Oleg_B 0:d05a7158dbad 445 if(r_b1 & 8) { a202=1; } else{ a202=0; }
Oleg_B 0:d05a7158dbad 446 if(r_b1 & 16){ a203=1; } else{ a203=0; }
Oleg_B 0:d05a7158dbad 447 if(r_b1 & 32){ a204=1; } else{ a204=0; }
Oleg_B 0:d05a7158dbad 448 if(r_b1 & 64){ sm2_mov=1; } else{ sm2_mov=0; }
Oleg_B 0:d05a7158dbad 449 if(r_b1 & 128){ sm2_alr=1; } else{ sm2_alr=0; }
Oleg_B 0:d05a7158dbad 450 sm2_pos = r_b2*100+r_b3*10+r_b4;
Oleg_B 0:d05a7158dbad 451 }
Oleg_B 0:d05a7158dbad 452
Oleg_B 0:d05a7158dbad 453 // inps from SM ADR=3
Oleg_B 0:d05a7158dbad 454 if(r_id==63){
Oleg_B 0:d05a7158dbad 455 if(r_b1 & 4) { a301=1; } else{ a301=0; }
Oleg_B 0:d05a7158dbad 456 if(r_b1 & 8) { a302=1; } else{ a302=0; }
Oleg_B 0:d05a7158dbad 457 if(r_b1 & 16){ a303=1; } else{ a303=0; }
Oleg_B 0:d05a7158dbad 458 if(r_b1 & 32){ a304=1; } else{ a304=0; }
Oleg_B 0:d05a7158dbad 459 if(r_b1 & 64){ sm3_mov=1; } else{ sm3_mov=0; }
Oleg_B 0:d05a7158dbad 460 if(r_b1 & 128){ sm3_alr=1; } else{ sm3_alr=0; }
Oleg_B 0:d05a7158dbad 461 sm3_pos = r_b2*100+r_b3*10+r_b4;
Oleg_B 0:d05a7158dbad 462 }
Oleg_B 0:d05a7158dbad 463
Oleg_B 0:d05a7158dbad 464 // inps from SM ADR=4
Oleg_B 0:d05a7158dbad 465 if(r_id==64){
Oleg_B 0:d05a7158dbad 466 if(r_b1 & 4) { a401=1; } else{ a401=0; }
Oleg_B 0:d05a7158dbad 467 if(r_b1 & 8) { a402=1; } else{ a402=0; }
Oleg_B 0:d05a7158dbad 468 if(r_b1 & 16){ a403=1; } else{ a403=0; }
Oleg_B 0:d05a7158dbad 469 if(r_b1 & 32){ a404=1; } else{ a404=0; }
Oleg_B 0:d05a7158dbad 470 if(r_b1 & 64){ sm4_mov=1; } else{ sm4_mov=0; }
Oleg_B 0:d05a7158dbad 471 if(r_b1 & 128){ sm4_alr=1; } else{ sm4_alr=0; }
Oleg_B 0:d05a7158dbad 472 sm4_pos = r_b2*100+r_b3*10+r_b4;
Oleg_B 0:d05a7158dbad 473 }
Oleg_B 0:d05a7158dbad 474
Oleg_B 0:d05a7158dbad 475
Oleg_B 0:d05a7158dbad 476
Oleg_B 0:d05a7158dbad 477 }
Oleg_B 0:d05a7158dbad 478 }
Oleg_B 0:d05a7158dbad 479
Oleg_B 0:d05a7158dbad 480 }
Oleg_B 0:d05a7158dbad 481
Oleg_B 0:d05a7158dbad 482 //----------------------------------------
Oleg_B 0:d05a7158dbad 483 // сохранение значения переменных для обработки
Oleg_B 0:d05a7158dbad 484 // в след.цикле (установка, сброс)
Oleg_B 0:d05a7158dbad 485 void save_stat(){
Oleg_B 0:d05a7158dbad 486
Oleg_B 0:d05a7158dbad 487 mx01=x01; mx02=x02; mx03=x03; mx04=x04;
Oleg_B 0:d05a7158dbad 488 mx05=x05; mx06=x06; mx07=x07; mx08=x08;
Oleg_B 0:d05a7158dbad 489 mx09=x09; mx10=x10; mx11=x11; mx12=x12;
Oleg_B 0:d05a7158dbad 490 mx13=x13; mx14=x14; mx15=x15; mx16=x16;
Oleg_B 0:d05a7158dbad 491 my01=y01; my02=y02; my03=y03; my04=y04;
Oleg_B 0:d05a7158dbad 492 my05=y05; my06=y06; my07=y07; my08=y08;
Oleg_B 0:d05a7158dbad 493
Oleg_B 0:d05a7158dbad 494 mx101=x101; mx102=x102; mx103=x103; mx104=x104;
Oleg_B 0:d05a7158dbad 495 mx105=x105; mx106=x106; mx107=x107; mx108=x108;
Oleg_B 0:d05a7158dbad 496 mx201=x201; mx202=x202; mx203=x103; mx204=x104;
Oleg_B 0:d05a7158dbad 497 mx205=x205; mx206=x206; mx207=x107; mx208=x108;
Oleg_B 0:d05a7158dbad 498 mx301=x301; mx302=x302; mx303=x303; mx304=x304;
Oleg_B 0:d05a7158dbad 499 mx305=x305; mx306=x306; mx307=x307; mx308=x308;
Oleg_B 0:d05a7158dbad 500 mx401=x401; mx402=x402; mx403=x403; mx404=x404;
Oleg_B 0:d05a7158dbad 501 mx405=x405; mx406=x406; mx407=x407; mx408=x408;
Oleg_B 0:d05a7158dbad 502 my101=y101; my102=y102; my103=y103;
Oleg_B 0:d05a7158dbad 503 my104=y104; my105=y105; my106=y106;
Oleg_B 0:d05a7158dbad 504 my201=y201; my202=y202; my203=y203;
Oleg_B 0:d05a7158dbad 505 my204=y204; my205=y205; my206=y206;
Oleg_B 0:d05a7158dbad 506 my301=y301; my302=y302; my303=y303;
Oleg_B 0:d05a7158dbad 507 my304=y304; my305=y305; my306=y306;
Oleg_B 0:d05a7158dbad 508 my401=y401; my402=y402; my403=y403;
Oleg_B 0:d05a7158dbad 509 my404=y404; my405=y405; my406=y406;
Oleg_B 0:d05a7158dbad 510
Oleg_B 0:d05a7158dbad 511 ma101=a101; ma102=a102; ma103=a103; ma104=a104;
Oleg_B 0:d05a7158dbad 512 ma201=a201; ma202=a202; ma203=a203; ma204=a204;
Oleg_B 0:d05a7158dbad 513 ma301=a301; ma302=a302; ma303=a303; ma304=a304;
Oleg_B 0:d05a7158dbad 514 ma401=a401; ma402=a402; ma403=a403; ma404=a404;
Oleg_B 0:d05a7158dbad 515 mb101=b101; mb102=b102; mb201=b201; mb202=b202;
Oleg_B 0:d05a7158dbad 516 mb301=b301; mb302=b302; mb401=b401; mb402=b402;
Oleg_B 0:d05a7158dbad 517
Oleg_B 0:d05a7158dbad 518 msm_outs=sm_outs;
Oleg_B 0:d05a7158dbad 519 msm_position=sm_position;
Oleg_B 0:d05a7158dbad 520
Oleg_B 0:d05a7158dbad 521 mdm1_outs=dm1_outs;
Oleg_B 0:d05a7158dbad 522 mdm2_outs=dm2_outs;
Oleg_B 0:d05a7158dbad 523 mdm3_outs=dm3_outs;
Oleg_B 0:d05a7158dbad 524 mdm4_outs=dm4_outs;
Oleg_B 0:d05a7158dbad 525
Oleg_B 0:d05a7158dbad 526
Oleg_B 0:d05a7158dbad 527
Oleg_B 0:d05a7158dbad 528 }
Oleg_B 0:d05a7158dbad 529
Oleg_B 0:d05a7158dbad 530 //----------------------------------------
Oleg_B 0:d05a7158dbad 531 // изменение значения секундных и милисекундных таймеров
Oleg_B 0:d05a7158dbad 532 // (дискретность 10 мсек)
Oleg_B 0:d05a7158dbad 533 void timers(){
Oleg_B 0:d05a7158dbad 534
Oleg_B 0:d05a7158dbad 535 int i = 10 ; // время цикла в 10мсек
Oleg_B 0:d05a7158dbad 536 int max1=30000; // макс. значение для мсек таймеров (30мин)
Oleg_B 0:d05a7158dbad 537 int max2=18000; // макс. значение для сек таймеров (5час)
Oleg_B 0:d05a7158dbad 538
Oleg_B 0:d05a7158dbad 539 // timers, 10ms
Oleg_B 0:d05a7158dbad 540 if(t_sys<1000){
Oleg_B 0:d05a7158dbad 541 t_sys=t_sys+i;
Oleg_B 0:d05a7158dbad 542 }else{
Oleg_B 0:d05a7158dbad 543 t_sys = 0;
Oleg_B 0:d05a7158dbad 544 if(t101<max2){t101=t101+1;}
Oleg_B 0:d05a7158dbad 545 if(t102<max2){t102=t102+1;}
Oleg_B 0:d05a7158dbad 546 if(t103<max2){t103=t103+1;}
Oleg_B 0:d05a7158dbad 547 if(t104<max2){t104=t104+1;}
Oleg_B 0:d05a7158dbad 548 if(t105<max2){t105=t105+1;}
Oleg_B 0:d05a7158dbad 549 if(t106<max2){t106=t106+1;}
Oleg_B 0:d05a7158dbad 550 if(t107<max2){t107=t107+1;}
Oleg_B 0:d05a7158dbad 551 if(t108<max2){t108=t108+1;}
Oleg_B 0:d05a7158dbad 552 if(t109<max2){t109=t109+1;}
Oleg_B 0:d05a7158dbad 553 if(t110<max2){t110=t110+1;}
Oleg_B 0:d05a7158dbad 554 }
Oleg_B 0:d05a7158dbad 555
Oleg_B 0:d05a7158dbad 556 if(t01<max1){t01=t01+i;}
Oleg_B 0:d05a7158dbad 557 if(t02<max1){t02=t02+i;}
Oleg_B 0:d05a7158dbad 558 if(t03<max1){t03=t03+i;}
Oleg_B 0:d05a7158dbad 559 if(t04<max1){t04=t04+i;}
Oleg_B 0:d05a7158dbad 560 if(t05<max1){t05=t05+i;}
Oleg_B 0:d05a7158dbad 561 if(t06<max1){t06=t06+i;}
Oleg_B 0:d05a7158dbad 562 if(t07<max1){t07=t07+i;}
Oleg_B 0:d05a7158dbad 563 if(t08<max1){t08=t08+i;}
Oleg_B 0:d05a7158dbad 564 if(t09<max1){t09=t09+i;}
Oleg_B 0:d05a7158dbad 565 if(t10<max1){t10=t10+i;}
Oleg_B 0:d05a7158dbad 566
Oleg_B 0:d05a7158dbad 567 }
Oleg_B 0:d05a7158dbad 568
Oleg_B 0:d05a7158dbad 569 //----------------------------------------
Oleg_B 0:d05a7158dbad 570 // прием и отправка посылок
Oleg_B 0:d05a7158dbad 571 // по CAN шине
Oleg_B 0:d05a7158dbad 572 void can_rw()
Oleg_B 0:d05a7158dbad 573 {
Oleg_B 0:d05a7158dbad 574 CANMessage msg_w;
Oleg_B 0:d05a7158dbad 575 CANMessage msg_r;
Oleg_B 0:d05a7158dbad 576
Oleg_B 0:d05a7158dbad 577 for(int i=0; i<=10; i++){ r_mess_id[i]=0; w_mess_id[i]=0; }
Oleg_B 0:d05a7158dbad 578 for(int i=0; i<=40; i++){ r_mess_data[i]=0; w_mess_data[i]=0; }
Oleg_B 0:d05a7158dbad 579
Oleg_B 0:d05a7158dbad 580
Oleg_B 0:d05a7158dbad 581 while (true){
Oleg_B 0:d05a7158dbad 582
Oleg_B 0:d05a7158dbad 583 // проверяем, если есть новая посылка
Oleg_B 0:d05a7158dbad 584 // то помещаем в очередь can_save_rd()
Oleg_B 0:d05a7158dbad 585 if(can.read(msg_r)){
Oleg_B 0:d05a7158dbad 586 int id = msg_r.id;
Oleg_B 0:d05a7158dbad 587 char b1 = msg_r.data[0];
Oleg_B 0:d05a7158dbad 588 char b2 = msg_r.data[1];
Oleg_B 0:d05a7158dbad 589 char b3 = msg_r.data[2];
Oleg_B 0:d05a7158dbad 590 char b4 = msg_r.data[3];
Oleg_B 0:d05a7158dbad 591 can_save_rd(id,b1,b2,b3,b4);
Oleg_B 0:d05a7158dbad 592 led_b = !led_b;
Oleg_B 0:d05a7158dbad 593 }
Oleg_B 0:d05a7158dbad 594
Oleg_B 0:d05a7158dbad 595
Oleg_B 0:d05a7158dbad 596 // проверяем очередь на отправку can_select_wr()
Oleg_B 0:d05a7158dbad 597 // и если есть , то отправляем
Oleg_B 0:d05a7158dbad 598 if(can_select_wr()){
Oleg_B 0:d05a7158dbad 599 msg_w.len = 4;
Oleg_B 0:d05a7158dbad 600 msg_w.id = w_id;
Oleg_B 0:d05a7158dbad 601 msg_w.data[0] = w_b1;
Oleg_B 0:d05a7158dbad 602 msg_w.data[1] = w_b2;
Oleg_B 0:d05a7158dbad 603 msg_w.data[2] = w_b3;
Oleg_B 0:d05a7158dbad 604 msg_w.data[3] = w_b4;
Oleg_B 0:d05a7158dbad 605 can.write(msg_w);
Oleg_B 0:d05a7158dbad 606
Oleg_B 0:d05a7158dbad 607 if(can.tderror()){ led_b = !led_b; w_alr=1; } else { w_alr=0; }
Oleg_B 0:d05a7158dbad 608
Oleg_B 0:d05a7158dbad 609 }
Oleg_B 0:d05a7158dbad 610
Oleg_B 0:d05a7158dbad 611
Oleg_B 0:d05a7158dbad 612 Thread::wait(2);
Oleg_B 0:d05a7158dbad 613 }
Oleg_B 0:d05a7158dbad 614
Oleg_B 0:d05a7158dbad 615 }
Oleg_B 0:d05a7158dbad 616
Oleg_B 0:d05a7158dbad 617 //----------------------------------------
Oleg_B 0:d05a7158dbad 618 // посимвольный прием из USB и сохранение
Oleg_B 0:d05a7158dbad 619 // информации в буфере, обрабатывается после того как все принято
Oleg_B 0:d05a7158dbad 620 void pc_rd()
Oleg_B 0:d05a7158dbad 621 {
Oleg_B 0:d05a7158dbad 622 sprintf(pc_buffer, "buff_ok");
Oleg_B 0:d05a7158dbad 623 while(1)
Oleg_B 0:d05a7158dbad 624 {
Oleg_B 0:d05a7158dbad 625 if( pc.readable() )
Oleg_B 0:d05a7158dbad 626 {
Oleg_B 0:d05a7158dbad 627 pc_buffer[pc_i] = pc.getc();
Oleg_B 0:d05a7158dbad 628 if(pc_i<MAX_SERL){pc_i++; }
Oleg_B 0:d05a7158dbad 629 pc_buffer[pc_i]=0;
Oleg_B 0:d05a7158dbad 630 }
Oleg_B 0:d05a7158dbad 631 }
Oleg_B 0:d05a7158dbad 632 }
Oleg_B 0:d05a7158dbad 633
Oleg_B 0:d05a7158dbad 634 //----------------------------------------
Oleg_B 0:d05a7158dbad 635 // поиск и чтение значения из строки
Oleg_B 0:d05a7158dbad 636 // возвращает целое число.
Oleg_B 0:d05a7158dbad 637 int read_val() {
Oleg_B 0:d05a7158dbad 638 char inp_c[10];
Oleg_B 0:d05a7158dbad 639 int val=0;
Oleg_B 0:d05a7158dbad 640 int i=0;
Oleg_B 0:d05a7158dbad 641 int p=0;
Oleg_B 0:d05a7158dbad 642
Oleg_B 0:d05a7158dbad 643 while(p<MAX_SERL){
Oleg_B 0:d05a7158dbad 644 if(pc_buffer[p]=='='){ break ; }
Oleg_B 0:d05a7158dbad 645 p++;
Oleg_B 0:d05a7158dbad 646 }
Oleg_B 0:d05a7158dbad 647
Oleg_B 0:d05a7158dbad 648 p++;
Oleg_B 0:d05a7158dbad 649 i=0; if(pc_buffer[p+i]>=48 && pc_buffer[p+i]<=57){ inp_c[i]=pc_buffer[p+i]; } else {inp_c[i]=0 ; }
Oleg_B 0:d05a7158dbad 650 i=1; if(pc_buffer[p+i]>=48 && pc_buffer[p+i]<=57){ inp_c[i]=pc_buffer[p+i]; } else {inp_c[i]=0 ; }
Oleg_B 0:d05a7158dbad 651 i=2; if(pc_buffer[p+i]>=48 && pc_buffer[p+i]<=57){ inp_c[i]=pc_buffer[p+i]; } else {inp_c[i]=0 ; }
Oleg_B 0:d05a7158dbad 652 i=3; if(pc_buffer[p+i]>=48 && pc_buffer[p+i]<=57){ inp_c[i]=pc_buffer[p+i]; } else {inp_c[i]=0 ; }
Oleg_B 0:d05a7158dbad 653 i=4; if(pc_buffer[p+i]>=48 && pc_buffer[p+i]<=57){ inp_c[i]=pc_buffer[p+i]; } else {inp_c[i]=0 ; }
Oleg_B 0:d05a7158dbad 654 i=5; if(pc_buffer[p+i]>=48 && pc_buffer[p+i]<=57){ inp_c[i]=pc_buffer[p+i]; } else {inp_c[i]=0 ; }
Oleg_B 0:d05a7158dbad 655 inp_c[6]=0 ;
Oleg_B 0:d05a7158dbad 656
Oleg_B 0:d05a7158dbad 657 val = atoi(inp_c);
Oleg_B 0:d05a7158dbad 658 return val;
Oleg_B 0:d05a7158dbad 659 }
Oleg_B 0:d05a7158dbad 660
Oleg_B 0:d05a7158dbad 661
Oleg_B 0:d05a7158dbad 662
Oleg_B 0:d05a7158dbad 663
Oleg_B 0:d05a7158dbad 664
Oleg_B 0:d05a7158dbad 665
Oleg_B 0:d05a7158dbad 666
Oleg_B 0:d05a7158dbad 667
Oleg_B 0:d05a7158dbad 668
Oleg_B 0:d05a7158dbad 669
Oleg_B 0:d05a7158dbad 670
Oleg_B 0:d05a7158dbad 671
Oleg_B 0:d05a7158dbad 672
Oleg_B 0:d05a7158dbad 673