Mayank Gupta / Mbed OS pelion-example-frdm

Dependencies:   FXAS21002 FXOS8700Q

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ftcd_comm_serial.h Source File

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 
00023 class FtcdCommSerial : public FtcdCommBase {
00024 
00025 public:
00026     /** Initialize serial object that communicate via stdin and stdout */
00027     FtcdCommSerial(ftcd_comm_network_endianness_e network_endianness, const uint8_t *header_token, bool use_signature);
00028 
00029     /** Not certain that we need to do anything here, but just in case we need
00030      * to do some clean-up at some point.
00031      */
00032     virtual ~FtcdCommSerial();
00033 
00034     /** Detects the message token from the communication line medium.
00035     *
00036     * @returns
00037     *     zero, if token detected and different value otherwise
00038     */
00039     virtual ftcd_comm_status_e is_token_detected(void);
00040 
00041     /** Reads the message size in bytes from the communication line medium.
00042     * This is the amount of bytes needed to allocate for the upcoming message bytes.
00043     *
00044     * @returns
00045     *     The message size in bytes in case of success, zero bytes otherwise.
00046     */
00047     virtual uint32_t read_message_size(void);
00048 
00049     /** Reads the message size in bytes from the communication line medium.
00050     * This is the amount of bytes needed to allocate for the upcoming message bytes.
00051     *
00052     * @param message_out The buffer to read into and return to the caller.
00053     * @param message_size The message size in bytes.
00054     *
00055     * @returns
00056     *     true upon success, false otherwise
00057     */
00058     virtual bool read_message(uint8_t *message_out, size_t message_size);
00059 
00060     /** Reads the message size in bytes from the communication line medium.
00061     * This is the amount of bytes needed to allocate for the upcoming message bytes.
00062     *
00063     * @param sig The buffer to read into and return to the caller.
00064     * @param sig_size The sig buffer size in bytes.
00065     *
00066     * @returns
00067     *     The message size in bytes in case of success, zero bytes otherwise.
00068     */
00069     virtual bool read_message_signature(uint8_t *sig, size_t sig_size);
00070 
00071     /** Writes the given data to the communication line medium.
00072     *
00073     * @param data The bytes to send through the communication line medium
00074     * @param data_size The data size in bytes
00075     *
00076     * @returns
00077     *     true upon success, false otherwise
00078     */
00079     virtual bool send(const uint8_t *data, uint32_t data_size);
00080 
00081 private:
00082 
00083     /** Reads a buffer from the serial line.
00084     *
00085     * @param buff_out A pointer to the buffer to read into, should be allocated by the caller
00086     * @param buff_max_size The max chars to read
00087     *
00088     * @returns
00089     *     the number of chars read, zero in case of an error
00090     */
00091     size_t _serial_read(char *buff_out, size_t buff_max_size);
00092 
00093     /** Writes a buffer to the serial line.
00094     *
00095     * @param buff A buffer to write.
00096     * @param buff_size The number of chars in buffer
00097     *
00098     * @returns
00099     *     the number of chars that was written, zero in case of an error
00100     */
00101     size_t _serial_write(const char *buff, size_t buff_size);
00102 };
00103 
00104 #endif  // __FTCD_COMM_SERIAL_H__