def hexStrToInt(s): """ 0xで始まるhex値の文字列をintにする """ if s[0:2] != '0x': raise ESSXValueException("bad value: " + s) try: return int(s[2:], 16) except ValueError as err: raise ESSXValueException("bad value: " + s)
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x0d: #ACK (_vgq ,_igq ,_vbq ,_ibq ,_wgq ,_wbq ,_icq ,_tmpq ,_chksum) = unpack("<HHHHHHHHH", recv_data[5:]) res["vgq"] = _vgq res["igq"] = _igq res["vbq"] = _vbq res["ibq"] = _ibq res["wgq"] = _wgq res["wbq"] = _wbq res["icq"] = _icq res["tmpq"] = _tmpq res["chksum"] = _chksum self.response = res elif _cmd == 0x8d: #NAK (_ercd ,_chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x01: #ACK (_cst, _ext, _chksum) = unpack("<HHH", recv_data[5:]) res["cst"] = _cst res["ext"] = _ext res["chksum"] = _chksum self.response = res elif _cmd == 0x81: #NAK (_ercd, _chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x17: #ACK (_pdz ,_mdz ,_chksum) = unpack("<HHH", recv_data[5:]) _pdz = eza2500_util.q_denormalize(_pdz, 14, '380', '0', '57', 'pdz') _mdz = eza2500_util.q_denormalize(_mdz, 14, '380', '0', '57', 'mdz') res["pdz"] = _pdz res["mdz"] = _mdz res["chksum"] = _chksum self.response = res elif _cmd == 0x97: #NAK (_ercd ,_chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x16: #ACK (_ccr, _ddr, _chksum) = unpack("<HHH", recv_data[5:]) _ccr = eza2500_util.q_denormalize(_ccr, 14, '48', '0', '12', 'ccr') _ddr = eza2500_util.q_denormalize(_ddr, 14, '48', '0', '12', 'ddr') res["ccr"] = _ccr res["ddr"] = _ddr res["chksum"] = _chksum self.response = res elif _cmd == 0x96: #NAK (_ercd, _chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x1d: #ACK (_bcf ,_cvb ,_dlb ,_cdb ,_ddb ,_chksum) = unpack("<HHHHHH", recv_data[5:]) _cvb = eza2500_util.q_denormalize(_cvb, 14, '48', '32', '62', 'cvb') _dlb = eza2500_util.q_denormalize(_dlb, 14, '48', '32', '64', 'dlb') _cdb = eza2500_util.q_denormalize(_cdb, 14, '48', '0', '12', 'cdb') _ddb = eza2500_util.q_denormalize(_ddb, 14, '48', '0', '12', 'ddb') res["bcf"] = _bcf res["cvb"] = _cvb res["dlb"] = _dlb res["cdb"] = _cdb res["ddb"] = _ddb res["chksum"] = _chksum self.response = res elif _cmd == 0x9d: #NAK (_ercd ,_chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data
def operationModeStr(v): """ operationModeの文字列を得る @param v データ(EZA2500での値を渡す) @return 文字列 """ if v == 0x0: return "Waiting" elif v == 0x1: return "Hateronomy CV Charging" elif v == 0x2: #EZA2500 0x2 return "Heteronomy CV" elif v == 0x22: return "Heteronomy CV" elif v == 0x4: return "Battery Autonomy" elif v == 0x14: #EZA2500 0x14 return "Grid Autonomy" elif v == 0x34: return "Grid Autonomy CC Battery" elif v == 0x41: #EZA2500 0x41 return "Heteronomy CV" raise ESSXValueException("bad value: operationMode: " + str(v))
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x1a: #ACK (_dvg, _drg, _chksum) = unpack("<HHH", recv_data[5:]) _dvg = eza2500_util.q_denormalize(_dvg, 14, '380', '260', '390', 'dvg') _drg = eza2500_util.q_denormalize(_drg, 13, '1', '0', '3.999', 'drg') res["dvg"] = _dvg res["drg"] = _drg res["chksum"] = _chksum self.response = res elif _cmd == 0x9a: #NAK (_ercd, _chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x0e: #ACK (_tsq, _tpq, _v5q, _fn1q, _fn2q, _fn3q, _fn4q, _fn5q, _chksum) = unpack("<HHHHHHHHH", recv_data[5:]) res["tsq"] = _tsq res["tpq"] = _tpq res["v5q"] = _v5q res["fn1q"] = _fn1q res["fn2q"] = _fn2q res["fn3q"] = _fn3q res["fn4q"] = _fn4q res["fn5q"] = _fn5q res["chksum"] = _chksum self.response = res elif _cmd == 0x8e: #NAK (_ercd, _chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data
def q_denormalize(val, q, ratings, min_val=None, max_val=None, name="", checkrange=False): """ Qフォーマットで非正規化する See. EZA§7 @param val データ(整数/固定小数点) @param q q値 @param ratings 定格値 @param min_val 最小値 @param max_val 最大値 @return 非正規化後の値 ratings, min_val, max_valはDecimal化されるので文字列で渡してもよい。 (そのほうが誤差を抑えらえる) """ if checkrange: if min_val == "None": min_val = None if max_val == "None": max_val = None if min_val != None: n_min_val = int(q_normalize(Decimal(min_val), q, ratings)) if max_val != None: n_max_val = int(q_normalize(Decimal(max_val), q, ratings)) retval = Decimal(val) * Decimal(ratings) / 2**q if checkrange: if min_val != None and int(val) < n_min_val: raise ESSXValueException("out of range: " + name + " " + str(retval) + " < " + str(min_val)) if max_val != None and int(val) > n_max_val: raise ESSXValueException("out of range: " + name + " " + str(retval) + " > " + str(max_val)) return retval
def strToNum(s): """ 文字列や数字をint(または float)にする もしintや float ならそのまま返す 0xで始まる文字列なら16進と判断してintにする。 0xで始まらなければ10進と判断する """ if isinstance(s, int): return s elif isinstance(s, float): return s elif s[0:2] == '0x': try: return int(s[2:], 16) except ValueError as err: raise ESSXValueException("bad value: " + s) else: try: return int(s, 10) except ValueError as err: raise ESSXValueException("bad value: " + s)
def checkOperationMode_2500(self, v): """ EZA2500のoperationModeの確認 """ if v == 0x0: return v elif v == 0x2: return v elif v == 0x14: return v elif v == 0x41: return v raise ESSXValueException("bad value: operation mode: " + str(v))
def q_normalize(val, q, ratings, min_val=None, max_val=None, name="", checkrange=False): """ Qフォーマットで正規化する See. EZA§7 @param val データ @param q q値 @param ratings 定格値 @param min_val 最小値 @param max_val 最大値 @param name エラー発生時に入れる名前 @return 正規化後の数(整数化さされていないので注意) ratings, min_val, max_valはDecimal化されるので文字列で渡してもよい。 (そのほうが誤差を抑えらえる) """ if checkrange: if min_val == "None": min_val = None if max_val == "None": max_val = None if min_val != None and Decimal(val) < Decimal(min_val): raise ESSXValueException("out of range: " + name + ": " + str(val) + " < " + str(min_val)) if max_val != None and Decimal(val) > Decimal(max_val): raise ESSXValueException("out of range: " + name + ": " + str(val) + " > " + str(max_val)) return (2**q) * Decimal(val) / Decimal(ratings)
def alarmStateStr(v): """ alarmStateの文字列を得る @param v データ @return 文字列 """ if v == 0: return "No alarm" elif v == 1: return "Light alarm" elif v == 2: return "Heavy alarm" else: raise ESSXValueException("bad value: alarmState: " + str(v))
def runningStateStr(v): """ runningStateの文字列を得る @param v データ @return 文字列 """ if v == 0: return "off" elif v == 1: return "charge" elif v == 2: return "discharge" else: raise ESSXValueException("bad value: runningState: " + str(v))
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x09: #ACK (_vg, _ig, _vb, _ib, _wg, _wb, _ic, _tmp, _chksum) = unpack("<hhhhhhhhH", recv_data[5:]) _vg = eza2500_util.q_denormalize(_vg, 14, '380', 'None', 'None', 'vg') _ig = eza2500_util.q_denormalize(_ig, 13, '7.8125', 'None', 'None', 'ig') _vb = eza2500_util.q_denormalize(_vb, 14, '48', 'None', 'None', 'vb') _ib = eza2500_util.q_denormalize(_ib, 13, '52.08', 'None', 'None', 'ib') _wg = eza2500_util.q_denormalize(_wg, 11, '2500', 'None', 'None', 'wg') _wb = eza2500_util.q_denormalize(_wb, 11, '2500', 'None', 'None', 'wb') _tmp = eza2500_util.q_denormalize(_tmp, 7, '1', 'None', 'None', 'tmp') res["vg"] = _vg res["ig"] = _ig res["vb"] = _vb res["ib"] = _ib res["wg"] = _wg res["wb"] = _wb res["ic"] = _ic res["tmp"] = _tmp res["chksum"] = _chksum self.response = res elif _cmd == 0x89: #NAK (_ercd, _chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x1c: #ACK (_cib, _dig, _ubv, _ugv, _obv, _ogv, _chksum) = unpack("<HHHHHHH", recv_data[5:]) _cib = eza2500_util.q_denormalize(_cib, 13, '52.08', '0', '56.77', 'cib') _dig = eza2500_util.q_denormalize(_dig, 13, '7.8125', '0', '8.5162', 'dig') _ubv = eza2500_util.q_denormalize(_ubv, 14, '48', '32', '68', 'ubv') _ugv = eza2500_util.q_denormalize(_ugv, 14, '380', '260', '425', 'ugv') _obv = eza2500_util.q_denormalize(_obv, 14, '48', '32', '68', 'obv') _ogv = eza2500_util.q_denormalize(_ogv, 14, '380', '260', '425', 'ogv') res["cib"] = _cib res["dig"] = _dig res["ubv"] = _ubv res["ugv"] = _ugv res["obv"] = _obv res["ogv"] = _ogv res["chksum"] = _chksum self.response = res elif _cmd == 0x9c: #NAK (_ercd, _chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data
def recv(self): essx_debug.log('recv') recv_data = self._recv() self.response_raw = recv_data res = {} (_sfd, _len, _ad1, _ad2, _cmd) = unpack("BBBBB", recv_data[0:5]) if _cmd == 0x0a: #ACK (_ts ,_tp ,_v5s ,_fan1 ,_fan2 ,_fan3 ,_fan4 ,_fan5 ,_chksum) = unpack("<hhhhhhhhH", recv_data[5:]) _v5s = eza2500_util.q_denormalize(_v5s, 10, '1', 'None', 'None', 'v5s') _fan1 = eza2500_util.q_denormalize(_fan1, 0, '1', 'None', 'None', 'fan1') _fan2 = eza2500_util.q_denormalize(_fan2, 0, '1', 'None', 'None', 'fan2') _fan3 = eza2500_util.q_denormalize(_fan3, 0, '1', 'None', 'None', 'fan3') _fan4 = eza2500_util.q_denormalize(_fan4, 0, '1', 'None', 'None', 'fan4') _fan5 = eza2500_util.q_denormalize(_fan5, 0, '1', 'None', 'None', 'fan5') res["ts"] = _ts res["tp"] = _tp res["v5s"] = _v5s res["fan1"] = _fan1 res["fan2"] = _fan2 res["fan3"] = _fan3 res["fan4"] = _fan4 res["fan5"] = _fan5 res["chksum"] = _chksum self.response = res elif _cmd == 0x8a: #NAK (_ercd ,_chksum) = unpack("<HH", recv_data[5:]) res["ercd"] = _ercd res["chksum"] = _chksum self.response = res raise ESSXDeviceException("error: ERCD=%x" % _ercd) else: raise ESSXValueException("bad response") self.response = res essx_debug.log('recv') #essx_debug.dump(recv_data) return recv_data