Name: Anonymous 2012-10-12 8:07
Hey prog
I need to break an unsigned long integer into bytes, send it over Serial1, then put it back together into an integer so that I can use it for a math operation (communication protocol, encryption thing).
The code I have is
I don't know why it doesn't work and I'm incredibly swamped. Any assistance would be incredibly appreciated. Its Pseudo C code for Arduino.
I tried using a loop cause maybe its not sending right, but that doesn't work either. How do I fix it in clear terms?
G sent me here.
I need to break an unsigned long integer into bytes, send it over Serial1, then put it back together into an integer so that I can use it for a math operation (communication protocol, encryption thing).
The code I have is
uint32_t sharedkey = 1225;
uint32_t othersharedIndex = 0;
void sendkey(uint32_t sharedindex) {
if(Serial1.available()){
// reads in a byte and shifts it over for the next byte
Serial1.write( (sharedindex >> 24) & 0xFF );
Serial1.write( (sharedindex >> 16) & 0xFF );
Serial1.write( (sharedindex >> 8) & 0xFF );
Serial1.write( sharedindex & 0xFF );
}
}
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
sendkey((uint32_t)sharedindex);
if (Serial1.available()){
//uint32_t B = Serial1.read();
//for(int i=0;i <=4; i++) super_data.read_byte[i]=Serial.read();
othersharedIndex = othersharedIndex | Serial1.read() << 24;
othersharedIndex = othersharedIndex | Serial1.read() << 16;
othersharedIndex = othersharedIndex | Serial1.read() << 8;
othersharedIndex = othersharedIndex | Serial1.read();
}I don't know why it doesn't work and I'm incredibly swamped. Any assistance would be incredibly appreciated. Its Pseudo C code for Arduino.
I tried using a loop cause maybe its not sending right, but that doesn't work either. How do I fix it in clear terms?
G sent me here.