Ярлыки

_GetPixelIndex (1) _SetPixelIndex (1) 3-phase (1) 800x480 (1) АЦП (1) генератор (1) синхронный усилитель (2) структура (1) учебный курс (1) шаговый двигатель (1) ШИМ (2) accert (1) AD7608 (1) AD8429 (1) ADC (5) amplifer (1) arccos (1) arcsin (1) arctang (2) arctg (3) ARM (2) arm_sqrt_q15 (2) assembler (6) ASSERT (1) atan (2) bit (1) Bitband (1) boot (3) bootlloader (1) BUTTON (1) C (5) C# (1) CAN (2) CC2530 (5) CMSIS (4) command (1) Cordic (1) Core746I (1) CubeMX (4) DBGMCU (2) debug (2) debug.ini (1) delegate (1) Digital Potentiometers (1) DigitalPOT (1) Discovery (1) DMA (9) DMA2D (1) DSP (1) DSP library (1) DWT (1) EFM32 (5) EmWin (9) EXTI (1) FATFS (1) FMC (2) FreeRTOS (2) gl868-dual cmux (1) GPIO (4) GUI (2) GUIBuilder (1) GUIDRV_CompactColor_16 (1) HAL (3) HappyGecko (1) Hard Fault (2) heap (1) I2C (1) ID (1) ILI9320 (1) ILI9325 (1) Initialisation (1) InitLTDC (1) Instrumentithion (1) Interrupt (4) ITR (1) JTAG (1) Keil (5) LCDConf (2) lock-in (1) LTCD (1) LTDC (3) main (1) memory (1) MINI_STM32 Revision 01 (1) nBoot0 (1) NVIC (1) OnePulse (2) OSAL (4) pack (1) phase (1) printf (3) Pulse (1) PWM (12) RCC (2) RCR (1) Register (1) RESET (2) RS232 (3) RSS (1) RTC (3) RTOS-RTX (1) RTT (1) RTX-RTOS (1) SDCard (1) SDRAM (6) Segger (2) SPI (3) sqrt (3) SSD1298 (1) SSD1963 (1) Standart Peripherial Library (3) STANDBAY (1) startup (1) STemWin (8) stepper motor (1) STlink (2) STM32 (17) STM32429ZI (1) STM32Cube (1) STM32DBG.IN (1) STM32F (28) STM32F0 (4) STM32F1 (13) STM32F4 (10) STM32F4 Discovery (1) STM32F407ZG (1) STM32F429 (2) STM32F746 (1) STOP (1) string (1) struct (1) SWD (1) SWD JTAG (1) Synhronization (1) system_stm32f4xx.c (1) SystemInit (1) SysTick (1) task (4) telit (1) TIM (27) typedef (1) UART (1) USART (9) viewer (2) WM_PAINT (1) Z-stack (5) ZigBee (5)

воскресенье, 22 ноября 2015 г.

ZNP software command interface

The ZNP software command interface is sub-divided into the following categories

 The SYS interface (MT_SYS) provides the application processor with a low level interface to the ZNP hardware and software.

 The Simple API interface (MT_SAPI) is a simplified ZigBee interface that can be used to quickly create simple ZigBee compliant networked applications. It allows for easy device configuration, network formation, binding and data transfer. However, a limitation of the Simple API is that it can only be used with one application registered endpoint. Therefore, it is recommended that applications that support multiple endpoints use the AF interface.

 The AF (MT_AF) and ZDO (MT_ZDO) interfaces feature the complete ZigBee interface and can be used to create a full range of ZigBee compliant applications. The AF (Application Framework) interface allows the application processor to register its application with the ZNP and send and receive data. The ZDO (ZigBee Device Object) interface provides various ZigBee management functions like device and service discovery.

 The UTIL (MT_UTIL) interface provides support functionalities such as setting PanId, getting device info, getting NV info, subscribing callbacks…etc.

суббота, 21 ноября 2015 г.

ZigBee packet from sniffer


пакета от координатора

межсетевая информация

P.nbr - номер пакета от сниффера 
Time - время после старта сниффера
Length - длина пакета
Frame control field - 
         Type DATA- тип принятого пакета 
                  000- Beacon
                  001 - Data
                  010 - Acnowledgmant
                  011 - MAC command                                          
                  100 - 111 - Reserved
          Sec - вкл/откл шифрования
          Pnd - Frame pending разбивка пакета на части 
          Ack.reg - необходимость подтверждения (0 - нет 1 - да)
          PAN_compr - 1-пакет внутрисетевой 0-для другой сети
Sequence number - номер пакета
Dest. PAN - адрес сети получателя
Dest. Addres - адрес получателя
Sourse Addres - адрес отправителя
MAC Payload (Medium Access Control)-сообщение по сети или между сетями


внутрисетевая информация

NWK Frame control field — поле описания текущего сеанса передачи
          Type - тип пакета
                    00 - Data
                    01 - NWC command
                    10 - 11 - Reserved
           Ver - Protocol vorsion
           DR - Discover route
           MF - Multicfst flag
           Sec - Security
           SR - Sourse route
           DIEEE - Destination IEEE addres 1 - для расширенной адресации
           SIEEE - Sourrse IEEE adsres 1 - для расширенной адресации
NWK Dest. Addres - адрес получателя
NWK Src. Addres - адрес отправителя
Broadcast Radius - максимальное количество роутеров для ретрансляции
Broadcust Seq. num - номер пакета
NWK Srq. IEEE Addres - полный адрес отправителя


передаваемая информация
NWK Uncnown Command
LQI - Link Quality Indication, ranging from 0x00 to 0xFF or
RSSI (Received Signal Strength Indicator with an approximation to the actual RF level, in dBm). 
FCS - контрольная сумма



пятница, 20 ноября 2015 г.

Zigbee security

4. Security Global Variables

Pre-configured NWK Key
/*********************************************************************
* SECURITY GLOBAL VARIABLES
*/
// This is the default pre-configured key,
// change this to make a unique key
// SEC_KEY_LEN is defined in ssp.h.
CONST byte defaultKey[SEC_KEY_LEN] =
{
// Key for In-House Testing
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
}; ( defaultKey is defined in nwk_globals.c)
// If true, preConfigKey should be configured on all devices on the network
// If false, it is configured only on the coordinator and sent to other devices upon joining

uint8 zgPreConfigKeys = FALSE; // TRUE;
If zgPreConfigKeys is set to TRUE, all devices should use the same pre-configured security key. If zgPreConfigKeys
is set to FALSE, the pre-configured key is set only on the coordinator device, and is handed to joining devices. The
key is sent in the clear over the last hop. Upon reset, the device will retrieve the pre-configured key from NV
memory if the NV_INIT compile option is defined (the NV item is called ZCD_NV_PRECFGKEY).
Trust Center Link Key
This is the trust center link key used as part of the Smart Energy profile secure joining process (see Z-Stack Smart
Energy Developer’s Guide for more details).
// This is the default pre-configured Trust Center Link key,
// change this to make a unique key, SEC_KEY_LEN is defined in ssp.h.
CONST byte defaultTCLinkKey[SEC_KEY_LEN] =
{
0x56, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77
}; ( defaultTCLinkKey is defined in nwk_globals.c)
If the NV_INIT compile option is defined, the stack uses the value loaded into zgPreConfigTCLinkKey from NV

memory (the NV item is called ZCD_NV_SECURE_PRECFG_TCLINKKEY).


5. Compile Options

The following compile options are used for debug trace and monitor test purposes.
MT_TASK
This compile option enables the device to be able to talk to the Z-Tool PC application, and to be able to output
minimal debug information using the debug_str() function. Removing this saves some code and RAM usage.
MT_ZDO_FUNC and other MT compile options
MT_ZDO_FUNC is an example of a compile option that enables the ZDO commands to be used with Z-Tool. Most
devices would not need all of the monitor test commands to be enabled. Each ZDO command can be enabled
individually in ZDConfig.h. Selectively enabling requests that need to be in the application minimizes code usage.
See the Z-Stack Compile options document for more information on the different MT compile options.
LCD_SUPPORTED
This turns on support for displaying debug trace information on development boards that support an LCD. On
development kit hardware platforms that do not support LCDs, setting LCD_SUPPORTED enables sending
information to the Serial Port (since it does not have an LCD display). Enabling this compile option uses a significant
portion of RAM.
LCD_SUPPORTED=DEBUG
Setting LCD_SUPPORTED=DEBUG enables sending information to both the LCD and Serial Port, so code is
actually larger. On platforms that do not support LCDs, debug information is only sent to the Serial Port, therefore
using less code.
BLINK_LEDS
The BLINK_LEDS compile option enables extended LED functionality at the expense of extra code and RAM

space.



6. Compiler Directives

The following compiler directives allow one to minimize RAM usage where applicable, or change different user
settings.
ZDAPP_CONFIG_PAN_ID
If this is set to something other than 0xFFFF (legal values are 0-0xFFFE), the coordinator will start with that PAN
ID, and routers and end devices will join the PAN set to that ID. If the NV_INIT compile option is defined, the user
can recall this value from NV memory (the NV item is called ZCD_NV_PANID). The user can configure this value
in NV memory using Z-Tool.
DEFAULT_CHANLIST
This is where the user can configure the channel list supported by their device.
NUM_DISC_ATTEMPTS
Controls the number of times a network discovery is performed before trying to join a network. The value of
zdoDiscCounter is initialized to 1 in ZDApp.c. This is tested against NUM_DISC_ATTEMPTS. If it is greater, then
it will call NLME_JoinRequest and associate to the chosen router. Example: Setting NUM_DISC_ATTEMPTS to 0
will only cause the device to do a beacon request once (i.e. only one scan). By default 3 scans are performed, since
zdoDiscCounter needs to reach 4 to break out of the scanning state.
MAX_RESUME_RETRY
Number of times to try orphan join before going to rejoin mode. With a default value of 1, the end device only sends
out one orphan notification over the air. If a coordinator alignment isn't received, the end device will assume no
previous parent exists on the network and will go to rejoin mode
NWK_START_DELAY
This #define gives the user the option of waiting NWK_START_DELAY number of milliseconds before starting up
the device on the network.
NWK_RETRY_DELAY
If starting the device failed (due to channel busy or no network found), this governs the time to wait to try again
BEACON_REQUEST_DELAY

Delay between each beacon request in a joining cycle
STARTING_SCAN_DURATION
The amount of time spent scanning on each channel
MAX_SCAN_DURATION
The maximum amount of time spent scanning on each channel
NWK_MAX_DEVICE_LIST
This is used to pre-allocate RAM for the child devices. Changing NWK_MAX_DEVICE_LIST by 1 changes the
size of the association table by 18 bytes. This setting should match the maximum number of children that a parent
node can support.
STACK_PROFILE_ID
By default the STACK_PROFILE_ID is set to the HOME_CONTROLS stack profile. The stack profile ID
determines the settings for the Cskip parameters, NWK_MODE, and the type of security being used (if used).
Therefore, changing the stack profile ID will typically allow the user to change the Cskip parameters using one
#define. If one needs to define their own topology, one can use the NETWORK_SPECIFIC stack profile ID.
MAX_NODE_DEPTH
Refers to how many successive parent-child links are possible and thus imposes a maximum range of the network.
This parameter is not applicable when using the Zigbee Pro stack profile ID since Zigbee Pro uses stochastic
addressing as its address assignment scheme.
These should be set based on how dense your network is expected to be and what ratio of router to end-device
devices you expect.
MAX_BCAST
This is the number of broadcast entries (for data packets) that can be held for the period of
BCAST_DELIVERY_TIME. Together, these two settings enforce the settling time for broadcast data packets
traversing through the network. For example, if MAX_BCAST_ENTRIES is set to 9, and
BCAST_DELIVERY_TIME is set to 10 (seconds), a device could send out 9 sequential broadcast data packets, but
would not be able to send out a 10th one until after 10 seconds.
PASSIVE_ACK_TIMEOUT
The amount of time the network layer waits before re-transmitting a broadcast message if it didn't hear the retransmission
from its neighbors.
MAX_BCAST_RETRIES
Number of retries for a broadcast message based on not hearing a neighbor reply in the amount of time defined by

PASSIVE_ACK_TIMEOUT.
BCAST_DELIVERY_TIME
The length of time a broadcast message is kept in the broadcast table. Set to 500ms more than retry time. Retry time
is defined as PASSIVE_ACK_TIMEOUT * (MaxBroadCastRetries + 1). If a broadcast message is being sent to end
devices, then this should be set in accordance with the polling rate of the end devices. For example 200 might be a
good number if the poll rate was set to 10 seconds for the end device.
MAX_RTG_ENTRIES
Defines the actual number of routing table entries available for general use and for use only in the case of route
repair. Routing entries refer to the number of routes that go through a particular node. If all devices are sending data
to a single device, there will be only route (because data has to reach only a single destination). Otherwise there can
be as many routes as there are destinations. But it is unlikely all routes will not go through any given device.
A gateway (concentrator) device ideally should have as many routing entries as devices it wishes to send messages
to, or have less, and let route entries expire. This will however let the system incur the overhead of doing route
discovery if a route doesn't exist for a particular destination. The number of routing table entries required can be
mitigated by using the Many-to-one/Source Routing feature of Zigbee Pro.
ROUTE_EXPIRY_TIME
This setting determines the number of seconds before a route expires if no data is transmitted on it (by default set to
30 which means that established routes will expire in 30 seconds from the time they are recorded). If routes change
often (due to router devices moving locations or end devices moving around within the network), one will want the
old routes to expire. The expiry time is reset to this value, each time a packet goes over a particular route. Therefore,
routes only expire if there is no traffic along it. After a route expires, routes are deleted when space is needed. It is
recommended to set this value to 0 to never allow routes to expire if the value of MAX_RTG_ENTRIES is
proportional to the number of devices to be reached on the network. The route expiry time is not so much a factor
when the Many-to-one/Source routing feature of Zigbee Pro is used.
NWK_INDIRECT_MSG_TIMEOUT
Time to hold a message for a sleeping End Device. This setting depends on the end device poll rate. One should
make this greater than the end device poll rate.
NWK_INDIRECT_CNT_RTG_TMR
Constant for seconds interval when calculating the indirect message timeout. Multiply this value by
NWK_INDIRECT_MSG_TIMEOUT to get the number of seconds that an indirect message gets buffered.
POLL_RATE
Milliseconds to wait between data request polls to the parent.
QUEUED_POLL_RATE
After receiving a data indication to poll immediately for queued messages. Units are in milliseconds.
RESPONSE_POLL_RATE

After receiving a data confirmation to poll immediately for response messages. Units are in milliseconds
MAX_POLL_FAILURE_RETRIES
Number of times an end device will poll its parent before indicating a loss of synchronization. Once this threshold
has been exceeded, the end device will attempt a Network Rejoin Request (per the Zigbee Specification). Note that a
larger value will cause longer delays for the child to rejoin the network.
By default, if any two poll requests are not mac ack'd in a row, then this causes a link failure to be flagged in the
stack. On every message sent out, neighbor table maintenance is performed. If two poll requests in a row are not mac
ack'd, this causes the forceLinkDown variable to be set to TRUE. This ultimately causes ZDO_SyncIndicationCB to
be called, which notifies the application that a sync loss with the parent occurred. Because there are 3 mac level
retries on data packets, and MAX_DATA_RETRIES is set to 2 by default, this results in a total of 8 physical data
request packets over the air missed in a row before sync indication is called. The equation would be something like:
No. of OTA retries before sync loss indication =
(MAX_POLL_FAILURE_RETRIES=MAX_DATA_RETRIES)*MAC_MAX_FRAME_RETRIES.
MAC_MAX_FRAME_RETRIES is set to 3 by default in mac_pib.c
REJOIN_POLL_RATE
This is used as an alternate response poll rate only for the network rejoin request. This rate is determined by the
response time of the parent that the device is trying to join.
NWK_MAX_DATA_RETRIES
This controls the number of retries that is perform by the network layer for the next hop message once the MAC layer
retries are exhausted for that message (note that MAC layer will retry 3 times before returning a failure status to the
network layer).
Cskip Array (Zigbee non-Pro ONLY)
The Cskip array needs to be edited by the user if they are attempting to change the network toplogy configuration.
For example if one uses:
#if ( STACK_PROFILE_ID == HOME_CONTROLS )
byte CskipRtrs[MAX_NODE_DEPTH+1] = {6,6,6,6,6,0};
byte CskipChldrn[MAX_NODE_DEPTH+1] = {20,20,20,20,20,0};
then any router or coordinator can have a maximum of 20 child devices, and out of those 20, 14 can be end devices,
6 can be router devices.
MAX_NEIGHBOR_ENTRIES
A neighbor is defined as anyone that the device hears from. i.e. a device within in next hop range. As seen from the
description of MAX_POLL_FAILURE_RETRIES, the neighbor table is checked for each poll request. It is then
important to note that if a neighbor table entry doesn't exist, and if there is no room in the neighbor table to create
one, then the ZDO_SyncIndicationCB will never be called and the device will never try to rejoin the network. So it is
advised to make this table as large as possible on the end device. It is also why clearing the neighbor table is required
as part of the ZDO_SyncIndicationCB code. The size of the neighbor table becomes even more important when the
SECURE=1 compile option is turned on since the received frame counter is stored here. Incoming messages will not

be processed if the link info doesn’t exist for the received frame.
NWK_MAX_BINDING_ENTRIES
This controls the maximum number of entries in the binding table. If binding is not used, set this to 1 to be minimize
RAM usage. Adjusting the number of entries by 1 changes the size of the binding table by 12 bytes.
MAX_BINDING_CLUSTER_IDS
This controls the maximum number of cluster IDs for each binding table entry. Set this to 1 if binding is not used in
order to minimize RAM usage.
APSC_MAX_FRAME_RETRIES
This controls the number of retries that will be attempted by the APS layer if APS acknowledgement service is used
for the transmitted message. In order to use APS acknowledgement service, pass into the options parameter a value
logically OR’d with the bitmask of AF_ACK_REQUEST (0x10) when calling the AF_DataRequest() function.
APSC_ACK_WAIT_DURATION_POLLED
This controls the time in milliseconds between retries when an APS ACK is not received. This is in addition to nwk

layer retries governed by MAX_DATA_RETRIES

четверг, 19 ноября 2015 г.

OSAL Zigbee Z-stack Main function

int main( void )
{
  // Turn off interrupts
  osal_int_disable( INTS_ALL );

  // Initialization for board related stuff such as LEDs
  HAL_BOARD_INIT();
  
  // Make sure supply voltage is high enough to run
  zmain_vdd_check();

  // Initialize board I/O
  InitBoard( OB_COLD );

  // Initialze HAL drivers
  HalDriverInit();

  // Initialize NV System
  osal_nv_init( NULL );

  // Initialize the MAC
  ZMacInit();

  // Determine the extended address
  zmain_ext_addr();

#if defined ZCL_KEY_ESTABLISH
  // Initialize the Certicom certificate information.
  zmain_cert_init();
#endif

  // Initialize basic NV items
  zgInit();

#ifndef NONWK
  // Since the AF isn't a task, call it's initialization routine
  afInit();
#endif

  // Initialize the operating system
  osal_init_system();

  // Allow interrupts
  osal_int_enable( INTS_ALL );

  // Final board initialization
  InitBoard( OB_READY );

  // Display information about this device
  zmain_dev_info();

  /* Display the device info on the LCD */
#ifdef LCD_SUPPORTED
  zmain_lcd_init();
#endif

#ifdef WDT_IN_PM1
  /* If WDT is used, this is a good place to enable it. */
  WatchDogEnable( WDTIMX );
#endif
HalLcdWriteString( "TEST12345678901234567890", HAL_LCD_LINE_2 );
  osal_start_system(); // No Return from here

  return 0;  // Shouldn't get here.
} // main()

OSAL Zigbee Z-stack



Список задач для EndDevice

// The order in this table must be identical to the task initialization calls below in osalInitTask.

const pTaskEventHandlerFn tasksArr[] = {
  macEventLoop,
  nwk_event_loop,
  Hal_ProcessEvent,
#if defined( MT_TASK )
  MT_ProcessEvent,
#endif
  APS_event_loop,
#if defined ( ZIGBEE_FRAGMENTATION )
  APSF_ProcessEvent,
#endif
  ZDApp_event_loop,
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
  ZDNwkMgr_event_loop,
#endif
  GenericApp_ProcessEvent
};

const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] );
uint16 *tasksEvents;

четверг, 12 ноября 2015 г.

Функции для работы со строковыми переменными (string code)


int strlen (char*p) { int i=0; while( *p++ ) i++; return i;//отлажено } //----------------------------------------------------------------------------------------------------------// //----------------------------------------------------------------------------------------------------------//