Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- delay(2000);
- // Calcuate weather parameters for serial and web
- calcWeather(); // Go calc all the various sensors
- // send weather out to serial port
- if (prevtemplm34_1 == templm34_1) // 2 in a row must be the same to send
- {
- Serial.write(0);
- Serial.write(templm34_1);
- Serial.write(templm34_1 ^ 0);
- }
- // send weather out to serial port
- if(prevtemplm34_2 == templm34_2) // 2 in a row must be the same to send
- {
- Serial.write(1);
- Serial.write(templm34_2);
- Serial.write(templm34_2 ^ 1);
- }
- // send weather out to serial port
- if(prevtemplm34_3 == templm34_3) // 2 in a row must be the same to send
- {
- Serial.write(2);
- Serial.write(templm34_3);
- Serial.write(templm34_3 ^ 2);
- }
- delay(2000);
- int readData ()
- {
- // There must be at least three available bytes to satisfy the protocol
- // Otherwise, wait until three bytes have arrived to read anything
- if (Serial.available() >= 3) {
- // Read the next three byte in the serial buffer
- incomingByteOne = Serial.read();
- Serial.write("Byte One: ");
- Serial.write(incomingByteOne);
- Serial.println();
- incomingByteTwo = Serial.read();
- Serial.write("Byte Two: ");
- Serial.write(incomingByteTwo);
- Serial.println();
- incomingByteThree = Serial.read();
- Serial.write("Byte Three: ");
- Serial.write(incomingByteThree);
- Serial.println();
- // XOR the first and second incoming bytes so that the result can be checked against the third error checking byte
- byte xorValue = incomingByteOne ^ incomingByteTwo;
- Serial.write("XOR VALUE: ");
- Serial.write(xorValue);
- Serial.println("Number of Errors: ");
- Serial.println(numberOfErrors);
- Serial.println();
- Serial.println();
- if(xorValue != incomingByteThree) {
- numberOfErrors++; // Add one to the total count of number of errors in transmission
- }
- else {
- // Mask for retrieving the five rightmost bits from incomingByteOne (00011111)
- byte maskForSensorNumber = 0x1f;
- // Shift incomingByteOne right 5 times in order to obtain the three bits representing the unit number
- int unitNumber = incomingByteOne >> 5;
- // AND incomingByteOne with the mask in order to retrieve only the five righmost bits representing the sensor number
- int sensorNumber = incomingByteOne & maskForSensorNumber;
- // Store the data for the correct sensor on the correct unit
- data[unitNumber][sensorNumber] = incomingByteTwo*1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement