Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-cloud-workshop-connect-HTS221 by
ftcd_comm_serial.h
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2017 ARM Ltd. 00003 // 00004 // Licensed under the Apache License, Version 2.0 (the "License"); 00005 // you may not use this file except in compliance with the License. 00006 // You may obtain a copy of the License at 00007 // 00008 // http://www.apache.org/licenses/LICENSE-2.0 00009 // 00010 // Unless required by applicable law or agreed to in writing, software 00011 // distributed under the License is distributed on an "AS IS" BASIS, 00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 // See the License for the specific language governing permissions and 00014 // limitations under the License. 00015 // ---------------------------------------------------------------------------- 00016 00017 #ifndef __FTCD_COMM_SERIAL_H__ 00018 #define __FTCD_COMM_SERIAL_H__ 00019 00020 #include "ftcd_comm_base.h" 00021 #include <inttypes.h> 00022 #include "mbed.h" 00023 00024 class FtcdCommSerial : public FtcdCommBase { 00025 00026 public: 00027 /** Initialize serial object that communicate via stdin and stdout */ 00028 FtcdCommSerial(ftcd_comm_network_endianness_e network_endianness, const uint8_t *header_token, bool use_signature); 00029 00030 /** Deprecated constructor for backward compatibility. 00031 Note, the TX, RX and baud params are ignored */ 00032 FtcdCommSerial(PinName TX, PinName RX, uint32_t baud, ftcd_comm_network_endianness_e network_endianness, const uint8_t *header_token, bool use_signature); 00033 00034 /** Not certain that we need to do anything here, but just in case we need 00035 * to do some clean-up at some point. 00036 */ 00037 virtual ~FtcdCommSerial(); 00038 00039 /** Detects the message token from the communication line medium. 00040 * 00041 * @returns 00042 * zero, if token detected and different value otherwise 00043 */ 00044 virtual ftcd_comm_status_e is_token_detected(void); 00045 00046 /** Reads the message size in bytes from the communication line medium. 00047 * This is the amount of bytes needed to allocate for the upcoming message bytes. 00048 * 00049 * @returns 00050 * The message size in bytes in case of success, zero bytes otherwise. 00051 */ 00052 virtual uint32_t read_message_size(void); 00053 00054 /** Reads the message size in bytes from the communication line medium. 00055 * This is the amount of bytes needed to allocate for the upcoming message bytes. 00056 * 00057 * @param message_out The buffer to read into and return to the caller. 00058 * @param message_size The message size in bytes. 00059 * 00060 * @returns 00061 * true upon success, false otherwise 00062 */ 00063 virtual bool read_message(uint8_t *message_out, size_t message_size); 00064 00065 /** Reads the message size in bytes from the communication line medium. 00066 * This is the amount of bytes needed to allocate for the upcoming message bytes. 00067 * 00068 * @param sig The buffer to read into and return to the caller. 00069 * @param sig_size The sig buffer size in bytes. 00070 * 00071 * @returns 00072 * The message size in bytes in case of success, zero bytes otherwise. 00073 */ 00074 virtual bool read_message_signature(uint8_t *sig, size_t sig_size); 00075 00076 /** Writes the given data to the communication line medium. 00077 * 00078 * @param data The bytes to send through the communication line medium 00079 * @param data_size The data size in bytes 00080 * 00081 * @returns 00082 * true upon success, false otherwise 00083 */ 00084 virtual bool send(const uint8_t *data, uint32_t data_size); 00085 00086 private: 00087 00088 /** Reads a buffer from the serial line. 00089 * 00090 * @param buff_out A pointer to the buffer to read into, should be allocated by the caller 00091 * @param buff_max_size The max chars to read 00092 * 00093 * @returns 00094 * the number of chars read, zero in case of an error 00095 */ 00096 size_t _serial_read(char *buff_out, size_t buff_max_size); 00097 00098 /** Writes a buffer to the serial line. 00099 * 00100 * @param buff A buffer to write. 00101 * @param buff_size The number of chars in buffer 00102 * 00103 * @returns 00104 * the number of chars that was written, zero in case of an error 00105 */ 00106 size_t _serial_write(const char *buff, size_t buff_size); 00107 }; 00108 00109 #endif // __FTCD_COMM_SERIAL_H__
Generated on Tue Jul 12 2022 19:12:12 by
1.7.2
