I want to know how can I read some attribute on local and remote zigbee device using TI zstack and how to put its value to uart. I'm zstack beginner. I managed to use uart with usb to uart converter and can send data to my pc. So I need to know how to get the attribute data. I've read api manual but didn't anderstand how to use zcl_SendRead function. Thanks.
Follow section "3.3 Send Read" of the "Z-Stack ZCL API.pdf" this should contain enough info for getting the read attr to the correct destination device. The contents of the readCmd is an array of attribute ID's, specific to the attribute(s) you want to read. You will need to consult the ZCL specification or device documentation to determine the correct Attr ID and Cluster ID.
An example for sending a read attr is shown below. It reads the ATTRID_MS_TEMPERATURE_MEASURED_VALUE attribute (from the ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT cluster) from device with short address 0x1234 and endpoint 0x1.
afAddrType_t dstAddr;
dstAddr.addrMode = afAddr16Bit;
dstAddr.addr.shortAddr = 0x1234; //set this to correct address
dstAddr.addr.endPoint = 0x1; // set this to correct ep
zclReadCmd_t *cmd = osal_mem_alloc((sizeof zclReadCmd_t) + sizeof(uint16));
cmd->numAttr = 1;
cmd->attrID[0] = ATTRID_MS_TEMPERATURE_MEASURED_VALUE;
zcl_SendRead( SAMPLETHERMOSTAT_ENDPOINT, &dstAddr,
ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT,
&cmd, ZCL_FRAME_CLIENT_SERVER_DIR,
hdr->fc.disableDefaultRsp, hdr->transSeqNum );
Once this command is sent you need to process the received the response, you will notice that the functions are contained in the ZStack Sample Applications but not populated, for instance the SampleSwitch application has zclSampleSw_ProcessInReadRspCmd() function, this will be called to process the read attr response and you will need to populate it to do what you want to do with the response.
Regards,
TC.
Related
I would like to retrieve the public IP address associated with a given network interface. I need to do something like
client = NetworkManagementClient(...)
interface = client.network_interfaces.get('rg', 'nic-name')
ip_config_id = interface[0].public_ip_address.id
ip_config = some_magic(ip_config_id) # What goes here?
return ip_config.ip_address
This question suggests that in order to implement the some_magic routine, I should parse the ID (by splitting on slashes) and call client.public_ip_addresses.get(). This question indicates that I can call resource_client.resources.get_by_uid, but that doesn't return a PublicIPAddress object (I know I can call as_dict on it and get the data that way).
Is there a way to get an object of the appropriate type (in this case PublicIPAddress) from an object's ID in Azure (without manually parsing the ID)?
Update:
Due to this issue: public_ip_address method within NetworkManagementClient will not return values, we cannot fetch the ip address from PublicIPAddress.
So currently, you can use any other workaround, For example:
myip = client.public_ip_addresses.get(" resource_group_name","public_ip_address_name")
print(myip.ip_address)
You can change this line of code ip_config_id = interface[0].public_ip_address.id to something like my_public_ip_address = interface.ip_configurations[0].public_ip_address, then the return type is PublicIPAddress.
For example:
I want my "GetContent" script to detect whether the device is "watch" and pass along an instruction to filter out candidate answers from a content.json file whose text field has a length greater than a certain number of characters.
content.json format:
{tags: ["literature"], text: "At once it struck me what quality went to form a man of achievement, especially in literature, and which Shakespeare possessed so enormously -- I mean negative capability, that is, when a man is capable of being in uncertainties, mysteries, doubts, without any irritable reaching after fact and reason. Source: John Keats", image: {url: "images/Shakespeare.jpg"}},
So the logic would be
if (watch) content = short_quotes_only
I would recommend exploring the device property of $vivContext (Documentation)
The device property will allow you to see which type of device a user is using (bixby-mobile, bixby-tv, etc.) and provide the data you wish to show for the device being used.
This combination of snippets worked for me:
device = $vivContext.device
console.log('device', device)
if (device == 'bixby-watch' ) { maxlength = 100
console.log('maxlength is now', maxlength)
}
then later in the script
//filters entitled content by length of text field in characters
content = content.filter(function(i) { return i.text.length < maxlength;
I am writing a set of register models using uvm_reg class. Individual register size is 8-bit. Register block is created to contains those registers:
class my_reg_block extends uvm_reg_block;
my_byte_reg reg_00;
my_byte_reg reg_01;
my_byte_reg reg_10;
my_byte_reg reg_11;
...
// build()
my_map.add_reg(reg_00, 32'h0000 /*offset*/, ""RW");
my_map.add_reg(reg_01, 32'h0001 /*offset*/, ""RW");
my_map.add_reg(reg_10, 32'h0002 /*offset*/, ""RW");
my_map.add_reg(reg_11, 32'h0003 /*offset*/, ""RW");
...
I have a register adapter that will translate read/write into bus transaction.
So, I am able to do this inside my sequence:
reg_00.write(status, 'hff, .parent(this));
The bus transaction will do write to that specific register: reg_00.
My problem is that the bus has byte_enable that allow it to write accross 4 register in double-word access. Using the existing register model above, is it possible to write/read in 4 register at the same time? Or do I need to create another set of registers (with 32-bit size)?
It would be something like this pseudo-code:
{reg_11,reg_10,reg_01,reg_00}.write(status, 'hffffffff, .parent(this));
Any suggestion?
you could try passing additional information like byte_enable to the adapter using the extension argument in the write function. Then the adapter can decide accordingly if this is a legal double word transaction and assign the bus transaction fields accordingly. see partial example below
virtual function uvm_sequence_item reg2bus(const ref uvm_reg_bus_op rw);
bus_trans trans;
uvm_reg_item item;
regtrans_params params;
item = get_item();
trans = bus_trans::type_id::create("trans");
if(item.extension == null)
`uvm_fatal("", "item.extension==null !!")
if(!$cast(params, item.extension))
`uvm_fatal("", "FAILED $cast(params, item.extension) !!")
trans.dst_chip_addr = params.chip_addr;
in the sequence:
block.reg_00.write(status, 32'hfffffffff .extension(params));
I'm using the BGScript for Bluetooth program. BGScript provides H/W interrupt listener API. The listener API name is hardware_io_port_status(delta, port, irq, state)
What I want to see the value are irq and state. BGScript can display value by using the SPI interface. The API interface is hardware_spi_transfer(channel, data_len, value_data)
I can display a string value like this
call hardware_spi_transfer(0,15,"Button 0 ") # OK
call hardware_spi_transfer(0,15,state) # NG Build Error
According to API Reference, I have to set the uint8array formatted value as the value_data. But I have no idea about converting from unit to unit8array.
API Reference
http://ezoelectro.narod.ru/doc-pdf/ble112/BLE_Stack_API_reference_v2.2.pdf
Can you help me? Thanks.
Isn't the problem that in your SPI call you set the length to 15
while you only want to send 1 byte?
call hardware_spi_transfer(0, 1, state)
If that does not work, try something like this, to explicitly save the state into a buffer variable:
dim state
dim buf(1)
call hardware_io_port_status(delta, port, irq, state)
buf(0:1) = state
call hardware_spi_transfer(0, 1, buf(0:1))
in the above replace delta, port, irq with your values.
How can I detect whenever the power cord is unplugged from electrical socket using JSR 256?
You would add javax.microedition.io.Connector.sensor to the API Permissions tab of the Application Descriptor of the project properties.
From a quick look at the specifications of the JSR:
(you might want to look for code examples, starting with Appendix D of the spec itself, the latest JavaME SDK, Sony Ericsson developer website, then google)
As always, I would be worried about fragmentation in the diverse implementations of the JSR, but here's my first idea:
import javax.microedition.sensor.*;
SensorInfo[] powerSensorInfoArray = SensorManager.findSensors("power","ambient");
//let's assume there is one SensorInfo in the array.
//open a connection to the sensor.
SensorConnection connection = (SensorConnection)Connector.open(powerSensorInfoArray[0].getUrl(), Connector.READ);
// add a DataListener to the connection
connection.setDataListener(new MyDataListener(), 1);
// implement the data listener
public class MyDataListener implements DataListener {
public void dataReceived(SensorConnection aSensor, Data[] aDataArray, boolean isDataLost) {
//let's assume there is only one channel for the sensor and no data was lost.
// figure out what kind of data the channel provides.
int dataType = aDataArray[0].getChannelInfo().getDataType();
//now, I suggest you switch on dataType and print the value on the screen
// experimentation on the JSR256 implementation you're targetting seems to be
// the only way to figure out out power data is formatted and what values mean.
//only one of the following 3 lines will work:
double[] valueArray = aDataArray[0].getDoubleValues();
int[] valueArray = aDataArray[0].getIntValues();
Object[] valueArray = aDataArray[0].getObjectValues();
// let's assume one value in the valueArray
String valueToPrint = "" + valueArray[0];
// see what happens with that and you plug or unplug the power supply cable.
}
}
You'll need to add javax.microedition.io.Connector.sensor to your MIDlet permissions.
-------EDIT------
Documentation from the JSR-256 implementation on Sony-Ericsson Satio phone (S60 5th edition):
The battery charge sensor has the following characteristics:
Quantity: battery_charge
Context type: device
URL: sensor:battery_charge;contextType=device;model=SonyEricsson
Channels: (index: name, range, unit)
0: battery_charge, 0-100, percent
1: charger_state, 0-1, boolean