hw_node module

This module is responsable for the handling of each node in the system.
It generates the setup pin configuration to send to the nodes.
It stores each node pin setup and last time sync.

class hw_node.HwNode(NodeSerialNumber, hwModel, address, node_fw)[source]
close()[source]
getHwType()[source]

Return the node hardware type like:

  • gl.inet_only
  • arduino_promini
  • rasberry_b_rev2_only
  • arduino2009
getLastNodeSync()[source]

Return the the time from last node time sync

getMaxPinNumber()[source]

Return the number of pin present in the node

getNodeActivity()[source]

Return the node activity status.

getNodeAddress()[source]

Return the node address , if the address is 0 then the node is the arduino over usb (todo)

getNodeFwVersion()[source]
Return a string containing the node firmware version
An example is “5.14”
getNodeHwModel()[source]
getNodeObjectAddress(objectName)[source]
Given a objectname it will return its address in the node

getNodeObjectFromAddress(objectAddress)[source]
Get the objectname in the node address

getNodeSectionMode()[source]
Warning:Never used
Return a list containing the node mode for each section (8 bit)
(the section0 is relative to the first 8 pins , from pin 0 to pin 7) msb left
(the section1 is relative to the pins from 8 to 15)
(the section2 is relative to the pins from 16 to 23 )
(the section3 is relative to the pins from 24 to 31)
(the section4 is relative to the pins from 32 to 39 )
(the section5 is relative to the pins from 40 to 47)
(the section6 is relative to the pins from 48 to 55 )
getNodeSectionModeByPin(pin)[source]
Deprecated , not used anymore.
Given a pin return the node mode for the section (8 bit) containing that pin.
getNodeSectionStatusByPin(pin)[source]

Given a pin return a tuple with:

  • The number of the section where the pin is located
  • The the node status register for the section (8 bit) containing that pin
Structure:
(the section0 is relative to the first 8 pins , from pin 0 to pin 7) msb left
(the section1 is relative to the pins from 8 to 15)
(the section2 is relative to the pins from 16 to 23 )
(the section3 is relative to the pins from 24 to 31)
(the section4 is relative to the pins from 32 to 39 )
(the section5 is relative to the pins from 40 to 47)
(the section6 is relative to the pins from 48 to 55 )
getNodeSerialNumber()[source]
Return the node serial number.
For example “Plug6way0001”
getNodeStatusList()[source]
Warning:

Never used

Return a list containing the node status for each pin.

getNodeTimeout()[source]
Return the time after which the node is declared inactive.
So if getLastNodeSync() is greater than this self.timeout the node will be setted as inactive
self.timeout is readed from hardwareModelDict in globalVar.py
getPinMode(pin)[source]

Deprecated , not used anymore

getPinModeList()[source]
Warning:

Never used

Return the Pin mode list containing all the pin mode.

getPinStatus(pin)[source]

Deprecated , not used anymore

getSetupMsg()[source]

Return a encoded string containing the setup mode for the node pins

I need to encode the pin setup in a sinmple and compact way. Here the protocol:

start with 's='
then  add    9 bytes that rappresent the pin used (1 for pin used 0 for not used)   
after that   9 bytes that rappresent the digital pin setup from pin0 to pin 127
after that   9 bytes that tell arduino which pin to set as analog input
after that   9 bytes that tell arduino which pin to set as pwm output
after that   9 bytes that tell arduino which pin to set as servo output
then  1   byte for future use , for now '#'
example:"s=000000000000000000000000000000000000000000000#"  
the 0 are not 0 but the value corrisponding to ascii '0'
total 48 byte 
getUsedPins()[source]

Return the list of used pins

getnodeObjectsDict()[source]
Get the objectname in the node address

isPinOk(pin)[source]

Return 1 if the given pin exist in this hardware node, 0 otherwise

setAnalogPinInputStatus(pin, status)[source]

Deprecated , not used anymore.

setDigitalPinInputStatus(pin, status)[source]

Deprecated , not used anymore.

setDigitalPinOutputStatus(pin, status)[source]

Deprecated , not used anymore

setNodeActivity(value)[source]

Set the node activity status with the one given.

Parameters:value
  • The value to set the node activity should be a integer of 0 or 1
    0 If the node is inactive
    1 If the node is active
setNodeAddress(address)[source]
Set the node address with the string passed
Example: “192.168.101.10”
setNodeAnalogInputStatusFromReg(pin_number, low_byte, high_byte)[source]
Given a pin number, and two bytes return the analog value in an single integer.
Since arduino analogRead return a 10 bit analog value to send it I need to split it in two bytes (8 bit each)
so arduino will send 2 bytes the low_byte and the high_byte , this function will rebuild the number from those two bytes
setNodeFwVersion(nodeVersion)[source]
Set the node firmware version with the given string
Example “4.15”
setNodeObjectAddress(objectAddress, objectName)[source]
Set the objectname to an address in the node

setNodePinMode(pin, mode)[source]
Given a pin number and a mode, set the pin mode
The options for mode are:
  • “DOUTPUT” : digital output
  • “AOUTPUT” : analog output
  • “SOUTPUT” : servo motor output
  • “DINPUT” : digital input
  • “AINPUT” : analog input
setNodeSectionDInputStatus(section_number, status_byte)[source]
Set the node status pins of a section (8 bit) received from arduino.
if the section status is different from the previous one then check
what pins changed and ask the webserver.py to change the webobj status of the relative pins
i don’t need a setNodeSectionDoutputStatus because the output status will be saved in the webobject status.
updateLastNodeSync(time)[source]

When called update the time from last node time sync with the given one