|
solarpowerlog trunk
|
00001 /* ---------------------------------------------------------------------------- 00002 solarpowerlog 00003 Copyright (C) 2009 Tobias Frost 00004 00005 This file is part of solarpowerlog. 00006 00007 Solarpowerlog is free software; However, it is dual-licenced 00008 as described in the file "COPYING". 00009 00010 For this file (CInverterSputnikSSeries.h), the license terms are: 00011 00012 You can redistribute it and/or modify it under the terms of the GNU Lesser 00013 General Public License (LGPL) as published by the Free Software Foundation; 00014 either version 3 of the License, or (at your option) any later version. 00015 00016 This program is distributed in the hope that it will be useful, but 00017 WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Library General Public 00022 License along with this proramm; if not, see 00023 <http://www.gnu.org/licenses/>. 00024 ---------------------------------------------------------------------------- 00025 */ 00026 00033 #ifndef CINVERTERSPUTNIKSSERIES_H_ 00034 #define CINVERTERSPUTNIKSSERIES_H_ 00035 00036 #ifdef HAVE_CONFIG_H 00037 #include "config.h" 00038 #endif 00039 00040 #if defined HAVE_INV_SPUTNIK 00041 00042 #include "Inverters/interfaces/InverterBase.h" 00043 #include "Inverters/BasicCommands.h" 00044 00045 #include <queue> 00046 00052 class CInverterSputnikSSeries: public IInverterBase 00053 { 00054 public: 00055 CInverterSputnikSSeries(const string & name, 00056 const string & configurationpath); 00057 virtual ~CInverterSputnikSSeries(); 00058 00059 virtual bool CheckConfig(); 00060 00062 virtual void ExecuteCommand(const ICommand *Command); 00063 00064 protected: 00066 static unsigned int CalcChecksum(const char* str, int len); 00067 00068 private: 00069 00071 enum Commands 00072 { 00073 CMD_INIT = 1000, 00074 CMD_WAIT4CONNECTION, 00075 CMD_IDENTFY_WAIT, 00076 CMD_POLL, 00077 CMD_WAIT_RECEIVE, 00078 CMD_DISCONNECTED, 00079 CMD_QUERY_IDENTIFY, 00080 CMD_EVALUATE_RECEIVE, 00081 CMD_WAIT_SENT, 00082 CMD_SEND_QUERIES, 00083 CMD_QUERY_POLL 00084 }; 00085 00087 enum Ports 00088 { 00089 QUERY = 100, COMMAND = 200, ALARM = 300, 00090 INTERFACE = 1000 00091 }; 00092 00094 enum query 00095 { 00096 TYP, SWV, BUILDVER, EC00, EC01, EC02, 00097 EC03, EC04, EC05, EC06, EC07, EC08, PAC, 00098 KHR, DYR, DMT, DDY, KYR, KMT, KDY, 00099 KT0, PIN, TNF, PRL, UDC, UL1, UL2, 00100 UL3, IDC, IL1, IL2, IL3, TKK, TK2, 00101 TK3, TMI, THR, SYS 00102 }; 00103 00105 void pushinverterquery(enum query q); 00106 00110 string assemblequerystring(); 00111 00113 int parsereceivedstring(const string& s); 00114 00116 bool parsetoken(string token); 00117 00119 queue<enum query> cmdqueue; 00120 00125 void tokenizer(const char *delimiters, const string& s, 00126 vector<string> &tokens); 00127 00128 // token handlers 00129 // they all will take its tokens and do whatever required, usually 00130 // updating Capabilities. 00131 bool token_TYP(const vector<string> &tokens); 00132 bool token_SWVER(const vector<string> &tokens); 00133 bool token_BUILDVER(const vector<string> &tokens); 00134 bool token_ECxx(const vector<string> &tokens); 00135 bool token_PAC(const vector<string> &tokens); 00136 bool token_KHR(const vector<string> &tokens); 00137 bool token_DYR(const vector<string> &tokens); 00138 bool token_DMT(const vector<string> &tokens); 00139 bool token_DDY(const vector<string> &tokens); 00140 bool token_KYR(const vector<string> &tokens); 00141 bool token_KMT(const vector<string> &tokens); 00142 bool token_KDY(const vector<string> &tokens); 00143 bool token_KT0(const vector<string> &tokens); 00144 bool token_PIN(const vector<string> &tokens); 00145 bool token_TNF(const vector<string> &tokens); 00146 bool token_PRL(const vector<string> &tokens); 00147 bool token_UDC(const vector<string> &tokens); 00148 bool token_UL1(const vector<string> &tokens); 00149 bool token_UL2(const vector<string> &tokens); 00150 bool token_UL3(const vector<string> &tokens); 00151 bool token_IDC(const vector<string> &tokens); 00152 bool token_IL1(const vector<string> &tokens); 00153 bool token_IL2(const vector<string> &tokens); 00154 bool token_IL3(const vector<string> &tokens); 00155 bool token_TKK(const vector<string> &tokens); 00156 bool token_TK2(const vector<string> &tokens); 00157 bool token_TK3(const vector<string> &tokens); 00158 bool token_TMI(const vector<string> &tokens); 00159 bool token_THR(const vector<string> &tokens); 00160 bool token_SYS(const vector<string> &tokens); 00161 00162 // a helper, as this is shared by two token parsers. 00163 void create_versioncapa(void); 00164 00166 int swversion; 00167 int swbuild; 00168 00170 unsigned int commadr; 00172 unsigned int ownadr; 00173 00175 unsigned int laststatuscode; 00176 00178 unsigned int errcnt_; 00179 }; 00180 00181 #endif 00182 00183 #endif /* CINVERTERSPUTNIKSSERIES_H_ */