This is code is part of a Technion course project in advanced IoT, implementing a device to read and transmit sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

Dependencies:   mbed Buffer

Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by ST

This is code is part of a Technion course project in advanced IoT, implementing a device to read and transmit sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

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_Reader"
  • Select a Platform like so:
  1. Click button at top-left
  2. Add Board
  3. Search "B-L072Z-LRWAN1" 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
Committer:
wardm
Date:
Sat May 19 11:41:10 2018 +0000
Revision:
12:02d779e8c4f6
Code for Technion Formula car sensors reader transmit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wardm 12:02d779e8c4f6 1
wardm 12:02d779e8c4f6 2 /**
wardm 12:02d779e8c4f6 3 * @file BufferedSerial.h
wardm 12:02d779e8c4f6 4 * @brief Software Buffer - Extends mbed Serial functionallity adding irq driven TX and RX
wardm 12:02d779e8c4f6 5 * @author sam grove
wardm 12:02d779e8c4f6 6 * @version 1.0
wardm 12:02d779e8c4f6 7 * @see
wardm 12:02d779e8c4f6 8 *
wardm 12:02d779e8c4f6 9 * Copyright (c) 2013
wardm 12:02d779e8c4f6 10 *
wardm 12:02d779e8c4f6 11 * Licensed under the Apache License, Version 2.0 (the "License");
wardm 12:02d779e8c4f6 12 * you may not use this file except in compliance with the License.
wardm 12:02d779e8c4f6 13 * You may obtain a copy of the License at
wardm 12:02d779e8c4f6 14 *
wardm 12:02d779e8c4f6 15 * http://www.apache.org/licenses/LICENSE-2.0
wardm 12:02d779e8c4f6 16 *
wardm 12:02d779e8c4f6 17 * Unless required by applicable law or agreed to in writing, software
wardm 12:02d779e8c4f6 18 * distributed under the License is distributed on an "AS IS" BASIS,
wardm 12:02d779e8c4f6 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
wardm 12:02d779e8c4f6 20 * See the License for the specific language governing permissions and
wardm 12:02d779e8c4f6 21 * limitations under the License.
wardm 12:02d779e8c4f6 22 */
wardm 12:02d779e8c4f6 23
wardm 12:02d779e8c4f6 24 #ifndef BUFFEREDSERIAL_H
wardm 12:02d779e8c4f6 25 #define BUFFEREDSERIAL_H
wardm 12:02d779e8c4f6 26
wardm 12:02d779e8c4f6 27 #include "mbed.h"
wardm 12:02d779e8c4f6 28 #include "MyBuffer.h"
wardm 12:02d779e8c4f6 29
wardm 12:02d779e8c4f6 30 /** A serial port (UART) for communication with other serial devices
wardm 12:02d779e8c4f6 31 *
wardm 12:02d779e8c4f6 32 * Can be used for Full Duplex communication, or Simplex by specifying
wardm 12:02d779e8c4f6 33 * one pin as NC (Not Connected)
wardm 12:02d779e8c4f6 34 *
wardm 12:02d779e8c4f6 35 * Example:
wardm 12:02d779e8c4f6 36 * @code
wardm 12:02d779e8c4f6 37 * #include "mbed.h"
wardm 12:02d779e8c4f6 38 * #include "BufferedSerial.h"
wardm 12:02d779e8c4f6 39 *
wardm 12:02d779e8c4f6 40 * BufferedSerial pc(USBTX, USBRX);
wardm 12:02d779e8c4f6 41 *
wardm 12:02d779e8c4f6 42 * int main()
wardm 12:02d779e8c4f6 43 * {
wardm 12:02d779e8c4f6 44 * while(1)
wardm 12:02d779e8c4f6 45 * {
wardm 12:02d779e8c4f6 46 * Timer s;
wardm 12:02d779e8c4f6 47 *
wardm 12:02d779e8c4f6 48 * s.start();
wardm 12:02d779e8c4f6 49 * pc.printf("Hello World - buffered\n");
wardm 12:02d779e8c4f6 50 * int buffered_time = s.read_us();
wardm 12:02d779e8c4f6 51 * wait(0.1f); // give time for the buffer to empty
wardm 12:02d779e8c4f6 52 *
wardm 12:02d779e8c4f6 53 * s.reset();
wardm 12:02d779e8c4f6 54 * printf("Hello World - blocking\n");
wardm 12:02d779e8c4f6 55 * int polled_time = s.read_us();
wardm 12:02d779e8c4f6 56 * s.stop();
wardm 12:02d779e8c4f6 57 * wait(0.1f); // give time for the buffer to empty
wardm 12:02d779e8c4f6 58 *
wardm 12:02d779e8c4f6 59 * pc.printf("printf buffered took %d us\n", buffered_time);
wardm 12:02d779e8c4f6 60 * pc.printf("printf blocking took %d us\n", polled_time);
wardm 12:02d779e8c4f6 61 * wait(0.5f);
wardm 12:02d779e8c4f6 62 * }
wardm 12:02d779e8c4f6 63 * }
wardm 12:02d779e8c4f6 64 * @endcode
wardm 12:02d779e8c4f6 65 */
wardm 12:02d779e8c4f6 66
wardm 12:02d779e8c4f6 67 /**
wardm 12:02d779e8c4f6 68 * @class BufferedSerial
wardm 12:02d779e8c4f6 69 * @brief Software buffers and interrupt driven tx and rx for Serial
wardm 12:02d779e8c4f6 70 */
wardm 12:02d779e8c4f6 71 class BufferedSerial : public RawSerial
wardm 12:02d779e8c4f6 72 {
wardm 12:02d779e8c4f6 73 private:
wardm 12:02d779e8c4f6 74 MyBuffer <char> _rxbuf;
wardm 12:02d779e8c4f6 75 MyBuffer <char> _txbuf;
wardm 12:02d779e8c4f6 76 uint32_t _buf_size;
wardm 12:02d779e8c4f6 77 uint32_t _tx_multiple;
wardm 12:02d779e8c4f6 78
wardm 12:02d779e8c4f6 79 void rxIrq(void);
wardm 12:02d779e8c4f6 80 void txIrq(void);
wardm 12:02d779e8c4f6 81 void prime(void);
wardm 12:02d779e8c4f6 82
wardm 12:02d779e8c4f6 83 public:
wardm 12:02d779e8c4f6 84 /** Create a BufferedSerial port, connected to the specified transmit and receive pins
wardm 12:02d779e8c4f6 85 * @param tx Transmit pin
wardm 12:02d779e8c4f6 86 * @param rx Receive pin
wardm 12:02d779e8c4f6 87 * @param buf_size printf() buffer size
wardm 12:02d779e8c4f6 88 * @param tx_multiple amount of max printf() present in the internal ring buffer at one time
wardm 12:02d779e8c4f6 89 * @param name optional name
wardm 12:02d779e8c4f6 90 * @note Either tx or rx may be specified as NC if unused
wardm 12:02d779e8c4f6 91 */
wardm 12:02d779e8c4f6 92 BufferedSerial(PinName tx, PinName rx, uint32_t buf_size = 256, uint32_t tx_multiple = 4,const char* name=NULL);
wardm 12:02d779e8c4f6 93
wardm 12:02d779e8c4f6 94 /** Destroy a BufferedSerial port
wardm 12:02d779e8c4f6 95 */
wardm 12:02d779e8c4f6 96 virtual ~BufferedSerial(void);
wardm 12:02d779e8c4f6 97
wardm 12:02d779e8c4f6 98 /** Check on how many bytes are in the rx buffer
wardm 12:02d779e8c4f6 99 * @return 1 if something exists, 0 otherwise
wardm 12:02d779e8c4f6 100 */
wardm 12:02d779e8c4f6 101 virtual int readable(void);
wardm 12:02d779e8c4f6 102
wardm 12:02d779e8c4f6 103 /** Check to see if the tx buffer has room
wardm 12:02d779e8c4f6 104 * @return 1 always has room and can overwrite previous content if too small / slow
wardm 12:02d779e8c4f6 105 */
wardm 12:02d779e8c4f6 106 virtual int writeable(void);
wardm 12:02d779e8c4f6 107
wardm 12:02d779e8c4f6 108 /** Get a single byte from the BufferedSerial Port.
wardm 12:02d779e8c4f6 109 * Should check readable() before calling this.
wardm 12:02d779e8c4f6 110 * @return A byte that came in on the Serial Port
wardm 12:02d779e8c4f6 111 */
wardm 12:02d779e8c4f6 112 virtual int getc(void);
wardm 12:02d779e8c4f6 113
wardm 12:02d779e8c4f6 114 /** Write a single byte to the BufferedSerial Port.
wardm 12:02d779e8c4f6 115 * @param c The byte to write to the Serial Port
wardm 12:02d779e8c4f6 116 * @return The byte that was written to the Serial Port Buffer
wardm 12:02d779e8c4f6 117 */
wardm 12:02d779e8c4f6 118 virtual int putc(int c);
wardm 12:02d779e8c4f6 119
wardm 12:02d779e8c4f6 120 /** Write a string to the BufferedSerial Port. Must be NULL terminated
wardm 12:02d779e8c4f6 121 * @param s The string to write to the Serial Port
wardm 12:02d779e8c4f6 122 * @return The number of bytes written to the Serial Port Buffer
wardm 12:02d779e8c4f6 123 */
wardm 12:02d779e8c4f6 124 virtual int puts(const char *s);
wardm 12:02d779e8c4f6 125
wardm 12:02d779e8c4f6 126 /** Write a formatted string to the BufferedSerial Port.
wardm 12:02d779e8c4f6 127 * @param format The string + format specifiers to write to the Serial Port
wardm 12:02d779e8c4f6 128 * @return The number of bytes written to the Serial Port Buffer
wardm 12:02d779e8c4f6 129 */
wardm 12:02d779e8c4f6 130 virtual int printf(const char* format, ...);
wardm 12:02d779e8c4f6 131
wardm 12:02d779e8c4f6 132 /** Write data to the Buffered Serial Port
wardm 12:02d779e8c4f6 133 * @param s A pointer to data to send
wardm 12:02d779e8c4f6 134 * @param length The amount of data being pointed to
wardm 12:02d779e8c4f6 135 * @return The number of bytes written to the Serial Port Buffer
wardm 12:02d779e8c4f6 136 */
wardm 12:02d779e8c4f6 137 virtual ssize_t write(const void *s, std::size_t length);
wardm 12:02d779e8c4f6 138 };
wardm 12:02d779e8c4f6 139
wardm 12:02d779e8c4f6 140 #endif