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.
Dependencies: EthernetInterface NetworkAPI mbed-rtos mbed
Fork of NetRelais by
controller.hpp
00001 /** 00002 * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com> 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00015 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00016 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00017 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00018 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00019 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00020 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00021 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00023 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 */ 00025 00026 #ifndef _CONTROLLER_HPP_ 00027 #define _CONTROLLER_HPP_ 00028 00029 #include <cstdio> 00030 #include <cstring> 00031 #include <vector> 00032 00033 #include "mbed.h" 00034 00035 #include "NetworkAPI/select.hpp" 00036 #include "NetworkAPI/tcp/socket.hpp" 00037 00038 class Controller 00039 { 00040 protected: 00041 typedef std::vector<DigitalOut *> DigitalOutputList; 00042 typedef std::vector<DigitalIn *> DigitalInputList; 00043 00044 struct { 00045 DigitalOutputList output; 00046 DigitalInputList input; 00047 } _io; 00048 00049 struct { 00050 network::tcp::Socket server; 00051 network::tcp::Socket client; 00052 } _network; 00053 00054 enum Command { 00055 C_None, 00056 C_Read, 00057 C_Write 00058 }; 00059 00060 enum ParseState { 00061 S_Init, 00062 S_Index, 00063 S_Execute, 00064 }; 00065 00066 enum ParseError { 00067 E_None = 0, 00068 E_Internal = -1, 00069 E_InvalidCommand = -2, 00070 E_InvalidFormat = -3, 00071 E_UnknownIndex = -4, 00072 E_InvalidValue = -5 00073 }; 00074 00075 public: 00076 ~Controller(); 00077 00078 int start(int port = 61850, int max_pending = 1); 00079 int stop(); 00080 00081 int dispatch(); 00082 00083 int addOutput(DigitalOut *output); 00084 DigitalOut *getOutput(size_t index); 00085 00086 int addInput(DigitalIn *input); 00087 DigitalIn *getInput(size_t index); 00088 00089 protected: 00090 bool _outputExists(DigitalOut *output); 00091 bool _inputExists(DigitalIn *input); 00092 00093 int _parseCommand(network::Buffer &buffer); 00094 }; 00095 00096 #endif // _CONTROLLER_HPP_
Generated on Tue Jul 19 2022 10:03:11 by
