ver. 1.0
Dependencies: EPOS2 NetServices mbed
Fork of SMTPClient_HelloWorld by
main.cpp@1:808150b7aebc, 2016-10-21 (annotated)
- Committer:
- joe_feubli
- Date:
- Fri Oct 21 15:13:21 2016 +0000
- Revision:
- 1:808150b7aebc
- Parent:
- 0:10508306e920
- Child:
- 2:3e35b0631651
Funktion mit Mailfunktion und Fehlerauswertung
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
segundo | 0:10508306e920 | 1 | #include "mbed.h" |
joe_feubli | 1:808150b7aebc | 2 | #include "EPOS2.h" |
segundo | 0:10508306e920 | 3 | #include "EthernetNetIf.h" |
segundo | 0:10508306e920 | 4 | #include "NTPClient.h" |
segundo | 0:10508306e920 | 5 | #include "SMTPClient.h" |
segundo | 0:10508306e920 | 6 | |
segundo | 0:10508306e920 | 7 | #define HOSTNAME "mbedSE" |
segundo | 0:10508306e920 | 8 | |
segundo | 0:10508306e920 | 9 | // server is domain name eg. mail.authsmtp.com |
segundo | 0:10508306e920 | 10 | // port is smtp port eg. 25 or 23 |
segundo | 0:10508306e920 | 11 | // domain must be acceptable to server (but often is not strictly enforced since does not affect FROM address) |
joe_feubli | 1:808150b7aebc | 12 | #define SERVER "puls.metanet.ch" |
segundo | 0:10508306e920 | 13 | #define PORT 25 |
joe_feubli | 1:808150b7aebc | 14 | #define USER "mbed@joejoe.ch" |
joe_feubli | 1:808150b7aebc | 15 | #define PASSWORD "maxon2016" |
joe_feubli | 1:808150b7aebc | 16 | #define DOMAIN "joejoe.ch" |
joe_feubli | 1:808150b7aebc | 17 | #define FROM_ADDRESS "mbed@maxonmotor.ch" |
joe_feubli | 1:808150b7aebc | 18 | #define TO_ADDRESS "dsqHmqCK@joejoe.ch" |
segundo | 0:10508306e920 | 19 | |
segundo | 0:10508306e920 | 20 | EthernetNetIf eth(HOSTNAME); |
joe_feubli | 1:808150b7aebc | 21 | |
joe_feubli | 1:808150b7aebc | 22 | |
joe_feubli | 1:808150b7aebc | 23 | //***********************************************************************************************************************************// |
joe_feubli | 1:808150b7aebc | 24 | //*** Global_Var *******************************************************************************************************************// |
joe_feubli | 1:808150b7aebc | 25 | //***********************************************************************************************************************************// |
joe_feubli | 1:808150b7aebc | 26 | |
joe_feubli | 1:808150b7aebc | 27 | Serial pc(USBTX, USBRX); // (tx, rx) |
joe_feubli | 1:808150b7aebc | 28 | CAN can(p9, p10); // Can Pin def |
joe_feubli | 1:808150b7aebc | 29 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
joe_feubli | 1:808150b7aebc | 30 | |
joe_feubli | 1:808150b7aebc | 31 | |
joe_feubli | 1:808150b7aebc | 32 | DigitalIn usv_ready(p23); |
joe_feubli | 1:808150b7aebc | 33 | InterruptIn buffering(p24); |
joe_feubli | 1:808150b7aebc | 34 | DigitalIn replace_battery(p25); |
joe_feubli | 1:808150b7aebc | 35 | |
joe_feubli | 1:808150b7aebc | 36 | DigitalOut led1(LED1); |
joe_feubli | 1:808150b7aebc | 37 | DigitalOut led2(LED2); |
joe_feubli | 1:808150b7aebc | 38 | DigitalOut led3(LED3); |
joe_feubli | 1:808150b7aebc | 39 | DigitalOut led4(LED4); |
joe_feubli | 1:808150b7aebc | 40 | |
joe_feubli | 1:808150b7aebc | 41 | bool epos1_homing = false; |
joe_feubli | 1:808150b7aebc | 42 | bool epos3_homing = false; |
joe_feubli | 1:808150b7aebc | 43 | |
joe_feubli | 1:808150b7aebc | 44 | bool node1_homed = false; |
joe_feubli | 1:808150b7aebc | 45 | bool node2_homed = false; |
joe_feubli | 1:808150b7aebc | 46 | bool node3_homed = false; |
joe_feubli | 1:808150b7aebc | 47 | bool node4_homed = false; |
joe_feubli | 1:808150b7aebc | 48 | bool node5_homed = false; |
joe_feubli | 1:808150b7aebc | 49 | bool node6_homed = true; |
joe_feubli | 1:808150b7aebc | 50 | bool node7_homed = true; |
joe_feubli | 1:808150b7aebc | 51 | |
joe_feubli | 1:808150b7aebc | 52 | bool Power_ein = true; |
joe_feubli | 1:808150b7aebc | 53 | bool node5_grundposition = false; |
joe_feubli | 1:808150b7aebc | 54 | |
joe_feubli | 1:808150b7aebc | 55 | bool ausfahren = false; |
joe_feubli | 1:808150b7aebc | 56 | bool einfahren = false; |
joe_feubli | 1:808150b7aebc | 57 | bool usv = false; |
joe_feubli | 1:808150b7aebc | 58 | bool error_sending = false; |
joe_feubli | 1:808150b7aebc | 59 | |
joe_feubli | 1:808150b7aebc | 60 | int current_step = 1; //HOMING |
joe_feubli | 1:808150b7aebc | 61 | int ausfahren_step = 1; |
joe_feubli | 1:808150b7aebc | 62 | int einfahren_step = 1; |
joe_feubli | 1:808150b7aebc | 63 | int usv_step = 1; |
joe_feubli | 1:808150b7aebc | 64 | int ErrorState1; |
joe_feubli | 1:808150b7aebc | 65 | int ErrorState2; |
joe_feubli | 1:808150b7aebc | 66 | int ErrorState3; |
joe_feubli | 1:808150b7aebc | 67 | int ErrorState4; |
joe_feubli | 1:808150b7aebc | 68 | int ErrorState5; |
joe_feubli | 1:808150b7aebc | 69 | int ErrorState6; |
joe_feubli | 1:808150b7aebc | 70 | int ErrorState7; |
joe_feubli | 1:808150b7aebc | 71 | int error_mails = 0; |
joe_feubli | 1:808150b7aebc | 72 | int arr[3]; //für die speicherung der Zähler |
joe_feubli | 1:808150b7aebc | 73 | int zaehler_buzzer; |
joe_feubli | 1:808150b7aebc | 74 | int zaehler_usv; |
joe_feubli | 1:808150b7aebc | 75 | int zaehler_mails; |
joe_feubli | 1:808150b7aebc | 76 | float speed = 1.5; |
segundo | 0:10508306e920 | 77 | |
joe_feubli | 1:808150b7aebc | 78 | void interrupt_usv(){ //Funktion, wird aufgeruffen durch den interrupt des USV's |
joe_feubli | 1:808150b7aebc | 79 | current_step = 5; |
joe_feubli | 1:808150b7aebc | 80 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 81 | } |
joe_feubli | 1:808150b7aebc | 82 | |
joe_feubli | 1:808150b7aebc | 83 | int main(){ ///////// Main |
joe_feubli | 1:808150b7aebc | 84 | led1 = 1; |
joe_feubli | 1:808150b7aebc | 85 | pc.baud(9600); |
joe_feubli | 1:808150b7aebc | 86 | |
joe_feubli | 1:808150b7aebc | 87 | buffering.rise(&interrupt_usv); //Interrupt für USV |
joe_feubli | 1:808150b7aebc | 88 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
joe_feubli | 1:808150b7aebc | 89 | |
joe_feubli | 1:808150b7aebc | 90 | wait(0.5); //Wartezeit bis Epos2 24/5 aufgestartet ist |
joe_feubli | 1:808150b7aebc | 91 | led2 = 1; |
joe_feubli | 1:808150b7aebc | 92 | wait(0.5); |
joe_feubli | 1:808150b7aebc | 93 | led3 = 1; |
joe_feubli | 1:808150b7aebc | 94 | wait(0.5); |
joe_feubli | 1:808150b7aebc | 95 | led4 = 1; |
joe_feubli | 1:808150b7aebc | 96 | wait(0.5); |
joe_feubli | 1:808150b7aebc | 97 | |
joe_feubli | 1:808150b7aebc | 98 | pc.printf("Initialisation CAN\n"); |
joe_feubli | 1:808150b7aebc | 99 | |
joe_feubli | 1:808150b7aebc | 100 | can.frequency(1000000); //Define Can baud in bit/s |
joe_feubli | 1:808150b7aebc | 101 | |
joe_feubli | 1:808150b7aebc | 102 | CANopen canOpen(&can, 0.001); //Define CanOpen Network(can function, periode of the CANopen driver in sec) |
joe_feubli | 1:808150b7aebc | 103 | canOpen.start(); //Start defined CanOpen Network |
joe_feubli | 1:808150b7aebc | 104 | |
joe_feubli | 1:808150b7aebc | 105 | EPOS2 MyEpos1(&canOpen, 1); //Define and connect the EPOS2 to the CanOpen Network(canOpen function, Node ID) |
joe_feubli | 1:808150b7aebc | 106 | EPOS2 MyEpos2(&canOpen, 2); //Define and connect the EPOS2 to the CanOpen Network(canOpen function, Node ID) |
joe_feubli | 1:808150b7aebc | 107 | EPOS2 MyEpos3(&canOpen, 3); //Define and connect the EPOS2 to the CanOpen Network(canOpen function, Node ID) |
joe_feubli | 1:808150b7aebc | 108 | EPOS2 MyEpos4(&canOpen, 4); //Define and connect the EPOS2 to the CanOpen Network(canOpen function, Node ID) |
joe_feubli | 1:808150b7aebc | 109 | EPOS2 MyEpos5(&canOpen, 5); //Define and connect the EPOS2 to the CanOpen Network(canOpen function, Node ID) |
joe_feubli | 1:808150b7aebc | 110 | EPOS2 MyEpos6(&canOpen, 6); //Define and connect the EPOS2 to the CanOpen Network(canOpen function, Node ID) |
joe_feubli | 1:808150b7aebc | 111 | EPOS2 MyEpos7(&canOpen, 7); //Define and connect the EPOS2 to the CanOpen Network(canOpen function, Node ID) |
joe_feubli | 1:808150b7aebc | 112 | |
joe_feubli | 1:808150b7aebc | 113 | pc.printf("Initialisation abgeschlossen\n"); |
joe_feubli | 1:808150b7aebc | 114 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 115 | |
joe_feubli | 1:808150b7aebc | 116 | MyEpos1.Reset(); |
joe_feubli | 1:808150b7aebc | 117 | MyEpos2.Reset(); |
joe_feubli | 1:808150b7aebc | 118 | MyEpos3.Reset(); |
joe_feubli | 1:808150b7aebc | 119 | MyEpos4.Reset(); |
joe_feubli | 1:808150b7aebc | 120 | MyEpos5.Reset(); |
joe_feubli | 1:808150b7aebc | 121 | MyEpos6.Reset(); |
joe_feubli | 1:808150b7aebc | 122 | MyEpos7.Reset(); |
joe_feubli | 1:808150b7aebc | 123 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 124 | pc.printf("Reset abgeschlossen\n"); |
joe_feubli | 1:808150b7aebc | 125 | |
joe_feubli | 1:808150b7aebc | 126 | led1 = 0; |
joe_feubli | 1:808150b7aebc | 127 | led2 = 0; |
joe_feubli | 1:808150b7aebc | 128 | led3 = 0; |
joe_feubli | 1:808150b7aebc | 129 | led4 = 0; |
joe_feubli | 1:808150b7aebc | 130 | MyEpos5.SetDigOut(4, 1); |
joe_feubli | 1:808150b7aebc | 131 | /*******************************************Internetverbindung aufbauen*******************************************************/ |
joe_feubli | 1:808150b7aebc | 132 | |
joe_feubli | 1:808150b7aebc | 133 | printf("\n\n/* Segundo Equipo SMTPClient library demonstration */\n"); |
joe_feubli | 1:808150b7aebc | 134 | printf("Make sure you have modified the SERVER, PORT etc in the source code\n"); |
joe_feubli | 1:808150b7aebc | 135 | |
joe_feubli | 1:808150b7aebc | 136 | EthernetErr ethErr; |
joe_feubli | 1:808150b7aebc | 137 | int count = 0; |
joe_feubli | 1:808150b7aebc | 138 | do { |
joe_feubli | 1:808150b7aebc | 139 | printf("Setting up %d...\n", ++count); |
joe_feubli | 1:808150b7aebc | 140 | ethErr = eth.setup(); |
joe_feubli | 1:808150b7aebc | 141 | if (ethErr) printf("Timeout\n", ethErr); |
joe_feubli | 1:808150b7aebc | 142 | current_step = 1;//zusätzlich hinzugefügt um wiederholungen zu unterbinden |
joe_feubli | 1:808150b7aebc | 143 | break;//zusätzlich hinzugefügt um wiederholungen zu unterbinden |
joe_feubli | 1:808150b7aebc | 144 | } while (ethErr != ETH_OK); |
joe_feubli | 1:808150b7aebc | 145 | |
joe_feubli | 1:808150b7aebc | 146 | printf("Connected OK\n"); |
joe_feubli | 1:808150b7aebc | 147 | const char* hwAddr = eth.getHwAddr(); |
joe_feubli | 1:808150b7aebc | 148 | printf("HW address : %02x:%02x:%02x:%02x:%02x:%02x\n", |
joe_feubli | 1:808150b7aebc | 149 | hwAddr[0], hwAddr[1], hwAddr[2], |
joe_feubli | 1:808150b7aebc | 150 | hwAddr[3], hwAddr[4], hwAddr[5]); |
joe_feubli | 1:808150b7aebc | 151 | |
joe_feubli | 1:808150b7aebc | 152 | IpAddr ethIp = eth.getIp(); |
joe_feubli | 1:808150b7aebc | 153 | printf("IP address : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]); |
joe_feubli | 1:808150b7aebc | 154 | |
joe_feubli | 1:808150b7aebc | 155 | NTPClient ntp; |
joe_feubli | 1:808150b7aebc | 156 | printf("NTP setTime...\n"); |
joe_feubli | 1:808150b7aebc | 157 | Host server(IpAddr(), 123, "pool.ntp.org"); |
joe_feubli | 1:808150b7aebc | 158 | printf("Result : %d\n", ntp.setTime(server)); |
joe_feubli | 1:808150b7aebc | 159 | |
joe_feubli | 1:808150b7aebc | 160 | time_t ctTime = time(NULL); |
joe_feubli | 1:808150b7aebc | 161 | ctTime = ctTime+ 7200; |
joe_feubli | 1:808150b7aebc | 162 | printf("\nTime is now (UTC): %d %s\n", ctTime, ctime(&ctTime)); |
segundo | 0:10508306e920 | 163 | |
joe_feubli | 1:808150b7aebc | 164 | Host host(IpAddr(), PORT, SERVER); |
joe_feubli | 1:808150b7aebc | 165 | SMTPClient smtp(host, DOMAIN, USER, PASSWORD, SMTP_AUTH_PLAIN); |
joe_feubli | 1:808150b7aebc | 166 | |
joe_feubli | 1:808150b7aebc | 167 | EmailMessage msg; |
joe_feubli | 1:808150b7aebc | 168 | /*******************************************Internetverbindung aufbauen*******************************************************/ |
joe_feubli | 1:808150b7aebc | 169 | /*******************************************Abrufen der aktuellen Zähler******************************************************/ |
joe_feubli | 1:808150b7aebc | 170 | FILE *fd_read = fopen("/local/zaehler.txt", "r"); |
joe_feubli | 1:808150b7aebc | 171 | if (fd_read) { |
joe_feubli | 1:808150b7aebc | 172 | fscanf(fd_read, "Buzzer Zähler = %d\n Fehler Zähler = %d\n Mails Zähler = %d\n",&arr[0], &arr[1], &arr[2]); |
joe_feubli | 1:808150b7aebc | 173 | zaehler_buzzer = arr[0]; |
joe_feubli | 1:808150b7aebc | 174 | zaehler_usv = arr[1]; |
joe_feubli | 1:808150b7aebc | 175 | zaehler_mails = arr[2]; |
joe_feubli | 1:808150b7aebc | 176 | } |
joe_feubli | 1:808150b7aebc | 177 | pc.printf ("Zähler Buzzer = %d\n",arr[0]); |
joe_feubli | 1:808150b7aebc | 178 | pc.printf ("Zähler USV = %d\n",arr[1]); |
joe_feubli | 1:808150b7aebc | 179 | pc.printf ("Zähler Error Mails = %d\n",arr[2]); |
joe_feubli | 1:808150b7aebc | 180 | fclose(fd_read); |
joe_feubli | 1:808150b7aebc | 181 | |
joe_feubli | 1:808150b7aebc | 182 | while(1){ |
segundo | 0:10508306e920 | 183 | |
joe_feubli | 1:808150b7aebc | 184 | if(error_sending == false){ |
joe_feubli | 1:808150b7aebc | 185 | if(MyEpos1.GetError() != 0 or MyEpos2.GetError() != 0 or MyEpos3.GetError() != 0 or MyEpos4.GetError() != 0 or MyEpos5.GetError() != 0 /*or MyEpos6.GetError() != 0 or MyEpos7.GetError() != 0*/){ |
joe_feubli | 1:808150b7aebc | 186 | MyEpos1.MoveVelocity(0, 500, 500); |
joe_feubli | 1:808150b7aebc | 187 | MyEpos2.MoveVelocity(0, 500, 500); |
joe_feubli | 1:808150b7aebc | 188 | MyEpos3.MoveVelocity(0, 500, 500); |
joe_feubli | 1:808150b7aebc | 189 | MyEpos4.MoveVelocity(0, 500, 500); |
joe_feubli | 1:808150b7aebc | 190 | MyEpos5.MoveVelocity(0, 500, 500); |
joe_feubli | 1:808150b7aebc | 191 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 192 | ErrorState1 = MyEpos1.GetError(); |
joe_feubli | 1:808150b7aebc | 193 | ErrorState2 = MyEpos2.GetError(); |
joe_feubli | 1:808150b7aebc | 194 | ErrorState3 = MyEpos3.GetError(); |
joe_feubli | 1:808150b7aebc | 195 | ErrorState4 = MyEpos4.GetError(); |
joe_feubli | 1:808150b7aebc | 196 | ErrorState5 = MyEpos5.GetError(); |
joe_feubli | 1:808150b7aebc | 197 | ErrorState6 = MyEpos6.GetError(); |
joe_feubli | 1:808150b7aebc | 198 | ErrorState7 = MyEpos7.GetError(); |
joe_feubli | 1:808150b7aebc | 199 | current_step = 7; //FEHLER |
joe_feubli | 1:808150b7aebc | 200 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 201 | pc.printf("ErrorState Panels/Kopf: Panel Aussen Linkss=%d, Panel Innen Links=%d, Panel Aussen Rechts=%d, Panel Innen Rechts=%d, Kopf=%d\r\n", ErrorState1, ErrorState2, ErrorState3, ErrorState4, ErrorState5); |
joe_feubli | 1:808150b7aebc | 202 | } |
joe_feubli | 1:808150b7aebc | 203 | |
joe_feubli | 1:808150b7aebc | 204 | if((MyEpos6.GetError() != 0 or MyEpos7.GetError() != 0) and current_step != 7){ |
joe_feubli | 1:808150b7aebc | 205 | current_step = 6; //FEHLER |
joe_feubli | 1:808150b7aebc | 206 | ErrorState1 = MyEpos1.GetError(); |
joe_feubli | 1:808150b7aebc | 207 | ErrorState2 = MyEpos2.GetError(); |
joe_feubli | 1:808150b7aebc | 208 | ErrorState3 = MyEpos3.GetError(); |
joe_feubli | 1:808150b7aebc | 209 | ErrorState4 = MyEpos4.GetError(); |
joe_feubli | 1:808150b7aebc | 210 | ErrorState5 = MyEpos5.GetError(); |
joe_feubli | 1:808150b7aebc | 211 | ErrorState6 = MyEpos6.GetError(); |
joe_feubli | 1:808150b7aebc | 212 | ErrorState7 = MyEpos7.GetError(); |
joe_feubli | 1:808150b7aebc | 213 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 214 | pc.printf("Bohrgestell/Bohrer ErrorState: Bohrgestell=%d, Bohrer=%d\r\n", ErrorState6, ErrorState7); |
joe_feubli | 1:808150b7aebc | 215 | } |
joe_feubli | 1:808150b7aebc | 216 | } |
joe_feubli | 1:808150b7aebc | 217 | |
joe_feubli | 1:808150b7aebc | 218 | switch (current_step){ |
joe_feubli | 1:808150b7aebc | 219 | case 1://HOMING: |
joe_feubli | 1:808150b7aebc | 220 | |
joe_feubli | 1:808150b7aebc | 221 | led1 = 1; |
joe_feubli | 1:808150b7aebc | 222 | if (Power_ein == true){ |
joe_feubli | 1:808150b7aebc | 223 | MyEpos1.Power(1); |
joe_feubli | 1:808150b7aebc | 224 | MyEpos2.Power(1); |
joe_feubli | 1:808150b7aebc | 225 | MyEpos3.Power(1); |
joe_feubli | 1:808150b7aebc | 226 | MyEpos4.Power(1); |
joe_feubli | 1:808150b7aebc | 227 | MyEpos5.Power(1); |
joe_feubli | 1:808150b7aebc | 228 | MyEpos6.Power(1); |
joe_feubli | 1:808150b7aebc | 229 | MyEpos7.Power(1); |
joe_feubli | 1:808150b7aebc | 230 | Power_ein = false; |
joe_feubli | 1:808150b7aebc | 231 | } |
joe_feubli | 1:808150b7aebc | 232 | |
joe_feubli | 1:808150b7aebc | 233 | /***********************HOMING*************************/ |
joe_feubli | 1:808150b7aebc | 234 | |
joe_feubli | 1:808150b7aebc | 235 | if (node1_homed == false){ |
joe_feubli | 1:808150b7aebc | 236 | if(epos1_homing == false){ |
joe_feubli | 1:808150b7aebc | 237 | MyEpos1.MoveVelocity(-400, 100, 100); //Fährt auf Endschalter vor Beginn mit Stromhoming |
joe_feubli | 1:808150b7aebc | 238 | epos1_homing = true; |
joe_feubli | 1:808150b7aebc | 239 | } |
joe_feubli | 1:808150b7aebc | 240 | if(MyEpos1.GetDigIn(4) == 1){ |
joe_feubli | 1:808150b7aebc | 241 | pc.printf("Homing1\n"); |
joe_feubli | 1:808150b7aebc | 242 | MyEpos1.Homing(); //Solarpanel_Aussen_Links |
joe_feubli | 1:808150b7aebc | 243 | node1_homed = true; |
joe_feubli | 1:808150b7aebc | 244 | break; |
joe_feubli | 1:808150b7aebc | 245 | } |
joe_feubli | 1:808150b7aebc | 246 | break; |
joe_feubli | 1:808150b7aebc | 247 | } |
joe_feubli | 1:808150b7aebc | 248 | |
joe_feubli | 1:808150b7aebc | 249 | |
joe_feubli | 1:808150b7aebc | 250 | if (node3_homed == false){ |
joe_feubli | 1:808150b7aebc | 251 | if (epos3_homing == false){ |
joe_feubli | 1:808150b7aebc | 252 | MyEpos3.MoveVelocity(400, 100, 100); //Fährt auf Endschalter vor Beginn mit Stromhoming |
joe_feubli | 1:808150b7aebc | 253 | epos3_homing = true; |
joe_feubli | 1:808150b7aebc | 254 | } |
joe_feubli | 1:808150b7aebc | 255 | if(MyEpos3.GetDigIn(4) == 1){ |
joe_feubli | 1:808150b7aebc | 256 | pc.printf("Homing3\n"); |
joe_feubli | 1:808150b7aebc | 257 | MyEpos3.Homing(); //Solarpanel_Aussen_Rechts |
joe_feubli | 1:808150b7aebc | 258 | node3_homed = true; |
joe_feubli | 1:808150b7aebc | 259 | } |
joe_feubli | 1:808150b7aebc | 260 | break; |
joe_feubli | 1:808150b7aebc | 261 | } |
joe_feubli | 1:808150b7aebc | 262 | |
joe_feubli | 1:808150b7aebc | 263 | if (node5_homed == false){ |
joe_feubli | 1:808150b7aebc | 264 | pc.printf("Homing5\n"); |
joe_feubli | 1:808150b7aebc | 265 | MyEpos5.Homing(); //Kopf |
joe_feubli | 1:808150b7aebc | 266 | MyEpos5.MoveAbsolute(-60000,800,100,100); //Kopf |
joe_feubli | 1:808150b7aebc | 267 | pc.printf("Fahren auf -60000\n"); |
joe_feubli | 1:808150b7aebc | 268 | while(MyEpos5.TargetReached()!=1){ |
joe_feubli | 1:808150b7aebc | 269 | if(MyEpos5.GetError() == 1){ |
joe_feubli | 1:808150b7aebc | 270 | break; |
joe_feubli | 1:808150b7aebc | 271 | } |
joe_feubli | 1:808150b7aebc | 272 | } |
joe_feubli | 1:808150b7aebc | 273 | pc.printf("Target reached\n"); |
joe_feubli | 1:808150b7aebc | 274 | node5_homed = true; |
joe_feubli | 1:808150b7aebc | 275 | break; |
joe_feubli | 1:808150b7aebc | 276 | } |
joe_feubli | 1:808150b7aebc | 277 | |
joe_feubli | 1:808150b7aebc | 278 | if (node7_homed == false){ |
joe_feubli | 1:808150b7aebc | 279 | pc.printf("Homing7\n"); |
joe_feubli | 1:808150b7aebc | 280 | MyEpos7.Homing(); //Bohrer |
joe_feubli | 1:808150b7aebc | 281 | node7_homed = true; |
joe_feubli | 1:808150b7aebc | 282 | break; |
joe_feubli | 1:808150b7aebc | 283 | } |
joe_feubli | 1:808150b7aebc | 284 | |
joe_feubli | 1:808150b7aebc | 285 | if (node1_homed == true and node2_homed == false){ |
joe_feubli | 1:808150b7aebc | 286 | if (node5_grundposition == false){ |
joe_feubli | 1:808150b7aebc | 287 | MyEpos5.MoveAbsolute(-60000,800,100,100); //Kopf |
joe_feubli | 1:808150b7aebc | 288 | } |
joe_feubli | 1:808150b7aebc | 289 | pc.printf("Homing2\n"); |
joe_feubli | 1:808150b7aebc | 290 | MyEpos2.Homing(); //Solarpanel_Innen_Links |
joe_feubli | 1:808150b7aebc | 291 | node2_homed = true; |
joe_feubli | 1:808150b7aebc | 292 | break; |
joe_feubli | 1:808150b7aebc | 293 | } |
joe_feubli | 1:808150b7aebc | 294 | |
joe_feubli | 1:808150b7aebc | 295 | if (node3_homed == true and node4_homed == false){ |
joe_feubli | 1:808150b7aebc | 296 | pc.printf("Homing4\n"); |
joe_feubli | 1:808150b7aebc | 297 | MyEpos4.Homing(); //Solarpanel_Innen_Rechts |
joe_feubli | 1:808150b7aebc | 298 | node4_homed = true; |
joe_feubli | 1:808150b7aebc | 299 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 300 | break; |
joe_feubli | 1:808150b7aebc | 301 | } |
joe_feubli | 1:808150b7aebc | 302 | |
joe_feubli | 1:808150b7aebc | 303 | |
joe_feubli | 1:808150b7aebc | 304 | |
joe_feubli | 1:808150b7aebc | 305 | if (node7_homed == true and node6_homed == false){ |
joe_feubli | 1:808150b7aebc | 306 | pc.printf("Homing6\n"); |
joe_feubli | 1:808150b7aebc | 307 | MyEpos6.Homing();//Bohrgestell |
joe_feubli | 1:808150b7aebc | 308 | node6_homed = true; |
joe_feubli | 1:808150b7aebc | 309 | break; |
joe_feubli | 1:808150b7aebc | 310 | } |
joe_feubli | 1:808150b7aebc | 311 | |
joe_feubli | 1:808150b7aebc | 312 | if (node2_homed == true and node4_homed == true and node5_grundposition == false){ |
joe_feubli | 1:808150b7aebc | 313 | MyEpos5.MoveAbsolute(500,800*speed,100,100); //Kopf |
joe_feubli | 1:808150b7aebc | 314 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 315 | while(MyEpos5.TargetReached() != 1){ |
joe_feubli | 1:808150b7aebc | 316 | if(MyEpos5.GetError() == 1){ |
joe_feubli | 1:808150b7aebc | 317 | break; |
joe_feubli | 1:808150b7aebc | 318 | } |
joe_feubli | 1:808150b7aebc | 319 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 320 | } |
joe_feubli | 1:808150b7aebc | 321 | node5_grundposition = true; |
joe_feubli | 1:808150b7aebc | 322 | break; |
joe_feubli | 1:808150b7aebc | 323 | } |
segundo | 0:10508306e920 | 324 | |
joe_feubli | 1:808150b7aebc | 325 | if (node1_homed == true and node2_homed == true and node3_homed == true and node4_homed == true and node5_homed == true and node6_homed == true and node7_homed == true){ |
joe_feubli | 1:808150b7aebc | 326 | pc.printf("Homing beendet\n"); |
joe_feubli | 1:808150b7aebc | 327 | node5_grundposition = false; |
joe_feubli | 1:808150b7aebc | 328 | Power_ein = true; |
joe_feubli | 1:808150b7aebc | 329 | MyEpos1.Power(0); |
joe_feubli | 1:808150b7aebc | 330 | MyEpos2.Power(0); |
joe_feubli | 1:808150b7aebc | 331 | MyEpos3.Power(0); |
joe_feubli | 1:808150b7aebc | 332 | MyEpos4.Power(0); |
joe_feubli | 1:808150b7aebc | 333 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 334 | MyEpos5.Power(0); |
joe_feubli | 1:808150b7aebc | 335 | current_step = 2;//BEREIT; |
joe_feubli | 1:808150b7aebc | 336 | } |
joe_feubli | 1:808150b7aebc | 337 | |
joe_feubli | 1:808150b7aebc | 338 | |
joe_feubli | 1:808150b7aebc | 339 | led1 = 0; |
joe_feubli | 1:808150b7aebc | 340 | break; |
joe_feubli | 1:808150b7aebc | 341 | |
joe_feubli | 1:808150b7aebc | 342 | |
joe_feubli | 1:808150b7aebc | 343 | case 2://BEREIT: |
joe_feubli | 1:808150b7aebc | 344 | led2 = 1; |
joe_feubli | 1:808150b7aebc | 345 | MyEpos5.SetDigOut(4,0); |
joe_feubli | 1:808150b7aebc | 346 | if (MyEpos5.GetDigIn(3) == 1){ |
joe_feubli | 1:808150b7aebc | 347 | zaehler_buzzer = zaehler_buzzer + 1; |
joe_feubli | 1:808150b7aebc | 348 | MyEpos5.SetDigOut(4,1); |
joe_feubli | 1:808150b7aebc | 349 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 350 | MyEpos1.Power(1); |
joe_feubli | 1:808150b7aebc | 351 | MyEpos2.Power(1); |
joe_feubli | 1:808150b7aebc | 352 | MyEpos3.Power(1); |
joe_feubli | 1:808150b7aebc | 353 | MyEpos4.Power(1); |
joe_feubli | 1:808150b7aebc | 354 | MyEpos5.Power(1); |
joe_feubli | 1:808150b7aebc | 355 | einfahren = false; |
joe_feubli | 1:808150b7aebc | 356 | ausfahren_step = 1; |
joe_feubli | 1:808150b7aebc | 357 | current_step = 3; |
joe_feubli | 1:808150b7aebc | 358 | error_mails = 0; |
joe_feubli | 1:808150b7aebc | 359 | wait(0.5); |
joe_feubli | 1:808150b7aebc | 360 | } |
joe_feubli | 1:808150b7aebc | 361 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 362 | led2 = 0; |
joe_feubli | 1:808150b7aebc | 363 | break; |
joe_feubli | 1:808150b7aebc | 364 | |
joe_feubli | 1:808150b7aebc | 365 | case 3://ABLAUF |
joe_feubli | 1:808150b7aebc | 366 | // pc.printf("Läuft...\n"); |
joe_feubli | 1:808150b7aebc | 367 | led3 = 1; |
joe_feubli | 1:808150b7aebc | 368 | if (einfahren == false){ |
joe_feubli | 1:808150b7aebc | 369 | switch (ausfahren_step){ |
joe_feubli | 1:808150b7aebc | 370 | case 1: |
joe_feubli | 1:808150b7aebc | 371 | MyEpos5.MoveAbsolute(-150000,800*speed,100*speed,100*speed); //Kopf |
joe_feubli | 1:808150b7aebc | 372 | ausfahren_step = 2; |
joe_feubli | 1:808150b7aebc | 373 | wait(1); |
joe_feubli | 1:808150b7aebc | 374 | break; |
joe_feubli | 1:808150b7aebc | 375 | |
joe_feubli | 1:808150b7aebc | 376 | case 2: |
joe_feubli | 1:808150b7aebc | 377 | if (MyEpos5.TargetReached()==1){ |
joe_feubli | 1:808150b7aebc | 378 | MyEpos1.MoveAbsolute(0,500,100,100); //Panel Aussen Links |
joe_feubli | 1:808150b7aebc | 379 | MyEpos3.MoveAbsolute(0,500,100,100); //Panel Aussen Rechts |
joe_feubli | 1:808150b7aebc | 380 | MyEpos2.MoveAbsolute(310000,500*speed,100*speed,100*speed); //Panel Innen Links |
joe_feubli | 1:808150b7aebc | 381 | MyEpos4.MoveAbsolute(-310000,500*speed,100*speed,100*speed); //Panel Innen Rechts |
joe_feubli | 1:808150b7aebc | 382 | ausfahren_step = 3; |
joe_feubli | 1:808150b7aebc | 383 | wait(1); |
joe_feubli | 1:808150b7aebc | 384 | } |
joe_feubli | 1:808150b7aebc | 385 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 386 | break; |
joe_feubli | 1:808150b7aebc | 387 | |
joe_feubli | 1:808150b7aebc | 388 | case 3: |
joe_feubli | 1:808150b7aebc | 389 | if (MyEpos2.GetActualPos() > 280000 and MyEpos4.GetActualPos() < -280000){ |
joe_feubli | 1:808150b7aebc | 390 | MyEpos1.MoveAbsolute(318000,500*speed,100*speed,100*speed); //Panel Aussen Links |
joe_feubli | 1:808150b7aebc | 391 | MyEpos3.MoveAbsolute(-318000,500*speed,100*speed,100*speed); //Panel Aussen Rechts |
joe_feubli | 1:808150b7aebc | 392 | |
joe_feubli | 1:808150b7aebc | 393 | ausfahren_step = 4; |
joe_feubli | 1:808150b7aebc | 394 | wait(1); |
joe_feubli | 1:808150b7aebc | 395 | } |
joe_feubli | 1:808150b7aebc | 396 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 397 | break; |
joe_feubli | 1:808150b7aebc | 398 | |
joe_feubli | 1:808150b7aebc | 399 | case 4: |
joe_feubli | 1:808150b7aebc | 400 | if (MyEpos1.TargetReached()==1 and MyEpos3.TargetReached()==1){ |
joe_feubli | 1:808150b7aebc | 401 | einfahren = true; |
joe_feubli | 1:808150b7aebc | 402 | einfahren_step = 1; |
joe_feubli | 1:808150b7aebc | 403 | wait(1); |
joe_feubli | 1:808150b7aebc | 404 | } |
joe_feubli | 1:808150b7aebc | 405 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 406 | break; |
joe_feubli | 1:808150b7aebc | 407 | |
joe_feubli | 1:808150b7aebc | 408 | |
joe_feubli | 1:808150b7aebc | 409 | |
joe_feubli | 1:808150b7aebc | 410 | }//switch (ausfahren_step) |
joe_feubli | 1:808150b7aebc | 411 | }//if (einfahren == false) |
joe_feubli | 1:808150b7aebc | 412 | |
joe_feubli | 1:808150b7aebc | 413 | if (einfahren == true){ |
joe_feubli | 1:808150b7aebc | 414 | ausfahren_step = 1; |
joe_feubli | 1:808150b7aebc | 415 | switch (einfahren_step){ |
joe_feubli | 1:808150b7aebc | 416 | case 1: |
joe_feubli | 1:808150b7aebc | 417 | MyEpos1.MoveAbsolute(10000,500*speed,100*speed,100*speed); //Panel Aussen Links |
joe_feubli | 1:808150b7aebc | 418 | MyEpos3.MoveAbsolute(-10000,500*speed,100*speed,100*speed); //Panel Aussen Rechts |
joe_feubli | 1:808150b7aebc | 419 | einfahren_step = 2; |
joe_feubli | 1:808150b7aebc | 420 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 421 | break; |
joe_feubli | 1:808150b7aebc | 422 | |
joe_feubli | 1:808150b7aebc | 423 | case 2: |
joe_feubli | 1:808150b7aebc | 424 | if (MyEpos1.GetActualPos() < 20000 and MyEpos3.GetActualPos() > -20000){ |
joe_feubli | 1:808150b7aebc | 425 | MyEpos1.MoveAbsolute(0,500,100,100); //Panel Aussen Links |
joe_feubli | 1:808150b7aebc | 426 | MyEpos3.MoveAbsolute(0,500,100,100); //Panel Aussen Rechts |
joe_feubli | 1:808150b7aebc | 427 | MyEpos2.MoveAbsolute(0,500*speed,100*speed,100*speed); //Panel Innen Links |
joe_feubli | 1:808150b7aebc | 428 | MyEpos4.MoveAbsolute(0,500*speed,100*speed,100*speed); //Panel Innen Rechts |
joe_feubli | 1:808150b7aebc | 429 | einfahren_step = 3; |
joe_feubli | 1:808150b7aebc | 430 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 431 | } |
joe_feubli | 1:808150b7aebc | 432 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 433 | break; |
joe_feubli | 1:808150b7aebc | 434 | |
joe_feubli | 1:808150b7aebc | 435 | case 3: |
joe_feubli | 1:808150b7aebc | 436 | if (MyEpos2.TargetReached()==1 and MyEpos4.TargetReached()==1){ |
joe_feubli | 1:808150b7aebc | 437 | MyEpos5.MoveAbsolute(1000,500*speed,100*speed,100*speed); //Kopf |
joe_feubli | 1:808150b7aebc | 438 | MyEpos1.Power(0); |
joe_feubli | 1:808150b7aebc | 439 | MyEpos2.Power(0); |
joe_feubli | 1:808150b7aebc | 440 | MyEpos3.Power(0); |
joe_feubli | 1:808150b7aebc | 441 | MyEpos4.Power(0); |
joe_feubli | 1:808150b7aebc | 442 | einfahren_step = 4; |
joe_feubli | 1:808150b7aebc | 443 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 444 | } |
joe_feubli | 1:808150b7aebc | 445 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 446 | break; |
joe_feubli | 1:808150b7aebc | 447 | |
joe_feubli | 1:808150b7aebc | 448 | case 4: |
joe_feubli | 1:808150b7aebc | 449 | if (MyEpos5.TargetReached()==1){ |
joe_feubli | 1:808150b7aebc | 450 | einfahren = false; |
joe_feubli | 1:808150b7aebc | 451 | current_step = 2; |
joe_feubli | 1:808150b7aebc | 452 | wait(1); |
joe_feubli | 1:808150b7aebc | 453 | MyEpos5.Power(0); |
joe_feubli | 1:808150b7aebc | 454 | } |
joe_feubli | 1:808150b7aebc | 455 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 456 | break; |
joe_feubli | 1:808150b7aebc | 457 | |
joe_feubli | 1:808150b7aebc | 458 | }//switch(einfahren_step) |
joe_feubli | 1:808150b7aebc | 459 | }//if einfahren == true) |
joe_feubli | 1:808150b7aebc | 460 | led3 = 0; |
joe_feubli | 1:808150b7aebc | 461 | break; |
joe_feubli | 1:808150b7aebc | 462 | |
joe_feubli | 1:808150b7aebc | 463 | case 5://USV: |
joe_feubli | 1:808150b7aebc | 464 | pc.printf("USV\n"); |
joe_feubli | 1:808150b7aebc | 465 | led4 = 1; |
joe_feubli | 1:808150b7aebc | 466 | MyEpos5.SetDigOut(4,1); |
joe_feubli | 1:808150b7aebc | 467 | switch (usv_step){ |
joe_feubli | 1:808150b7aebc | 468 | case 0: |
joe_feubli | 1:808150b7aebc | 469 | pc.printf("USV 0\n"); |
joe_feubli | 1:808150b7aebc | 470 | zaehler_usv = zaehler_usv + 1; |
joe_feubli | 1:808150b7aebc | 471 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 472 | MyEpos1.Power(1); |
joe_feubli | 1:808150b7aebc | 473 | MyEpos2.Power(1); |
joe_feubli | 1:808150b7aebc | 474 | MyEpos3.Power(1); |
joe_feubli | 1:808150b7aebc | 475 | MyEpos4.Power(1); |
joe_feubli | 1:808150b7aebc | 476 | MyEpos5.Power(1); |
joe_feubli | 1:808150b7aebc | 477 | MyEpos6.Power(1); |
joe_feubli | 1:808150b7aebc | 478 | MyEpos7.Power(1); |
joe_feubli | 1:808150b7aebc | 479 | usv_step = 1; |
joe_feubli | 1:808150b7aebc | 480 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 481 | break; |
joe_feubli | 1:808150b7aebc | 482 | |
joe_feubli | 1:808150b7aebc | 483 | case 1: |
joe_feubli | 1:808150b7aebc | 484 | pc.printf("USV 1\n"); |
joe_feubli | 1:808150b7aebc | 485 | MyEpos1.MoveAbsolute(2000,500,500,500); //Panel_Aussen_Links |
joe_feubli | 1:808150b7aebc | 486 | MyEpos3.MoveAbsolute(-2000,500,500,500); //Panel_Aussen_Rechts |
joe_feubli | 1:808150b7aebc | 487 | wait(0.1); |
segundo | 0:10508306e920 | 488 | |
joe_feubli | 1:808150b7aebc | 489 | if (MyEpos1.TargetReached()==1 and MyEpos3.TargetReached()==1){ |
joe_feubli | 1:808150b7aebc | 490 | usv_step = 2; |
joe_feubli | 1:808150b7aebc | 491 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 492 | } |
joe_feubli | 1:808150b7aebc | 493 | break; |
joe_feubli | 1:808150b7aebc | 494 | |
joe_feubli | 1:808150b7aebc | 495 | case 2: |
joe_feubli | 1:808150b7aebc | 496 | pc.printf("USV 2\n"); |
joe_feubli | 1:808150b7aebc | 497 | MyEpos1.MoveAbsolute(0,500,100,100); //Panel Aussen Links |
joe_feubli | 1:808150b7aebc | 498 | MyEpos3.MoveAbsolute(0,500,100,100); //Panel Aussen Links |
joe_feubli | 1:808150b7aebc | 499 | |
joe_feubli | 1:808150b7aebc | 500 | MyEpos2.MoveAbsolute(0,500,500,500); //Panel_Innen_Links |
joe_feubli | 1:808150b7aebc | 501 | MyEpos4.MoveAbsolute(0,500,500,500); //Panel_Innen_Links |
joe_feubli | 1:808150b7aebc | 502 | wait(0.1); |
segundo | 0:10508306e920 | 503 | |
joe_feubli | 1:808150b7aebc | 504 | if (MyEpos2.TargetReached()==1 and MyEpos4.TargetReached()==1 /*and MyEpos6.TargetReached()==1*/){ |
joe_feubli | 1:808150b7aebc | 505 | usv_step = 3; |
joe_feubli | 1:808150b7aebc | 506 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 507 | } |
joe_feubli | 1:808150b7aebc | 508 | break; |
joe_feubli | 1:808150b7aebc | 509 | |
joe_feubli | 1:808150b7aebc | 510 | case 3: |
joe_feubli | 1:808150b7aebc | 511 | pc.printf("USV 3\n"); |
joe_feubli | 1:808150b7aebc | 512 | MyEpos5.MoveAbsolute(0,800,500,500); //Kopf |
joe_feubli | 1:808150b7aebc | 513 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 514 | if (MyEpos5.TargetReached()==1){ |
joe_feubli | 1:808150b7aebc | 515 | usv_step = 4; |
joe_feubli | 1:808150b7aebc | 516 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 517 | } |
joe_feubli | 1:808150b7aebc | 518 | break; |
joe_feubli | 1:808150b7aebc | 519 | |
joe_feubli | 1:808150b7aebc | 520 | case 4: |
joe_feubli | 1:808150b7aebc | 521 | pc.printf("USV 4\n"); |
joe_feubli | 1:808150b7aebc | 522 | MyEpos1.Power(0); |
joe_feubli | 1:808150b7aebc | 523 | MyEpos2.Power(0); |
joe_feubli | 1:808150b7aebc | 524 | MyEpos3.Power(0); |
joe_feubli | 1:808150b7aebc | 525 | MyEpos4.Power(0); |
joe_feubli | 1:808150b7aebc | 526 | MyEpos5.Power(0); |
joe_feubli | 1:808150b7aebc | 527 | MyEpos6.Power(0); |
joe_feubli | 1:808150b7aebc | 528 | MyEpos7.Power(0); |
joe_feubli | 1:808150b7aebc | 529 | |
joe_feubli | 1:808150b7aebc | 530 | FILE *fd_write = fopen("/local/zaehler.txt", "w"); // Open "out.txt" on the local file system for writing |
joe_feubli | 1:808150b7aebc | 531 | if (fd_write) { |
joe_feubli | 1:808150b7aebc | 532 | fprintf(fd_write, "Buzzer Zähler = %d\n Fehler Zähler = %d\n Mails Zähler = %d\n", zaehler_buzzer, zaehler_usv, zaehler_mails); |
joe_feubli | 1:808150b7aebc | 533 | fclose(fd_write); |
joe_feubli | 1:808150b7aebc | 534 | } |
joe_feubli | 1:808150b7aebc | 535 | current_step = 8; //email versenden |
joe_feubli | 1:808150b7aebc | 536 | usv_step = 5; |
joe_feubli | 1:808150b7aebc | 537 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 538 | break; |
joe_feubli | 1:808150b7aebc | 539 | |
joe_feubli | 1:808150b7aebc | 540 | case 5: |
joe_feubli | 1:808150b7aebc | 541 | pc.printf("USV 5\n"); |
joe_feubli | 1:808150b7aebc | 542 | if(buffering == 1){ |
joe_feubli | 1:808150b7aebc | 543 | led3 = 1; |
joe_feubli | 1:808150b7aebc | 544 | } else { |
joe_feubli | 1:808150b7aebc | 545 | led3 = 0; |
joe_feubli | 1:808150b7aebc | 546 | Power_ein = true; |
joe_feubli | 1:808150b7aebc | 547 | current_step=1; |
joe_feubli | 1:808150b7aebc | 548 | usv_step=0; |
joe_feubli | 1:808150b7aebc | 549 | ausfahren_step=1; |
joe_feubli | 1:808150b7aebc | 550 | einfahren_step=1; |
joe_feubli | 1:808150b7aebc | 551 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 552 | break; |
joe_feubli | 1:808150b7aebc | 553 | } |
joe_feubli | 1:808150b7aebc | 554 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 555 | break; |
joe_feubli | 1:808150b7aebc | 556 | }//switch(usv_step) |
joe_feubli | 1:808150b7aebc | 557 | led4 = 0; |
joe_feubli | 1:808150b7aebc | 558 | break; |
joe_feubli | 1:808150b7aebc | 559 | |
joe_feubli | 1:808150b7aebc | 560 | case 6: //Fehler Bohrer/Bohrgestell |
joe_feubli | 1:808150b7aebc | 561 | error_sending = true; |
joe_feubli | 1:808150b7aebc | 562 | pc.printf("Fehler RESET Bohrer\n"); |
joe_feubli | 1:808150b7aebc | 563 | MyEpos5.MoveVelocity(0, 500, 500); |
joe_feubli | 1:808150b7aebc | 564 | MyEpos6.MoveVelocity(0, 500, 500); |
joe_feubli | 1:808150b7aebc | 565 | wait(3); |
joe_feubli | 1:808150b7aebc | 566 | MyEpos5.Reset(); |
joe_feubli | 1:808150b7aebc | 567 | MyEpos5.Power(1); |
joe_feubli | 1:808150b7aebc | 568 | MyEpos6.Reset(); |
joe_feubli | 1:808150b7aebc | 569 | MyEpos6.Power(1); |
joe_feubli | 1:808150b7aebc | 570 | node1_homed = false; |
joe_feubli | 1:808150b7aebc | 571 | node2_homed = false; |
joe_feubli | 1:808150b7aebc | 572 | current_step = 8; |
joe_feubli | 1:808150b7aebc | 573 | break; |
joe_feubli | 1:808150b7aebc | 574 | |
joe_feubli | 1:808150b7aebc | 575 | case 7: |
joe_feubli | 1:808150b7aebc | 576 | error_sending = true; |
joe_feubli | 1:808150b7aebc | 577 | pc.printf("Fehler RESET2\n"); |
joe_feubli | 1:808150b7aebc | 578 | wait(3); |
joe_feubli | 1:808150b7aebc | 579 | MyEpos1.Reset(); |
joe_feubli | 1:808150b7aebc | 580 | MyEpos1.Power(1); |
joe_feubli | 1:808150b7aebc | 581 | MyEpos2.Reset(); |
joe_feubli | 1:808150b7aebc | 582 | MyEpos2.Power(1); |
joe_feubli | 1:808150b7aebc | 583 | MyEpos3.Reset(); |
joe_feubli | 1:808150b7aebc | 584 | MyEpos3.Power(1); |
joe_feubli | 1:808150b7aebc | 585 | MyEpos4.Reset(); |
joe_feubli | 1:808150b7aebc | 586 | MyEpos4.Power(1); |
joe_feubli | 1:808150b7aebc | 587 | MyEpos5.Reset(); |
joe_feubli | 1:808150b7aebc | 588 | MyEpos5.Power(1); |
joe_feubli | 1:808150b7aebc | 589 | pc.printf("Fehler RESET3\n"); |
joe_feubli | 1:808150b7aebc | 590 | epos1_homing = false; |
joe_feubli | 1:808150b7aebc | 591 | epos3_homing = false; |
joe_feubli | 1:808150b7aebc | 592 | node1_homed = false; |
joe_feubli | 1:808150b7aebc | 593 | node2_homed = false; |
joe_feubli | 1:808150b7aebc | 594 | node3_homed = false; |
joe_feubli | 1:808150b7aebc | 595 | node4_homed = false; |
joe_feubli | 1:808150b7aebc | 596 | node5_homed = false; |
joe_feubli | 1:808150b7aebc | 597 | Power_ein = true; |
joe_feubli | 1:808150b7aebc | 598 | if(MyEpos2.GetActualPos() < 100000 or MyEpos4.GetActualPos() > -100000){ |
joe_feubli | 1:808150b7aebc | 599 | pc.printf("Fehler RESET4\n"); |
joe_feubli | 1:808150b7aebc | 600 | if (MyEpos1.GetError() == 0 and MyEpos3.GetError() == 0){ |
joe_feubli | 1:808150b7aebc | 601 | MyEpos1.Homing(); |
joe_feubli | 1:808150b7aebc | 602 | MyEpos3.Homing(); |
joe_feubli | 1:808150b7aebc | 603 | } |
joe_feubli | 1:808150b7aebc | 604 | MyEpos1.MoveAbsolute(0,500,100,100); |
joe_feubli | 1:808150b7aebc | 605 | MyEpos3.MoveAbsolute(0,500,100,100); |
joe_feubli | 1:808150b7aebc | 606 | MyEpos2.MoveAbsolute(0,500,100,100); //Panel Innen Links |
joe_feubli | 1:808150b7aebc | 607 | MyEpos4.MoveAbsolute(0,500,100,100); //Panel Innen Rechts |
joe_feubli | 1:808150b7aebc | 608 | while (MyEpos2.TargetReached() != 1 or MyEpos4.TargetReached() != 1){ |
joe_feubli | 1:808150b7aebc | 609 | pc.printf("Fehler RESET5\n"); |
joe_feubli | 1:808150b7aebc | 610 | if(MyEpos2.GetError() != 0 or MyEpos4.GetError() != 1){ |
joe_feubli | 1:808150b7aebc | 611 | pc.printf("Fehler RESET6\n"); |
joe_feubli | 1:808150b7aebc | 612 | //wait(0.1); |
joe_feubli | 1:808150b7aebc | 613 | current_step = 8; |
joe_feubli | 1:808150b7aebc | 614 | break; |
joe_feubli | 1:808150b7aebc | 615 | } |
joe_feubli | 1:808150b7aebc | 616 | //wait(0.1); |
joe_feubli | 1:808150b7aebc | 617 | } |
joe_feubli | 1:808150b7aebc | 618 | } |
joe_feubli | 1:808150b7aebc | 619 | current_step = 8; |
joe_feubli | 1:808150b7aebc | 620 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 621 | pc.printf("Fehler RESET7\n"); |
segundo | 0:10508306e920 | 622 | |
joe_feubli | 1:808150b7aebc | 623 | break; |
joe_feubli | 1:808150b7aebc | 624 | |
joe_feubli | 1:808150b7aebc | 625 | case 8: |
joe_feubli | 1:808150b7aebc | 626 | if (error_mails < 3) { |
joe_feubli | 1:808150b7aebc | 627 | zaehler_mails = zaehler_mails + 1; |
joe_feubli | 1:808150b7aebc | 628 | error_mails = error_mails +1; |
joe_feubli | 1:808150b7aebc | 629 | time_t ctTime = time(NULL); |
joe_feubli | 1:808150b7aebc | 630 | ctTime = ctTime+ 7200; |
joe_feubli | 1:808150b7aebc | 631 | msg.setFrom(FROM_ADDRESS); |
joe_feubli | 1:808150b7aebc | 632 | msg.addTo(TO_ADDRESS); |
joe_feubli | 1:808150b7aebc | 633 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 634 | msg.printf("Subject: mbed at %s", ctime(&ctTime)); |
joe_feubli | 1:808150b7aebc | 635 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 636 | msg.printf("Resetversuche: %d\n", error_mails); |
joe_feubli | 1:808150b7aebc | 637 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 638 | msg.printf("Resetversuche: %d\n", error_mails); |
joe_feubli | 1:808150b7aebc | 639 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 640 | msg.printf("Errorcode Motor 1: %d\n", ErrorState1); |
joe_feubli | 1:808150b7aebc | 641 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 642 | msg.printf("Errorcode Motor 2: %d\n", ErrorState2); |
joe_feubli | 1:808150b7aebc | 643 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 644 | msg.printf("Errorcode Motor 3: %d\n", ErrorState3); |
joe_feubli | 1:808150b7aebc | 645 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 646 | msg.printf("Errorcode Motor 4: %d\n", ErrorState4); |
joe_feubli | 1:808150b7aebc | 647 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 648 | msg.printf("Errorcode Motor 5: %d\n", ErrorState5); |
joe_feubli | 1:808150b7aebc | 649 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 650 | msg.printf("Errorcode Motor 6: %d\n", ErrorState6); |
joe_feubli | 1:808150b7aebc | 651 | wait_ms(10); |
joe_feubli | 1:808150b7aebc | 652 | msg.printf("Errorcode Motor 7: %d\n\n", ErrorState7); |
joe_feubli | 1:808150b7aebc | 653 | msg.printf("Zähler Buzzer: %d\n", zaehler_buzzer); |
joe_feubli | 1:808150b7aebc | 654 | msg.printf("Zähler USV: %d\n", zaehler_usv); |
joe_feubli | 1:808150b7aebc | 655 | msg.printf("Zähler Error-Mails: %d\n", zaehler_mails); |
joe_feubli | 1:808150b7aebc | 656 | wait(0.1); |
joe_feubli | 1:808150b7aebc | 657 | msg.printf("\n"); |
joe_feubli | 1:808150b7aebc | 658 | msg.printf("Liebe Grüsse\n"); |
joe_feubli | 1:808150b7aebc | 659 | msg.printf("mbed\n"); |
joe_feubli | 1:808150b7aebc | 660 | printf("Send result %d\n", smtp.send(&msg)); |
joe_feubli | 1:808150b7aebc | 661 | printf("Last response | %s", smtp.getLastResponse().c_str()); |
joe_feubli | 1:808150b7aebc | 662 | msg.clearContent(); |
joe_feubli | 1:808150b7aebc | 663 | ErrorState1 = 0; |
joe_feubli | 1:808150b7aebc | 664 | ErrorState2 = 0; |
joe_feubli | 1:808150b7aebc | 665 | ErrorState3 = 0; |
joe_feubli | 1:808150b7aebc | 666 | ErrorState4 = 0; |
joe_feubli | 1:808150b7aebc | 667 | ErrorState5 = 0; |
joe_feubli | 1:808150b7aebc | 668 | ErrorState6 = 0; |
joe_feubli | 1:808150b7aebc | 669 | ErrorState7 = 0; |
joe_feubli | 1:808150b7aebc | 670 | FILE *fd_write = fopen("/local/zaehler.txt", "w"); // Open "out.txt" on the local file system for writing |
joe_feubli | 1:808150b7aebc | 671 | if (fd_write) { |
joe_feubli | 1:808150b7aebc | 672 | fprintf(fd_write, "Buzzer Zähler = %d\n Fehler Zähler = %d\n Mails Zähler = %d\n", zaehler_buzzer, zaehler_usv, zaehler_mails); |
joe_feubli | 1:808150b7aebc | 673 | fclose(fd_write); |
joe_feubli | 1:808150b7aebc | 674 | } |
joe_feubli | 1:808150b7aebc | 675 | pc.printf("emailing ENDE\n"); |
joe_feubli | 1:808150b7aebc | 676 | }//if (error_mails < 3) |
joe_feubli | 1:808150b7aebc | 677 | usv_step = 5; |
joe_feubli | 1:808150b7aebc | 678 | current_step = 5; |
joe_feubli | 1:808150b7aebc | 679 | error_sending = false; |
joe_feubli | 1:808150b7aebc | 680 | break; |
joe_feubli | 1:808150b7aebc | 681 | }//switch (current_step) |
joe_feubli | 1:808150b7aebc | 682 | }//while |
joe_feubli | 1:808150b7aebc | 683 | }//main |
segundo | 0:10508306e920 | 684 |