Last active
February 15, 2016 11:51
-
-
Save reinzor/203a4c32ef6229a7a21c to your computer and use it in GitHub Desktop.
Extract can frame data signal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MASK32(nbits) ((0xffffffff)>> (32-nbits)) | |
uint32_t extractSignal(uint8_t* frame, uint8_t startbit, uint8_t length, bool is_big_endian) | |
{ | |
uint8_t startByte = startbit/8; | |
uint8_t startBitInByte = startbit % 8; | |
uint8_t endByte = 0; | |
uint8_t count = 0; | |
uint8_t target = frame[startByte] >> startBitInByte; | |
uint8_t currentTargetLength = (8-startBitInByte); | |
if(is_big_endian) // (big endian) | |
{ | |
endByte = startByte - ((length-(8-startBitInByte))/8); // wow if this works??? | |
for(count = startByte-1; count > endByte; count --) | |
{ | |
target |= frame[count] << currentTargetLength; | |
currentTargetLength += 8; | |
} | |
} | |
else // Intel (little endian) | |
{ | |
endByte = (startbit+length) / 8; | |
for(count = startByte+1; count < endByte; count ++) | |
{ | |
target |= frame[count] << currentTargetLength; | |
currentTargetLength += 8; | |
} | |
} | |
target &= MASK32(length); | |
return target; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment