![](/media/cache/profiles/4b0986230d9d7aded7f0c24033d221d4.jpg.50x50_q85.jpg)
Programme de contrôle de l'octopode 4DOF, Theraphosa-Salconi.
CtrlBridge
- fonction quelquonque pour communiquer avec les module
- fonction quelquonque pour faire des recherche dans les module dispo
- autre fonction pour jouer avec MemRegistre
Version 1.2.0
- Ajout d'un mode de simulation pour tester le code avec seulement un contrôleur stm32
source/ComSpi.cpp@16:5ea4337d785f, 2015-04-23 (annotated)
- Committer:
- salco
- Date:
- Thu Apr 23 00:53:11 2015 +0000
- Revision:
- 16:5ea4337d785f
- Parent:
- 15:91b3c572d9df
- Child:
- 17:095f670f9c14
toute a foirer faut faire un role back;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
salco | 7:dcfd81d7f93f | 1 | |
salco | 7:dcfd81d7f93f | 2 | #include "ComSpi.h" |
salco | 7:dcfd81d7f93f | 3 | |
salco | 7:dcfd81d7f93f | 4 | ComSpi::ComSpi(PinName mosi, PinName miso, PinName sclk, PinName _unused) : SPI(mosi,miso,sclk,_unused) |
salco | 7:dcfd81d7f93f | 5 | { |
salco | 7:dcfd81d7f93f | 6 | // m_com = new SPI(mosi,miso,sclk,_unused); |
salco | 7:dcfd81d7f93f | 7 | //m_regPortUse=0; |
salco | 7:dcfd81d7f93f | 8 | //m_regPortLost=0; |
salco | 7:dcfd81d7f93f | 9 | m_demuxPos=0; |
salco | 7:dcfd81d7f93f | 10 | demuxIsUse=false; |
salco | 15:91b3c572d9df | 11 | chainedListFirst = 0; |
salco | 15:91b3c572d9df | 12 | chainedListLast = 0; |
salco | 15:91b3c572d9df | 13 | flagSPI.getBytes = 0; |
salco | 15:91b3c572d9df | 14 | //result = 0; |
salco | 15:91b3c572d9df | 15 | counterData = 0; |
salco | 15:91b3c572d9df | 16 | counterTotale = 0; |
salco | 15:91b3c572d9df | 17 | /*for(int i=0;i<MAXTABLE;i++) |
salco | 15:91b3c572d9df | 18 | { |
salco | 15:91b3c572d9df | 19 | bufferSend[i] = 0; |
salco | 15:91b3c572d9df | 20 | bufferReceive[i] = 0; |
salco | 15:91b3c572d9df | 21 | } |
salco | 15:91b3c572d9df | 22 | bufferSend[0] = SYNC;*/ |
salco | 15:91b3c572d9df | 23 | } |
salco | 15:91b3c572d9df | 24 | |
salco | 15:91b3c572d9df | 25 | struct module_t* ComSpi::createModule(void) { |
salco | 15:91b3c572d9df | 26 | if(chainedListFirst == 0) { |
salco | 15:91b3c572d9df | 27 | chainedListFirst = new module_t ; |
salco | 15:91b3c572d9df | 28 | chainedListLast = chainedListFirst; |
salco | 15:91b3c572d9df | 29 | } else { |
salco | 15:91b3c572d9df | 30 | chainedListLast->next = new module_t; |
salco | 15:91b3c572d9df | 31 | chainedListLast = chainedListLast->next; |
salco | 15:91b3c572d9df | 32 | } |
salco | 15:91b3c572d9df | 33 | chainedListLast->next = 0; |
salco | 15:91b3c572d9df | 34 | return chainedListLast; |
salco | 7:dcfd81d7f93f | 35 | } |
salco | 7:dcfd81d7f93f | 36 | |
salco | 7:dcfd81d7f93f | 37 | ComSpi::ComSpi(PinName mosi, PinName miso, PinName sclk, PinName demuxA, PinName demuxB, PinName demuxC, PinName demuxD, PinName demuxEnable) |
salco | 11:496453b45e25 | 38 | : SPI(mosi,miso,sclk), m_demuxA(demuxA), m_demuxB(demuxB), m_demuxC(demuxC), m_demuxD(demuxD), m_demuxEnable(demuxEnable) |
salco | 7:dcfd81d7f93f | 39 | { |
salco | 7:dcfd81d7f93f | 40 | m_demuxPos=0; |
salco | 7:dcfd81d7f93f | 41 | demuxIsUse=true; |
salco | 15:91b3c572d9df | 42 | format(8,0);//16,0); //recente modification |
salco | 7:dcfd81d7f93f | 43 | } |
salco | 7:dcfd81d7f93f | 44 | |
salco | 7:dcfd81d7f93f | 45 | ComSpi::~ComSpi() |
salco | 7:dcfd81d7f93f | 46 | { |
salco | 15:91b3c572d9df | 47 | //pt deleter les pointeur mais sa ser pas vrm a grand chause |
salco | 7:dcfd81d7f93f | 48 | //if(m_com) |
salco | 7:dcfd81d7f93f | 49 | // delete(m_com); |
salco | 7:dcfd81d7f93f | 50 | } |
salco | 7:dcfd81d7f93f | 51 | void ComSpi::change_demux(void) |
salco | 7:dcfd81d7f93f | 52 | { |
salco | 9:7295385f02b2 | 53 | if(demuxIsUse) { |
salco | 10:7e6aeaebe1a2 | 54 | DigitalOut pinDemuxA(m_demuxA); |
salco | 10:7e6aeaebe1a2 | 55 | DigitalOut pinDemuxB(m_demuxB); |
salco | 10:7e6aeaebe1a2 | 56 | DigitalOut pinDemuxC(m_demuxC); |
salco | 10:7e6aeaebe1a2 | 57 | DigitalOut pinDemuxD(m_demuxD); |
salco | 15:91b3c572d9df | 58 | DigitalOut pinDemuxEnable(m_demuxEnable);//,1); |
salco | 15:91b3c572d9df | 59 | //wait(1); |
salco | 10:7e6aeaebe1a2 | 60 | pinDemuxEnable=0; |
salco | 15:91b3c572d9df | 61 | //wait(1); |
salco | 10:7e6aeaebe1a2 | 62 | if(m_demuxPos & 1) pinDemuxA=1; //0b0001 |
salco | 10:7e6aeaebe1a2 | 63 | else pinDemuxA=0; |
salco | 10:7e6aeaebe1a2 | 64 | if(m_demuxPos & 2) pinDemuxB=1; //0b0010 |
salco | 10:7e6aeaebe1a2 | 65 | else pinDemuxB=0; |
salco | 10:7e6aeaebe1a2 | 66 | if(m_demuxPos & 4) pinDemuxC=1; //0b0100 |
salco | 10:7e6aeaebe1a2 | 67 | else pinDemuxC=0; |
salco | 10:7e6aeaebe1a2 | 68 | if(m_demuxPos & 8) pinDemuxD=1; //0b1000 |
salco | 10:7e6aeaebe1a2 | 69 | else pinDemuxD=0; |
salco | 15:91b3c572d9df | 70 | //wait(1); |
salco | 15:91b3c572d9df | 71 | // pinDemuxEnable=1; |
salco | 15:91b3c572d9df | 72 | //wait(1); |
salco | 9:7295385f02b2 | 73 | } |
salco | 7:dcfd81d7f93f | 74 | } |
salco | 9:7295385f02b2 | 75 | char ComSpi::next_demux(void) |
salco | 7:dcfd81d7f93f | 76 | { |
salco | 9:7295385f02b2 | 77 | char result = (char)-1; |
salco | 7:dcfd81d7f93f | 78 | |
salco | 7:dcfd81d7f93f | 79 | if(demuxIsUse) { |
salco | 7:dcfd81d7f93f | 80 | (m_demuxPos == 15)? m_demuxPos=0:m_demuxPos++; |
salco | 7:dcfd81d7f93f | 81 | change_demux(); |
salco | 9:7295385f02b2 | 82 | result = m_demuxPos; |
salco | 7:dcfd81d7f93f | 83 | } |
salco | 7:dcfd81d7f93f | 84 | return result; |
salco | 7:dcfd81d7f93f | 85 | } |
salco | 9:7295385f02b2 | 86 | char ComSpi::back_demux(void) |
salco | 7:dcfd81d7f93f | 87 | { |
salco | 9:7295385f02b2 | 88 | char result = (char)-1; |
salco | 10:7e6aeaebe1a2 | 89 | |
salco | 7:dcfd81d7f93f | 90 | if(demuxIsUse) { |
salco | 7:dcfd81d7f93f | 91 | (m_demuxPos == 0)? m_demuxPos=15:m_demuxPos--; |
salco | 7:dcfd81d7f93f | 92 | change_demux(); |
salco | 10:7e6aeaebe1a2 | 93 | |
salco | 10:7e6aeaebe1a2 | 94 | result = m_demuxPos; |
salco | 7:dcfd81d7f93f | 95 | } |
salco | 7:dcfd81d7f93f | 96 | return result; |
salco | 7:dcfd81d7f93f | 97 | } |
salco | 10:7e6aeaebe1a2 | 98 | char ComSpi::get_demux(void) |
salco | 10:7e6aeaebe1a2 | 99 | { |
salco | 10:7e6aeaebe1a2 | 100 | char result = (char)-1; |
salco | 10:7e6aeaebe1a2 | 101 | if(demuxIsUse) |
salco | 10:7e6aeaebe1a2 | 102 | result=m_demuxPos; |
salco | 10:7e6aeaebe1a2 | 103 | return result ; |
salco | 10:7e6aeaebe1a2 | 104 | } |
salco | 15:91b3c572d9df | 105 | unsigned char spiCurrentState; |
salco | 15:91b3c572d9df | 106 | int ComSpi::write(int value) |
salco | 15:91b3c572d9df | 107 | { |
salco | 15:91b3c572d9df | 108 | DigitalOut pinDemuxEnable(m_demuxEnable); |
salco | 15:91b3c572d9df | 109 | //DigitalOut pinDemuxEnable(m_demuxEnable,0); |
salco | 15:91b3c572d9df | 110 | int a; |
salco | 15:91b3c572d9df | 111 | pinDemuxEnable=1; |
salco | 15:91b3c572d9df | 112 | /* switch(spiCurrentState) |
salco | 15:91b3c572d9df | 113 | { |
salco | 15:91b3c572d9df | 114 | case 0: |
salco | 15:91b3c572d9df | 115 | a= SPI::write(0x12); |
salco | 15:91b3c572d9df | 116 | spiCurrentState++; |
salco | 15:91b3c572d9df | 117 | break; |
salco | 15:91b3c572d9df | 118 | default: |
salco | 15:91b3c572d9df | 119 | a= SPI::write(0xF5); |
salco | 15:91b3c572d9df | 120 | spiCurrentState =0; |
salco | 15:91b3c572d9df | 121 | break; |
salco | 15:91b3c572d9df | 122 | }*/ |
salco | 15:91b3c572d9df | 123 | wait_us(5); |
salco | 15:91b3c572d9df | 124 | a= SPI::write(value); |
salco | 15:91b3c572d9df | 125 | wait_us(5); |
salco | 15:91b3c572d9df | 126 | pinDemuxEnable=0; |
salco | 15:91b3c572d9df | 127 | sneekpeek.append(1,value); |
salco | 15:91b3c572d9df | 128 | wait_us(1000); |
salco | 15:91b3c572d9df | 129 | return a; |
salco | 15:91b3c572d9df | 130 | } |
salco | 15:91b3c572d9df | 131 | |
salco | 10:7e6aeaebe1a2 | 132 | |
salco | 14:ca1a9230ba7f | 133 | bool ComSpi::send(char portID,unsigned char adresseModule,string *flag,string *data) |
salco | 7:dcfd81d7f93f | 134 | { |
salco | 7:dcfd81d7f93f | 135 | bool result=false; |
salco | 10:7e6aeaebe1a2 | 136 | string formatedDataSend; |
salco | 15:91b3c572d9df | 137 | string formatedDataReceive;//DEBUG_COMPACT |
salco | 15:91b3c572d9df | 138 | char settingMaster = 0; |
salco | 15:91b3c572d9df | 139 | char settingSlave = 0; |
salco | 12:bf44013497c8 | 140 | |
salco | 15:91b3c572d9df | 141 | debug(DEBUG_SEND| DEBUG_COMPACT, "\n\r -Debut du send. "); |
salco | 12:bf44013497c8 | 142 | |
salco | 11:496453b45e25 | 143 | debug(DEBUG_SEND, "\n\r -Debut set demux. "); |
salco | 15:91b3c572d9df | 144 | |
salco | 15:91b3c572d9df | 145 | if(portID < 1) portID = 0; |
salco | 15:91b3c572d9df | 146 | else if(portID > 16) portID = 16; |
salco | 15:91b3c572d9df | 147 | debug(DEBUG_SEND, "\n\r -Change PORT. "); |
salco | 15:91b3c572d9df | 148 | m_demuxPos = portID; |
salco | 15:91b3c572d9df | 149 | change_demux(); |
salco | 15:91b3c572d9df | 150 | |
salco | 11:496453b45e25 | 151 | debug(DEBUG_SEND, "\n\r -Fin set demux. "); |
salco | 12:bf44013497c8 | 152 | |
salco | 10:7e6aeaebe1a2 | 153 | // Sync // |
salco | 11:496453b45e25 | 154 | debug(DEBUG_SEND, "\n\r -Debut Sync. "); |
salco | 10:7e6aeaebe1a2 | 155 | formatedDataSend.append(1,SYNC); |
salco | 15:91b3c572d9df | 156 | debug(DEBUG_COMPACT, "\n\r -SYNC ADDED: %02X ",formatedDataSend[0]); |
salco | 11:496453b45e25 | 157 | debug(DEBUG_SEND, "\n\r -Fin Sync. "); |
salco | 12:bf44013497c8 | 158 | |
salco | 10:7e6aeaebe1a2 | 159 | // Address // |
salco | 11:496453b45e25 | 160 | debug(DEBUG_SEND, "\n\r -Debut Address. "); |
salco | 10:7e6aeaebe1a2 | 161 | formatedDataSend.append(1,adresseModule); |
salco | 15:91b3c572d9df | 162 | debug(DEBUG_COMPACT, "\n\r -ADDR ADDED: %02X, %02X ",formatedDataSend[0],formatedDataSend[1]); |
salco | 11:496453b45e25 | 163 | debug(DEBUG_SEND, "\n\r -Fin Address. "); |
salco | 12:bf44013497c8 | 164 | |
salco | 10:7e6aeaebe1a2 | 165 | // PFB // |
salco | 11:496453b45e25 | 166 | debug(DEBUG_SEND, "\n\r -Debut PFB. "); |
salco | 16:5ea4337d785f | 167 | // if(flag != 0) |
salco | 16:5ea4337d785f | 168 | // { |
salco | 10:7e6aeaebe1a2 | 169 | switch(flag->size()) { |
salco | 10:7e6aeaebe1a2 | 170 | case 1: |
salco | 16:5ea4337d785f | 171 | if(flag->at(0) == 0) formatedDataSend.append(1,0<<6); //0 byte |
salco | 16:5ea4337d785f | 172 | else formatedDataSend.append(1,1<<6); //1 byte |
salco | 10:7e6aeaebe1a2 | 173 | break; |
salco | 10:7e6aeaebe1a2 | 174 | |
salco | 10:7e6aeaebe1a2 | 175 | case 2: |
salco | 15:91b3c572d9df | 176 | formatedDataSend.append(1,2<<6); //2 byte |
salco | 10:7e6aeaebe1a2 | 177 | break; |
salco | 10:7e6aeaebe1a2 | 178 | |
salco | 10:7e6aeaebe1a2 | 179 | case 3: |
salco | 15:91b3c572d9df | 180 | formatedDataSend.append(1,3<<6); //3 byte |
salco | 10:7e6aeaebe1a2 | 181 | break; |
salco | 10:7e6aeaebe1a2 | 182 | |
salco | 10:7e6aeaebe1a2 | 183 | default: |
salco | 16:5ea4337d785f | 184 | formatedDataSend.append(1,0<<6); //cas impossible //0 byte |
salco | 10:7e6aeaebe1a2 | 185 | break; |
salco | 10:7e6aeaebe1a2 | 186 | } |
salco | 16:5ea4337d785f | 187 | //} |
salco | 15:91b3c572d9df | 188 | debug(DEBUG_COMPACT, "\n\r -PFB ADDED: %02X, %02X, %02X ",formatedDataSend[0],formatedDataSend[1],formatedDataSend[2]); |
salco | 11:496453b45e25 | 189 | debug(DEBUG_SEND, "\n\r -Fin PFB. "); |
salco | 12:bf44013497c8 | 190 | |
salco | 10:7e6aeaebe1a2 | 191 | // gestion ACK/NAK |
salco | 11:496453b45e25 | 192 | debug(DEBUG_SEND, "\n\r -Debut ACK/NAK. "); |
salco | 12:bf44013497c8 | 193 | formatedDataSend.at(formatedDataSend.length()-1) |= (NOACK << 4); |
salco | 15:91b3c572d9df | 194 | debug(DEBUG_COMPACT, "\n\r -ACK ADDED: %02X, %02X, %02X ",formatedDataSend[0],formatedDataSend[1],formatedDataSend[2]); |
salco | 11:496453b45e25 | 195 | debug(DEBUG_SEND, "\n\r -Fin ACK/NAK. "); |
salco | 12:bf44013497c8 | 196 | |
salco | 10:7e6aeaebe1a2 | 197 | // NDB // |
salco | 11:496453b45e25 | 198 | debug(DEBUG_SEND, "\n\r -Debut NDB. "); |
salco | 10:7e6aeaebe1a2 | 199 | switch(data->size()) { |
salco | 10:7e6aeaebe1a2 | 200 | case 1: |
salco | 12:bf44013497c8 | 201 | formatedDataSend.at(formatedDataSend.length()-1) |= 1; |
salco | 10:7e6aeaebe1a2 | 202 | break; |
salco | 10:7e6aeaebe1a2 | 203 | |
salco | 10:7e6aeaebe1a2 | 204 | case 2: |
salco | 12:bf44013497c8 | 205 | formatedDataSend.at(formatedDataSend.length()-1) |= 2; |
salco | 10:7e6aeaebe1a2 | 206 | break; |
salco | 10:7e6aeaebe1a2 | 207 | |
salco | 10:7e6aeaebe1a2 | 208 | case 3: |
salco | 12:bf44013497c8 | 209 | formatedDataSend.at(formatedDataSend.length()-1) |= 3; |
salco | 10:7e6aeaebe1a2 | 210 | break; |
salco | 10:7e6aeaebe1a2 | 211 | |
salco | 10:7e6aeaebe1a2 | 212 | default: |
salco | 12:bf44013497c8 | 213 | formatedDataSend.at(formatedDataSend.length()-1) |= 0; |
salco | 10:7e6aeaebe1a2 | 214 | break; |
salco | 10:7e6aeaebe1a2 | 215 | } |
salco | 15:91b3c572d9df | 216 | //debug(DEBUG_COMPACT, "\n\r -NDB ADDED: %02X, %02X, %02X ",formatedDataSend[0],formatedDataSend[1],formatedDataSend[2]); |
salco | 11:496453b45e25 | 217 | debug(DEBUG_SEND, "\n\r -Fin NDB. "); |
salco | 12:bf44013497c8 | 218 | |
salco | 15:91b3c572d9df | 219 | settingMaster = formatedDataSend[formatedDataSend.length()-1]; |
salco | 15:91b3c572d9df | 220 | |
salco | 10:7e6aeaebe1a2 | 221 | // flag // |
salco | 11:496453b45e25 | 222 | debug(DEBUG_SEND, "\n\r -Debut flag. "); |
salco | 12:bf44013497c8 | 223 | if(flag->size() != 0) { |
salco | 10:7e6aeaebe1a2 | 224 | formatedDataSend.append(*flag); |
salco | 15:91b3c572d9df | 225 | //debug(DEBUG_COMPACT, "\n\r -FLAG ADDED: %02X, %02X, %02X, %02X ",formatedDataSend[0],formatedDataSend[1],formatedDataSend[2],formatedDataSend[3]); |
salco | 12:bf44013497c8 | 226 | } |
salco | 11:496453b45e25 | 227 | debug(DEBUG_SEND, "\n\r -Fin flag. "); |
salco | 12:bf44013497c8 | 228 | |
salco | 15:91b3c572d9df | 229 | //ici tu envoi deja ton premier stuf |
salco | 15:91b3c572d9df | 230 | |
salco | 15:91b3c572d9df | 231 | |
salco | 15:91b3c572d9df | 232 | debug(DEBUG_SLIM, "\n\r -settingMaster : %X , %i, %X ",settingMaster, (2+(settingMaster>>6)),formatedDataSend[(2+(settingMaster>>6))] ); |
salco | 15:91b3c572d9df | 233 | |
salco | 15:91b3c572d9df | 234 | |
salco | 15:91b3c572d9df | 235 | |
salco | 15:91b3c572d9df | 236 | for(int retryLoop=0; (retryLoop<3) && (!result); retryLoop++) { |
salco | 12:bf44013497c8 | 237 | |
salco | 15:91b3c572d9df | 238 | debug(DEBUG_SEND|DEBUG_COMPACT, "\n\r -Tentative: %d \n\r",retryLoop); |
salco | 15:91b3c572d9df | 239 | formatedDataReceive.clear(); |
salco | 15:91b3c572d9df | 240 | settingSlave =0; |
salco | 15:91b3c572d9df | 241 | counterTotale =0; |
salco | 15:91b3c572d9df | 242 | sneekpeek.clear(); |
salco | 15:91b3c572d9df | 243 | //Send Data |
salco | 15:91b3c572d9df | 244 | // debug(DEBUG_SEND, "\n\r -Debut Send Data. "); |
salco | 15:91b3c572d9df | 245 | // debug(DEBUG_SEND|DEBUG_COMPACT, "\n\r -Send: "); |
salco | 15:91b3c572d9df | 246 | // for (unsigned i=0; i<formatedDataSend.length(); ++i) debug(DEBUG_SEND |DEBUG_COMPACT, "%02X,",formatedDataSend.at(i)); |
salco | 10:7e6aeaebe1a2 | 247 | |
salco | 15:91b3c572d9df | 248 | //int twoBytesArray; |
salco | 15:91b3c572d9df | 249 | //twoBytesArray = (formatedDataSend[0]<<8)|(formatedDataSend[1]); |
salco | 15:91b3c572d9df | 250 | //twoBytesArray=write(twoBytesArray); |
salco | 13:51bbdc349f20 | 251 | |
salco | 15:91b3c572d9df | 252 | for(int i = 0; (i < formatedDataSend.length()) && (i<=(2+(settingMaster>>6))); ++i) { |
salco | 15:91b3c572d9df | 253 | formatedDataReceive.append(1,write(formatedDataSend[i]));//debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r -A:%i ",i); |
salco | 15:91b3c572d9df | 254 | debug(DEBUG_SEND |DEBUG_COMPACT, " %02X,",formatedDataSend.at(i)); |
salco | 15:91b3c572d9df | 255 | } |
salco | 13:51bbdc349f20 | 256 | |
salco | 15:91b3c572d9df | 257 | if(formatedDataReceive[0] == SYNC) { |
salco | 15:91b3c572d9df | 258 | debug(DEBUG_COMPACT, "\n\r -Receve transmission. "); |
salco | 15:91b3c572d9df | 259 | //!!!!!!!! Problem ici write dans un mais pas lautre |
salco | 15:91b3c572d9df | 260 | wait_us(3000); |
salco | 15:91b3c572d9df | 261 | if(retryLoop == 0) { |
salco | 15:91b3c572d9df | 262 | formatedDataSend.append(1,0);//2,0); cest une patch tempo parce que je trouve pas ou il manque la donner |
salco | 15:91b3c572d9df | 263 | } |
salco | 15:91b3c572d9df | 264 | formatedDataReceive.append(1,write(0)); |
salco | 15:91b3c572d9df | 265 | // debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r -B: "); |
salco | 15:91b3c572d9df | 266 | |
salco | 15:91b3c572d9df | 267 | settingSlave = formatedDataReceive[formatedDataReceive.length()-1]; |
salco | 15:91b3c572d9df | 268 | debug(DEBUG_COMPACT, "\n\r -settingSlave %02X",settingSlave); |
salco | 15:91b3c572d9df | 269 | if(retryLoop == 0) { |
salco | 15:91b3c572d9df | 270 | /*switch(formatedDataReceive[formatedDataSend.length()-1] >> 6) { |
salco | 15:91b3c572d9df | 271 | case 1: |
salco | 15:91b3c572d9df | 272 | formatedDataSend.append(1,0); //1 byte |
salco | 15:91b3c572d9df | 273 | break; |
salco | 13:51bbdc349f20 | 274 | |
salco | 15:91b3c572d9df | 275 | case 2: |
salco | 15:91b3c572d9df | 276 | formatedDataSend.append(2,0); //2 byte |
salco | 15:91b3c572d9df | 277 | break; |
salco | 13:51bbdc349f20 | 278 | |
salco | 15:91b3c572d9df | 279 | case 3: |
salco | 15:91b3c572d9df | 280 | formatedDataSend.append(3,0); //3 byte |
salco | 15:91b3c572d9df | 281 | break; |
salco | 12:bf44013497c8 | 282 | |
salco | 15:91b3c572d9df | 283 | //default: |
salco | 15:91b3c572d9df | 284 | // formatedDataSend.append(1,0<<6); //0 byte |
salco | 15:91b3c572d9df | 285 | // break; |
salco | 15:91b3c572d9df | 286 | }*/ |
salco | 15:91b3c572d9df | 287 | formatedDataSend.append(settingSlave>>6,0); |
salco | 15:91b3c572d9df | 288 | } |
salco | 13:51bbdc349f20 | 289 | |
salco | 15:91b3c572d9df | 290 | int bufferFlag = 0; |
salco | 15:91b3c572d9df | 291 | |
salco | 15:91b3c572d9df | 292 | for(int i = (settingMaster>>6); i != 0; i--) { //ici on remplie le buffer des data du flag |
salco | 15:91b3c572d9df | 293 | // je considere avec erreur que il nexiste pas de flag plus grand que 2 bytes (facilite le code de depart) |
salco | 15:91b3c572d9df | 294 | //!!! Pt metre fonct stein qui tronc de debut a fin pour remplacer les linge dessous. |
salco | 15:91b3c572d9df | 295 | bufferFlag = bufferFlag<<8; |
salco | 15:91b3c572d9df | 296 | bufferFlag += formatedDataSend[2+i]; |
salco | 13:51bbdc349f20 | 297 | } |
salco | 12:bf44013497c8 | 298 | |
salco | 15:91b3c572d9df | 299 | counterTotale = ((2+(settingMaster>>6))+1); |
salco | 15:91b3c572d9df | 300 | counterTotale = counterTotale+(settingSlave>>6)+abs((settingMaster & 0x0F) - (settingSlave & 0x0F)); |
salco | 16:5ea4337d785f | 301 | debug( "\n\r -size : %02X",counterTotale); |
salco | 16:5ea4337d785f | 302 | |
salco | 15:91b3c572d9df | 303 | switch(bufferFlag) { //plus facile pour savoir ce que tu doit tatenre a recevoire |
salco | 15:91b3c572d9df | 304 | case 1://Request Init Info |
salco | 15:91b3c572d9df | 305 | if(retryLoop == 0) { |
salco | 15:91b3c572d9df | 306 | |
salco | 15:91b3c572d9df | 307 | formatedDataSend.append(settingSlave & 0x0F,0); |
salco | 15:91b3c572d9df | 308 | //chek pour comment avoir un address |
salco | 15:91b3c572d9df | 309 | } |
salco | 15:91b3c572d9df | 310 | //verifier si la fonction fait ce quil edt suposer |
salco | 15:91b3c572d9df | 311 | for(int i = ((2+(settingMaster>>6))+1); i < formatedDataSend.length()-1; ++i) { |
salco | 15:91b3c572d9df | 312 | formatedDataReceive.append(1,write(formatedDataSend[i])); |
salco | 15:91b3c572d9df | 313 | //debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r -C:%i ",i); |
salco | 15:91b3c572d9df | 314 | } |
salco | 15:91b3c572d9df | 315 | //templatePtr =searchAddr(0); |
salco | 15:91b3c572d9df | 316 | // 1 byte flag + 3 byte de data |
salco | 15:91b3c572d9df | 317 | //bufferSend[4] = (1<<6) + 3;//[2+(bufferReceive[2]>>6)+1] = (1<<6); |
salco | 15:91b3c572d9df | 318 | |
salco | 15:91b3c572d9df | 319 | |
salco | 15:91b3c572d9df | 320 | //if((templatePtr->next)==0) |
salco | 15:91b3c572d9df | 321 | // bufferSend[5] = 0b101;//bufferReceive[2+(bufferReceive[2]>>6)+1+bufferReceive[2+(bufferReceive[2]>>6)+1]] = 0b101; |
salco | 15:91b3c572d9df | 322 | //else |
salco | 15:91b3c572d9df | 323 | // bufferSend[5] = 0b10; |
salco | 15:91b3c572d9df | 324 | |
salco | 15:91b3c572d9df | 325 | //bufferSend[6] = templatePtr->basicInfo.osnapRegisterB.getByte; |
salco | 15:91b3c572d9df | 326 | //bufferSend[7] = templatePtr->basicInfo.osnapRegisterC.getByte; |
salco | 15:91b3c572d9df | 327 | //bufferSend[8] = templatePtr->basicInfo.osnapRegisterD.getByte; |
salco | 15:91b3c572d9df | 328 | break; |
salco | 15:91b3c572d9df | 329 | |
salco | 15:91b3c572d9df | 330 | case 2: //Slave contient un/des autre(s) module(s) sans adresses |
salco | 15:91b3c572d9df | 331 | break; |
salco | 15:91b3c572d9df | 332 | |
salco | 15:91b3c572d9df | 333 | case 3: //Flag Critique |
salco | 15:91b3c572d9df | 334 | break; |
salco | 15:91b3c572d9df | 335 | |
salco | 15:91b3c572d9df | 336 | case 4: //Flag Alerte |
salco | 15:91b3c572d9df | 337 | break; |
salco | 15:91b3c572d9df | 338 | |
salco | 15:91b3c572d9df | 339 | case 5: //Slave ne contient plus de module sans adresse |
salco | 15:91b3c572d9df | 340 | break; |
salco | 15:91b3c572d9df | 341 | |
salco | 15:91b3c572d9df | 342 | case 6: //Master request address update |
salco | 15:91b3c572d9df | 343 | break; |
salco | 15:91b3c572d9df | 344 | |
salco | 15:91b3c572d9df | 345 | default: //Get update (normale) |
salco | 16:5ea4337d785f | 346 | //if(retryLoop == 0) { |
salco | 16:5ea4337d785f | 347 | // formatedDataSend.append(abs((settingMaster & 0x0F) - (settingSlave & 0x0F)),0);//je considere que cest fait apres avoire ajouter les data a nous |
salco | 16:5ea4337d785f | 348 | // } |
salco | 15:91b3c572d9df | 349 | break; |
salco | 15:91b3c572d9df | 350 | } |
salco | 15:91b3c572d9df | 351 | //counterTotale = 2+(bufferReceive[2]>>6)+1; |
salco | 15:91b3c572d9df | 352 | //counterTotale = counterTotale+(bufferSend[counterTotale]>>6)+abs((bufferReceive[2] & 0x5F) - (bufferSend[counterTotale] & 0x5F)); |
salco | 16:5ea4337d785f | 353 | // if(retryLoop == 0) { |
salco | 16:5ea4337d785f | 354 | debug( "\n\r -size : %02X , %02X",formatedDataSend.size(),counterTotale); |
salco | 16:5ea4337d785f | 355 | // if(formatedDataSend.size()<counterTotale){ |
salco | 16:5ea4337d785f | 356 | // formatedDataSend.append(counterTotale-formatedDataSend.size(),0); |
salco | 16:5ea4337d785f | 357 | //} |
salco | 16:5ea4337d785f | 358 | //} |
salco | 15:91b3c572d9df | 359 | |
salco | 15:91b3c572d9df | 360 | |
salco | 15:91b3c572d9df | 361 | |
salco | 15:91b3c572d9df | 362 | // Envoie le reste si liker // |
salco | 15:91b3c572d9df | 363 | // DATA // |
salco | 15:91b3c572d9df | 364 | unsigned short templateValue=0; |
salco | 15:91b3c572d9df | 365 | if(retryLoop == 0) { |
salco | 13:51bbdc349f20 | 366 | // CRC // |
salco | 15:91b3c572d9df | 367 | debug(DEBUG_SEND, "\n\r -Debut CRC16. "); |
salco | 15:91b3c572d9df | 368 | //CRC16* templateCRC; |
salco | 15:91b3c572d9df | 369 | //templateCRC = new CRC16(); |
salco | 15:91b3c572d9df | 370 | //!!!utiliser string cest plus simple |
salco | 15:91b3c572d9df | 371 | |
salco | 15:91b3c572d9df | 372 | |
salco | 15:91b3c572d9df | 373 | //char templateTable[formatedDataSend.length()+1]; |
salco | 15:91b3c572d9df | 374 | //for (unsigned i=0; i<formatedDataSend.length()+1; ++i) templateTable[i]=0; |
salco | 15:91b3c572d9df | 375 | //for (unsigned i=0; i<formatedDataSend.length(); ++i) templateTable[i]=formatedDataSend[i]; |
salco | 15:91b3c572d9df | 376 | //debug(DEBUG_SEND, "\n\r - envoi au crc: %02X,%02X,%02X,%02X,%02X,%02X ",templateTable[0],templateTable[1],templateTable[2],templateTable[3],templateTable[4],templateTable[5],templateTable[6]); |
salco | 15:91b3c572d9df | 377 | |
salco | 15:91b3c572d9df | 378 | // templateValue = /*templateCRC->*/calculateCRC16(templateTable,formatedDataSend.size()-1); //atention pt un probleme de sortie du range |
salco | 15:91b3c572d9df | 379 | //templateValue = /*templateCRC->calculateCRC16*/CRC16_BUYPASS(formatedDataSend.c_str(),formatedDataSend.size()); //atention pt un probleme de sortie du range |
salco | 15:91b3c572d9df | 380 | templateValue =CRC16_BUYPASS(sneekpeek.c_str(),sneekpeek.size()); //patch |
salco | 15:91b3c572d9df | 381 | |
salco | 15:91b3c572d9df | 382 | formatedDataSend.append(1,templateValue>>8); |
salco | 15:91b3c572d9df | 383 | formatedDataSend.append(1,templateValue & 0xFF); |
salco | 15:91b3c572d9df | 384 | } |
salco | 15:91b3c572d9df | 385 | formatedDataReceive.append(1,write(formatedDataSend[formatedDataSend.size()-2]));//templateValue>>8)); |
salco | 15:91b3c572d9df | 386 | //debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r -D: "); |
salco | 15:91b3c572d9df | 387 | formatedDataReceive.append(1,write(formatedDataSend[formatedDataSend.size()-1]));//(templateValue & 0xFF)); |
salco | 15:91b3c572d9df | 388 | //debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r -E: "); |
salco | 15:91b3c572d9df | 389 | |
salco | 15:91b3c572d9df | 390 | |
salco | 15:91b3c572d9df | 391 | |
salco | 15:91b3c572d9df | 392 | /////////////////////// |
salco | 15:91b3c572d9df | 393 | |
salco | 15:91b3c572d9df | 394 | //avant faut calculer les dernier byte grace a la version 2.0 |
salco | 15:91b3c572d9df | 395 | /*for(int i = 0; i < formatedDataSend.length(); ++i) { |
salco | 15:91b3c572d9df | 396 | formatedDataReceive.append(1,write(formatedDataSend[i])); |
salco | 15:91b3c572d9df | 397 | }*/ |
salco | 13:51bbdc349f20 | 398 | |
salco | 15:91b3c572d9df | 399 | // verification du CRC slave |
salco | 15:91b3c572d9df | 400 | // CRC // |
salco | 15:91b3c572d9df | 401 | templateValue = CRC16_BUYPASS(formatedDataReceive.c_str(),formatedDataReceive.size()-2);// utiliser les data de setting slave |
salco | 15:91b3c572d9df | 402 | |
salco | 15:91b3c572d9df | 403 | if(((templateValue>>8)==(formatedDataReceive.at( formatedDataReceive.length()-2))) && |
salco | 15:91b3c572d9df | 404 | ((templateValue&0xFF)==(formatedDataReceive.at( formatedDataReceive.length()-1)))) |
salco | 15:91b3c572d9df | 405 | { |
salco | 15:91b3c572d9df | 406 | result=true; |
salco | 15:91b3c572d9df | 407 | } |
salco | 15:91b3c572d9df | 408 | else |
salco | 15:91b3c572d9df | 409 | { |
salco | 15:91b3c572d9df | 410 | result=false; |
salco | 15:91b3c572d9df | 411 | } |
salco | 15:91b3c572d9df | 412 | //templateValue=((formatedDataReceive.at( formatedDataReceive.length()-2)) << 8); |
salco | 15:91b3c572d9df | 413 | //templateValue|=formatedDataReceive.at(formatedDataReceive.length()-1); |
salco | 15:91b3c572d9df | 414 | |
salco | 15:91b3c572d9df | 415 | // for (unsigned i=0; i<formatedDataReceive.length()-2; ++i) { |
salco | 15:91b3c572d9df | 416 | // templateValue-=formatedDataReceive[i]; |
salco | 15:91b3c572d9df | 417 | // } |
salco | 15:91b3c572d9df | 418 | // debug(DEBUG_SEND, "\n\r -CRC==0? value: %i. ", templateValue); |
salco | 15:91b3c572d9df | 419 | // (templateValue==0)? result=true:result=false; |
salco | 13:51bbdc349f20 | 420 | } |
salco | 15:91b3c572d9df | 421 | debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r -Send : "); |
salco | 15:91b3c572d9df | 422 | for (unsigned i=0; i<formatedDataSend.length(); i++) debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "%02X,",formatedDataSend.at(i)); |
salco | 15:91b3c572d9df | 423 | debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r -Reveive: "); |
salco | 15:91b3c572d9df | 424 | for (unsigned i=0; i<formatedDataReceive.length(); i++) debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "%02X,",formatedDataReceive.at(i)); |
salco | 15:91b3c572d9df | 425 | debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r -Sneekpe: "); |
salco | 15:91b3c572d9df | 426 | /*for (unsigned i=0; i<sneekpeek.length(); i++)*/ debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "%04X,",CRC16_BUYPASS(formatedDataReceive.c_str(),formatedDataReceive.size()-2));//sneekpeek.at(i)); |
salco | 15:91b3c572d9df | 427 | debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r-Sneekpe: %04X,",CRC16_BUYPASS(formatedDataSend.c_str(),formatedDataSend.size()-2));//sneekpeek.at(i)); |
salco | 15:91b3c572d9df | 428 | debug(DEBUG_SEND|DEBUG_COMPACT|DEBUG_SLIM, "\n\r-Sneekpe: %04X,",CRC16_BUYPASS(sneekpeek.c_str(),sneekpeek.size()-2));//sneekpeek.at(i)); |
salco | 15:91b3c572d9df | 429 | |
salco | 15:91b3c572d9df | 430 | }//templateValue = /*templateCRC->*/calculateCRC16(formatedDataSend.c_str(),formatedDataSend.size()-1);sneekpeek |
salco | 15:91b3c572d9df | 431 | /////////////////////// |
salco | 15:91b3c572d9df | 432 | // // old // |
salco | 15:91b3c572d9df | 433 | // |
salco | 15:91b3c572d9df | 434 | // // data // |
salco | 15:91b3c572d9df | 435 | // debug(DEBUG_SEND, "\n\r -Debut data. "); |
salco | 15:91b3c572d9df | 436 | // if(data->size() != 0) { |
salco | 15:91b3c572d9df | 437 | // formatedDataSend.append(*data); |
salco | 15:91b3c572d9df | 438 | // debug(DEBUG_COMPACT, "\n\r -DATA ADDED: %02X, %02X, %02X, %02X, %02X ",formatedDataSend[0],formatedDataSend[1],formatedDataSend[2],formatedDataSend[3],formatedDataSend[4]); |
salco | 15:91b3c572d9df | 439 | // } |
salco | 15:91b3c572d9df | 440 | // debug(DEBUG_SEND, "\n\r -Fin data. "); |
salco | 15:91b3c572d9df | 441 | // |
salco | 15:91b3c572d9df | 442 | // // CRC // |
salco | 15:91b3c572d9df | 443 | // debug(DEBUG_SEND, "\n\r -Debut CRC16. "); |
salco | 15:91b3c572d9df | 444 | // //CRC16* templateCRC; |
salco | 15:91b3c572d9df | 445 | // //templateCRC = new CRC16(); |
salco | 15:91b3c572d9df | 446 | // unsigned short templateValue; |
salco | 15:91b3c572d9df | 447 | // char templateTable[34]; |
salco | 15:91b3c572d9df | 448 | // for (unsigned i=0; i<34; ++i) templateTable[i]=0; |
salco | 15:91b3c572d9df | 449 | // for (unsigned i=0; i<formatedDataSend.length(); ++i) templateTable[i]=formatedDataSend[i]; |
salco | 15:91b3c572d9df | 450 | // debug(DEBUG_SEND, "\n\r - envoi au crc: %02X,%02X,%02X,%02X,%02X,%02X ",templateTable[0],templateTable[1],templateTable[2],templateTable[3],templateTable[4],templateTable[5],templateTable[6]); |
salco | 15:91b3c572d9df | 451 | // |
salco | 15:91b3c572d9df | 452 | // templateValue = /*templateCRC->*/calculateCRC16(templateTable,formatedDataSend.size()-1); //atention pt un probleme de sortie du range |
salco | 15:91b3c572d9df | 453 | // |
salco | 15:91b3c572d9df | 454 | // formatedDataSend.append(1,templateValue>>8); |
salco | 15:91b3c572d9df | 455 | // formatedDataSend.append(1,templateValue & 0xFF); |
salco | 15:91b3c572d9df | 456 | // |
salco | 15:91b3c572d9df | 457 | // // if(templateCRC) |
salco | 15:91b3c572d9df | 458 | // // delete templateCRC; |
salco | 15:91b3c572d9df | 459 | // debug(DEBUG_COMPACT, "\n\r -DATA ADDED: %02X, %02X, %02X, %02X, %02X, %02X, %02X ",formatedDataSend[0],formatedDataSend[1],formatedDataSend[2],formatedDataSend[3],formatedDataSend[4],formatedDataSend[5],formatedDataSend[6]); |
salco | 15:91b3c572d9df | 460 | // debug(DEBUG_SEND, "\n\r -Fin CRC16. "); |
salco | 15:91b3c572d9df | 461 | // |
salco | 15:91b3c572d9df | 462 | // //Send Data |
salco | 15:91b3c572d9df | 463 | // debug(DEBUG_SEND, "\n\r -Debut Send Data. "); |
salco | 15:91b3c572d9df | 464 | // debug(DEBUG_SEND|DEBUG_COMPACT, "\n\r -Send: "); |
salco | 15:91b3c572d9df | 465 | // for (unsigned i=0; i<formatedDataSend.length(); ++i) debug(DEBUG_SEND |DEBUG_COMPACT, "%02X,",formatedDataSend.at(i)); |
salco | 15:91b3c572d9df | 466 | // |
salco | 15:91b3c572d9df | 467 | // int twoBytesArray; |
salco | 15:91b3c572d9df | 468 | // twoBytesArray = (formatedDataSend[0]<<8)|(formatedDataSend[1]); |
salco | 15:91b3c572d9df | 469 | // |
salco | 15:91b3c572d9df | 470 | // for(int i=0; (i<3) && (!result); i++) { |
salco | 15:91b3c572d9df | 471 | // debug(DEBUG_SEND|DEBUG_COMPACT, "\n\r -Tentative: %d",i); |
salco | 15:91b3c572d9df | 472 | // |
salco | 15:91b3c572d9df | 473 | // twoBytesArray=write(twoBytesArray); |
salco | 15:91b3c572d9df | 474 | // |
salco | 15:91b3c572d9df | 475 | // if(twoBytesArray>>8 == SYNC) {// twoBytesArray ==(Sync)//+(PFB+ACK+NDB)) |
salco | 15:91b3c572d9df | 476 | // // Envoie le reste si liker si liker // |
salco | 15:91b3c572d9df | 477 | // debug(DEBUG_SEND|DEBUG_COMPACT, "\n\r -Debut Traitement de l'information. "); |
salco | 15:91b3c572d9df | 478 | // debug(DEBUG_SEND|DEBUG_COMPACT, "\n\r -Receive: %02X",twoBytesArray); |
salco | 15:91b3c572d9df | 479 | // |
salco | 15:91b3c572d9df | 480 | // formatedDataReceive.clear(); |
salco | 15:91b3c572d9df | 481 | // formatedDataReceive.append(1,twoBytesArray>>8); |
salco | 15:91b3c572d9df | 482 | // formatedDataReceive.append(1,twoBytesArray & 0xFF); |
salco | 15:91b3c572d9df | 483 | // |
salco | 15:91b3c572d9df | 484 | // for (unsigned i=2; i<formatedDataSend.length(); ++i) { |
salco | 15:91b3c572d9df | 485 | // twoBytesArray = formatedDataSend[i]; |
salco | 15:91b3c572d9df | 486 | // i++; |
salco | 15:91b3c572d9df | 487 | // if(i<formatedDataSend.length()) |
salco | 15:91b3c572d9df | 488 | // twoBytesArray = (twoBytesArray<<8) + formatedDataSend[i]; |
salco | 15:91b3c572d9df | 489 | // |
salco | 15:91b3c572d9df | 490 | // twoBytesArray=write(twoBytesArray); |
salco | 15:91b3c572d9df | 491 | // formatedDataReceive.append(1,twoBytesArray>>8); |
salco | 15:91b3c572d9df | 492 | // formatedDataReceive.append(1,twoBytesArray&0xFF); |
salco | 15:91b3c572d9df | 493 | // } |
salco | 15:91b3c572d9df | 494 | // |
salco | 15:91b3c572d9df | 495 | // // CRC // |
salco | 15:91b3c572d9df | 496 | // unsigned short templateValue=1; |
salco | 15:91b3c572d9df | 497 | // templateValue=formatedDataReceive.at(formatedDataReceive.length()-2) << 8; |
salco | 15:91b3c572d9df | 498 | // templateValue|=formatedDataReceive.at(formatedDataReceive.length()-1); |
salco | 15:91b3c572d9df | 499 | // |
salco | 15:91b3c572d9df | 500 | // for (unsigned i=0; i<formatedDataReceive.length()-2; ++i) { |
salco | 15:91b3c572d9df | 501 | // templateValue-=formatedDataReceive[i]; |
salco | 15:91b3c572d9df | 502 | // } |
salco | 15:91b3c572d9df | 503 | // debug(DEBUG_SEND, "\n\r -CRC==0? value: %i. ", templateValue); |
salco | 15:91b3c572d9df | 504 | // (templateValue==0)? result=true:result=false; |
salco | 15:91b3c572d9df | 505 | //} |
salco | 15:91b3c572d9df | 506 | //} |
salco | 15:91b3c572d9df | 507 | //debug(DEBUG_SEND, "\n\r -Fin Send Data. "); |
salco | 15:91b3c572d9df | 508 | // |
salco | 15:91b3c572d9df | 509 | |
salco | 15:91b3c572d9df | 510 | |
salco | 15:91b3c572d9df | 511 | |
salco | 12:bf44013497c8 | 512 | |
salco | 13:51bbdc349f20 | 513 | if(result) { |
salco | 13:51bbdc349f20 | 514 | // Traitement de l'information // |
salco | 12:bf44013497c8 | 515 | debug(DEBUG_SEND, "\n\r -Debut Traitement de l'information. "); |
salco | 12:bf44013497c8 | 516 | debug(DEBUG_SEND, "\n\r -Receive: "); |
salco | 15:91b3c572d9df | 517 | for (unsigned i=0; i<formatedDataReceive.length(); ++i)debug(DEBUG_SEND|DEBUG_COMPACT, "%02X,",formatedDataReceive.at(i)); |
salco | 12:bf44013497c8 | 518 | |
salco | 10:7e6aeaebe1a2 | 519 | // flag // |
salco | 10:7e6aeaebe1a2 | 520 | flag->clear(); |
salco | 16:5ea4337d785f | 521 | if((settingSlave>>6) != 0) |
salco | 16:5ea4337d785f | 522 | { |
salco | 16:5ea4337d785f | 523 | //string str = formatedDataReceive.substr( ((2+(settingMaster>>6))+1+1),(settingSlave>>6)); |
salco | 16:5ea4337d785f | 524 | flag->append(formatedDataReceive.substr( ((2+(settingMaster>>6))+1+1),(settingSlave>>6)));// = &str; |
salco | 16:5ea4337d785f | 525 | |
salco | 16:5ea4337d785f | 526 | //debug(DEBUG_SLIM, "\n\r -flag get: "); |
salco | 16:5ea4337d785f | 527 | //for (unsigned i=0; i<str.length(); i++) debug(DEBUG_SLIM, "%02X,",str.at(i)); |
salco | 16:5ea4337d785f | 528 | } |
salco | 15:91b3c572d9df | 529 | //twoBytesArray=formatedDataReceive[2]; |
salco | 15:91b3c572d9df | 530 | //!!!!! wtf is that cest claire que sa pete la com |
salco | 16:5ea4337d785f | 531 | /*string::iterator it=formatedDataReceive.begin()+3; |
salco | 13:51bbdc349f20 | 532 | |
salco | 15:91b3c572d9df | 533 | switch(settingSlave>>6) { |
salco | 10:7e6aeaebe1a2 | 534 | case 1: |
salco | 10:7e6aeaebe1a2 | 535 | flag->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 536 | it++; |
salco | 10:7e6aeaebe1a2 | 537 | break; |
salco | 7:dcfd81d7f93f | 538 | |
salco | 10:7e6aeaebe1a2 | 539 | case 2: |
salco | 10:7e6aeaebe1a2 | 540 | flag->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 541 | it++; |
salco | 10:7e6aeaebe1a2 | 542 | flag->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 543 | it++; |
salco | 10:7e6aeaebe1a2 | 544 | break; |
salco | 7:dcfd81d7f93f | 545 | |
salco | 10:7e6aeaebe1a2 | 546 | case 3: |
salco | 10:7e6aeaebe1a2 | 547 | flag->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 548 | it++; |
salco | 10:7e6aeaebe1a2 | 549 | flag->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 550 | it++; |
salco | 10:7e6aeaebe1a2 | 551 | flag->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 552 | it++; |
salco | 16:5ea4337d785f | 553 | break;*/ |
salco | 7:dcfd81d7f93f | 554 | |
salco | 10:7e6aeaebe1a2 | 555 | /*default: |
salco | 10:7e6aeaebe1a2 | 556 | formatedDataSend.append(1,0<<6); |
salco | 10:7e6aeaebe1a2 | 557 | break;*/ |
salco | 16:5ea4337d785f | 558 | // } |
salco | 12:bf44013497c8 | 559 | |
salco | 10:7e6aeaebe1a2 | 560 | // ACK/NAK |
salco | 10:7e6aeaebe1a2 | 561 | // |
salco | 7:dcfd81d7f93f | 562 | |
salco | 10:7e6aeaebe1a2 | 563 | // NDB // |
salco | 10:7e6aeaebe1a2 | 564 | data->clear(); |
salco | 16:5ea4337d785f | 565 | if((settingSlave&0x0F) != 0) |
salco | 16:5ea4337d785f | 566 | { |
salco | 16:5ea4337d785f | 567 | //string str = formatedDataReceive.substr( ((2+(settingMaster>>6))+1+(settingSlave>>6)+1),(settingSlave&0x0F)); |
salco | 16:5ea4337d785f | 568 | data->append(formatedDataReceive.substr( ((2+(settingMaster>>6))+1+(settingSlave>>6)+1),(settingSlave&0x0F))); |
salco | 16:5ea4337d785f | 569 | |
salco | 16:5ea4337d785f | 570 | //debug(DEBUG_SLIM, "\n\r -data get: "); |
salco | 16:5ea4337d785f | 571 | //for (unsigned i=0; i<str.length(); i++) debug(DEBUG_SLIM, "%02X,",str.at(i)); |
salco | 16:5ea4337d785f | 572 | } |
salco | 15:91b3c572d9df | 573 | //!!!!! same shit faut rebild la chose en bas |
salco | 16:5ea4337d785f | 574 | /* switch(settingSlave&0xFF) { |
salco | 10:7e6aeaebe1a2 | 575 | case 1: |
salco | 10:7e6aeaebe1a2 | 576 | data->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 577 | it++; |
salco | 10:7e6aeaebe1a2 | 578 | break; |
salco | 7:dcfd81d7f93f | 579 | |
salco | 10:7e6aeaebe1a2 | 580 | case 2: |
salco | 10:7e6aeaebe1a2 | 581 | data->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 582 | it++; |
salco | 10:7e6aeaebe1a2 | 583 | data->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 584 | it++; |
salco | 10:7e6aeaebe1a2 | 585 | break; |
salco | 10:7e6aeaebe1a2 | 586 | |
salco | 10:7e6aeaebe1a2 | 587 | case 3: |
salco | 10:7e6aeaebe1a2 | 588 | data->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 589 | it++; |
salco | 10:7e6aeaebe1a2 | 590 | data->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 591 | it++; |
salco | 10:7e6aeaebe1a2 | 592 | data->append(1,*it); |
salco | 10:7e6aeaebe1a2 | 593 | it++; |
salco | 16:5ea4337d785f | 594 | break;*/ |
salco | 10:7e6aeaebe1a2 | 595 | |
salco | 10:7e6aeaebe1a2 | 596 | /*default: |
salco | 10:7e6aeaebe1a2 | 597 | |
salco | 10:7e6aeaebe1a2 | 598 | break;*/ |
salco | 16:5ea4337d785f | 599 | //} |
salco | 13:51bbdc349f20 | 600 | } |
salco | 12:bf44013497c8 | 601 | |
salco | 12:bf44013497c8 | 602 | debug(DEBUG_SEND, "\n\r -Fin Traitement de l'information. "); |
salco | 15:91b3c572d9df | 603 | debug(DEBUG_SEND|DEBUG_COMPACT, "\n\r -Fin du send. "); |
salco | 7:dcfd81d7f93f | 604 | return result; |
salco | 7:dcfd81d7f93f | 605 | } |