![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test
ElevatorMessenge.cpp@1:a7bdc6b05f96, 2019-01-24 (annotated)
- Committer:
- hodgins
- Date:
- Thu Jan 24 06:52:36 2019 +0000
- Revision:
- 1:a7bdc6b05f96
- Parent:
- 0:e541909ea6b0
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hodgins | 0:e541909ea6b0 | 1 | #include "Communication.h" |
hodgins | 0:e541909ea6b0 | 2 | #include "ElevatorMessenge.h" |
hodgins | 0:e541909ea6b0 | 3 | |
hodgins | 0:e541909ea6b0 | 4 | |
hodgins | 0:e541909ea6b0 | 5 | // Funkcia, ktorá posiela príkazy výťahu na pohyb |
hodgins | 0:e541909ea6b0 | 6 | void moveElevator(int i) |
hodgins | 0:e541909ea6b0 | 7 | { |
hodgins | 0:e541909ea6b0 | 8 | if (i == 0) // Výťah má zastať |
hodgins | 0:e541909ea6b0 | 9 | { |
hodgins | 0:e541909ea6b0 | 10 | char stopMotor[] = {0x01}; |
hodgins | 0:e541909ea6b0 | 11 | paket stop = {.adresa = 0xf1, .dlzkaDat = 0x01, .data = stopMotor}; |
hodgins | 0:e541909ea6b0 | 12 | sendData(stop); |
hodgins | 0:e541909ea6b0 | 13 | } |
hodgins | 0:e541909ea6b0 | 14 | if (i == 1) // Výťah sa má pohnúť smerom na hor - rýchlosť 100 |
hodgins | 0:e541909ea6b0 | 15 | { |
hodgins | 0:e541909ea6b0 | 16 | char up[] = {0x02, 0x00, 0x00, 0x00, 0x64}; |
hodgins | 0:e541909ea6b0 | 17 | paket moveUp = {.adresa = 0xf1, .dlzkaDat = 0x05, .data = up}; |
hodgins | 0:e541909ea6b0 | 18 | sendData(moveUp); |
hodgins | 0:e541909ea6b0 | 19 | } |
hodgins | 0:e541909ea6b0 | 20 | if (i == -1) // V=yťah sa má pohnúť smerom na dol - rýchlosť -100 |
hodgins | 0:e541909ea6b0 | 21 | { |
hodgins | 0:e541909ea6b0 | 22 | char down[] = {0x02, 0xff, 0xff, 0xff, 0x9c}; |
hodgins | 0:e541909ea6b0 | 23 | paket moveDown = {.adresa = 0xf1, .dlzkaDat = 0x05, .data = down}; |
hodgins | 0:e541909ea6b0 | 24 | sendData(moveDown); |
hodgins | 0:e541909ea6b0 | 25 | } |
hodgins | 0:e541909ea6b0 | 26 | } |
hodgins | 0:e541909ea6b0 | 27 | |
hodgins | 0:e541909ea6b0 | 28 | //Funkcia rieši zasviedenie LED vo výťahu, nutný 2 miestny parameter |
hodgins | 0:e541909ea6b0 | 29 | void elevatorLedON(int id) |
hodgins | 0:e541909ea6b0 | 30 | { |
hodgins | 0:e541909ea6b0 | 31 | char command[] = {0x01}; |
hodgins | 0:e541909ea6b0 | 32 | char adresa = 0x00; |
hodgins | 0:e541909ea6b0 | 33 | |
hodgins | 0:e541909ea6b0 | 34 | switch(id) // prvá vonkajšia/vnútorná LED, druhá číslica je poschodie |
hodgins | 0:e541909ea6b0 | 35 | { |
hodgins | 0:e541909ea6b0 | 36 | case 01: adresa = 0x10 ; break; // Prízemie, LED na poschodí-vonkajšia |
hodgins | 0:e541909ea6b0 | 37 | case 02: adresa = 0x20 ; break; |
hodgins | 0:e541909ea6b0 | 38 | case 11: adresa = 0x11 ; break; |
hodgins | 0:e541909ea6b0 | 39 | case 12: adresa = 0x21 ; break; // 1.poschodie, vnútorná LED |
hodgins | 0:e541909ea6b0 | 40 | case 21: adresa = 0x12 ; break; |
hodgins | 0:e541909ea6b0 | 41 | case 22: adresa = 0x22 ; break; |
hodgins | 0:e541909ea6b0 | 42 | case 31: adresa = 0x13 ; break; |
hodgins | 0:e541909ea6b0 | 43 | case 32: adresa = 0x23 ; break; |
hodgins | 0:e541909ea6b0 | 44 | case 41: adresa = 0x14 ; break; |
hodgins | 0:e541909ea6b0 | 45 | case 42: adresa = 0x24 ; break; |
hodgins | 0:e541909ea6b0 | 46 | } |
hodgins | 0:e541909ea6b0 | 47 | paket ledOn = {.adresa = adresa, .dlzkaDat = 0x01, .data = command}; |
hodgins | 0:e541909ea6b0 | 48 | sendData(ledOn); // Odoslanie správy |
hodgins | 0:e541909ea6b0 | 49 | } |
hodgins | 0:e541909ea6b0 | 50 | |
hodgins | 0:e541909ea6b0 | 51 | //Funkcia, ktorá posiela príkazy výťahu, čo sa má zobraziť na displeji |
hodgins | 0:e541909ea6b0 | 52 | void elevatorDisplay(int direction, int floor) |
hodgins | 0:e541909ea6b0 | 53 | { |
hodgins | 0:e541909ea6b0 | 54 | char command [2]; |
hodgins | 0:e541909ea6b0 | 55 | switch(direction) // Zobrazuje pohyb výťahu |
hodgins | 0:e541909ea6b0 | 56 | { |
hodgins | 0:e541909ea6b0 | 57 | case -1: command[0]=0x02; break; // Smer dolu |
hodgins | 0:e541909ea6b0 | 58 | case 0: command[0]=0xFF; break; // Stojí |
hodgins | 0:e541909ea6b0 | 59 | case 1: command[0]=0x01; break; // Smer hore |
hodgins | 0:e541909ea6b0 | 60 | default: |
hodgins | 0:e541909ea6b0 | 61 | command[0]=0x00; // Neplatné dáta |
hodgins | 0:e541909ea6b0 | 62 | } |
hodgins | 0:e541909ea6b0 | 63 | switch(floor) // Aktuálne poschodie |
hodgins | 0:e541909ea6b0 | 64 | { |
hodgins | 0:e541909ea6b0 | 65 | case 0: command[1]=0x50; break; // Prízemie |
hodgins | 0:e541909ea6b0 | 66 | case 1: command[1]=0x31; break; // 1.poschodie |
hodgins | 0:e541909ea6b0 | 67 | case 2: command[1]=0x32; break; |
hodgins | 0:e541909ea6b0 | 68 | case 3: command[1]=0x33; break; |
hodgins | 0:e541909ea6b0 | 69 | case 4: command[1]=0x34; break; // 4.poschodie |
hodgins | 0:e541909ea6b0 | 70 | default: |
hodgins | 0:e541909ea6b0 | 71 | command[1]=0x2D; // Nedefinovaný stav "-" |
hodgins | 0:e541909ea6b0 | 72 | } |
hodgins | 0:e541909ea6b0 | 73 | |
hodgins | 0:e541909ea6b0 | 74 | paket display = {.adresa = 0x30, .dlzkaDat = 0x02, .data = command}; |
hodgins | 0:e541909ea6b0 | 75 | sendData(display); // Odoslanie správy |
hodgins | 0:e541909ea6b0 | 76 | } |
hodgins | 0:e541909ea6b0 | 77 | |
hodgins | 0:e541909ea6b0 | 78 | //Funkcia na zatváranie a otváranie dverí |
hodgins | 0:e541909ea6b0 | 79 | void elevatorCabineLock(bool lock) |
hodgins | 0:e541909ea6b0 | 80 | { |
hodgins | 0:e541909ea6b0 | 81 | char command[1]; |
hodgins | 0:e541909ea6b0 | 82 | if (lock) //ak bol parameter true - dvere sa zavrú |
hodgins | 0:e541909ea6b0 | 83 | { |
hodgins | 0:e541909ea6b0 | 84 | command[0] = 0x01; |
hodgins | 0:e541909ea6b0 | 85 | } |
hodgins | 0:e541909ea6b0 | 86 | else //inak sa dvere otvoria |
hodgins | 0:e541909ea6b0 | 87 | { |
hodgins | 0:e541909ea6b0 | 88 | command[0] = 0x00; |
hodgins | 0:e541909ea6b0 | 89 | } |
hodgins | 0:e541909ea6b0 | 90 | paket reset = {.adresa = 0xf0, .dlzkaDat = 0x01, .data = command}; |
hodgins | 0:e541909ea6b0 | 91 | sendData(reset); // Odoslanie správy |
hodgins | 0:e541909ea6b0 | 92 | } |
hodgins | 0:e541909ea6b0 | 93 | |
hodgins | 0:e541909ea6b0 | 94 | //Funkcia zasielajúca na konzolu výťahu chybovú hlášku |
hodgins | 0:e541909ea6b0 | 95 | void sendError() |
hodgins | 0:e541909ea6b0 | 96 | { |
hodgins | 0:e541909ea6b0 | 97 | paket errorText = {.adresa = 0xD0, .dlzkaDat = 0x0C, .data = "Error data\n\r"}; |
hodgins | 0:e541909ea6b0 | 98 | sendData(errorText); |
hodgins | 0:e541909ea6b0 | 99 | } |
hodgins | 0:e541909ea6b0 | 100 | |
hodgins | 0:e541909ea6b0 | 101 | //Funkcia na zhas=inanie LED indikátorov - zhasnú obe LED na poschodí |
hodgins | 0:e541909ea6b0 | 102 | void elevatorLedOFF(int id) |
hodgins | 0:e541909ea6b0 | 103 | { |
hodgins | 0:e541909ea6b0 | 104 | char command [] = {0x00}; |
hodgins | 0:e541909ea6b0 | 105 | char adresa_1=0x00; |
hodgins | 0:e541909ea6b0 | 106 | char adresa_2=0x00; |
hodgins | 0:e541909ea6b0 | 107 | |
hodgins | 0:e541909ea6b0 | 108 | switch(id) // Na ktorom poschodí sa má zhasnúť |
hodgins | 0:e541909ea6b0 | 109 | { |
hodgins | 0:e541909ea6b0 | 110 | case 0: adresa_1 =0x10; adresa_2 =0x20 ;break; //Prízemie |
hodgins | 0:e541909ea6b0 | 111 | case 1: adresa_1 =0x11; adresa_2 =0x21 ;break; //1.poschodie |
hodgins | 0:e541909ea6b0 | 112 | case 2: adresa_1 =0x12; adresa_2 =0x22 ;break; |
hodgins | 0:e541909ea6b0 | 113 | case 3: adresa_1 =0x13; adresa_2 =0x23 ;break; |
hodgins | 0:e541909ea6b0 | 114 | case 4: adresa_1 =0x14; adresa_2 =0x24 ;break; |
hodgins | 0:e541909ea6b0 | 115 | } |
hodgins | 0:e541909ea6b0 | 116 | paket ledOff_1 = {.adresa = adresa_1, .dlzkaDat = 0x01, .data = command}; |
hodgins | 0:e541909ea6b0 | 117 | paket ledOff_2 = {.adresa = adresa_2, .dlzkaDat = 0x01, .data = command}; |
hodgins | 0:e541909ea6b0 | 118 | sendData(ledOff_1); // LED na poschodí |
hodgins | 0:e541909ea6b0 | 119 | sendData(ledOff_2); // LED vo výťahu |
hodgins | 0:e541909ea6b0 | 120 | } |