|
![]() | 作者: zhanjiajun [zhanjiajun]
![]() |
登录 |
<font color=red>本帖由 [TecZm] 从 << UNIX系统>> 转移而来</font><p></p>void send_OTA(byte *msg) //是参数. { byte *Get_Message; byte Get_Length; Get_Length = msg[1]; //已知传入的指针的第一个字节为长度. Get_Message = &msg[2]; //参数的第二个字节是一个BYTE的指针.指向真正存放数据的地址. } 问题一:我要读出Get_Message所指向内存区的数据.如果这个数据我在输入的时候是定义的结构体.struct Messgae_Send{ int i; byte Test_Message; }Addr_Send; 哪我在读出的时候,是否定义一样的结构指针(struct Message_Send *Ptr)指向他.然后: int i = ptr->i; byte Send_M = ptr->Test_Message; 可否这样? 问题二:传入的参数是一个byte *msg的指针,&msg[2]是得到其第二个字节的值的地址,这个地址也是一个二进制(计算机的表示),是否可以将这个地址用一个BYTE的指针来指向他进行操作. 就是上面的Ptr,我如何才能读出其数据,这一点我问都问不清楚,我的指针的概念有些不清楚.各位请帮我一下! 再描述一下 一\ ,我的内存里面的内容是串口传进来的,是通讯用的.也就是说,传进来只是一个二进制流数据,但是这些数据可以传输之前定义好,通俗的问是:我两边的传送(结构类型数据)和接收(同样结构的指针)的结构是否可以进行如上的操作. 二\ &MSG[2] :得到了MSG[2]的内容呢?还是得到了MSG[2]这个字节的地址. 如果我有一个byte指针,指向了具体定义好的内容,我如何得到第N个字节的内容.能否举例一下. 是这样的,我要发送出的内容是msg[2]里面的内容中的一部份,msg[1]则是要发送的内容的长度,这两个是参数,发送的时候交将调用OSAL(OS application layer API)中的OTS_SEND孙数,我就是要在调用之前,将MSG[2]的内容扣一部分起来,而MSG[1]的长度自然要减去相应的字节数. MSG[1]是字节(BYTE)型,MSG[2]是一个BYTE的指针类型. byte send_Length; byte *Data; 请各位大哥帮我. 人在深圳,刚才找到工作,不容易呀!这个地方. [此贴被 飘渺虚心(zhanjiajun) 在 08月26日13时03分 编辑过] |
地主 发表时间: 05-08-25 20:20 |
![]() | 回复: SysHu0teR [syshunter] ![]() |
登录 |
第一个问题你可以在接收到数据后用(struct Message_Send *)将原来的格式强制转换下, 第二个问题不好说呀,得看你的MSG[]是怎么定义的。如果你的MSG之前没定义成指针数组(type *msg[]),而仅仅是数组或字符串指针类型,你的MSG[2]是不能被允许赋予一个地址值的。 |
B1层 发表时间: 05-08-26 15:10 |
![]() | 回复: zhanjiajun [zhanjiajun] ![]() |
登录 |
msg是一个结构指针,大约是这样的: * TYPEDEFS */ typedef struct { byte task_id; // Task id of allocating task, then // changed when sent byte dest_task_id; // filled in when sent, cleared when // received. byte send_len; // filled in when sent } osal_msg_rec_header_t; typedef struct { osal_msg_rec_header_t hdr; byte *msg_ptr; } osal_msg_received_t; 应用层大约用了这些: byte *msgPtr; zAddrType_t *dstAddr; osal_msg_received_t *msg; afIncomingMSGPacket_t *MSGpkt; [此贴被 飘渺虚心(zhanjiajun) 在 08月26日18时07分 编辑过] |
B2层 发表时间: 05-08-26 18:06 |
![]() | 回复: zhanjiajun [zhanjiajun] ![]() |
登录 |
case ZDO_NEW_DSTADDR: dstEP = msgPtr[1]; dstAddr = (zAddrType_t *)&msgPtr[2]; SerialApp_DstAddr.addrMode = dstAddr->addrMode; SerialApp_DstAddr.endPoint = dstEP; if ( dstAddr->addrMode == Addr16Bit ) SerialApp_DstAddr.addr.shortAddr = dstAddr->addr.shortAddr; else { osal_memcpy( SerialApp_DstAddr.addr.extAddr, dstAddr->addr.extAddr, Z_EXTADDR_LEN ); } SetLed( LED4, LED_ON ); break; |
B3层 发表时间: 05-08-26 18:08 |
![]() | 回复: zhanjiajun [zhanjiajun] ![]() |
登录 |
现在我用两台PC相互可以完全收帧,通过串口和并行线,但愿,一我接上我们使用的ROITER设备进行远程传输的时候就死活都读不出来前面的IEEE网络地址,我用AccessPort可以看到我的帧(没有按结构定义,只是一串二进制数据,里面前八位是地址)是完整的,结果从中间设备一出来,在另一台PC上时,就只有下面的数据和前面的一位,即第八位的网络地址. 我在读这个的时候: dstAddr = (zAddrType_t *)&msgPtr[2]; dstAddr是一个结构,就是上面提到发送时的地址结构,我读到上面的程序时,觉得是不是PC机上如果要指定发送地址,就一定要定义与单板一样数据结构,而这个结构我用VC定义好了,以后用串口的MSCOMM来发送,里面要用到VAIANT数据类型,是BYTE,所以,我只能用(BYTE *)(定义的数据结构)来进行强制类型转换,结果现在走不下去了. 因为转换后,用 hr = SafeArrayPutElement(pSA,temp,&Temp_Data);发送出 去.结果前面的结构里面的内容根本不对.请帮忙!! SerialApp_DstAddr.addrMode = dstAddr->addrMode; SerialApp_DstAddr.endPoint = dstEP; 而这个地址,是我必须指定的唯一的,目的地址.由于对AVR不熟悉,调试起来很困难呀,请大哥们帮一下了. |
B4层 发表时间: 05-08-26 18:19 |
![]() | 回复: zhanjiajun [zhanjiajun] ![]() |
登录 |
/********************************************************************* Filename: SerialApp.c Revised: $Date: 2005/02/07 17:21:58 $ Revision: $Revision: 1.17 $ Description: - Serial Transfer Application (no Profile). This sample application is basically a cable replacement and it should be customize for your application. A PC (or any device) sends a data to the serial port on this application's device. This device transmit the message to another device with the same application running. The other device received the over-the-air message and sends the message to the device (or PC) connect to its serial port. This applications doesn't have a profile, so it handles everything directly - itself. Key control: SW1: SW2: initiates end device binding SW3: SW4: initiates a match description request Notes: Copyright (c) 2005 by Figure 8 Wireless, Inc., All Rights Reserved. Permission to use, reproduce, copy, prepare derivative works, modify, distribute, perform, display or sell this software and/or its documentation for any purpose is prohibited without the express written consent of Figure 8 Wireless, Inc. *********************************************************************/ /********************************************************************* * INCLUDES */ #include "OSAL.h" #include "MTSPCI.h" #include "AF.h" #include "ZDApp.h" #include "SerialApp.h" #if !defined( WIN32 ) #include "OnBoard.h" #endif /********************************************************************* * MACROS */ /********************************************************************* * CONSTANTS */ /********************************************************************* * TYPEDEFS */ /********************************************************************* * GLOBAL VARIABLES */ // This is the Cluster ID List and should be filled with Application // specific cluster IDs. const byte SerialApp_ClusterList[SERIALAPP_MAX_CLUSTERS] = { SERIALAPP_CLUSTERID1, SERIALAPP_CLUSTERID2 }; const SimpleDescriptionFormat_t SerialApp_SimpleDesc = { SERIALAPP_ENDPOINT, // int Endpoint; SERIALAPP_PROFID, // uint16 AppProfId[2]; SERIALAPP_DEVICEID, // uint16 AppDeviceId[2]; SERIALAPP_DEVICE_VERSION, // int AppDevVer:4; SERIALAPP_FLAGS, // int AppFlags:4; SERIALAPP_MAX_CLUSTERS, // byte AppNumInClusters; (byte*)SerialApp_ClusterList, // byte *pAppInClusterList; SERIALAPP_MAX_CLUSTERS, // byte AppNumOutClusters; (byte*)SerialApp_ClusterList // byte *pAppOutClusterList; }; // This is the Endpoint/Interface description. It is defined here, but // filled-in in SerialApp_Init(). Another way to go would be to fill // in the structure here and make it a "const" (in code space). The // way it's defined in this sample app it is define in RAM. endPointDesc_t SerialApp_epDesc; /********************************************************************* * EXTERNAL VARIABLES */ /********************************************************************* * EXTERNAL FUNCTIONS */ /********************************************************************* * LOCAL VARIABLES */ byte SerialApp_TaskID; // Task ID for internal task/event processing // This variable will be received when // SerialApp_Init() is called. devStates_t SerialApp_NwkState; byte SerialApp_TransID; // This is the unique message ID (counter) afAddrType_t SerialApp_DstAddr; /********************************************************************* * LOCAL FUNCTIONS */ void SerialApp_HandleKeys( byte shift, byte keys ); void SerialApp_ProcessMSGCmd( afIncomingMSGPacket_t *pckt ); void SerialApp_SendOTA_MSG( byte *msg ); /********************************************************************* * NETWORK LAYER CALLBACKS */ /********************************************************************* * PUBLIC FUNCTIONS */ /********************************************************************* * @fn SerialApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void SerialApp_Init( byte task_id ) { SerialApp_TransID = 0; SerialApp_TaskID = task_id; SerialApp_NwkState = DEV_INIT; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). SerialApp_DstAddr.endPoint = 0; // SerialApp_DstAddr.addr.shortAddr = 0; // SerialApp_DstAddr.addrMode = AddrNotPresent; // BYTE afextAddr[8] = { 0x00,0x12,0x4B,0x00,0x00,0x00,0x08,0x79}; SerialApp_DstAddr.addr.extAddr[0] = 0x00; SerialApp_DstAddr.addr.extAddr[1] = 0x12; SerialApp_DstAddr.addr.extAddr[2] = 0x4B; SerialApp_DstAddr.addr.extAddr[3] = 0x00; SerialApp_DstAddr.addr.extAddr[4] = 0x00; SerialApp_DstAddr.addr.extAddr[5] = 0x00; SerialApp_DstAddr.addr.extAddr[6] = 0x08; SerialApp_DstAddr.addr.extAddr[7] = 0x79; SerialApp_DstAddr.addrMode = afAddr64Bit; // Fill out the endpoint/interface description. SerialApp_epDesc.endPoint = SERIALAPP_ENDPOINT;; SerialApp_epDesc.task_id = &SerialApp_TaskID; SerialApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SerialApp_SimpleDesc; SerialApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint/interface description with the AF afRegister( &SerialApp_epDesc ); // Register for all key events - this app will handle all key events RegisterForKeys( task_id ); // Register Task_ID with MTSPCI so serial messages know where to go MT_SerialRegisterTaskID( task_id ); // Set the serial I/O baud rate MT_SetZAppBaudRate( BR_1200 ); // Set the amount of time to wait for a quiet time. This will determine // the end of a message/buffer. The serial driver will collect serial data // in its buffer, until this amount of quiet time, then it will send the // buffer to this application. This quiet time is in milliseconds. MT_SetZAppMinGap( 5 ); // Enable App Flow Control. This allows the serial driver to send collected // serial data to this application. App Flow Control permits this application // to determine when to allow serial data to be delivered from the driver. MT_SerialFlowControl( ZAPP_PORT, APP_FLOW_ENABLE ); #if defined ( LCD_SUPPORTED ) // Update the display WriteLCDString( 2, "SerialApp" ); #endif } /********************************************************************* * @fn SerialApp_ProcessEvent * * @brief Generic Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return none */ void SerialApp_ProcessEvent( byte task_id, UINT16 events ) { byte dstEP; byte *msgPtr; zAddrType_t *dstAddr; osal_msg_received_t *msg; afIncomingMSGPacket_t *MSGpkt; // Data Confirmation message fields byte sentEP; byte sentTransID; // This should match the value sent ZStatus_t sentStatus; if ( events & SYS_EVENT_MSG ) { msg = osal_msg_receive( SerialApp_TaskID ); while ( msg ) { msgPtr = msg->msg_ptr; switch ( *msgPtr ) { case KEY_CHANGE: SerialApp_HandleKeys( msgPtr[KEY_CHANGE_SHIFT_IDX], msgPtr[KEY_CHANGE_KEYS_IDX] ); break; case AF_DATA_CONFIRM_CMD: // This message is received as a confirmation of a data packet sent. // The status is of ZStatus_t type [defined in ZComDef.h] // The message fields are defined in AF.h sentEP = msgPtr[AF_DATA_CONFIRM_ENDPOINT]; sentStatus = (ZStatus_t)msgPtr[AF_DATA_CONFIRM_STATUS]; sentTransID = msgPtr[AF_DATA_CONFIRM_TRANSID]; // Action taken when confirmation is received. if ( sentStatus != ZSuccess ) { // The data wasn't delivered, // Error recovery code goes here } // Turn on flow control MT_SerialFlowControl( ZAPP_PORT, APP_FLOW_ON ); break; case MT_INCOMING_ZAPP_PORT: // Process the incoming serial message SerialApp_SendOTA_MSG( msgPtr ); break; case AF_INCOMING_MSG_CMD: // convert to incoming packet format MSGpkt = (afIncomingMSGPacket_t *)&(msgPtr[1]); // Process the incoming RF message SerialApp_ProcessMSGCmd( MSGpkt ); // Release the data buffer if ( MSGpkt->cmd.DataLength ) osal_mem_free( MSGpkt->cmd.Data ); //Data buffer first break; case ZDO_NEW_DSTADDR: dstEP = msgPtr[1]; dstAddr = (zAddrType_t *)&msgPtr[2]; SerialApp_DstAddr.addrMode = dstAddr->addrMode; SerialApp_DstAddr.endPoint = dstEP; if ( dstAddr->addrMode == Addr16Bit ) SerialApp_DstAddr.addr.shortAddr = dstAddr->addr.shortAddr; else { osal_memcpy( SerialApp_DstAddr.addr.extAddr, dstAddr->addr.extAddr, Z_EXTADDR_LEN ); } SetLed( LED4, LED_ON ); break; case ZDO_STATE_CHANGE: SerialApp_NwkState = (devStates_t)msgPtr[1]; break; default: break; } // Release the memory osal_msg_deallocate( msgPtr ); // Process next event message msg = osal_msg_receive( SerialApp_TaskID ); } } if ( events & SERIALAPP_MSG_HOLD_EVT ) { // Previous attempt to send message failed SetLed( LED4, LED_FLASH ); // Error recovery code goes here, // For now, we just ignore the last packet. MT_SerialFlowControl( ZAPP_PORT, APP_FLOW_ON ); } } /********************************************************************* * Event Generation Functions */ /********************************************************************* * @fn SerialApp_HandleKeys * * @brief Handles all key events for this device. * * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * EVAL_SW4 * EVAL_SW3 * EVAL_SW2 * EVAL_SW1 * * @return none */ void SerialApp_HandleKeys( byte shift, byte keys ) { // Shift is used to make each button/switch dual purpose. if ( shift ) { if ( keys & EVAL_SW1 ) { } if ( keys & EVAL_SW2 ) { } if ( keys & EVAL_SW3 ) { } if ( keys & EVAL_SW4 ) { } } else { if ( keys & EVAL_SW1 ) { } if ( keys & EVAL_SW2 ) { // Initiate an End Device Bind Request for the mandatory endpoint ZDApp_SendEndDeviceBindReq( SerialApp_epDesc.endPoint ); } if ( keys & EVAL_SW3 ) { } if ( keys & EVAL_SW4 ) { // Initiate a Match Description Request (Service Discovery) // for the mandatory endpoint ZDApp_AutoFindDestination( SerialApp_epDesc.endPoint ); } } } /********************************************************************* * LOCAL FUNCTIONS */ /********************************************************************* * @fn SerialApp_ProcessMSGCmd * * @brief Data message processor callback. This function processes * any incoming data - probably from other devices. So, based * on cluster ID, perform the intended action. * * @param none * * @return none */ void SerialApp_ProcessMSGCmd( afIncomingMSGPacket_t *pkt ) { switch ( pkt->clusterId ) { case SERIALAPP_CLUSTERID1: // Visual indication that message came in BlinkLed( LED2, 1, 90, 90 ); // Send the data out the serial port MT_SerialSendZAppMsg( pkt->cmd.Data, pkt->cmd.DataLength ); //SerialApp_SendOTA_MSG(pkt->cmd.Data); break; case SERIALAPP_CLUSTERID2: default: break; } } /********************************************************************* * @fn SerialApp_SendOTA_MSG * * @brief Sends the received serial message out over the air. * * @param msg - ptr to osal message buffer * * @return none */ void SerialApp_SendOTA_MSG( byte *msg ) { afStatus_t stat; // This message is setup to use APS ACKs (application layer acknowledgements) // APS ACKs take up bandwidth. If you would like to increase the transmit // rate and you don't care about ACKing at the application, turn off APS ACK // by replacing AF_MSG_ACK_REQUEST with 0 in the function call below. stat = afFillAndSendMessage( &SerialApp_DstAddr, SerialApp_epDesc.endPoint, SERIALAPP_CLUSTERID1, 1, FRAMETYPE_MSG, &SerialApp_TransID, NULL, NULL, NULL, NULL, msg[1], &msg[2], AF_MSG_ACK_REQUEST, true, AF_DEFAULT_RADIUS ); if ( stat != ZSuccess ) // Wait to retry sending OTA message osal_start_timer( SERIALAPP_MSG_HOLD_EVT, SERIALAPP_MSG_HOLD_TIMEOUT ); else // Visual indication that message went out BlinkLed( LED1, 1, 90, 90 ); } /********************************************************************* *********************************************************************/ |
B5层 发表时间: 05-08-26 18:22 |
![]() | 回复: zhanjiajun [zhanjiajun] ![]() |
登录 |
UP!please |
B6层 发表时间: 05-08-31 17:30 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号