This is code is part of a Technion course project in advanced IoT, implementing a device to receive and present sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.
Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by
This is code is part of a Technion course project in advanced IoT, implementing a device to receive sensors data from another L072CZ-LRWAN1 installed on a Formula racing car (built by students at Technion - Israel Institute of Technology), and sends it to a GUI presenting the data (GUI project: github.com/ward-mattar/TechnionFormulaGUI).
How to install
- Create an account on Mbed: https://os.mbed.com/account/signup/
- Import project into Compiler
- In the Program Workspace select "Formula_Nucleo_Receiver"
- Select a Platform like so:
- Click button at top-left
- Add Board
- Search "NUCLEO F103RB" and then "Add to your Mbed Compiler"
- Finally click "Compile", if the build was successful, the binary would download automatically
- To install it on device simply plug it in to a PC, open device drive and drag then drop binary file in it
BufferedSerial/BufferedSerial.h@12:046346a16ff4, 2018-05-19 (annotated)
- Committer:
- wardm
- Date:
- Sat May 19 15:42:38 2018 +0000
- Revision:
- 12:046346a16ff4
V1.0.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wardm | 12:046346a16ff4 | 1 | |
wardm | 12:046346a16ff4 | 2 | /** |
wardm | 12:046346a16ff4 | 3 | * @file BufferedSerial.h |
wardm | 12:046346a16ff4 | 4 | * @brief Software Buffer - Extends mbed Serial functionallity adding irq driven TX and RX |
wardm | 12:046346a16ff4 | 5 | * @author sam grove |
wardm | 12:046346a16ff4 | 6 | * @version 1.0 |
wardm | 12:046346a16ff4 | 7 | * @see |
wardm | 12:046346a16ff4 | 8 | * |
wardm | 12:046346a16ff4 | 9 | * Copyright (c) 2013 |
wardm | 12:046346a16ff4 | 10 | * |
wardm | 12:046346a16ff4 | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
wardm | 12:046346a16ff4 | 12 | * you may not use this file except in compliance with the License. |
wardm | 12:046346a16ff4 | 13 | * You may obtain a copy of the License at |
wardm | 12:046346a16ff4 | 14 | * |
wardm | 12:046346a16ff4 | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
wardm | 12:046346a16ff4 | 16 | * |
wardm | 12:046346a16ff4 | 17 | * Unless required by applicable law or agreed to in writing, software |
wardm | 12:046346a16ff4 | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
wardm | 12:046346a16ff4 | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
wardm | 12:046346a16ff4 | 20 | * See the License for the specific language governing permissions and |
wardm | 12:046346a16ff4 | 21 | * limitations under the License. |
wardm | 12:046346a16ff4 | 22 | */ |
wardm | 12:046346a16ff4 | 23 | |
wardm | 12:046346a16ff4 | 24 | #ifndef BUFFEREDSERIAL_H |
wardm | 12:046346a16ff4 | 25 | #define BUFFEREDSERIAL_H |
wardm | 12:046346a16ff4 | 26 | |
wardm | 12:046346a16ff4 | 27 | #include "mbed.h" |
wardm | 12:046346a16ff4 | 28 | #include "MyBuffer.h" |
wardm | 12:046346a16ff4 | 29 | |
wardm | 12:046346a16ff4 | 30 | /** A serial port (UART) for communication with other serial devices |
wardm | 12:046346a16ff4 | 31 | * |
wardm | 12:046346a16ff4 | 32 | * Can be used for Full Duplex communication, or Simplex by specifying |
wardm | 12:046346a16ff4 | 33 | * one pin as NC (Not Connected) |
wardm | 12:046346a16ff4 | 34 | * |
wardm | 12:046346a16ff4 | 35 | * Example: |
wardm | 12:046346a16ff4 | 36 | * @code |
wardm | 12:046346a16ff4 | 37 | * #include "mbed.h" |
wardm | 12:046346a16ff4 | 38 | * #include "BufferedSerial.h" |
wardm | 12:046346a16ff4 | 39 | * |
wardm | 12:046346a16ff4 | 40 | * BufferedSerial pc(USBTX, USBRX); |
wardm | 12:046346a16ff4 | 41 | * |
wardm | 12:046346a16ff4 | 42 | * int main() |
wardm | 12:046346a16ff4 | 43 | * { |
wardm | 12:046346a16ff4 | 44 | * while(1) |
wardm | 12:046346a16ff4 | 45 | * { |
wardm | 12:046346a16ff4 | 46 | * Timer s; |
wardm | 12:046346a16ff4 | 47 | * |
wardm | 12:046346a16ff4 | 48 | * s.start(); |
wardm | 12:046346a16ff4 | 49 | * pc.printf("Hello World - buffered\n"); |
wardm | 12:046346a16ff4 | 50 | * int buffered_time = s.read_us(); |
wardm | 12:046346a16ff4 | 51 | * wait(0.1f); // give time for the buffer to empty |
wardm | 12:046346a16ff4 | 52 | * |
wardm | 12:046346a16ff4 | 53 | * s.reset(); |
wardm | 12:046346a16ff4 | 54 | * printf("Hello World - blocking\n"); |
wardm | 12:046346a16ff4 | 55 | * int polled_time = s.read_us(); |
wardm | 12:046346a16ff4 | 56 | * s.stop(); |
wardm | 12:046346a16ff4 | 57 | * wait(0.1f); // give time for the buffer to empty |
wardm | 12:046346a16ff4 | 58 | * |
wardm | 12:046346a16ff4 | 59 | * pc.printf("printf buffered took %d us\n", buffered_time); |
wardm | 12:046346a16ff4 | 60 | * pc.printf("printf blocking took %d us\n", polled_time); |
wardm | 12:046346a16ff4 | 61 | * wait(0.5f); |
wardm | 12:046346a16ff4 | 62 | * } |
wardm | 12:046346a16ff4 | 63 | * } |
wardm | 12:046346a16ff4 | 64 | * @endcode |
wardm | 12:046346a16ff4 | 65 | */ |
wardm | 12:046346a16ff4 | 66 | |
wardm | 12:046346a16ff4 | 67 | /** |
wardm | 12:046346a16ff4 | 68 | * @class BufferedSerial |
wardm | 12:046346a16ff4 | 69 | * @brief Software buffers and interrupt driven tx and rx for Serial |
wardm | 12:046346a16ff4 | 70 | */ |
wardm | 12:046346a16ff4 | 71 | class BufferedSerial : public RawSerial |
wardm | 12:046346a16ff4 | 72 | { |
wardm | 12:046346a16ff4 | 73 | private: |
wardm | 12:046346a16ff4 | 74 | MyBuffer <char> _rxbuf; |
wardm | 12:046346a16ff4 | 75 | MyBuffer <char> _txbuf; |
wardm | 12:046346a16ff4 | 76 | uint32_t _buf_size; |
wardm | 12:046346a16ff4 | 77 | uint32_t _tx_multiple; |
wardm | 12:046346a16ff4 | 78 | |
wardm | 12:046346a16ff4 | 79 | void rxIrq(void); |
wardm | 12:046346a16ff4 | 80 | void txIrq(void); |
wardm | 12:046346a16ff4 | 81 | void prime(void); |
wardm | 12:046346a16ff4 | 82 | |
wardm | 12:046346a16ff4 | 83 | public: |
wardm | 12:046346a16ff4 | 84 | /** Create a BufferedSerial port, connected to the specified transmit and receive pins |
wardm | 12:046346a16ff4 | 85 | * @param tx Transmit pin |
wardm | 12:046346a16ff4 | 86 | * @param rx Receive pin |
wardm | 12:046346a16ff4 | 87 | * @param buf_size printf() buffer size |
wardm | 12:046346a16ff4 | 88 | * @param tx_multiple amount of max printf() present in the internal ring buffer at one time |
wardm | 12:046346a16ff4 | 89 | * @param name optional name |
wardm | 12:046346a16ff4 | 90 | * @note Either tx or rx may be specified as NC if unused |
wardm | 12:046346a16ff4 | 91 | */ |
wardm | 12:046346a16ff4 | 92 | BufferedSerial(PinName tx, PinName rx, uint32_t buf_size = 256, uint32_t tx_multiple = 4,const char* name=NULL); |
wardm | 12:046346a16ff4 | 93 | |
wardm | 12:046346a16ff4 | 94 | /** Destroy a BufferedSerial port |
wardm | 12:046346a16ff4 | 95 | */ |
wardm | 12:046346a16ff4 | 96 | virtual ~BufferedSerial(void); |
wardm | 12:046346a16ff4 | 97 | |
wardm | 12:046346a16ff4 | 98 | /** Check on how many bytes are in the rx buffer |
wardm | 12:046346a16ff4 | 99 | * @return 1 if something exists, 0 otherwise |
wardm | 12:046346a16ff4 | 100 | */ |
wardm | 12:046346a16ff4 | 101 | virtual int readable(void); |
wardm | 12:046346a16ff4 | 102 | |
wardm | 12:046346a16ff4 | 103 | /** Check to see if the tx buffer has room |
wardm | 12:046346a16ff4 | 104 | * @return 1 always has room and can overwrite previous content if too small / slow |
wardm | 12:046346a16ff4 | 105 | */ |
wardm | 12:046346a16ff4 | 106 | virtual int writeable(void); |
wardm | 12:046346a16ff4 | 107 | |
wardm | 12:046346a16ff4 | 108 | /** Get a single byte from the BufferedSerial Port. |
wardm | 12:046346a16ff4 | 109 | * Should check readable() before calling this. |
wardm | 12:046346a16ff4 | 110 | * @return A byte that came in on the Serial Port |
wardm | 12:046346a16ff4 | 111 | */ |
wardm | 12:046346a16ff4 | 112 | virtual int getc(void); |
wardm | 12:046346a16ff4 | 113 | |
wardm | 12:046346a16ff4 | 114 | /** Write a single byte to the BufferedSerial Port. |
wardm | 12:046346a16ff4 | 115 | * @param c The byte to write to the Serial Port |
wardm | 12:046346a16ff4 | 116 | * @return The byte that was written to the Serial Port Buffer |
wardm | 12:046346a16ff4 | 117 | */ |
wardm | 12:046346a16ff4 | 118 | virtual int putc(int c); |
wardm | 12:046346a16ff4 | 119 | |
wardm | 12:046346a16ff4 | 120 | /** Write a string to the BufferedSerial Port. Must be NULL terminated |
wardm | 12:046346a16ff4 | 121 | * @param s The string to write to the Serial Port |
wardm | 12:046346a16ff4 | 122 | * @return The number of bytes written to the Serial Port Buffer |
wardm | 12:046346a16ff4 | 123 | */ |
wardm | 12:046346a16ff4 | 124 | virtual int puts(const char *s); |
wardm | 12:046346a16ff4 | 125 | |
wardm | 12:046346a16ff4 | 126 | /** Write a formatted string to the BufferedSerial Port. |
wardm | 12:046346a16ff4 | 127 | * @param format The string + format specifiers to write to the Serial Port |
wardm | 12:046346a16ff4 | 128 | * @return The number of bytes written to the Serial Port Buffer |
wardm | 12:046346a16ff4 | 129 | */ |
wardm | 12:046346a16ff4 | 130 | virtual int printf(const char* format, ...); |
wardm | 12:046346a16ff4 | 131 | |
wardm | 12:046346a16ff4 | 132 | /** Write data to the Buffered Serial Port |
wardm | 12:046346a16ff4 | 133 | * @param s A pointer to data to send |
wardm | 12:046346a16ff4 | 134 | * @param length The amount of data being pointed to |
wardm | 12:046346a16ff4 | 135 | * @return The number of bytes written to the Serial Port Buffer |
wardm | 12:046346a16ff4 | 136 | */ |
wardm | 12:046346a16ff4 | 137 | virtual ssize_t write(const void *s, std::size_t length); |
wardm | 12:046346a16ff4 | 138 | }; |
wardm | 12:046346a16ff4 | 139 | |
wardm | 12:046346a16ff4 | 140 | #endif |