Simple interface for Mbed Cloud Client
Embed:
(wiki syntax)
Show/hide line numbers
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 "mbed.h" 00021 #include "ftcd_comm_base.h" 00022 #include <inttypes.h> 00023 00024 00025 00026 class FtcdCommSerial : public FtcdCommBase { 00027 00028 public: 00029 /** 00030 * The constructor gets from the application initialized serial object. The object should be configured for both TX and RX and application's baud rate. 00031 */ 00032 FtcdCommSerial(Serial *pc, 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 * Pointer that should be set to initialized serial object. 00089 */ 00090 Serial *_pc; 00091 /** Reads a buffer from the serial line. 00092 * 00093 * @param buff_out A pointer to the buffer to read into, should be allocated by the caller 00094 * @param buff_max_size The max chars to read 00095 * 00096 * @returns 00097 * the number of chars read, zero in case of an error 00098 */ 00099 size_t _serial_read(char *buff_out, size_t buff_max_size); 00100 00101 /** Writes a buffer to the serial line. 00102 * 00103 * @param buff A buffer to write. 00104 * @param buff_size The number of chars in buffer 00105 * 00106 * @returns 00107 * the number of chars that was written, zero in case of an error 00108 */ 00109 size_t _serial_write(const char *buff, size_t buff_size); 00110 }; 00111 00112 #endif // __FTCD_COMM_SERIAL_H__
Generated on Tue Jul 12 2022 19:01:34 by 1.7.2