Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
CtrlBridge.cpp
00001 00002 #include "CtrlBridge.h" 00003 00004 CtrlBridge *CtrlBridge::uniqueInstance; 00005 00006 /** 00007 * @brief Constructeur priver appler par la fonction getInstance() 00008 */ 00009 CtrlBridge::CtrlBridge() 00010 : m_Memory(), ssc32(PA_9, PA_10), 00011 spiLowSpeed (SPI_LOW_MOSI, SPI_LOW_MISO, SPI_LOW_SCK, SPI_LOW_DEMUXA, SPI_LOW_DEMUXB, SPI_LOW_DEMUXC, SPI_LOW_DEMUXD, SPI_LOW_CS), 00012 spiHighSpeed(SPI_HIGH_MOSI, SPI_HIGH_MISO, SPI_HIGH_SCK, SPI_HIGH_DEMUXA, SPI_HIGH_DEMUXB, SPI_HIGH_DEMUXC, SPI_HIGH_DEMUXD, SPI_HIGH_CS), 00013 pc(SERIAL_TX, SERIAL_RX) 00014 { 00015 //faire en sorte d'init SPI speed ici 00016 m_regPortUse=0; 00017 m_regPortLost=0; 00018 spiLowSpeed.format(8,0); 00019 spiLowSpeed.frequency(/*10000*/10000); 00020 } 00021 00022 CtrlBridge::~CtrlBridge() 00023 { 00024 } 00025 00026 /** 00027 * @brief Methode permetant une seul instance de la classe 00028 * @return Retourne l'unique instance de la classe 00029 */ 00030 CtrlBridge *CtrlBridge::getInstance() 00031 { 00032 if(!uniqueInstance) { 00033 uniqueInstance = new CtrlBridge(); 00034 } 00035 return uniqueInstance; 00036 } 00037 00038 bool CtrlBridge::initCom(void) 00039 { 00040 //char positionInitial; 00041 bool portUse; 00042 unsigned char adresse; 00043 string flag; 00044 string data; 00045 Module* templateModule ; 00046 templateModule= new Module; 00047 00048 debug(DEBUG_INITMODULE, "\n\rInit::debut"); 00049 //flag.clear(); 00050 //flag.append(1,Request_Init_Info); 00051 //positionInitial = spiLowSpeed.next_demux(); 00052 for(char i=0; i != 15; i++) { 00053 debug(DEBUG_INITMODULE, "\n\r -Debut de boucle :%d ", i); 00054 //flag = Request_Init_Info; 00055 //portUse = spiLowSpeed.send(i,0,&flag,&data); 00056 //if( portUse ) { 00057 // m_regPortUse|=(1<< i); 00058 00059 do { 00060 debug(DEBUG_INITMODULE," IN"); 00061 flag = Request_Init_Info; 00062 adresse = m_Memory.getAdressDispo(0x80);//80 parce que cest le conecteur droit 00063 debug(DEBUG_INITMODULE, "\n\r -addresse use :%d", adresse); 00064 data.clear(); 00065 data.append(4,1); 00066 portUse = spiLowSpeed.send(i,adresse,&flag,&data); 00067 debug(DEBUG_INITMODULE, "\n\r -Port use result :%d", portUse); 00068 00069 if((flag.empty()) && (data.empty()))// data vide 00070 portUse=false; 00071 00072 if( portUse ) { 00073 debug(DEBUG_INITMODULE, "\n\r -flag get: "); 00074 for (unsigned j=0; j<flag.length(); j++) debug(DEBUG_INITMODULE, "%02X,",flag.at(j)); 00075 debug(DEBUG_INITMODULE, "\n\r -data get: "); 00076 for (unsigned j=0; j<data.length(); j++) debug(DEBUG_INITMODULE, "%02X,",data.at(j)); 00077 00078 00079 m_regPortUse|=(1<< i); 00080 debug(DEBUG_INITMODULE, "\n\r -Port use :%d", m_regPortUse); 00081 00082 templateModule->regA = adresse; 00083 debug(DEBUG_INITMODULE, "\n\r -Adrr use :%d", adresse); 00084 00085 templateModule->regB = (spiLowSpeed.get_demux()<<4)+(data[0]&0x0F); 00086 templateModule->regB |= data[0]; 00087 debug(DEBUG_INITMODULE, "\n\r -regB use :%02X", templateModule->regB); 00088 00089 templateModule->regC = data[1]; 00090 debug(DEBUG_INITMODULE, "\n\r -regC use :%02X", templateModule->regC); 00091 00092 templateModule->regD = data[2]; 00093 debug(DEBUG_INITMODULE, "\n\r -regD use :%02X", templateModule->regD); 00094 00095 switch(templateModule->regD >>6) { 00096 case 1://Capteur 00097 debug(DEBUG_INITMODULE, "\n\r -Add Capteur"); 00098 m_Memory.addCapteur(*templateModule); 00099 break; 00100 00101 case 2://Actionneur 00102 debug(DEBUG_INITMODULE, "\n\r -Add Actionneur"); 00103 m_Memory.addActioneur(*templateModule); 00104 break; 00105 00106 00107 case 3://Memoire 00108 debug(DEBUG_INITMODULE, "\n\r -Add Memoire"); 00109 m_Memory.addMemoire(*templateModule); 00110 break; 00111 00112 default: 00113 break; 00114 } 00115 00116 if(flag[0] == SLAVE_NO_MORE_EMPTY_ADDR_MODULE) 00117 portUse=false; 00118 00119 } 00120 debug(DEBUG_INITMODULE," OUT"); 00121 } while(portUse); 00122 debug(DEBUG_INITMODULE, "\n\r -Fin de boucle :%d", i); 00123 } 00124 00125 if(templateModule) 00126 delete templateModule; 00127 00128 debug(DEBUG_INITMODULE, "\n\rInit::Fin"); 00129 return true; 00130 } 00131 00132 bool CtrlBridge::tryComPort(char portID) 00133 { 00134 if(portID <= (char)-1)portID=0; 00135 if(portID > 15)portID=15; 00136 string flag; 00137 flag.clear(); 00138 string data; 00139 data.clear(); 00140 return spiLowSpeed.send(portID,0,&flag,&data); 00141 } 00142 00143 bool CtrlBridge::send( const unsigned char &adresse,string &flag, string &data) 00144 { 00145 debug(DEBUF_SEND, "\n\rSend::Debut"); 00146 bool result = false; 00147 Module moduleRequested; 00148 if(m_Memory.isAdresseValide(adresse,moduleRequested)) { 00149 00150 if(adresse&0x80) 00151 { 00152 debug(DEBUF_SEND, "\n\rPointeur SPI: %d",&spiLowSpeed); 00153 //debug(DEBUF_SEND, "\n\rPointeur SPI: %p",spiLowSpeed); 00154 result = spiLowSpeed.send(moduleRequested.regB>>4,adresse,&flag,&data); 00155 } 00156 else 00157 result = spiHighSpeed.send(moduleRequested.regB>>4,adresse,&flag,&data); 00158 //result = true; 00159 } 00160 debug(DEBUF_SEND, "\n\rSend::Fin"); 00161 return result; 00162 } 00163 00164 string CtrlBridge::findModule(const char &peripheriqueID, const char &type, const char &sousType, const char &posSpatial) 00165 { 00166 debug(DEBUF_FINDMODULE, "\n\rFindModule::Debut"); 00167 string result; 00168 int maxSize; 00169 Module moduleScan; 00170 bool goodModule; 00171 00172 debug(DEBUF_FINDMODULE, "\n\r -peripheriqueID: %02X",peripheriqueID); 00173 debug(DEBUF_FINDMODULE, "\n\r -type: %02X",type); 00174 debug(DEBUF_FINDMODULE, "\n\r -sousType: %02X",sousType); 00175 debug(DEBUF_FINDMODULE, "\n\r -posSpatial: %02X",posSpatial); 00176 00177 debug(DEBUF_FINDMODULE, "\n\r -Debut scan Actioneur"); 00178 maxSize = m_Memory.getSizeActioneur(); 00179 debug(DEBUF_FINDMODULE, "\n\r -MaxSize: %02d",maxSize); 00180 goodModule = true; 00181 moduleScan= m_Memory.firstActioneur(); 00182 00183 for(int i=0; i < maxSize; i++) { 00184 if((peripheriqueID != 0) && (peripheriqueID != moduleScan.regB>>4)){ 00185 goodModule =false; 00186 debug(DEBUF_FINDMODULE, "\n\r -peripheriqueID: %02d == moduleScan.regB>>4: %02d",peripheriqueID,moduleScan.regB>>4); 00187 } 00188 else if((type != 0) && (type != moduleScan.regD>>6)){ 00189 goodModule =false; 00190 debug(DEBUF_FINDMODULE, "\n\r -type: %02d == moduleScan.regD>>6: %02d",type,moduleScan.regD>>6); 00191 } 00192 else if((sousType != 0) && (sousType != (moduleScan.regD & 0x3F))){ 00193 goodModule =false; 00194 debug(DEBUF_FINDMODULE, "\n\r -sousType: %02d == (moduleScan.regD & 0x3F): %02d",sousType,(moduleScan.regD & 0x3F)); 00195 } 00196 else if((posSpatial != 0) && (posSpatial != (moduleScan.regC & 0x3F))){ 00197 goodModule =false; 00198 debug(DEBUF_FINDMODULE, "\n\r -posSpatial: %02d == (moduleScan.regC & 0x3F): %02d",posSpatial,(moduleScan.regC & 0x3F)); 00199 } 00200 00201 if(goodModule){ 00202 result.append(1,moduleScan.regA); 00203 debug(DEBUF_FINDMODULE, "\n\r -Find one!"); 00204 } 00205 if((goodModule)&&(peripheriqueID != 0) && (peripheriqueID != moduleScan.regB>>4)) goodModule =false; 00206 00207 moduleScan= m_Memory.nextActioneur(); 00208 } 00209 debug(DEBUF_FINDMODULE, "\n\r -Fin scan Actioneur"); 00210 //debug(DEBUF_FINDMODULE, "\n\r -Result size: %0i",result.size()); 00211 debug(DEBUF_FINDMODULE, "\n\r -Debut scan Capteur"); 00212 00213 maxSize = m_Memory.getSizeCapteur(); 00214 debug(DEBUF_FINDMODULE, "\n\r -MaxSize: %02d",maxSize); 00215 00216 moduleScan= m_Memory.firstCapteur(); 00217 00218 for(int i=0; i < maxSize; i++) { 00219 goodModule = true; 00220 debug(DEBUF_FINDMODULE, "\n\r -adresse: %02x",moduleScan.regA); 00221 debug(DEBUF_FINDMODULE, "\n\r -peripheriqueID: %02d == moduleScan.regB>>4: %02d",peripheriqueID,moduleScan.regB>>4); 00222 debug(DEBUF_FINDMODULE, "\n\r -type: %02d == moduleScan.regD>>6: %02d",type,moduleScan.regD>>6); 00223 debug(DEBUF_FINDMODULE, "\n\r -sousType: %02d == (moduleScan.regD & 0x3F): %02d",sousType,(moduleScan.regD & 0x3F)); 00224 debug(DEBUF_FINDMODULE, "\n\r -posSpatial: %02d == (moduleScan.regC & 0x3F): %02d",posSpatial,(moduleScan.regC & 0x3F)); 00225 00226 if((peripheriqueID != 0) && (peripheriqueID != moduleScan.regB>>4)){ 00227 goodModule =false; 00228 debug(DEBUF_FINDMODULE, "\n\r -false"); 00229 } 00230 else if((type != 0) && (type != moduleScan.regD>>6)){ 00231 goodModule =false; 00232 debug(DEBUF_FINDMODULE, "\n\r -false"); 00233 } 00234 else if((sousType != 0) && (sousType != (moduleScan.regD & 0x3F))){ 00235 goodModule =false; 00236 debug(DEBUF_FINDMODULE, "\n\r -false"); 00237 } 00238 else if((posSpatial != 0) && (posSpatial != (moduleScan.regC & 0x3F))){ 00239 goodModule =false; 00240 debug(DEBUF_FINDMODULE, "\n\r -false"); 00241 } 00242 00243 if(goodModule){ 00244 result.append(1,moduleScan.regA); 00245 debug(DEBUF_FINDMODULE, "\n\r -Find one!"); 00246 } 00247 if((goodModule)&&(peripheriqueID != 0) && (peripheriqueID != moduleScan.regB>>4)) goodModule =false; 00248 00249 moduleScan= m_Memory.nextCapteur(); 00250 } 00251 debug(DEBUF_FINDMODULE, "\n\r -Fin scan Capteur"); 00252 //debug(DEBUF_FINDMODULE, "\n\r -Result size: %0i",result.size()); 00253 debug(DEBUF_FINDMODULE, "\n\r -Debut scan Memoire"); 00254 00255 maxSize = m_Memory.getSizeMemoire(); 00256 debug(DEBUF_FINDMODULE, "\n\r -MaxSize: %02d",maxSize); 00257 goodModule = true; 00258 moduleScan= m_Memory.firstMemoire(); 00259 00260 for(int i=0; i < maxSize; i++) { 00261 if((peripheriqueID != 0) && (peripheriqueID != moduleScan.regB>>4)){ 00262 goodModule =false; 00263 debug(DEBUF_FINDMODULE, "\n\r -peripheriqueID: %02d == moduleScan.regB>>4: %02d",peripheriqueID,moduleScan.regB>>4); 00264 } 00265 else if((type != 0) && (type != moduleScan.regD>>6)){ 00266 goodModule =false; 00267 debug(DEBUF_FINDMODULE, "\n\r -type: %02d == moduleScan.regD>>6: %02d",type,moduleScan.regD>>6); 00268 } 00269 else if((sousType != 0) && (sousType != (moduleScan.regD & 0x3F))){ 00270 goodModule =false; 00271 debug(DEBUF_FINDMODULE, "\n\r -sousType: %02d == (moduleScan.regD & 0x3F): %02d",sousType,(moduleScan.regD & 0x3F)); 00272 } 00273 else if((posSpatial != 0) && (posSpatial != (moduleScan.regC & 0x3F))){ 00274 goodModule =false; 00275 debug(DEBUF_FINDMODULE, "\n\r -posSpatial: %02d == (moduleScan.regC & 0x3F): %02d",posSpatial,(moduleScan.regC & 0x3F)); 00276 } 00277 00278 if(goodModule){ 00279 result.append(1,moduleScan.regA); 00280 debug(DEBUF_FINDMODULE, "\n\r -Find one!"); 00281 } 00282 if((goodModule)&&(peripheriqueID != 0) && (peripheriqueID != moduleScan.regB>>4)) goodModule =false; 00283 00284 moduleScan= m_Memory.nextMemoire(); 00285 } 00286 debug(DEBUF_FINDMODULE, "\n\r -Fin scan Memoire"); 00287 // debug(DEBUF_FINDMODULE, "\n\r -Result size: %0i",result.size()); 00288 debug(DEBUF_FINDMODULE, "\n\rFindModule::Fin"); 00289 return result; 00290 } 00291 00292 int CtrlBridge::size(const char &peripheriqueID, const char &type, const char &sousType, const char &posSpatial) 00293 { 00294 int result; 00295 string templateString; 00296 00297 templateString = findModule(peripheriqueID,type,sousType,posSpatial); 00298 result = templateString.size()-1;//pas sure si on met -1 00299 return result; 00300 }
Generated on Tue Jul 12 2022 19:04:21 by
1.7.2