emi2.cpp
1 /* 2 EIBD eib bus access and management daemon 3 Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #include "emi2.h" 21 22 #include "emi.h" 23 24 EMI2Driver::EMI2Driver (LowLevelIface* c, IniSectionPtr& s, LowLevelDriver *i) : EMI_Common(c,s,i) 25 { 26 t->setAuxName("EMI2"); 27 sendLocal_done.set<EMI2Driver,&EMI2Driver::sendLocal_done_cb>(this); 28 reset_timer.set<EMI2Driver,&EMI2Driver::reset_timer_cb>(this); 29 } 30 31 void 32 EMI2Driver::sendLocal_done_cb(bool success) 33 { 34 if (!success || sendLocal_done_next == N_bad) 35 { 36 stop(true); 37 LowLevelFilter::stop(true); 38 } 39 else if (sendLocal_done_next == N_down) 40 LowLevelFilter::stop(false); 41 else if (sendLocal_done_next == N_up) 42 LowLevelFilter::started(); 43 else if (sendLocal_done_next == N_open) 44 { 45 sendLocal_done_next = N_up; 46 const uint8_t t2[] = { 0xa9, 0x00, 0x18, 0x34, 0x56, 0x78, 0x0a }; 47 send_Local (CArray (t2, sizeof (t2)),1); 48 } 49 else if (sendLocal_done_next == N_enter) 50 { 51 sendLocal_done_next = N_up; 52 const uint8_t t2[] = { 0xa9, 0x90, 0x18, 0x34, 0x45, 0x67, 0x8a }; 53 send_Local (CArray (t2, sizeof (t2)),1); 54 } 55 56 } 57 58 void 59 EMI2Driver::cmdEnterMonitor () 60 { 61 sendLocal_done_next = N_enter; 62 const uint8_t t1[] = { 0xa9, 0x1E, 0x12, 0x34, 0x56, 0x78, 0x9a }; 63 send_Local (CArray (t1, sizeof (t1)),1); 64 } 65 66 void 67 EMI2Driver::cmdLeaveMonitor () 68 { 69 if (wait_confirm_low) 70 { 71 sendLocal_done_next = N_want_leave; 72 return; 73 } 74 sendLocal_done_next = N_down; 75 uint8_t t[] = { 0xa9, 0x1E, 0x12, 0x34, 0x56, 0x78, 0x9a }; 76 send_Local (CArray (t, sizeof (t)),1); 77 } 78 79 void 80 EMI2Driver::cmdOpen () 81 { 82 sendLocal_done_next = N_open; 83 const uint8_t t1[] = { 0xa9, 0x1E, 0x12, 0x34, 0x56, 0x78, 0x9a }; 84 send_Local (CArray (t1, sizeof (t1)),1); 85 } 86 87 void 88 EMI2Driver::cmdClose () 89 { 90 if (wait_confirm_low) 91 { 92 sendLocal_done_next = N_want_close; 93 return; 94 } 95 sendLocal_done_next = N_down; 96 uint8_t t[] = { 0xa9, 0x1E, 0x12, 0x34, 0x56, 0x78, 0x9a }; 97 send_Local (CArray (t, sizeof (t)),1); 98 } 99 100 void EMI2Driver::started() 101 { 102 reset_ack_wait = true; 103 reset_timer.start(0.5, 0); 104 sendReset(); 105 } 106 107 void EMI2Driver::reset_timer_cb(ev::timer&, int) 108 { 109 ERRORPRINTF(t, E_ERROR | 57, "reset timed out"); 110 stop(true); 111 } 112 113 void EMI2Driver::do_send_Next() 114 { 115 if (reset_ack_wait) 116 { 117 reset_ack_wait = false; 118 reset_timer.stop(); 119 EMI_Common::started(); 120 } 121 else if (sendLocal_done_next == N_want_close) 122 { 123 wait_confirm_low = false; 124 cmdClose(); 125 } 126 else if (sendLocal_done_next == N_want_leave) 127 { 128 wait_confirm_low = false; 129 cmdLeaveMonitor(); 130 } 131 else 132 EMI_Common::do_send_Next(); 133 } 134 135 const uint8_t * 136 EMI2Driver::getIndTypes() const 137 { 138 static const uint8_t indTypes[] = { 0x2E, 0x29, 0x2B }; 139 return indTypes; 140 } 141