test

Dependencies:   mbed Watchdog stm32-sensor-base2

Committer:
nestedslk
Date:
Sat Jul 18 14:59:04 2020 +0000
Revision:
4:f6e22dd39313
Parent:
2:b7fdc74e5c5d
testing version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nestedslk 4:f6e22dd39313 1 #ifndef RS485_H
nestedslk 4:f6e22dd39313 2 #define RS485_H
nestedslk 4:f6e22dd39313 3
nestedslk 4:f6e22dd39313 4 #include "BufferedSerial.h"
nestedslk 4:f6e22dd39313 5 #include "mbed.h"
nestedslk 4:f6e22dd39313 6
nestedslk 4:f6e22dd39313 7 class RS485 : public BufferedSerial
ommpy 2:b7fdc74e5c5d 8 {
nestedslk 4:f6e22dd39313 9 private:
nestedslk 4:f6e22dd39313 10 typedef unsigned int word;
nestedslk 4:f6e22dd39313 11 typedef uint8_t byte;
nestedslk 4:f6e22dd39313 12 typedef uint8_t boolean;
nestedslk 4:f6e22dd39313 13 typedef void (*voidFuncPtr)(void);
nestedslk 4:f6e22dd39313 14
ommpy 2:b7fdc74e5c5d 15 public:
nestedslk 4:f6e22dd39313 16 /** Create a BufferedSerial port, connected to the specified transmit and receive pins
ommpy 2:b7fdc74e5c5d 17 * @param tx Transmit pin
ommpy 2:b7fdc74e5c5d 18 * @param rx Receive pin
nestedslk 4:f6e22dd39313 19 * @param dere Enable pin, this pin should be connected to !RE and DE
nestedslk 4:f6e22dd39313 20 * @note uses BufferedSerial
ommpy 2:b7fdc74e5c5d 21 */
nestedslk 4:f6e22dd39313 22 RS485(PinName tx, PinName rx, PinName dere);
nestedslk 4:f6e22dd39313 23
nestedslk 4:f6e22dd39313 24 /** calculate 8-bit CRC
nestedslk 4:f6e22dd39313 25 * cyclic redundancy check
nestedslk 4:f6e22dd39313 26 * @param addr byte pointer of information to use (typical an byte array)
nestedslk 4:f6e22dd39313 27 * @param len length of byte of information were converting
nestedslk 4:f6e22dd39313 28 * @return the CRC byte
nestedslk 4:f6e22dd39313 29 */
nestedslk 4:f6e22dd39313 30 static byte crc8 (const byte *addr, byte len);
nestedslk 4:f6e22dd39313 31
nestedslk 4:f6e22dd39313 32 /** sendComplemented byte
nestedslk 4:f6e22dd39313 33 * send a byte complemented, repeated
nestedslk 4:f6e22dd39313 34 * only values sent would be (in hex):
nestedslk 4:f6e22dd39313 35 * 0F, 1E, 2D, 3C, 4B, 5A, 69, 78, 87, 96, A5, B4, C3, D2, E1, F0
nestedslk 4:f6e22dd39313 36 * @what the byte to complement
nestedslk 4:f6e22dd39313 37 */
nestedslk 4:f6e22dd39313 38 void sendComplemented (const byte what);
ommpy 2:b7fdc74e5c5d 39
nestedslk 4:f6e22dd39313 40 /** send message
nestedslk 4:f6e22dd39313 41 * cyclic redundancy check
nestedslk 4:f6e22dd39313 42 * @param data the data to be sent through RS485
nestedslk 4:f6e22dd39313 43 * @param length length of the data
nestedslk 4:f6e22dd39313 44 * @note puts STX at start, ETX at end, and add CRC
nestedslk 4:f6e22dd39313 45 */
nestedslk 4:f6e22dd39313 46 void sendMsg (const byte * data, const byte length);
nestedslk 4:f6e22dd39313 47
nestedslk 4:f6e22dd39313 48 /** receive message
nestedslk 4:f6e22dd39313 49 * reads serial port and populates data
nestedslk 4:f6e22dd39313 50 * @param data buffer to receive into
nestedslk 4:f6e22dd39313 51 * @param length length of the data
nestedslk 4:f6e22dd39313 52 * @param timeout clock_mseconds before timing out
nestedslk 4:f6e22dd39313 53 * @return the number of bytes received
nestedslk 4:f6e22dd39313 54 *
nestedslk 4:f6e22dd39313 55 */
nestedslk 4:f6e22dd39313 56 byte recvMsg (byte * data, const byte length, unsigned long timeout);
nestedslk 4:f6e22dd39313 57
nestedslk 4:f6e22dd39313 58
nestedslk 4:f6e22dd39313 59 };
nestedslk 4:f6e22dd39313 60 #endif