Rev 112 | Rev 151 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 112 | Rev 113 | ||
---|---|---|---|
Line 172... | Line 172... | ||
172 | /**************************************************************/ |
172 | /**************************************************************/ |
173 | void MKProtocol_CollectSerialFrame(Buffer_t* pRxBuff, u8 c) |
173 | void MKProtocol_CollectSerialFrame(Buffer_t* pRxBuff, u8 c) |
174 | { |
174 | { |
175 | if(pRxBuff->Locked == FALSE) |
175 | if(pRxBuff->Locked == FALSE) |
176 | { // rx buffer not locked |
176 | { // rx buffer not locked |
177 | if((pRxBuff->Position == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received |
177 | if(c == '#') // if syncronisation character is received |
178 | { |
178 | { |
- | 179 | pRxBuff->Position = 0; // reset buffer |
|
179 | pRxBuff->pData[pRxBuff->Position++] = c; // copy 1st byte to buffer |
180 | pRxBuff->pData[pRxBuff->Position++] = c; // copy 1st byte to buffer |
180 | pRxBuff->DataBytes = 1; |
181 | pRxBuff->DataBytes = 1; |
181 | } |
182 | } |
182 | else if (pRxBuff->Position < pRxBuff->Size) // rx buffer not full |
183 | else if (pRxBuff->Position < pRxBuff->Size) // rx buffer not full |
183 | { |
184 | { |
Line 199... | Line 200... | ||
199 | crc1 = '=' + crc / 64; |
200 | crc1 = '=' + crc / 64; |
200 | crc2 = '=' + crc % 64; |
201 | crc2 = '=' + crc % 64; |
201 | // compare checksum to transmitted checksum bytes |
202 | // compare checksum to transmitted checksum bytes |
202 | if((crc1 == pRxBuff->pData[pRxBuff->Position-2]) && (crc2 == pRxBuff->pData[pRxBuff->Position-1])) |
203 | if((crc1 == pRxBuff->pData[pRxBuff->Position-2]) && (crc2 == pRxBuff->pData[pRxBuff->Position-1])) |
203 | { // checksum is valid |
204 | { // checksum is valid |
204 | pRxBuff->Locked = TRUE; // lock the rxd buffer |
- | |
205 | pRxBuff->pData[pRxBuff->Position++] = '\r'; // set termination character |
205 | pRxBuff->pData[pRxBuff->Position++] = '\r'; // set termination character |
206 | pRxBuff->DataBytes = pRxBuff->Position; |
206 | pRxBuff->DataBytes = pRxBuff->Position; |
207 | pRxBuff->Position = 0; |
207 | pRxBuff->Position = 0; |
- | 208 | pRxBuff->Locked = TRUE; // lock the rxd buffer |
|
208 | // if 2nd byte is an 'R' start bootloader |
209 | // if 2nd byte is an 'R' start bootloader |
209 | if(pRxBuff->pData[2] == 'R') |
210 | if(pRxBuff->pData[2] == 'R') |
210 | { |
211 | { |
211 | PowerOff(); |
212 | PowerOff(); |
212 | VIC_DeInit(); |
213 | VIC_DeInit(); |