📄 mtel.lst
字号:
420
421 case CMD_DEBUG_STR:
422 MT_ProcessDebugStr( (mtDebugStr_t *)msg );
423 break;
424
425 case CB_FUNC:
426 /*
427 Build SPI message here instead of redundantly calling MT_BuildSPIMsg
428 because we have copied data already in the allocated message
429 */
430
431 /* msg_ptr is the beginning of the intended SPI message */
432 len = SPI_0DATA_MSG_LEN + msg_ptr[DATALEN_FIELD];
433
434 /*
435 FCS goes to the last byte in the message and is calculated over all
436 the bytes except FCS and SOP
437 */
438 msg_ptr[len-1] = SPIMgr_CalcFCS( msg_ptr + 1 , (byte)(len-2) );
439
440 #ifdef SPI_MGR_DEFAULT_PORT
441 HalUARTWrite ( SPI_MGR_DEFAULT_PORT, msg_ptr, len );
442 #endif
443 break;
444
445 #if !defined ( NONWK )
446 case MT_SYS_APP_RSP_MSG:
447 len = SPI_0DATA_MSG_LEN + msg_ptr[DATALEN_FIELD];
448 MTProcessAppRspMsg( msg_ptr, len );
449 break;
450 #endif // NONWK
451 #endif // ZTOOL
452
453 default:
454 break;
455 }
456
457 if ( deallocate )
458 {
459 osal_msg_deallocate( (uint8 *)msg );
460 }
461 }
462
463 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
464 /*********************************************************************
465 * @fn MT_ProcessDebugMsg
466 *
467 * @brief
468 *
469 * Build and send a debug message.
470 *
471 * @param byte *data - pointer to the data portion of the debug message
472 *
473 * @return void
474 */
475 void MT_ProcessDebugMsg( mtDebugMsg_t *msg )
476 {
477 byte *msg_ptr;
478 byte dataLen;
479 uint8 buf[11];
480 uint8 *pBuf;
481
482 // Calculate the data length based
483 dataLen = 5 + (msg->numParams * sizeof ( uint16 ));
484
485 // Get a message buffer to build the debug message
486 msg_ptr = osal_msg_allocate( (byte)(SPI_0DATA_MSG_LEN + dataLen + 1) );
487 if ( msg_ptr )
488 {
489 // Build the message
490 pBuf = buf;
491 *pBuf++ = msg->compID;
492 *pBuf++ = msg->severity;
493 *pBuf++ = msg->numParams;
494
495 if ( msg->numParams >= 1 )
496 {
497 *pBuf++ = HI_UINT16( msg->param1 );
498 *pBuf++ = LO_UINT16( msg->param1 );
499 }
500
501 if ( msg->numParams >= 2 )
502 {
503 *pBuf++ = HI_UINT16( msg->param2 );
504 *pBuf++ = LO_UINT16( msg->param2 );
505 }
506
507 if ( msg->numParams == 3 )
508 {
509 *pBuf++ = HI_UINT16( msg->param3 );
510 *pBuf++ = LO_UINT16( msg->param3 );
511 }
512
513 *pBuf++ = HI_UINT16( msg->timestamp );
514 *pBuf++ = LO_UINT16( msg->timestamp );
515
516 #ifdef SPI_MGR_DEFAULT_PORT
517 MT_BuildSPIMsg( SPI_CMD_DEBUG_MSG, &msg_ptr[1], dataLen, buf );
518 HalUARTWrite ( SPI_MGR_DEFAULT_PORT, &msg_ptr[1], SPI_0DATA_MSG_LEN + dataLen );
519 #endif
520 osal_msg_deallocate( msg_ptr );
521 }
522 }
523 #endif // ZTOOL
524
525 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
526 /*********************************************************************
527 * @fn MT_ProcessDebugStr
528 *
529 * @brief
530 *
531 * Build and send a debug string.
532 *
533 * @param byte *dstr - pointer to the data portion of the debug message
534 *
535 * @return void
536 */
537 void MT_ProcessDebugStr( mtDebugStr_t *dstr )
538 {
539 byte *msg_ptr;
540
541 // Get a message buffer to build the debug message
542 msg_ptr = osal_mem_alloc( (byte)(SPI_0DATA_MSG_LEN + dstr->sln) );
543 if ( msg_ptr )
544 {
545 #ifdef SPI_MGR_DEFAULT_PORT
546 MT_BuildSPIMsg( SPI_RESPONSE_BIT | SPI_SYS_STRING_MSG, msg_ptr, dstr->sln, dstr->pString );
547 HalUARTWrite ( SPI_MGR_DEFAULT_PORT, msg_ptr, SPI_0DATA_MSG_LEN + dstr->sln );
548 #endif
549 osal_mem_free( msg_ptr );
550 }
551 }
552 #endif // ZTOOL
553
554 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
555 /*********************************************************************
556 * @fn MT_ProcessSetNV
557 *
558 * @brief
559 *
560 * The Set NV serial message.
561 *
562 * @param byte *msg - pointer to the data
563 *
564 * @return ZSuccess if successful
565 *
566 * @MT SPI_CMD_SYS_SET_NV
567 */
568 byte MT_ProcessSetNV( byte *pData )
569 {
570 uint16 attrib;
571 uint16 attlen;
572
573 attrib = (uint16) *pData++;
574 attlen = osal_nv_item_len( attrib );
575
576 return osal_nv_write( attrib, 0, attlen, pData );
577 }
578 #endif
579
580 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
581 /*********************************************************************
582 * @fn MT_ProcessGetNV
583 *
584 * @brief
585 *
586 * The Get NV serial message.
587 *
588 * @param byte *msg - pointer to the data
589 *
590 * @return void
591 *
592 * @MT SPI_CMD_SYS_GET_NV
593 *
594 */
595 void MT_ProcessGetNV( byte *pData )
596 {
597 uint16 attrib;
598 uint16 attlen;
599 uint16 buflen;
600 uint8 *buf;
601
602 attrib = (uint16)*pData;
603 attlen = osal_nv_item_len( attrib );
604
605 buflen = attlen + 2;
606 buf = osal_mem_alloc( buflen );
607 if ( buf != NULL )
608 {
609 osal_memset( buf, 0, buflen );
610
611 buf[0] = osal_nv_read( attrib, 0, attlen, &buf[2] );
612 buf[1] = (uint8)attrib;
613
614 MT_BuildAndSendZToolResponse( (SPI_0DATA_MSG_LEN + buflen),
615 (SPI_RESPONSE_BIT | SPI_CMD_SYS_GET_NV),
616 buflen, buf );
617 osal_mem_free( buf );
618 }
619 }
620 #endif
621
622 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
623 #if !defined ( NONWK )
624 /***************************************************************************************************
625 * @fn MT_ProcessGetNvInfo
626 *
627 * @brief
628 *
629 * The Get NV Info serial message.
630 *
631 * @param byte *msg - pointer to the data
632 *
633 * @return void
634 *
635 * @MT SPI_CMD_SYS_GET_NV_INFO
636 *
637 ***************************************************************************************************/
638 void MT_ProcessGetNvInfo( void )
639 {
640 uint8 len;
641 uint8 stat;
642 uint8 *buf;
643 uint8 *pBuf;
644 uint16 tmp16;
645 uint32 tmp32;
646
647 // Get required length of buffer
648 // Status + ExtAddr + ChanList + PanID + SecLevel + PreCfgKey
649 len = 1 + Z_EXTADDR_LEN + 4 + 2 + 1 + SEC_KEY_LEN;
650
651 buf = osal_mem_alloc( len );
652 if ( buf )
653 {
654 // Assume NV not available
655 osal_memset( buf, 0xFF, len );
656
657 // Skip over status
658 pBuf = buf + 1;
659
660 // Start with 64-bit extended address
661 stat = osal_nv_read( ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, pBuf );
662 if ( stat ) stat = 0x01;
663 MT_ReverseBytes( pBuf, Z_EXTADDR_LEN );
664 pBuf += Z_EXTADDR_LEN;
665
666 // Scan channel list (bit mask)
667 if ( osal_nv_read( ZCD_NV_CHANLIST, 0, sizeof( tmp32 ), &tmp32 ) )
668 stat |= 0x02;
669 else
670 {
671 pBuf[0] = BREAK_UINT32( tmp32, 3 );
672 pBuf[1] = BREAK_UINT32( tmp32, 2 );
673 pBuf[2] = BREAK_UINT32( tmp32, 1 );
674 pBuf[3] = BREAK_UINT32( tmp32, 0 );
675 }
676 pBuf += sizeof( tmp32 );
677
678 // ZigBee PanID
679 if ( osal_nv_read( ZCD_NV_PANID, 0, sizeof( tmp16 ), &tmp16 ) )
680 stat |= 0x04;
681 else
682 {
683 pBuf[0] = HI_UINT16( tmp16 );
684 pBuf[1] = LO_UINT16( tmp16 );
685 }
686 pBuf += sizeof( tmp16 );
687
688 // Security level
689 if ( osal_nv_read( ZCD_NV_SECURITY_LEVEL, 0, sizeof( uint8 ), pBuf++ ) )
690 stat |= 0x08;
691
692 // Pre-configured security key
693 if ( osal_nv_read( ZCD_NV_PRECFGKEY, 0, SEC_KEY_LEN, pBuf ) )
694 stat |= 0x10;
695
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -