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