Practical Arduino Cool Projects for Open Source Hardware- P29

Practical Arduino Cool Projects for Open Source Hardware- P29: A schematic or circuit diagram is a diagram that describes the interconnections in an electrical or electronic device. In the projects presented in Practical Arduino, we’ve taken the approach of providing both a photograph and/or line drawing of the completed device along with a schematic. While learning to read schematics takes a modest investment of your time, it will prove useful time and time again as you develop your projects. With that in mind, we present a quick how-to in this section | CHAPTER 13 WEATHER STATION RECEIVER Because there is a high probability that data sent by the transmitter will be corrupt or only partially received it s important to have some way to check the validity of the message. The La Crosse transmitter includes a checksum in the message so the receiver can make sure it arrived correctly. The checksum calculation function doesn t take any arguments because when invoked it operates on global variables that have already been set and all it needs to return is a pass fail response value. Internally the function uses the variable dataPos to indicate the position within the data array that it will examine and it accumulates the result of examining each byte into the checksum variable byte PacketAndChecksum_OK_WS2355 void byte dataPos byte checksum It skips across the first four bytes though because they re the timestamp and aren t included in the checksum calculation which only applies to the first 48 bites 12 nibbles of the message payload. checksum 0 for dataPos 4 dataPos 10 dataPos checksum bICP_WSR_PacketData bICP_WSR_PacketOutputPointer dataPos 4 checksum bICP_WSR_PacketData bICP_WSR_PacketOutputPointer dataPos 0x0F The accumulated value then has a bitwise AND operator applied against the value 0x0F. checksum 0x0F The result is then compared to the checksum value sent in the transmission and the function immediately exits with a false value if it fails the test. if checksum bICP_WSR_PacketData bICP_WSR_PacketOutputPointer 10 4 return false The next thing that is checked is the first non-timestamp byte of the message payload which must always be 0x09 or binary 00001001. This appears to be a general identifier for this type of weather station and might be different for other models but for our purposes we can simply do a direct comparison and ignore messages that don t have this byte set correctly. if bICP_WSR_PacketData bICP_WSR_PacketOutputPointer 4 0x09 return false If those checks all passed then the message is probably .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.