Uhh I love that
As for pyinsim itself, I'm currently experimenting with Struct objects to use the compiled format string and classes for the packets instead of UserDicts.
Classes look like this
and the __raisePacketEvent would simply do something like
Still working on the class definitions, don't know how it'll work out but I'll definitely give it a try. UserDicts are a good solution but they do feel kind of "hackish" to me
As for pyinsim itself, I'm currently experimenting with Struct objects to use the compiled format string and classes for the packets instead of UserDicts.
_PACKET_FORMAT = {
ISP_ISI : struct.Struct('4B2HBcH16s16s'),
ISP_VER : struct.Struct('4B8s6sH'),
ISP_TINY : struct.Struct('4B'),
ISP_SMALL : struct.Struct('4BI'),
ISP_STA : struct.Struct('4BfH10B6s2B'),
ISP_SCH : struct.Struct('8B'),
ISP_SFP : struct.Struct('4BH2B'),
ISP_SCC : struct.Struct('8B'),
ISP_CPP : struct.Struct('4B3i3H2Bf2H'),
ISP_ISM : struct.Struct('8B32s'),
ISP_MSO : struct.Struct('8B128s'),
ISP_III : struct.Struct('8B64s'),
ISP_MST : struct.Struct('4B64s'),
ISP_MTC : struct.Struct('8B64s'),
ISP_MOD : struct.Struct('4B4i'),
ISP_VTN : struct.Struct('8B'),
ISP_RST : struct.Struct('8B6s2B6H'),
ISP_NCN : struct.Struct('4B24s24s4B'),
ISP_CNL : struct.Struct('8B'),
ISP_CPR : struct.Struct('4B24s8s'),
ISP_NPL : struct.Struct('6BH24s8s4s16s8Bi4B'),
ISP_PLP : struct.Struct('4B'),
ISP_PLL : struct.Struct('4B'),
ISP_LAP : struct.Struct('4B2I2H4B'),
ISP_SPX : struct.Struct('4B2I4B'),
ISP_PIT : struct.Struct('4B2H8B2I'),
ISP_PSF : struct.Struct('4B2I'),
ISP_PLA : struct.Struct('8B'),
ISP_CCH : struct.Struct('8B'),
ISP_PEN : struct.Struct('8B'),
ISP_TOC : struct.Struct('8B'),
ISP_FLG : struct.Struct('8B'),
ISP_PFL : struct.Struct('4B2H'),
ISP_FIN : struct.Struct('4B2I4B2H'),
ISP_RES : struct.Struct('4B24s24s8s4s2I4B2H2BH'),
ISP_REO : struct.Struct('36B'),
ISP_NLP : struct.Struct('4B'),
ISP_MCI : struct.Struct('4B'),
ISP_MSX : struct.Struct('BBBB96s'),
ISP_MSL : struct.Struct('BBBB128s'),
ISP_CRS : struct.Struct('4B'),
ISP_BFN : struct.Struct('8B'),
ISP_AXI : struct.Struct('6BH32s'),
ISP_AXO : struct.Struct('4B'),
ISP_BTN : struct.Struct('12B240s'),
ISP_BTC : struct.Struct('8B'),
ISP_BTT : struct.Struct('8B96s'),
ISP_RIP : struct.Struct('8B2H64s'),
ISP_SSH : struct.Struct('8B32s'),
NODELAP : struct.Struct('2H2B'),
COMPCAR : struct.Struct('2H4B3i3Hh'),
OUTSIM : struct.Struct('I12f4i'),
OUTGAUGE : struct.Struct('I4sH2B12f16s16si'),
}
Classes look like this
class IS_TINY:
def __init__(self, ReqI = 0, SubT = None):
self._Size = 4
self._Type = ISP_TINY
self.ReqI = ReqI
self.SubT = SubT
def pack(self):
return _PACKET_FORMAT[self._Type].pack(self._Size, self._Type, self.ReqI, self.SubT)
and the __raisePacketEvent would simply do something like
(...)
packet = _PACKET_DEFINITIONS[packetType](*_PACKET_FORMAT[packetType].unpack(data)[2:])
(...)
Still working on the class definitions, don't know how it'll work out but I'll definitely give it a try. UserDicts are a good solution but they do feel kind of "hackish" to me