pcbbc:
Yes, I understand exactly what you want to do and it still has nothing to do with the ASCII characters '0' and '1''.
Here is an example...
uint8_t iRN = 0;
uint8_t RN[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00 };
uint8_t GetRNByte()
{
uint8_t rn = RN[iRN++];
if (iRN >= sizeof(RN)) iRN = 0;
return rn;
}
void Encode(uint8_t* msg, uint8_t len, uint8_t* buf)
{
while (len--)
{
uint8_t b = *msg++;
for (uint8_t i = 0; i < 8; i++)
{
uint8_t rn = GetRNByte();
if (b & 0x80) rn ^= 0xFF;
*buf++ = rn;
b <<= 1;
}
}
}
void Decode(uint8_t* buf, uint8_t len, uint8_t* msg)
{
while (len--)
{
uint8_t b = 0;
for (uint8_t i = 0; i < 8; i++)
{
uint8_t rn = GetRNByte();
b <<= 1;
if (*buf++ != rn) b |= 1;
}
*msg++ = b;
}
}
void setup() {
uint8_t source[] = "Hi";
uint8_t encoded[16];
uint8_t result[3];
Serial.begin(115200);
Serial.print("Source:");
Serial.println((char*)source);
iRN = 0;
Encode(source, 2, encoded);
iRN = 0;
Decode(encoded, 2, result);
result[2] = 0; // null terminator
Serial.print("Result:");
Serial.println((char*)result);
}
void loop() {
}
Edit:
I've no idea how you are generating your pseudo random noise. I have hard coded an array of (not very) random numbers for testing.
I've no idea how you are decoding the incoming DSSS bytes back into bits. What if there is not an exact match with the PRN? I assumed an exact match is a zero bit in, anything else a 1. Almost certainly this is not correct, but it will do for an example.
What sensor, what wireless link? Or is this just a coding exercise/simulation?
This is a project. For wireless comunication i,m using some cheap RF transmitter and reciever working on 433MHZ(they are called Aurel TX SAW MID 3V and Aurel RX MID 3V) and for the sensor im using DTH22 temperature and umidity sensor.
About the pseudonoise , its not going to be a real PN code , but a n bits long code(ex n=8) that is gonna be known on the transmitter and reciever part too.