vytah okomentovany
Fork of f by
main.cpp@1:d7c31658c3dd, 2017-12-23 (annotated)
- Committer:
- radovan
- Date:
- Sat Dec 23 19:15:49 2017 +0000
- Revision:
- 1:d7c31658c3dd
- Parent:
- 0:7a5957039c5f
posledny-okomentovany
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
radovan | 0:7a5957039c5f | 1 | #include "mbed.h" |
radovan | 0:7a5957039c5f | 2 | #include "MMA8451Q.h" |
radovan | 1:d7c31658c3dd | 3 | //#include "main.h" |
radovan | 0:7a5957039c5f | 4 | |
radovan | 0:7a5957039c5f | 5 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
radovan | 0:7a5957039c5f | 6 | PinName const SDA = PTE25; |
radovan | 0:7a5957039c5f | 7 | PinName const SCL = PTE24; |
radovan | 0:7a5957039c5f | 8 | #elif defined (TARGET_KL05Z) |
radovan | 0:7a5957039c5f | 9 | PinName const SDA = PTB4; |
radovan | 0:7a5957039c5f | 10 | PinName const SCL = PTB3; |
radovan | 0:7a5957039c5f | 11 | #elif defined (TARGET_K20D50M) |
radovan | 0:7a5957039c5f | 12 | PinName const SDA = PTB1; |
radovan | 0:7a5957039c5f | 13 | PinName const SCL = PTB0; |
radovan | 0:7a5957039c5f | 14 | #else |
radovan | 0:7a5957039c5f | 15 | #error TARGET NOT DEFINED |
radovan | 0:7a5957039c5f | 16 | #endif |
radovan | 0:7a5957039c5f | 17 | |
radovan | 0:7a5957039c5f | 18 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
radovan | 1:d7c31658c3dd | 19 | |
radovan | 0:7a5957039c5f | 20 | #define ELEVATOR_BUTTONf_FAMILY 0xc0 |
radovan | 0:7a5957039c5f | 21 | #define DIODEf_FAMILY 0x10 |
radovan | 0:7a5957039c5f | 22 | #define LIMIT_SWITCH_FAMILY 0xe0 |
radovan | 0:7a5957039c5f | 23 | #define ELEVATOR_BUTTONc_FAMILY 0xb0 |
radovan | 0:7a5957039c5f | 24 | #define DIODEc_FAMILY 0x20 |
radovan | 0:7a5957039c5f | 25 | |
radovan | 0:7a5957039c5f | 26 | #define ELEVATOR_CABIN 0xf0 |
radovan | 0:7a5957039c5f | 27 | #define MOTOR 0xf1 |
radovan | 0:7a5957039c5f | 28 | #define WATCHDOG_TIMER 0xfe |
radovan | 0:7a5957039c5f | 29 | |
radovan | 0:7a5957039c5f | 30 | #define INFORMATION_DISPLAY 0x30 |
radovan | 0:7a5957039c5f | 31 | //crc pri mojej adrese 0xAA |
radovan | 0:7a5957039c5f | 32 | #define CRC_LEDc2OFF 0xd2 |
radovan | 0:7a5957039c5f | 33 | #define CRC_LEDc2ON 0x8c |
radovan | 0:7a5957039c5f | 34 | #define CRC_LEDc3OFF 0x79 |
radovan | 0:7a5957039c5f | 35 | #define CRC_LEDc3ON 0x27 |
radovan | 0:7a5957039c5f | 36 | #define CRC_LEDc1OFF 0x36 |
radovan | 0:7a5957039c5f | 37 | #define CRC_LEDc1ON 0x68 |
radovan | 0:7a5957039c5f | 38 | #define CRC_LEDc0OFF 0x9d |
radovan | 0:7a5957039c5f | 39 | #define CRC_LEDc0ON 0xc3 |
radovan | 0:7a5957039c5f | 40 | #define CRC_LEDc4OFF 0x03 |
radovan | 0:7a5957039c5f | 41 | #define CRC_LEDc4ON 0x5d |
radovan | 0:7a5957039c5f | 42 | |
radovan | 0:7a5957039c5f | 43 | #define CRC_ELElock 0xda |
radovan | 0:7a5957039c5f | 44 | #define CRC_ELEunlock 0x84 |
radovan | 0:7a5957039c5f | 45 | |
radovan | 0:7a5957039c5f | 46 | #define CRC_MOTORdown 0xfc |
radovan | 0:7a5957039c5f | 47 | #define CRC_MOTORstop 0x71 |
radovan | 0:7a5957039c5f | 48 | #define CRC_MOTORup 0xf7 |
radovan | 0:7a5957039c5f | 49 | |
radovan | 0:7a5957039c5f | 50 | #define CRC_INFDd4 0x9a |
radovan | 0:7a5957039c5f | 51 | #define CRC_INFDd3 0x19 |
radovan | 0:7a5957039c5f | 52 | #define CRC_INFDd2 0x47 |
radovan | 0:7a5957039c5f | 53 | #define CRC_INFDd1 0xa5 |
radovan | 0:7a5957039c5f | 54 | |
radovan | 0:7a5957039c5f | 55 | #define CRC_INFDn3 0xdd |
radovan | 0:7a5957039c5f | 56 | #define CRC_INFDn4 0x5e |
radovan | 0:7a5957039c5f | 57 | #define CRC_INFDn2 0x83 |
radovan | 0:7a5957039c5f | 58 | #define CRC_INFDn1 0x61 |
radovan | 0:7a5957039c5f | 59 | #define CRC_INFDn0 0x5a |
radovan | 0:7a5957039c5f | 60 | |
radovan | 0:7a5957039c5f | 61 | #define CRC_INFDu0 0xcb |
radovan | 0:7a5957039c5f | 62 | #define CRC_INFDu1 0xf0 |
radovan | 0:7a5957039c5f | 63 | #define CRC_INFDu2 0x12 |
radovan | 0:7a5957039c5f | 64 | #define CRC_INFDu3 0x4c |
radovan | 0:7a5957039c5f | 65 | |
radovan | 0:7a5957039c5f | 66 | #define CRC_LEDf3OFF 0xa7 |
radovan | 0:7a5957039c5f | 67 | #define CRC_LEDf3ON 0xf9 |
radovan | 0:7a5957039c5f | 68 | #define CRC_LEDf4OFF 0xdd |
radovan | 0:7a5957039c5f | 69 | #define CRC_LEDf4ON 0x83 |
radovan | 0:7a5957039c5f | 70 | #define CRC_LEDf2OFF 0x0c |
radovan | 0:7a5957039c5f | 71 | #define CRC_LEDf2ON 0x52 |
radovan | 0:7a5957039c5f | 72 | #define CRC_LEDf1OFF 0xe8 |
radovan | 0:7a5957039c5f | 73 | #define CRC_LEDf1ON 0xb6 |
radovan | 0:7a5957039c5f | 74 | #define CRC_LEDf0OFF 0x43 |
radovan | 0:7a5957039c5f | 75 | #define CRC_LEDf0ON 0x1d |
radovan | 0:7a5957039c5f | 76 | |
radovan | 0:7a5957039c5f | 77 | #define CRC_WATCHDOG 0x4f |
radovan | 0:7a5957039c5f | 78 | |
radovan | 0:7a5957039c5f | 79 | InterruptIn intin(PTA15); |
radovan | 0:7a5957039c5f | 80 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
radovan | 0:7a5957039c5f | 81 | Serial pc(USBTX, USBRX,57600); |
radovan | 0:7a5957039c5f | 82 | char odpovedzac[4]; |
radovan | 0:7a5957039c5f | 83 | char poziadavky[5]= {'N','N','N','N','N'}; |
radovan | 0:7a5957039c5f | 84 | char poziciaVytahu=0x04; |
radovan | 0:7a5957039c5f | 85 | char bufpole[200]; |
radovan | 0:7a5957039c5f | 86 | int zb=0; |
radovan | 0:7a5957039c5f | 87 | int kb=0; |
radovan | 0:7a5957039c5f | 88 | char smerPohybu=0x03; |
radovan | 0:7a5957039c5f | 89 | char aktualnePoschodie='4'; |
radovan | 0:7a5957039c5f | 90 | unsigned char spravaVS[10]; |
radovan | 0:7a5957039c5f | 91 | |
radovan | 0:7a5957039c5f | 92 | void posli(int pokial); |
radovan | 0:7a5957039c5f | 93 | void watchdogReset(); |
radovan | 0:7a5957039c5f | 94 | /** |
radovan | 0:7a5957039c5f | 95 | *void citaj() |
radovan | 0:7a5957039c5f | 96 | *funkcia volana pri vzniknuti prerusenia pre citanie od serioveho portu |
radovan | 0:7a5957039c5f | 97 | *do kruhoveho buffera "bufpole" nacita 1 znak. |
radovan | 0:7a5957039c5f | 98 | */ |
radovan | 0:7a5957039c5f | 99 | void citaj() |
radovan | 0:7a5957039c5f | 100 | { |
radovan | 0:7a5957039c5f | 101 | while(pc.readable()==1) { |
radovan | 0:7a5957039c5f | 102 | bufpole[kb]=pc.getc(); |
radovan | 0:7a5957039c5f | 103 | kb=(kb+1)%200; |
radovan | 0:7a5957039c5f | 104 | } |
radovan | 0:7a5957039c5f | 105 | } |
radovan | 1:d7c31658c3dd | 106 | /** void prerusenieACC() |
radovan | 0:7a5957039c5f | 107 | *funkcia volana pri vzniknuti prerusenia od accelerometra |
radovan | 0:7a5957039c5f | 108 | *posle simulatoru spravu pre zastavenie vytahu |
radovan | 0:7a5957039c5f | 109 | */ |
radovan | 0:7a5957039c5f | 110 | void prerusenieACC() |
radovan | 0:7a5957039c5f | 111 | { |
radovan | 0:7a5957039c5f | 112 | uint8_t datan[1]; |
radovan | 0:7a5957039c5f | 113 | acc.readRegs(0x0C,datan,1); |
radovan | 0:7a5957039c5f | 114 | |
radovan | 0:7a5957039c5f | 115 | if((datan[0]&0x04)==0x04) { |
radovan | 0:7a5957039c5f | 116 | acc.readRegs(0x16,datan,1); |
radovan | 0:7a5957039c5f | 117 | char breakOn[6]= {0xA0,0xf,0xAA,0x01,0x01,0x08}; |
radovan | 0:7a5957039c5f | 118 | //poslem spravu |
radovan | 0:7a5957039c5f | 119 | for(int ind=0; ind<6; ind++) { |
radovan | 0:7a5957039c5f | 120 | while(pc.writable()==0) {} |
radovan | 0:7a5957039c5f | 121 | pc.putc(breakOn[ind]); |
radovan | 0:7a5957039c5f | 122 | } |
radovan | 0:7a5957039c5f | 123 | |
radovan | 0:7a5957039c5f | 124 | } |
radovan | 0:7a5957039c5f | 125 | } |
radovan | 1:d7c31658c3dd | 126 | /** void main() |
radovan | 0:7a5957039c5f | 127 | *nastavuje akcelerometer pre vytvaranie prerusenia pre freefall |
radovan | 0:7a5957039c5f | 128 | *spracovava v nekonecnej slucke spravy z kruhoveho buffera |
radovan | 0:7a5957039c5f | 129 | *v pravidelnych intervaloch resetuje watchdog |
radovan | 0:7a5957039c5f | 130 | */ |
radovan | 0:7a5957039c5f | 131 | int main() |
radovan | 0:7a5957039c5f | 132 | { |
radovan | 0:7a5957039c5f | 133 | spravaVS[0]=0xA0;//zaciatok |
radovan | 0:7a5957039c5f | 134 | spravaVS[2]=0xAA;//ja |
radovan | 0:7a5957039c5f | 135 | |
radovan | 0:7a5957039c5f | 136 | Timer timerReset; |
radovan | 0:7a5957039c5f | 137 | |
radovan | 0:7a5957039c5f | 138 | pc.attach(&citaj,pc.RxIrq); |
radovan | 0:7a5957039c5f | 139 | timerReset.start(); |
radovan | 0:7a5957039c5f | 140 | intin.fall(&prerusenieACC); |
radovan | 0:7a5957039c5f | 141 | |
radovan | 0:7a5957039c5f | 142 | uint8_t pomPole[2] = {0x2A, 0x20}; |
radovan | 0:7a5957039c5f | 143 | acc.writeRegs(pomPole, 2); |
radovan | 0:7a5957039c5f | 144 | |
radovan | 0:7a5957039c5f | 145 | pomPole[0]=0x15; |
radovan | 0:7a5957039c5f | 146 | pomPole[1]=0xB8; |
radovan | 0:7a5957039c5f | 147 | acc.writeRegs(pomPole,2); |
radovan | 0:7a5957039c5f | 148 | |
radovan | 0:7a5957039c5f | 149 | pomPole[0]=0x17; |
radovan | 0:7a5957039c5f | 150 | pomPole[1]=0x03; |
radovan | 0:7a5957039c5f | 151 | acc.writeRegs(pomPole,2); |
radovan | 0:7a5957039c5f | 152 | |
radovan | 0:7a5957039c5f | 153 | pomPole[0]=0x18; |
radovan | 0:7a5957039c5f | 154 | pomPole[1]=0x06; |
radovan | 0:7a5957039c5f | 155 | acc.writeRegs(pomPole,2); |
radovan | 0:7a5957039c5f | 156 | |
radovan | 0:7a5957039c5f | 157 | pomPole[0]=0x2D; |
radovan | 0:7a5957039c5f | 158 | pomPole[1]=0x04; |
radovan | 0:7a5957039c5f | 159 | acc.writeRegs(pomPole,2); |
radovan | 0:7a5957039c5f | 160 | |
radovan | 0:7a5957039c5f | 161 | pomPole[0]=0x2E; |
radovan | 0:7a5957039c5f | 162 | pomPole[1]=0x00; |
radovan | 0:7a5957039c5f | 163 | acc.writeRegs(pomPole,2); |
radovan | 0:7a5957039c5f | 164 | |
radovan | 0:7a5957039c5f | 165 | uint8_t data[1]; |
radovan | 0:7a5957039c5f | 166 | acc.readRegs(0x2A,data,1); |
radovan | 0:7a5957039c5f | 167 | data[0]=data[0]| 0x01; |
radovan | 0:7a5957039c5f | 168 | |
radovan | 0:7a5957039c5f | 169 | pomPole[0]=0x2A; |
radovan | 0:7a5957039c5f | 170 | pomPole[1]=data[0]; |
radovan | 0:7a5957039c5f | 171 | acc.writeRegs(pomPole,2); |
radovan | 0:7a5957039c5f | 172 | |
radovan | 0:7a5957039c5f | 173 | watchdogReset(); |
radovan | 0:7a5957039c5f | 174 | int cas=timerReset.read_ms(); |
radovan | 0:7a5957039c5f | 175 | while(true) { |
radovan | 0:7a5957039c5f | 176 | |
radovan | 0:7a5957039c5f | 177 | int pocetdat=0; |
radovan | 0:7a5957039c5f | 178 | if(zb<=kb) { |
radovan | 0:7a5957039c5f | 179 | pocetdat=kb-zb; |
radovan | 0:7a5957039c5f | 180 | } else { |
radovan | 0:7a5957039c5f | 181 | pocetdat=(199-zb)+1+kb; |
radovan | 0:7a5957039c5f | 182 | } |
radovan | 0:7a5957039c5f | 183 | |
radovan | 0:7a5957039c5f | 184 | if(pocetdat>4&&pocetdat>=4+bufpole[zb+3]+1) {//spracuvavam spravu |
radovan | 0:7a5957039c5f | 185 | odpovedzac[0]=bufpole[zb]; |
radovan | 0:7a5957039c5f | 186 | zb=(zb+1)%200; |
radovan | 0:7a5957039c5f | 187 | |
radovan | 0:7a5957039c5f | 188 | odpovedzac[1]=bufpole[zb]; |
radovan | 0:7a5957039c5f | 189 | zb=(zb+1)%200; |
radovan | 0:7a5957039c5f | 190 | |
radovan | 0:7a5957039c5f | 191 | odpovedzac[2]=bufpole[zb]; |
radovan | 0:7a5957039c5f | 192 | zb=(zb+1)%200; |
radovan | 0:7a5957039c5f | 193 | |
radovan | 0:7a5957039c5f | 194 | odpovedzac[3]=bufpole[zb]; |
radovan | 0:7a5957039c5f | 195 | |
radovan | 0:7a5957039c5f | 196 | int v=odpovedzac[3]+1; |
radovan | 0:7a5957039c5f | 197 | char data; |
radovan | 0:7a5957039c5f | 198 | for(int ind=0; ind<v; ind++) { |
radovan | 0:7a5957039c5f | 199 | zb=(zb+1)%200; |
radovan | 0:7a5957039c5f | 200 | if(ind==0) { |
radovan | 0:7a5957039c5f | 201 | data= bufpole[zb]; |
radovan | 0:7a5957039c5f | 202 | } |
radovan | 0:7a5957039c5f | 203 | } |
radovan | 0:7a5957039c5f | 204 | zb=(zb+1)%200; |
radovan | 0:7a5957039c5f | 205 | |
radovan | 0:7a5957039c5f | 206 | char rodina=(odpovedzac[2]&0xf0); |
radovan | 0:7a5957039c5f | 207 | char jedinec=(odpovedzac[2]&0x0f); |
radovan | 0:7a5957039c5f | 208 | watchdogReset(); |
radovan | 0:7a5957039c5f | 209 | |
radovan | 0:7a5957039c5f | 210 | if(rodina==ELEVATOR_BUTTONf_FAMILY) { |
radovan | 0:7a5957039c5f | 211 | |
radovan | 0:7a5957039c5f | 212 | if(poziadavky[0]=='N'&&jedinec!=poziciaVytahu) { |
radovan | 0:7a5957039c5f | 213 | |
radovan | 0:7a5957039c5f | 214 | poziadavky[0]=jedinec;//ulozim na ktore poschodie ma vytah ist |
radovan | 0:7a5957039c5f | 215 | //svietim diodu na poschodi |
radovan | 0:7a5957039c5f | 216 | spravaVS[1]=DIODEf_FAMILY|jedinec;//prijimatel |
radovan | 0:7a5957039c5f | 217 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 218 | spravaVS[4]=0x01;//data |
radovan | 0:7a5957039c5f | 219 | |
radovan | 0:7a5957039c5f | 220 | if(jedinec==0x04) { |
radovan | 0:7a5957039c5f | 221 | spravaVS[5]=CRC_LEDf4ON; |
radovan | 0:7a5957039c5f | 222 | } else if(jedinec==0x03) { |
radovan | 0:7a5957039c5f | 223 | spravaVS[5]=CRC_LEDf3ON; |
radovan | 0:7a5957039c5f | 224 | } else if(jedinec==0x02) { |
radovan | 0:7a5957039c5f | 225 | spravaVS[5]=CRC_LEDf2ON; |
radovan | 0:7a5957039c5f | 226 | } else if(jedinec==0x01) { |
radovan | 0:7a5957039c5f | 227 | spravaVS[5]=CRC_LEDf1ON; |
radovan | 0:7a5957039c5f | 228 | } else { |
radovan | 0:7a5957039c5f | 229 | spravaVS[5]=CRC_LEDf0ON; |
radovan | 0:7a5957039c5f | 230 | } |
radovan | 0:7a5957039c5f | 231 | posli(6); |
radovan | 0:7a5957039c5f | 232 | |
radovan | 0:7a5957039c5f | 233 | //zamykam vytah |
radovan | 0:7a5957039c5f | 234 | spravaVS[1]=ELEVATOR_CABIN;//prijimatel |
radovan | 0:7a5957039c5f | 235 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 236 | spravaVS[4]=0x01;//data |
radovan | 0:7a5957039c5f | 237 | spravaVS[5]=CRC_ELElock; |
radovan | 0:7a5957039c5f | 238 | posli(6); |
radovan | 0:7a5957039c5f | 239 | |
radovan | 0:7a5957039c5f | 240 | //uved motor do pohybu |
radovan | 0:7a5957039c5f | 241 | spravaVS[1]=MOTOR;//prijimatel |
radovan | 0:7a5957039c5f | 242 | spravaVS[3]=5;//pocet dat |
radovan | 0:7a5957039c5f | 243 | spravaVS[4]=0x2;//pohni vytah |
radovan | 0:7a5957039c5f | 244 | |
radovan | 0:7a5957039c5f | 245 | if(poziadavky[0]>poziciaVytahu) { |
radovan | 0:7a5957039c5f | 246 | smerPohybu=0x01; |
radovan | 0:7a5957039c5f | 247 | spravaVS[5]=0x64; |
radovan | 0:7a5957039c5f | 248 | spravaVS[6]=0x00; |
radovan | 0:7a5957039c5f | 249 | spravaVS[7]=0x00; |
radovan | 0:7a5957039c5f | 250 | spravaVS[8]=0x00; |
radovan | 0:7a5957039c5f | 251 | spravaVS[9]=CRC_MOTORup; |
radovan | 0:7a5957039c5f | 252 | } else { |
radovan | 0:7a5957039c5f | 253 | smerPohybu=0x02; |
radovan | 0:7a5957039c5f | 254 | spravaVS[5]=0x9C; |
radovan | 0:7a5957039c5f | 255 | spravaVS[6]=0xFF; |
radovan | 0:7a5957039c5f | 256 | spravaVS[7]=0xFF; |
radovan | 0:7a5957039c5f | 257 | spravaVS[8]=0xFF; |
radovan | 0:7a5957039c5f | 258 | spravaVS[9]=CRC_MOTORdown; |
radovan | 0:7a5957039c5f | 259 | } |
radovan | 0:7a5957039c5f | 260 | posli(10); |
radovan | 0:7a5957039c5f | 261 | |
radovan | 0:7a5957039c5f | 262 | //zobrazenie pohybu |
radovan | 0:7a5957039c5f | 263 | spravaVS[1]=INFORMATION_DISPLAY;//prijimatel |
radovan | 0:7a5957039c5f | 264 | spravaVS[3]=2;//pocet dat |
radovan | 0:7a5957039c5f | 265 | spravaVS[4]=smerPohybu;//data |
radovan | 0:7a5957039c5f | 266 | spravaVS[5]=aktualnePoschodie;//data |
radovan | 0:7a5957039c5f | 267 | |
radovan | 0:7a5957039c5f | 268 | if(smerPohybu==0x02) { //smer pohybu dole |
radovan | 0:7a5957039c5f | 269 | if(aktualnePoschodie=='4') { |
radovan | 0:7a5957039c5f | 270 | spravaVS[6]=CRC_INFDd4; |
radovan | 0:7a5957039c5f | 271 | } else if(aktualnePoschodie=='3') { |
radovan | 0:7a5957039c5f | 272 | spravaVS[6]=CRC_INFDd3; |
radovan | 0:7a5957039c5f | 273 | } else if(aktualnePoschodie=='2') { |
radovan | 0:7a5957039c5f | 274 | spravaVS[6]=CRC_INFDd2; |
radovan | 0:7a5957039c5f | 275 | } else { |
radovan | 0:7a5957039c5f | 276 | spravaVS[6]=CRC_INFDd1; |
radovan | 0:7a5957039c5f | 277 | } |
radovan | 0:7a5957039c5f | 278 | } else {//smer pohybu hore |
radovan | 0:7a5957039c5f | 279 | if(aktualnePoschodie=='3') { |
radovan | 0:7a5957039c5f | 280 | spravaVS[6]=CRC_INFDu3; |
radovan | 0:7a5957039c5f | 281 | } else if(aktualnePoschodie=='2') { |
radovan | 0:7a5957039c5f | 282 | spravaVS[6]=CRC_INFDu2; |
radovan | 0:7a5957039c5f | 283 | } else if(aktualnePoschodie=='1') { |
radovan | 0:7a5957039c5f | 284 | spravaVS[6]=CRC_INFDu1; |
radovan | 0:7a5957039c5f | 285 | } else { |
radovan | 0:7a5957039c5f | 286 | spravaVS[6]=CRC_INFDu0; |
radovan | 0:7a5957039c5f | 287 | } |
radovan | 0:7a5957039c5f | 288 | } |
radovan | 0:7a5957039c5f | 289 | posli(7); |
radovan | 0:7a5957039c5f | 290 | |
radovan | 0:7a5957039c5f | 291 | }//if poziadavky[0]=='N'&&poziadavky[0]!=poziciaVytahu |
radovan | 0:7a5957039c5f | 292 | |
radovan | 0:7a5957039c5f | 293 | } else if(rodina==ELEVATOR_BUTTONc_FAMILY) { |
radovan | 0:7a5957039c5f | 294 | |
radovan | 0:7a5957039c5f | 295 | //ak bolo stlacene tlacidlo na inom poschodi ako akualnom a tato poziadavka este nie je v poli |
radovan | 0:7a5957039c5f | 296 | if(poziciaVytahu!=jedinec) { |
radovan | 0:7a5957039c5f | 297 | char pom=0x00; |
radovan | 0:7a5957039c5f | 298 | char pohni=0x00; |
radovan | 0:7a5957039c5f | 299 | for(int i=0; i<5; i++) { |
radovan | 0:7a5957039c5f | 300 | if(poziadavky[i]==jedinec) { |
radovan | 0:7a5957039c5f | 301 | pom=0x01; |
radovan | 0:7a5957039c5f | 302 | } |
radovan | 0:7a5957039c5f | 303 | if(poziadavky[i]=='N'&&pom==0x00) { |
radovan | 0:7a5957039c5f | 304 | poziadavky[i]=jedinec; |
radovan | 0:7a5957039c5f | 305 | pom=0x02; |
radovan | 0:7a5957039c5f | 306 | if(i==0) { |
radovan | 0:7a5957039c5f | 307 | pohni=0x03; |
radovan | 0:7a5957039c5f | 308 | } |
radovan | 0:7a5957039c5f | 309 | break; |
radovan | 0:7a5957039c5f | 310 | } |
radovan | 0:7a5957039c5f | 311 | } |
radovan | 0:7a5957039c5f | 312 | if(pom==0x02) { |
radovan | 0:7a5957039c5f | 313 | //zasvieti diodu vnutri vytahu |
radovan | 0:7a5957039c5f | 314 | spravaVS[1]=DIODEc_FAMILY|jedinec;//prijimatel |
radovan | 0:7a5957039c5f | 315 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 316 | spravaVS[4]=0x01;//data |
radovan | 0:7a5957039c5f | 317 | |
radovan | 0:7a5957039c5f | 318 | if(jedinec==0x04) { |
radovan | 0:7a5957039c5f | 319 | spravaVS[5]=CRC_LEDc4ON; |
radovan | 0:7a5957039c5f | 320 | } else if(jedinec==0x03) { |
radovan | 0:7a5957039c5f | 321 | spravaVS[5]=CRC_LEDc3ON; |
radovan | 0:7a5957039c5f | 322 | } else if(jedinec==0x02) { |
radovan | 0:7a5957039c5f | 323 | spravaVS[5]=CRC_LEDc2ON; |
radovan | 0:7a5957039c5f | 324 | } else if(jedinec==0x01) { |
radovan | 0:7a5957039c5f | 325 | spravaVS[5]=CRC_LEDc1ON; |
radovan | 0:7a5957039c5f | 326 | } else { |
radovan | 0:7a5957039c5f | 327 | spravaVS[5]=CRC_LEDc0ON; |
radovan | 0:7a5957039c5f | 328 | } |
radovan | 0:7a5957039c5f | 329 | posli(6); |
radovan | 0:7a5957039c5f | 330 | |
radovan | 0:7a5957039c5f | 331 | } |
radovan | 0:7a5957039c5f | 332 | |
radovan | 0:7a5957039c5f | 333 | if(pohni==0x03) { |
radovan | 0:7a5957039c5f | 334 | //uzamknutie vytahu |
radovan | 0:7a5957039c5f | 335 | spravaVS[1]=ELEVATOR_CABIN;//prijimatel |
radovan | 0:7a5957039c5f | 336 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 337 | spravaVS[4]=0x01;//data |
radovan | 0:7a5957039c5f | 338 | spravaVS[5]=CRC_ELElock; |
radovan | 0:7a5957039c5f | 339 | posli(6); |
radovan | 0:7a5957039c5f | 340 | |
radovan | 0:7a5957039c5f | 341 | //uved motor do pohybu |
radovan | 0:7a5957039c5f | 342 | spravaVS[1]=MOTOR;//prijimatel |
radovan | 0:7a5957039c5f | 343 | spravaVS[3]=5;//pocet dat |
radovan | 0:7a5957039c5f | 344 | spravaVS[4]=0x2;//data |
radovan | 0:7a5957039c5f | 345 | |
radovan | 0:7a5957039c5f | 346 | if(poziadavky[0]>poziciaVytahu) { |
radovan | 0:7a5957039c5f | 347 | smerPohybu=0x01; |
radovan | 0:7a5957039c5f | 348 | spravaVS[5]=0x64; |
radovan | 0:7a5957039c5f | 349 | spravaVS[6]=0x00; |
radovan | 0:7a5957039c5f | 350 | spravaVS[7]=0x00; |
radovan | 0:7a5957039c5f | 351 | spravaVS[8]=0x00; |
radovan | 0:7a5957039c5f | 352 | spravaVS[9]=CRC_MOTORup; |
radovan | 0:7a5957039c5f | 353 | |
radovan | 0:7a5957039c5f | 354 | } else { |
radovan | 0:7a5957039c5f | 355 | smerPohybu=0x02; |
radovan | 0:7a5957039c5f | 356 | spravaVS[5]=0x9C; |
radovan | 0:7a5957039c5f | 357 | spravaVS[6]=0xFF; |
radovan | 0:7a5957039c5f | 358 | spravaVS[7]=0xFF; |
radovan | 0:7a5957039c5f | 359 | spravaVS[8]=0xFF; |
radovan | 0:7a5957039c5f | 360 | spravaVS[9]=CRC_MOTORdown; |
radovan | 0:7a5957039c5f | 361 | } |
radovan | 0:7a5957039c5f | 362 | posli(10); |
radovan | 0:7a5957039c5f | 363 | |
radovan | 0:7a5957039c5f | 364 | //zobrazenie pohybu |
radovan | 0:7a5957039c5f | 365 | spravaVS[1]=INFORMATION_DISPLAY;//prijimatel |
radovan | 0:7a5957039c5f | 366 | spravaVS[3]=2;//pocet dat |
radovan | 0:7a5957039c5f | 367 | spravaVS[4]=smerPohybu;//data |
radovan | 0:7a5957039c5f | 368 | spravaVS[5]=aktualnePoschodie;//data |
radovan | 0:7a5957039c5f | 369 | |
radovan | 0:7a5957039c5f | 370 | if(smerPohybu==0x02) { //smer pohybu dole |
radovan | 0:7a5957039c5f | 371 | if(aktualnePoschodie=='4') { |
radovan | 0:7a5957039c5f | 372 | spravaVS[6]=CRC_INFDd4; |
radovan | 0:7a5957039c5f | 373 | } else if(aktualnePoschodie=='3') { |
radovan | 0:7a5957039c5f | 374 | spravaVS[6]=CRC_INFDd3; |
radovan | 0:7a5957039c5f | 375 | } else if(aktualnePoschodie=='2') { |
radovan | 0:7a5957039c5f | 376 | spravaVS[6]=CRC_INFDd2; |
radovan | 0:7a5957039c5f | 377 | } else { |
radovan | 0:7a5957039c5f | 378 | spravaVS[6]=CRC_INFDd1; |
radovan | 0:7a5957039c5f | 379 | } |
radovan | 0:7a5957039c5f | 380 | } else {//smer pohybu hore |
radovan | 0:7a5957039c5f | 381 | if(aktualnePoschodie=='3') { |
radovan | 0:7a5957039c5f | 382 | spravaVS[6]=CRC_INFDu3; |
radovan | 0:7a5957039c5f | 383 | } else if(aktualnePoschodie=='2') { |
radovan | 0:7a5957039c5f | 384 | spravaVS[6]=CRC_INFDu2; |
radovan | 0:7a5957039c5f | 385 | } else if(aktualnePoschodie=='1') { |
radovan | 0:7a5957039c5f | 386 | spravaVS[6]=CRC_INFDu1; |
radovan | 0:7a5957039c5f | 387 | } else { |
radovan | 0:7a5957039c5f | 388 | spravaVS[6]=CRC_INFDu0; |
radovan | 0:7a5957039c5f | 389 | } |
radovan | 0:7a5957039c5f | 390 | } |
radovan | 0:7a5957039c5f | 391 | posli(7); |
radovan | 0:7a5957039c5f | 392 | } |
radovan | 0:7a5957039c5f | 393 | } |
radovan | 0:7a5957039c5f | 394 | |
radovan | 0:7a5957039c5f | 395 | } else if(rodina==LIMIT_SWITCH_FAMILY) { |
radovan | 0:7a5957039c5f | 396 | |
radovan | 0:7a5957039c5f | 397 | if(data==0x01&&poziadavky[0]==jedinec) { //dalej od switchu |
radovan | 0:7a5957039c5f | 398 | //zastavenie vytahu |
radovan | 0:7a5957039c5f | 399 | spravaVS[1]=MOTOR;//prijimatel |
radovan | 0:7a5957039c5f | 400 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 401 | spravaVS[4]=0x1;//data |
radovan | 0:7a5957039c5f | 402 | spravaVS[5]=CRC_MOTORstop; |
radovan | 0:7a5957039c5f | 403 | posli(6); |
radovan | 0:7a5957039c5f | 404 | |
radovan | 0:7a5957039c5f | 405 | } else if(data==0x02&&poziadavky[0]==jedinec) { //blizko pri switchi spravne poschodie |
radovan | 0:7a5957039c5f | 406 | //posunutie poziadaviek |
radovan | 0:7a5957039c5f | 407 | for(int i=0; i<4; i++) { |
radovan | 0:7a5957039c5f | 408 | poziadavky[i]=poziadavky[i+1]; |
radovan | 0:7a5957039c5f | 409 | } |
radovan | 0:7a5957039c5f | 410 | poziadavky[4]='N'; |
radovan | 0:7a5957039c5f | 411 | poziciaVytahu=jedinec; |
radovan | 0:7a5957039c5f | 412 | //odomknutie vytahu |
radovan | 0:7a5957039c5f | 413 | spravaVS[1]=ELEVATOR_CABIN;//prijimatel |
radovan | 0:7a5957039c5f | 414 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 415 | spravaVS[4]=0x00;//data |
radovan | 0:7a5957039c5f | 416 | spravaVS[5]=CRC_ELEunlock; |
radovan | 0:7a5957039c5f | 417 | posli(6); |
radovan | 0:7a5957039c5f | 418 | |
radovan | 0:7a5957039c5f | 419 | //zhasnutie diody na poschodi |
radovan | 0:7a5957039c5f | 420 | spravaVS[1]=DIODEf_FAMILY|jedinec;//prijimatel |
radovan | 0:7a5957039c5f | 421 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 422 | spravaVS[4]=0x00;//data |
radovan | 0:7a5957039c5f | 423 | |
radovan | 0:7a5957039c5f | 424 | if(jedinec==0x04) { |
radovan | 0:7a5957039c5f | 425 | spravaVS[5]=CRC_LEDf4OFF; |
radovan | 0:7a5957039c5f | 426 | } else if(jedinec==0x03) { |
radovan | 0:7a5957039c5f | 427 | spravaVS[5]=CRC_LEDf3OFF; |
radovan | 0:7a5957039c5f | 428 | } else if(jedinec==0x02) { |
radovan | 0:7a5957039c5f | 429 | spravaVS[5]=CRC_LEDf2OFF; |
radovan | 0:7a5957039c5f | 430 | } else if(jedinec==0x01) { |
radovan | 0:7a5957039c5f | 431 | spravaVS[5]=CRC_LEDf1OFF; |
radovan | 0:7a5957039c5f | 432 | } else { |
radovan | 0:7a5957039c5f | 433 | spravaVS[5]=CRC_LEDf0OFF; |
radovan | 0:7a5957039c5f | 434 | } |
radovan | 0:7a5957039c5f | 435 | |
radovan | 0:7a5957039c5f | 436 | posli(6); |
radovan | 0:7a5957039c5f | 437 | |
radovan | 0:7a5957039c5f | 438 | //zhasne diodu vnutri vytahu |
radovan | 0:7a5957039c5f | 439 | spravaVS[1]=DIODEc_FAMILY|jedinec;//prijimatel |
radovan | 0:7a5957039c5f | 440 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 441 | spravaVS[4]=0x00;//data |
radovan | 0:7a5957039c5f | 442 | |
radovan | 0:7a5957039c5f | 443 | if(jedinec==0x04) { |
radovan | 0:7a5957039c5f | 444 | spravaVS[5]=CRC_LEDc4OFF; |
radovan | 0:7a5957039c5f | 445 | aktualnePoschodie='4'; |
radovan | 0:7a5957039c5f | 446 | } else if(jedinec==0x03) { |
radovan | 0:7a5957039c5f | 447 | spravaVS[5]=CRC_LEDc3OFF; |
radovan | 0:7a5957039c5f | 448 | aktualnePoschodie='3'; |
radovan | 0:7a5957039c5f | 449 | } else if(jedinec==0x02) { |
radovan | 0:7a5957039c5f | 450 | spravaVS[5]=CRC_LEDc2OFF; |
radovan | 0:7a5957039c5f | 451 | aktualnePoschodie='2'; |
radovan | 0:7a5957039c5f | 452 | } else if(jedinec==0x01) { |
radovan | 0:7a5957039c5f | 453 | spravaVS[5]=CRC_LEDc1OFF; |
radovan | 0:7a5957039c5f | 454 | aktualnePoschodie='1'; |
radovan | 0:7a5957039c5f | 455 | } else { |
radovan | 0:7a5957039c5f | 456 | spravaVS[5]=CRC_LEDc0OFF; |
radovan | 0:7a5957039c5f | 457 | aktualnePoschodie='P'; |
radovan | 0:7a5957039c5f | 458 | } |
radovan | 0:7a5957039c5f | 459 | |
radovan | 0:7a5957039c5f | 460 | posli(6); |
radovan | 0:7a5957039c5f | 461 | |
radovan | 0:7a5957039c5f | 462 | smerPohybu=0x03; |
radovan | 0:7a5957039c5f | 463 | //zobrazenie pohybu |
radovan | 0:7a5957039c5f | 464 | spravaVS[1]=INFORMATION_DISPLAY;//prijimatel |
radovan | 0:7a5957039c5f | 465 | spravaVS[3]=2;//pocet dat |
radovan | 0:7a5957039c5f | 466 | spravaVS[4]=smerPohybu;//data |
radovan | 0:7a5957039c5f | 467 | spravaVS[5]=aktualnePoschodie;//data |
radovan | 0:7a5957039c5f | 468 | |
radovan | 0:7a5957039c5f | 469 | if(jedinec==0x04) { |
radovan | 0:7a5957039c5f | 470 | spravaVS[6]=CRC_INFDn4; |
radovan | 0:7a5957039c5f | 471 | } else if(jedinec==0x03) { |
radovan | 0:7a5957039c5f | 472 | spravaVS[6]=CRC_INFDn3; |
radovan | 0:7a5957039c5f | 473 | } else if(jedinec==0x02) { |
radovan | 0:7a5957039c5f | 474 | spravaVS[6]=CRC_INFDn2; |
radovan | 0:7a5957039c5f | 475 | } else if(jedinec==0x01) { |
radovan | 0:7a5957039c5f | 476 | spravaVS[6]=CRC_INFDn1; |
radovan | 0:7a5957039c5f | 477 | } else { |
radovan | 0:7a5957039c5f | 478 | spravaVS[6]=CRC_INFDn0; |
radovan | 0:7a5957039c5f | 479 | } |
radovan | 0:7a5957039c5f | 480 | posli(7); |
radovan | 0:7a5957039c5f | 481 | watchdogReset(); |
radovan | 0:7a5957039c5f | 482 | |
radovan | 0:7a5957039c5f | 483 | //cakam vzdy po zastaveni vytahu |
radovan | 0:7a5957039c5f | 484 | int zac; |
radovan | 0:7a5957039c5f | 485 | Timer cakaj; |
radovan | 0:7a5957039c5f | 486 | for(int t=0; t<=10; t++) { |
radovan | 0:7a5957039c5f | 487 | cakaj.start(); |
radovan | 0:7a5957039c5f | 488 | zac=cakaj.read_ms(); |
radovan | 0:7a5957039c5f | 489 | while(true) { |
radovan | 0:7a5957039c5f | 490 | if((cakaj.read_ms()-zac)>=500) { |
radovan | 0:7a5957039c5f | 491 | watchdogReset(); |
radovan | 0:7a5957039c5f | 492 | break; |
radovan | 0:7a5957039c5f | 493 | } |
radovan | 0:7a5957039c5f | 494 | } |
radovan | 0:7a5957039c5f | 495 | |
radovan | 0:7a5957039c5f | 496 | cakaj.stop(); |
radovan | 0:7a5957039c5f | 497 | cakaj.reset(); |
radovan | 0:7a5957039c5f | 498 | } |
radovan | 0:7a5957039c5f | 499 | |
radovan | 0:7a5957039c5f | 500 | if(poziadavky[0]!='N') { //ak este mam niekde ist tak spustim vytah |
radovan | 0:7a5957039c5f | 501 | |
radovan | 0:7a5957039c5f | 502 | //uzamknutie vytahu |
radovan | 0:7a5957039c5f | 503 | spravaVS[1]=ELEVATOR_CABIN;//prijimatel |
radovan | 0:7a5957039c5f | 504 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 505 | spravaVS[4]=0x01;//data |
radovan | 0:7a5957039c5f | 506 | spravaVS[5]=CRC_ELElock; |
radovan | 0:7a5957039c5f | 507 | posli(6); |
radovan | 0:7a5957039c5f | 508 | |
radovan | 0:7a5957039c5f | 509 | //uved motor do pohybu |
radovan | 0:7a5957039c5f | 510 | spravaVS[1]=MOTOR;//prijimatel |
radovan | 0:7a5957039c5f | 511 | spravaVS[3]=5;//pocet dat |
radovan | 0:7a5957039c5f | 512 | spravaVS[4]=0x2;//data |
radovan | 0:7a5957039c5f | 513 | |
radovan | 0:7a5957039c5f | 514 | if(poziadavky[0]>poziciaVytahu) { |
radovan | 0:7a5957039c5f | 515 | smerPohybu=0x01; |
radovan | 0:7a5957039c5f | 516 | spravaVS[5]=0x64; |
radovan | 0:7a5957039c5f | 517 | spravaVS[6]=0x00; |
radovan | 0:7a5957039c5f | 518 | spravaVS[7]=0x00; |
radovan | 0:7a5957039c5f | 519 | spravaVS[8]=0x00; |
radovan | 0:7a5957039c5f | 520 | spravaVS[9]=CRC_MOTORup; |
radovan | 0:7a5957039c5f | 521 | |
radovan | 0:7a5957039c5f | 522 | } else { |
radovan | 0:7a5957039c5f | 523 | smerPohybu=0x02; |
radovan | 0:7a5957039c5f | 524 | spravaVS[5]=0x9C; |
radovan | 0:7a5957039c5f | 525 | spravaVS[6]=0xFF; |
radovan | 0:7a5957039c5f | 526 | spravaVS[7]=0xFF; |
radovan | 0:7a5957039c5f | 527 | spravaVS[8]=0xFF; |
radovan | 0:7a5957039c5f | 528 | spravaVS[9]=CRC_MOTORdown; |
radovan | 0:7a5957039c5f | 529 | } |
radovan | 0:7a5957039c5f | 530 | posli(10); |
radovan | 0:7a5957039c5f | 531 | |
radovan | 0:7a5957039c5f | 532 | //zobrazenie pohybu |
radovan | 0:7a5957039c5f | 533 | spravaVS[1]=INFORMATION_DISPLAY;//prijimatel |
radovan | 0:7a5957039c5f | 534 | spravaVS[3]=2;//pocet dat |
radovan | 0:7a5957039c5f | 535 | spravaVS[4]=smerPohybu;//data |
radovan | 0:7a5957039c5f | 536 | spravaVS[5]=aktualnePoschodie;//data |
radovan | 0:7a5957039c5f | 537 | |
radovan | 0:7a5957039c5f | 538 | if(smerPohybu==0x02) { //smer pohybu dole |
radovan | 0:7a5957039c5f | 539 | if(aktualnePoschodie=='4') { |
radovan | 0:7a5957039c5f | 540 | spravaVS[6]=CRC_INFDd4; |
radovan | 0:7a5957039c5f | 541 | } else if(aktualnePoschodie=='3') { |
radovan | 0:7a5957039c5f | 542 | spravaVS[6]=CRC_INFDd3; |
radovan | 0:7a5957039c5f | 543 | } else if(aktualnePoschodie=='2') { |
radovan | 0:7a5957039c5f | 544 | spravaVS[6]=CRC_INFDd2; |
radovan | 0:7a5957039c5f | 545 | } else { |
radovan | 0:7a5957039c5f | 546 | spravaVS[6]=CRC_INFDd1; |
radovan | 0:7a5957039c5f | 547 | } |
radovan | 0:7a5957039c5f | 548 | } else {//smer pohybu hore |
radovan | 0:7a5957039c5f | 549 | if(aktualnePoschodie=='3') { |
radovan | 0:7a5957039c5f | 550 | spravaVS[6]=CRC_INFDu3; |
radovan | 0:7a5957039c5f | 551 | } else if(aktualnePoschodie=='2') { |
radovan | 0:7a5957039c5f | 552 | spravaVS[6]=CRC_INFDu2; |
radovan | 0:7a5957039c5f | 553 | } else if(aktualnePoschodie=='1') { |
radovan | 0:7a5957039c5f | 554 | spravaVS[6]=CRC_INFDu1; |
radovan | 0:7a5957039c5f | 555 | } else { |
radovan | 0:7a5957039c5f | 556 | spravaVS[6]=CRC_INFDu0; |
radovan | 0:7a5957039c5f | 557 | } |
radovan | 0:7a5957039c5f | 558 | } |
radovan | 0:7a5957039c5f | 559 | posli(7); |
radovan | 0:7a5957039c5f | 560 | } |
radovan | 0:7a5957039c5f | 561 | |
radovan | 0:7a5957039c5f | 562 | } else if(data==0x02&&poziadavky[0]!=jedinec) {//blizko ale nezastavujem |
radovan | 0:7a5957039c5f | 563 | |
radovan | 0:7a5957039c5f | 564 | if(jedinec==0x04) { |
radovan | 0:7a5957039c5f | 565 | aktualnePoschodie='4'; |
radovan | 0:7a5957039c5f | 566 | } else if(jedinec==0x03) { |
radovan | 0:7a5957039c5f | 567 | aktualnePoschodie='3'; |
radovan | 0:7a5957039c5f | 568 | } else if(jedinec==0x02) { |
radovan | 0:7a5957039c5f | 569 | aktualnePoschodie='2'; |
radovan | 0:7a5957039c5f | 570 | } else if(jedinec==0x01) { |
radovan | 0:7a5957039c5f | 571 | aktualnePoschodie='1'; |
radovan | 0:7a5957039c5f | 572 | } else { |
radovan | 0:7a5957039c5f | 573 | aktualnePoschodie='P'; |
radovan | 0:7a5957039c5f | 574 | } |
radovan | 0:7a5957039c5f | 575 | |
radovan | 0:7a5957039c5f | 576 | //zobrazenie pohybu |
radovan | 0:7a5957039c5f | 577 | spravaVS[1]=INFORMATION_DISPLAY;//prijimatel |
radovan | 0:7a5957039c5f | 578 | spravaVS[3]=2;//pocet dat |
radovan | 0:7a5957039c5f | 579 | spravaVS[4]=smerPohybu;//data |
radovan | 0:7a5957039c5f | 580 | spravaVS[5]=aktualnePoschodie;//data |
radovan | 0:7a5957039c5f | 581 | |
radovan | 0:7a5957039c5f | 582 | if(smerPohybu==0x02) { //smer pohybu dole |
radovan | 0:7a5957039c5f | 583 | if(aktualnePoschodie=='4') { |
radovan | 0:7a5957039c5f | 584 | spravaVS[6]=CRC_INFDd4; |
radovan | 0:7a5957039c5f | 585 | } else if(aktualnePoschodie=='3') { |
radovan | 0:7a5957039c5f | 586 | spravaVS[6]=CRC_INFDd3; |
radovan | 0:7a5957039c5f | 587 | } else if(aktualnePoschodie=='2') { |
radovan | 0:7a5957039c5f | 588 | spravaVS[6]=CRC_INFDd2; |
radovan | 0:7a5957039c5f | 589 | } else { |
radovan | 0:7a5957039c5f | 590 | spravaVS[6]=CRC_INFDd1; |
radovan | 0:7a5957039c5f | 591 | } |
radovan | 0:7a5957039c5f | 592 | } else {//smer pohybu hore |
radovan | 0:7a5957039c5f | 593 | if(aktualnePoschodie=='3') { |
radovan | 0:7a5957039c5f | 594 | spravaVS[6]=CRC_INFDu3; |
radovan | 0:7a5957039c5f | 595 | } else if(aktualnePoschodie=='2') { |
radovan | 0:7a5957039c5f | 596 | spravaVS[6]=CRC_INFDu2; |
radovan | 0:7a5957039c5f | 597 | } else if(aktualnePoschodie=='1') { |
radovan | 0:7a5957039c5f | 598 | spravaVS[6]=CRC_INFDu1; |
radovan | 0:7a5957039c5f | 599 | } else { |
radovan | 0:7a5957039c5f | 600 | spravaVS[6]=CRC_INFDu0; |
radovan | 0:7a5957039c5f | 601 | } |
radovan | 0:7a5957039c5f | 602 | } |
radovan | 0:7a5957039c5f | 603 | posli(7); |
radovan | 0:7a5957039c5f | 604 | } |
radovan | 0:7a5957039c5f | 605 | }//LIMIT_SWITCH_FAMILY |
radovan | 0:7a5957039c5f | 606 | }//sprava dostatocne velka |
radovan | 0:7a5957039c5f | 607 | if((timerReset.read_ms()-cas)>=600) { |
radovan | 0:7a5957039c5f | 608 | watchdogReset(); |
radovan | 0:7a5957039c5f | 609 | cas=timerReset.read_ms(); |
radovan | 0:7a5957039c5f | 610 | } |
radovan | 0:7a5957039c5f | 611 | }//while true |
radovan | 0:7a5957039c5f | 612 | }//main |
radovan | 0:7a5957039c5f | 613 | /** |
radovan | 0:7a5957039c5f | 614 | *void posli() |
radovan | 0:7a5957039c5f | 615 | *posle spravu z pola spravaVS pokial nedostane potvrdzujucu odpoved do 200ms posiela spravu znova |
radovan | 0:7a5957039c5f | 616 | *@param <pokial> pocet znakov na odoslanie |
radovan | 0:7a5957039c5f | 617 | */ |
radovan | 0:7a5957039c5f | 618 | void posli(int pokial) |
radovan | 0:7a5957039c5f | 619 | { |
radovan | 0:7a5957039c5f | 620 | Timer timer; |
radovan | 0:7a5957039c5f | 621 | int potvrdenie=0; |
radovan | 0:7a5957039c5f | 622 | timer.start(); |
radovan | 0:7a5957039c5f | 623 | while(potvrdenie==0) { |
radovan | 0:7a5957039c5f | 624 | //poslem spravu |
radovan | 0:7a5957039c5f | 625 | for(int ind=0; ind<pokial; ind++) { |
radovan | 0:7a5957039c5f | 626 | while(pc.writable()==0) {} |
radovan | 0:7a5957039c5f | 627 | pc.putc(spravaVS[ind]); |
radovan | 0:7a5957039c5f | 628 | } |
radovan | 0:7a5957039c5f | 629 | int pocdat=0; |
radovan | 0:7a5957039c5f | 630 | int begin=timer.read_ms(); |
radovan | 0:7a5957039c5f | 631 | while((timer.read_ms()-begin)<200) { |
radovan | 0:7a5957039c5f | 632 | if(zb<=kb) { |
radovan | 0:7a5957039c5f | 633 | pocdat=kb-zb; |
radovan | 0:7a5957039c5f | 634 | } else { |
radovan | 0:7a5957039c5f | 635 | pocdat=200-zb+kb; |
radovan | 0:7a5957039c5f | 636 | } |
radovan | 0:7a5957039c5f | 637 | char prerus=0x00; |
radovan | 0:7a5957039c5f | 638 | for(int t=0; t<=pocdat-5; t++) { |
radovan | 0:7a5957039c5f | 639 | if(bufpole[(zb+t)%200]==0xA0&&bufpole[(zb+t+3)%200]==0x00) { |
radovan | 0:7a5957039c5f | 640 | int k=(zb+t-1)%200;//index dat od ktoreho treba zacat presuvat |
radovan | 0:7a5957039c5f | 641 | if(t==0) { |
radovan | 0:7a5957039c5f | 642 | zb=(zb+5)%200; |
radovan | 0:7a5957039c5f | 643 | prerus=0x01; |
radovan | 0:7a5957039c5f | 644 | break; |
radovan | 0:7a5957039c5f | 645 | } |
radovan | 0:7a5957039c5f | 646 | while(true) { |
radovan | 0:7a5957039c5f | 647 | bufpole[(k+5)%200]=bufpole[k]; |
radovan | 0:7a5957039c5f | 648 | if(k==zb) { |
radovan | 0:7a5957039c5f | 649 | zb=(zb+5)%200; |
radovan | 0:7a5957039c5f | 650 | break; |
radovan | 0:7a5957039c5f | 651 | } |
radovan | 0:7a5957039c5f | 652 | k--; |
radovan | 0:7a5957039c5f | 653 | if(k<0) { |
radovan | 0:7a5957039c5f | 654 | k=199; |
radovan | 0:7a5957039c5f | 655 | } |
radovan | 0:7a5957039c5f | 656 | }//while |
radovan | 0:7a5957039c5f | 657 | prerus=0x01; |
radovan | 0:7a5957039c5f | 658 | break; |
radovan | 0:7a5957039c5f | 659 | } //if |
radovan | 0:7a5957039c5f | 660 | }//for |
radovan | 0:7a5957039c5f | 661 | if(prerus==0x01) { |
radovan | 0:7a5957039c5f | 662 | potvrdenie=1; |
radovan | 0:7a5957039c5f | 663 | break; |
radovan | 0:7a5957039c5f | 664 | } |
radovan | 0:7a5957039c5f | 665 | }//while timer |
radovan | 0:7a5957039c5f | 666 | }//while potvrdenie==0 |
radovan | 0:7a5957039c5f | 667 | timer.stop(); |
radovan | 0:7a5957039c5f | 668 | timer.reset(); |
radovan | 0:7a5957039c5f | 669 | |
radovan | 0:7a5957039c5f | 670 | }//koniec posli |
radovan | 0:7a5957039c5f | 671 | /* |
radovan | 0:7a5957039c5f | 672 | *void watchdogReset() |
radovan | 0:7a5957039c5f | 673 | *psole spravu pre resetovanie watchdogu caka na potvrdenie |
radovan | 0:7a5957039c5f | 674 | */ |
radovan | 0:7a5957039c5f | 675 | void watchdogReset() |
radovan | 0:7a5957039c5f | 676 | { |
radovan | 0:7a5957039c5f | 677 | spravaVS[1]=WATCHDOG_TIMER;//prijimatel |
radovan | 0:7a5957039c5f | 678 | spravaVS[3]=1;//pocet dat |
radovan | 0:7a5957039c5f | 679 | spravaVS[4]=0x05;//data |
radovan | 0:7a5957039c5f | 680 | spravaVS[5]=CRC_WATCHDOG;//data |
radovan | 0:7a5957039c5f | 681 | posli(6); |
radovan | 0:7a5957039c5f | 682 | } |