Closed kdschlosser closed 5 years ago
never mind.. after trying to figure this out for the past 3 hours. only when i finally post an issue do i find the issue and fix it..
sorry folks!
You can always check http://bamboo.my-ho.st/bamboo/browse/OZW-OZWLNX when you have compile issues.
As you can see we have a compile failure on older versions of VS right now. I need to investigate and fix that.
I am having a booger of a time with one thing. and it doesn't make any sense. I am getting the error below even tho I do have an overloaded method declared. It beats the hell out of me why it's doing that.
Error compiling Cython file:
------------------------------------------------------------
...
cret = self.manager.SetValueListSelection(values_map.at(id), type_string)
logger.debug("SetValueListSelection %s", cret)
ret = 1 if cret else 0
elif datatype == "BitSet":
type_bool = value
cret = self.manager.SetValue(values_map.at(id), pos, type_bool)
^
------------------------------------------------------------
What is type_bool from the compiler perspective? It’s probably not sure if it’s a integer or ???
You could wrap it in a static_cast
Or do something like if Val = python_true ? true : false in the setvalue call if it can’t be cast.
ok so this code is Cython code. Cython code = C++ code and python code smashed into a single language.
It is similar to C++ code in terms of the verbage and having to declare variable types. the syntax and statements are python. there needs to be a header file of sorts in Cython where you declare classes methods and class variables.
there are some datatypes that would need to be cast into a python version of it. and some that really do not.
bool
is not one of the types that needs to be cast. and int
in python pretty much covers all of your uint*
and int*
data types. as well as ushort*
and short*
there is more then that. but to keep it simple we will leave it there. There is only checking does for min/max when converting from python to C++ and nothing is done when passing from C++ to python. I believe that is how it works. I have not dove into it. But from my work with PyWinAPI and porting the Windows SDK to python this is what I have come up with. I doubt it is going to be much different because of Cython.
you have a "header" file of corts as well as the source file. very similiar to what is done in C++
file extensions header = .pyd source = .pyx
This code is from the "header" (.pxd) file Cython does allow for overloading. You can see that done for SetValue. and you can also see the declaring of the overload SetValue(value id, pos, value) for the BitSet value type.
cdef extern from "Manager.h" namespace "OpenZWave":
cdef cppclass Manager:
# // Destructor
void Destroy()
# // Configuration
# deprecated void WriteConfig(uint32_t homeid)
Options* GetOptions()
# // Drivers
bool AddDriver(string serialport)
bool RemoveDriver(string controllerPath)
uint8_t GetControllerNodeId(uint32_t homeid)
uint8_t GetSUCNodeId(uint32_t homeid)
bool IsPrimaryController(uint32_t homeid)
bool IsStaticUpdateController(uint32_t homeid)
bool IsBridgeController(uint32_t homeid)
string getVersionAsString()
string getVersionLongAsString()
string GetLibraryVersion(uint32_t homeid)
string GetLibraryTypeName(uint32_t homeid)
int32_t GetSendQueueCount( uint32_t homeId )
void LogDriverStatistics( uint32_t homeId )
void GetDriverStatistics( uint32_t homeId, DriverData* data )
void GetNodeStatistics( uint32_t homeId, uint8_t nodeid, NodeData* data )
ControllerInterface GetControllerInterfaceType( uint32_t homeId )
string GetControllerPath( uint32_t homeId )
# // Network
void TestNetworkNode( uint32_t homeId, uint8_t nodeId, uint32_t count )
void TestNetwork( uint32_t homeId, uint32_t count )
void HealNetworkNode( uint32_t homeId, uint32_t nodeId, bool _doRR )
void HealNetwork( uint32_t homeId, bool doRR)
# // Polling
uint32_t GetPollInterval()
void SetPollInterval(uint32_t milliseconds, bIntervalBetweenPolls)
bool EnablePoll(ValueID& valueId, uint8_t intensity)
bool DisablePoll(ValueID& valueId)
bool isPolled(ValueID& valueId)
void SetPollIntensity( ValueID& valueId, uint8_t intensity)
uint8_t GetPollIntensity(ValueID& valueId)
# // Node Information
bool RefreshNodeInfo(uint32_t homeid, uint8_t nodeid)
bool RequestNodeState(uint32_t homeid, uint8_t nodeid)
bool RequestNodeDynamic( uint32_t homeId, uint8_t nodeId )
bool IsNodeListeningDevice(uint32_t homeid, uint8_t nodeid)
bool IsNodeFrequentListeningDevice( uint32_t homeId, uint8_t nodeId )
bool IsNodeBeamingDevice( uint32_t homeId, uint8_t nodeId )
bool IsNodeRoutingDevice(uint32_t homeid, uint8_t nodeid)
bool IsNodeSecurityDevice( uint32_t homeId, uint8_t nodeId )
bool IsNodeZWavePlus( uint32_t homeId, uint8_t nodeId )
uint32_t GetNodeMaxBaudRate(uint32_t homeid, uint8_t nodeid)
uint8_t GetNodeVersion(uint32_t homeid, uint8_t nodeid)
uint8_t GetNodeSecurity(uint32_t homeid, uint8_t nodeid)
uint8_t GetNodeBasic(uint32_t homeid, uint8_t nodeid)
uint8_t GetNodeGeneric(uint32_t homeid, uint8_t nodeid)
uint8_t GetNodeSpecific(uint32_t homeid, uint8_t nodeid)
string GetNodeType(uint32_t homeid, uint8_t nodeid)
uint16_t GetNodeDeviceType(uint32_t homeid, uint8_t nodeid)
string GetNodeDeviceTypeString(uint32_t homeid, uint8_t nodeid)
uint8_t GetNodeRole(uint32_t homeid, uint8_t nodeid)
string GetNodeRoleString(uint32_t homeid, uint8_t nodeid)
uint8_t GetNodePlusType(uint32_t homeid, uint8_t nodeid)
string GetNodePlusTypeString(uint32_t homeid, uint8_t nodeid)
uint32_t GetNodeNeighbors(uint32_t homeid, uint8_t nodeid, uint8_t** nodeNeighbors)
string GetNodeManufacturerName(uint32_t homeid, uint8_t nodeid)
string GetNodeProductName(uint32_t homeid, uint8_t nodeid)
string GetNodeName(uint32_t homeid, uint8_t nodeid)
string GetNodeLocation(uint32_t homeid, uint8_t nodeid)
string GetNodeManufacturerId(uint32_t homeid, uint8_t nodeid)
string GetNodeProductType(uint32_t homeid, uint8_t nodeid)
string GetNodeProductId(uint32_t homeid, uint8_t nodeid)
void SetNodeManufacturerName(uint32_t homeid, uint8_t nodeid, string manufacturerName)
void SetNodeProductName(uint32_t homeid, uint8_t nodeid, string productName)
void SetNodeName(uint32_t homeid, uint8_t nodeid, string productName)
void SetNodeLocation(uint32_t homeid, uint8_t nodeid, string location)
# deprecated void SetNodeOn(uint32_t homeid, uint8_t nodeid)
# deprecated void SetNodeOff(uint32_t homeid, uint8_t nodeid)
# deprecated void SetNodeLevel(uint32_t homeid, uint8_t nodeid, uint8_t level)
bool IsMultiInstance(uint32_t homeid, uint8_t nodeid)
bool IsNodeInfoReceived(uint32_t homeid, uint8_t nodeid)
bool IsNodePlusInfoReceived(uint32_t homeid, uint8_t nodeid)
bool GetNodeClassInformation( uint32_t homeId, uint8_t nodeId, uint8_t commandClassId,
string *className, uint8_t *classVersion)
bool IsNodeAwake(uint32_t homeid, uint8_t nodeid)
bool IsNodeFailed(uint32_t homeid, uint8_t nodeid)
string GetNodeQueryStage(uint32_t homeid, uint8_t nodeid)
uint8_t GetNodeIcon(uint32_t homeid, uint8_t nodeid)
string GetNodeIconName(uint32_t homeid, uint8_t nodeid)
# // Values
string GetValueLabel(ValueID& valueid)
void SetValueLabel(ValueID& valueid, string value)
string GetValueUnits(ValueID& valueid)
void SetValueUnits(ValueID& valueid, string value)
string GetValueHelp(ValueID& valueid)
void SetValueHelp(ValueID& valueid, string value)
uint32_t GetValueMin(ValueID& valueid)
uint32_t GetValueMax(ValueID& valueid)
bool IsValueReadOnly(ValueID& valueid)
bool IsValueWriteOnly(ValueID& valueid)
bool IsValueSet(ValueID& valueid)
bool IsValuePolled( ValueID& valueid )
bool GetValueAsBitSet(ValueID& valueid, uint8_t _pos, bool* o_value)
bool GetValueAsBool(ValueID& valueid, bool* o_value)
bool GetValueAsByte(ValueID& valueid, uint8_t* o_value)
bool GetValueAsFloat(ValueID& valueid, float* o_value)
bool GetValueAsInt(ValueID& valueid, int32_t* o_value)
bool GetValueAsShort(ValueID& valueid, int16_t* o_value)
bool GetValueAsRaw(ValueID& valueid, uint8_t** o_value, uint8_t* o_length )
bool GetValueAsString(ValueID& valueid, string* o_value)
bool GetValueListSelection(ValueID& valueid, string* o_value)
bool GetValueListSelection(ValueID& valueid, int32_t* o_value)
bool GetValueListItems(ValueID& valueid, vector[string]* o_value)
bool GetValueListValues(ValueID& valueid, vector[int32_t]* o_value)
bool SetValue(ValueID& valueid, bool value)
bool SetValue(ValueID& valueid, uint8_t value)
bool SetValue(ValueID& valueid, float value)
bool SetValue(ValueID& valueid, int32_t value)
bool SetValue(ValueID& valueid, int16_t value)
bool SetValue(ValueID& valueid, uint8_t* value, uint8_t length)
bool SetValue(ValueID& valueid, uint8_t pos, bool value)
bool SetValue(ValueID& valueid, string value)
bool SetValueListSelection(ValueID& valueid, string selecteditem)
bool RefreshValue(ValueID& valueid)
void SetChangeVerified(ValueID& valueid, bool verify)
bool GetChangeVerified(ValueID& valueid)
bool PressButton(ValueID& valueid)
bool ReleaseButton(ValueID& valueid)
bool GetValueFloatPrecision(ValueID& valueid, uint8_t* o_value)
# // Climate Control
uint8_t GetNumSwitchPoints(ValueID& valueid)
bool SetSwitchPoint(ValueID& valueid, uint8_t hours, uint8_t minutes, uint8_t setback)
bool RemoveSwitchPoint(ValueID& valueid, uint8_t hours, uint8_t minutes)
bool ClearSwitchPoints(ValueID& valueid)
bool GetSwitchPoint(ValueID& valueid, uint8_t idx, uint8_t* o_hours, uint8_t* o_minutes, int8_t* o_setback)
# // SwitchAll
# deprecated void SwitchAllOn(uint32_t homeid)
# deprecated void SwitchAllOff(uint32_t homeid)
# // Configuration Parameters
bool SetConfigParam(uint32_t homeid, uint8_t nodeid, uint8_t param, uint32_t value, uint8_t size)
void RequestConfigParam(uint32_t homeid, uint8_t nodeid, uint8_t aram)
void RequestAllConfigParams(uint32_t homeid, uint8_t nodeid)
# // Groups
uint8_t GetNumGroups(uint32_t homeid, uint8_t nodeid)
uint32_t GetAssociations(uint32_t homeid, uint8_t nodeid, uint8_t groupidx, struct_associations o_associations)
#~ cython overloading problem
#~ src-lib/libopenzwave/libopenzwave.pyx:3739:58: no suitable method found
#~ uint32_t GetAssociations(uint32_t homeid, uint8_t nodeid, uint8_t groupidx, int_associations o_associations)
uint8_t GetMaxAssociations(uint32_t homeid, uint8_t nodeid, uint8_t groupidx)
string GetGroupLabel(uint32_t homeid, uint8_t nodeid, uint8_t groupidx)
void AddAssociation(uint32_t homeid, uint8_t nodeid, uint8_t groupidx, uint8_t targetnodeid, uint8_t instance)
void RemoveAssociation(uint32_t homeid, uint8_t nodeid, uint8_t groupidx, uint8_t targetnodeid, uint8_t instance)
bool AddWatcher(pfnOnNotification_t notification, void* context)
bool RemoveWatcher(pfnOnNotification_t notification, void* context)
# void NotifyWatchers(Notification*)
# // Controller Commands
void ResetController(uint32_t homeid)
void SoftReset(uint32_t homeid)
#Deprecated
bool BeginControllerCommand(uint32_t homeid, ControllerCommand _command, pfnControllerCallback_t _callback, void* _context, bool _highPower, uint8_t _nodeId, uint8_t _arg )
bool CancelControllerCommand(uint32_t homeid)
bool AddNode(uint32_t homeid, bool _doSecurity)
bool RemoveNode(uint32_t homeid)
bool RemoveFailedNode(uint32_t homeid, uint8_t nodeid)
bool HasNodeFailed(uint32_t homeid, uint8_t nodeid)
bool ReplaceFailedNode(uint32_t homeid, uint8_t nodeid)
bool AssignReturnRoute(uint32_t homeid, uint8_t nodeid)
bool RequestNodeNeighborUpdate(uint32_t homeid, uint8_t nodeid)
bool RequestNetworkUpdate(uint32_t homeid, uint8_t nodeid)
bool ReplicationSend(uint32_t homeid, uint8_t nodeid)
bool DeleteAllReturnRoutes(uint32_t homeid, uint8_t nodeid)
bool SendNodeInformation(uint32_t homeid, uint8_t nodeid)
bool CreateNewPrimary(uint32_t homeid)
bool TransferPrimaryRole(uint32_t homeid)
bool ReceiveConfiguration(uint32_t homeid)
bool CreateButton(uint32_t homeid, uint8_t nodeid, uint8_t buttonid)
bool DeleteButton(uint32_t homeid, uint8_t nodeid, uint8_t buttonid)
so now in the .pyx file you are going to see more code that looks like python then in the .pyd file which is closer to C++ code. because the code in the .pyx is closer to python we cannot declare overloaded methods. these methods are what is directly accessed by the importing module. which is going to be python. so it has to be compatible with python. call this the go between. the middle man. it does all of the needed type changes and evaluation of the data being bapped to it to be able to determine the proper call that needs to be made. It is almost the same as what I had outlined with being able to compile openzwave as a python module. except what this method does would be coded in C code. this is just flipped.
here is the code from the .pyx file it is the serValue method that is accessed from python_openzwave. because the creation of overloaded methods cannot be made we have to add any and all parameters that may be used to the method. and supply them with default values.
I added the code so it is no different then what is already there. i just tacked on the additional code to the bottom. This is why I do not know why it is not working. But you will see what I am talking about with some data types needing conversion and others do not.
def setValue(self, id, value, pos=0):
'''
.. _setValue:
Sets the value of a device valueid.
Due to the possibility of a device being asleep, the command is assumed to suceeed, and the value
held by the node is updated directly. This will be reverted by a future status message from the device
if the Z-Wave message actually failed to get through. Notification callbacks will be sent in both cases.
:param id: The ID of a value.
:type id: int
:param value: The value to set.
:type value: int
:return: An integer representing the result of the operation 0 : The C method fails, 1 : The C method succeed, 2 : Can't find id in the map
:rtype: int
'''
cdef float type_float
cdef bool type_bool
cdef uint8_t type_byte
cdef int32_t type_int
cdef int16_t type_short
cdef string type_string
cdef uint8_t* type_raw
ret = 2
if values_map.find(id) != values_map.end():
datatype = PyValueTypes[values_map.at(id).GetType()]
if datatype == "Bool":
type_bool = value
cret = self.manager.SetValue(values_map.at(id), type_bool)
ret = 1 if cret else 0
elif datatype == "Byte":
type_byte = value
cret = self.manager.SetValue(values_map.at(id), type_byte)
ret = 1 if cret else 0
elif datatype == "Raw":
type_raw = <uint8_t*> malloc(len(value)*sizeof(uint8_t))
for x in range(0, len(value)):
#print value[x]
type_raw[x] = ord(value[x])
cret = self.manager.SetValue(values_map.at(id), type_raw, len(value))
ret = 1 if cret else 0
free(type_raw)
elif datatype == "Decimal":
type_float = value
cret = self.manager.SetValue(values_map.at(id), type_float)
ret = 1 if cret else 0
elif datatype == "Int":
type_int = value
cret = self.manager.SetValue(values_map.at(id), type_int)
ret = 1 if cret else 0
elif datatype == "Short":
type_short = value
cret = self.manager.SetValue(values_map.at(id), type_short)
ret = 1 if cret else 0
elif datatype == "String":
if six.PY3:
type_string = str_to_cppstr(value)
else:
type_string = str_to_cppstr(string(value))
cret = self.manager.SetValue(values_map.at(id), type_string)
ret = 1 if cret else 0
elif datatype == "Button":
type_bool = value
cret = self.manager.SetValue(values_map.at(id), type_bool)
ret = 1 if cret else 0
elif datatype == "List":
logger.debug("SetValueListSelection %s", value)
if six.PY3:
type_string = str_to_cppstr(value)
else:
type_string = str_to_cppstr(string(value))
cret = self.manager.SetValueListSelection(values_map.at(id), type_string)
logger.debug("SetValueListSelection %s", cret)
ret = 1 if cret else 0
elif datatype == "BitSet":
type_bool = value
cret = self.manager.SetValue(values_map.at(id), pos, type_bool)
ret = 1 if cret else 0
return ret
never mind. I now see what the problem is.. HOLY COW!!!
I am such a dum dum i need to cast the pos into a uint8_t and i am not doing that. OYE VAE!
well this is what helped me to figure it out. sometimes it is just explaining it that will make the problem reveal it's self.
OK folks. I have one for ya.
I am trying to compile the current code in the master branch and I am encountering compiler errors.
This is the setup. openzwave is being compiled from inside python. I updated the windows build portion of the library. the code has been added to python_openzwave it will be in the next release. The build system works fine with the previous release of openzwave.
BUILD ENVIRONMENT
COMPILER ARGUMENTS
ERROR
The compiler hangs when compiling Utils.cpp. This error does not show until I perform a keyboard interrupt. then the compiler starts to move again spits out this error and of course the program exists because i did a keyboard interrupt.
The new build system for python_openzwave does not use the solution foles included with openzwave. instead I create an identical build environment that would be created if using visual studio or vcvarsall. I do this without using vcvarsall (it has issues). I then call cl.exe directly passing the compiler arguments outlined above.
If there is someone that is running a Windows box and has Visual Studio, Visual C, or the Visual Studio Build Tools and is willing to test to make sure that the problem is not isolated to only my machine. That would be a HUGE help.
To do that you need to download the 0.5.x branch and run
python setup.py build --flavor=dev
the program should take care of everything.