| | |
| | | * frame length of approximately 2.66 ms with above configuration. */ |
| | | #define RESP_RX_TO_FINAL_TX_DLY_UUS 400 |
| | | /* Receive response timeout. See NOTE 5 below. */ |
| | | #define RESP_RX_TIMEOUT_UUS 600 |
| | | #define RESP_RX_TIMEOUT_UUS 9600 |
| | | |
| | | #define POLL_RX_TO_RESP_TX_DLY_UUS 420 |
| | | /* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */ |
| | |
| | | #define ANCTIMEUS 16 |
| | | #define ANCSEND_INTERVAL 18 |
| | | #define SIGNALPOWER 20 |
| | | //DATA POLL |
| | | #define CURENTPACKNUM_IDX 7 |
| | | #define TOTALPACKNUM_IDX 8 |
| | | #define DATA_IDX 10 |
| | | |
| | | |
| | | #define POLL 0x01 |
| | | #define RESPONSE 0x02 |
| | | #define FINAL 0x03 |
| | | #define SYNC 0x04 |
| | | |
| | | #define DATA_POLL 0x21 |
| | | #define DATA_RESPONSE 0x22 |
| | | /*------------------------------------ Variables ------------------------------------------*/ |
| | | /* Default communication configuration. We use here EVK1000's default mode (mode 3). */ |
| | | static dwt_config_t config = { |
| | |
| | | |
| | | /* Frames used in the ranging process. See NOTE 2 below. */ |
| | | static uint8_t tx_poll_msg[20] = {0}; |
| | | static uint8_t tx_sync_msg[14] = {0}; |
| | | static uint8_t tx_sync_msg[140] = {0}; |
| | | //static uint8_t rx_resp_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'V', 'E', 'W', 'A', 0x10, 0x02, 0, 0, 0, 0}; |
| | | static uint8_t tx_final_msg[24] = {0}; |
| | | |
| | |
| | | |
| | | /* Buffer to store received response message. |
| | | * Its size is adjusted to longest frame that this example code is supposed to handle. */ |
| | | #define RX_BUF_LEN 24 |
| | | #define RX_BUF_LEN 224 |
| | | static uint8_t rx_buffer[RX_BUF_LEN]; |
| | | |
| | | /* Time-stamps of frames transmission/reception, expressed in device time units. |
| | |
| | | memcpy(&tx_final_msg[TAG_ID_IDX], &dev_id, 4); |
| | | memcpy(&tx_resp_msg[ANCHOR_ID_IDX], &dev_id, 4); |
| | | memcpy(&tx_sync_msg[ANCHOR_ID_IDX], &dev_id, 4); |
| | | memcpy(&tx_sync_msg[TAG_ID_IDX], &dev_id, 4); |
| | | |
| | | memcpy(&tx_resp_msg[ANCSEND_INTERVAL], &g_com_map[COM_INTERVAL], 2); |
| | | } |
| | |
| | | u16 checksum; |
| | | int8_t tag_delaytime; |
| | | extern uint16_t sync_timer; |
| | | u16 tmp_time; |
| | | u16 tmp_time; |
| | | u32 start_poll; |
| | | extern float dw_vbat; |
| | | extern u16 slottime,max_slotnum,current_slotpos,tyncpoll_time; |
| | | void Tag_App(void)//å鿍¡å¼(TAGæ ç¾) |
| | | { |
| | | uint32_t frame_len; |
| | | uint32_t final_tx_time; |
| | | u32 start_poll; |
| | | |
| | | u8 i,getsync_flag=0; |
| | | u8 bat_percent; |
| | | //LED0_ON; |
| | |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | } |
| | | u8 frame_len,jumptime; |
| | | u8 rec_gpsdata[1000]; |
| | | extern u8 RTCMdata[2000]; |
| | | u16 recgpsdata_i,recdata_len; |
| | | void UWBSendOnePackData(u8* data_addr,u8 len) |
| | | { |
| | | delay_ms(jumptime); |
| | | g_Resttimer = 0; |
| | | LED0_BLINK; |
| | | g_start_sync_flag=1; |
| | | dwt_forcetrxoff(); |
| | | dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置åéåå¼å¯æ¥æ¶ï¼å¹¶è®¾å®å»¶è¿æ¶é´ |
| | | dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); |
| | | tx_sync_msg[MESSAGE_TYPE_IDX]=DATA_POLL; |
| | | memcpy(&tx_sync_msg[DATA_IDX],data_addr,len); |
| | | dwt_writetxdata(len+14, tx_sync_msg, 0);//å°Pollå
æ°æ®ä¼ ç»DW1000ï¼å°å¨å¼å¯åéæ¶ä¼ åºå» |
| | | dwt_writetxfctrl(len+14, 0);//设置è¶
宽带åéæ°æ®é¿åº¦ |
| | | dwt_starttx(DWT_START_TX_IMMEDIATE| DWT_RESPONSE_EXPECTED); |
| | | start_poll = time32_incr; |
| | | recgpsdata_i = 0; |
| | | while(time32_incr - start_poll<100) |
| | | { |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//䏿æ¥è¯¢è¯çç¶æç´å°æåæ¥æ¶æè
åçé误 |
| | | { |
| | | }; |
| | | if(status_reg==0xffffffff) |
| | | { |
| | | NVIC_SystemReset(); |
| | | } |
| | | |
| | | if (status_reg & SYS_STATUS_RXFCG)//妿æåæ¥æ¶ |
| | | { |
| | | /* Clear good RX frame event and TX frame sent in the DW1000 status register. */ |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG | SYS_STATUS_TXFRS);//æ¸
æ¥å¯å卿 å¿ä½ |
| | | |
| | | /* A frame has been received, read it into the local buffer. */ |
| | | frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK; //è·å¾æ¥æ¶å°çæ°æ®é¿åº¦ |
| | | |
| | | dwt_readrxdata(rx_buffer, frame_len, 0); //è¯»åæ¥æ¶æ°æ® |
| | | |
| | | dwt_rxenable(0); |
| | | /* Check that the frame is the expected response from the companion "DS TWR responder" example. |
| | | * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */ |
| | | |
| | | if (rx_buffer[MESSAGE_TYPE_IDX] == DATA_RESPONSE ) //å¤ææ¥æ¶å°çæ°æ®æ¯å¦æ¯responseæ°æ® |
| | | { |
| | | recdata_len = frame_len-14; |
| | | memcpy(&rec_gpsdata[recgpsdata_i],&rx_buffer[DATA_IDX],recdata_len); |
| | | recgpsdata_i+=recdata_len; |
| | | if(rx_buffer[CURENTPACKNUM_IDX]==1) |
| | | { |
| | | USART_puts(rec_gpsdata,recgpsdata_i); |
| | | break; |
| | | } |
| | | }else{ |
| | | jumptime=time32_incr%20; |
| | | } |
| | | }else{ |
| | | jumptime=time32_incr%20; |
| | | } |
| | | } |
| | | } |
| | | |
| | | char *HIDO_UtilStrnchr(const char *_pcStr, char _cChr, HIDO_UINT32 u32N) |
| | | { |
| | | int32_t i = 0; |
| | | for (i = 0; i < u32N; i++) |
| | | { |
| | | if (_pcStr[i] == _cChr) |
| | | { |
| | | return (char *) (_pcStr + i); |
| | | } |
| | | } |
| | | |
| | | return NULL; |
| | | } |
| | | |
| | | HIDO_UINT8 HIDO_UtilCharToHex(HIDO_CHAR _cCh) |
| | | { |
| | | return (_cCh >= '0' && _cCh <= '9') ? |
| | | (_cCh - '0') : |
| | | (_cCh >= 'A' && _cCh <= 'F' ? |
| | | (_cCh - 'A' + 0x0A) : |
| | | (_cCh >= 'a' && _cCh <= 'f' ? _cCh - 'a' + 0x0A : 0)); |
| | | } |
| | | |
| | | HIDO_UINT32 HIDO_UtilStrBufToInt(HIDO_CHAR *_pcStringBuf, HIDO_UINT32 _u32BufLen) |
| | | { |
| | | HIDO_UINT32 u32Temp = 0; |
| | | |
| | | while (_u32BufLen != 0) |
| | | { |
| | | u32Temp = u32Temp * 10 + HIDO_UtilCharToHex(*_pcStringBuf); |
| | | _pcStringBuf++; |
| | | _u32BufLen--; |
| | | } |
| | | |
| | | return u32Temp; |
| | | } |
| | | |
| | | /****************************************************************************** |
| | | Description : Get gps latitude from gps data |
| | | parameter : data: gps data pointer, len: gps data length, gps: ST_GPS pointer |
| | | Return : TRUE on success, FALSE on fail |
| | | author : DuJian |
| | | history : 2012-7-27 new |
| | | ******************************************************************************/ |
| | | static int32_t GPS_ParseLat(HIDO_DataStruct *_pstLatData, double *lat) |
| | | { |
| | | uint32_t u32Len = _pstLatData->m_u32Len; |
| | | char *pcStart = (char *) _pstLatData->m_pData; |
| | | char *pcDot = NULL; |
| | | uint32_t u32TempLen = 0; |
| | | double dd; |
| | | double mmmm; |
| | | double mm; |
| | | |
| | | if (u32Len < 9) |
| | | { |
| | | return HIDO_ERR; |
| | | } |
| | | |
| | | pcDot = HIDO_UtilStrnchr(pcStart, '.', u32Len); |
| | | if (NULL == pcDot || (pcDot - pcStart) != 4) |
| | | { |
| | | return HIDO_ERR; |
| | | } |
| | | |
| | | dd = HIDO_UtilStrBufToInt(pcStart, 2); |
| | | mm = HIDO_UtilStrBufToInt(pcStart + 2, 2); |
| | | u32TempLen = u32Len - (pcDot + 1 - pcStart); |
| | | mmmm = HIDO_UtilStrBufToInt(pcDot + 1, u32TempLen); |
| | | while(u32TempLen != 0) |
| | | { |
| | | mmmm /= 10.0; |
| | | u32TempLen--; |
| | | } |
| | | |
| | | mm = mm + mmmm; |
| | | *lat = dd + (mm / 60.0); |
| | | |
| | | return HIDO_OK; |
| | | } |
| | | static int32_t GPS_ParseHeight(HIDO_DataStruct *_pstLatData, double *height) |
| | | { |
| | | uint32_t u32Len = _pstLatData->m_u32Len; |
| | | char *pcStart = (char *) _pstLatData->m_pData; |
| | | char *pcDot = NULL; |
| | | uint32_t u32TempLen = 0; |
| | | double dd; |
| | | double mmmm; |
| | | double mm; |
| | | |
| | | pcDot = HIDO_UtilStrnchr(pcStart, '.', u32Len); |
| | | u32TempLen = pcDot - pcStart; |
| | | mm = HIDO_UtilStrBufToInt(pcStart, u32TempLen); |
| | | u32TempLen = u32Len - (pcDot + 1 - pcStart); |
| | | mmmm = HIDO_UtilStrBufToInt(pcDot + 1, u32TempLen); |
| | | while(u32TempLen != 0) |
| | | { |
| | | mmmm /= 10.0; |
| | | u32TempLen--; |
| | | } |
| | | *height = mm + mmmm; |
| | | return HIDO_OK; |
| | | } |
| | | /****************************************************************************** |
| | | Description : Get gps longitude from gps data |
| | | parameter : data: gps data pointer, len: gps data length, gps: ST_GPS pointer |
| | | Return : TRUE on success, FALSE on fail |
| | | author : DuJian |
| | | history : 2012-7-27 new |
| | | ******************************************************************************/ |
| | | static int32_t GPS_ParseLon(HIDO_DataStruct *_pstLonData, double *lon) |
| | | { |
| | | uint32_t u32Len = _pstLonData->m_u32Len; |
| | | char *pcStart = (char *) _pstLonData->m_pData; |
| | | char *pcDot = NULL; |
| | | uint32_t u32TempLen = 0; |
| | | double ddd; |
| | | double mmmm; |
| | | double mm; |
| | | |
| | | if (u32Len < 10) |
| | | { |
| | | return HIDO_ERR; |
| | | } |
| | | |
| | | pcDot = HIDO_UtilStrnchr(pcStart, '.', u32Len); |
| | | if (NULL == pcDot || (pcDot - pcStart) != 5) |
| | | { |
| | | return HIDO_ERR; |
| | | } |
| | | |
| | | ddd = HIDO_UtilStrBufToInt(pcStart, 3); |
| | | mm = HIDO_UtilStrBufToInt(pcStart + 3, 2); |
| | | u32TempLen = u32Len - (pcDot + 1 - pcStart); |
| | | mmmm = HIDO_UtilStrBufToInt(pcDot + 1, u32TempLen); |
| | | while(u32TempLen != 0) |
| | | { |
| | | mmmm /= 10.0; |
| | | u32TempLen--; |
| | | } |
| | | |
| | | mm = mm + mmmm; |
| | | *lon = ddd + (mm / 60.0); |
| | | |
| | | return HIDO_OK; |
| | | } |
| | | |
| | | extern u8 gpsdataready_flag; |
| | | extern u16 gps_packlen; |
| | | u8 totalpack_num,currentpack_num; |
| | | u16 sendtimes; |
| | | void RecOnePackData(void) |
| | | { |
| | | dwt_setrxtimeout(0);//è®¾å®æ¥æ¶è¶
æ¶æ¶é´ï¼0使²¡æè¶
æ¶æ¶é´ |
| | | |
| | | /* Activate reception immediately. */ |
| | | dwt_rxenable(0);//æå¼æ¥æ¶ |
| | | |
| | | /* Poll for reception of a frame or error/timeout. See NOTE 7 below. */ |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR))&&!g_start_send_flag&&!g_start_sync_flag)//䏿æ¥è¯¢è¯çç¶æç´å°æ¥æ¶æåæè
åºç°é误 |
| | | { |
| | | IdleTask(); |
| | | }; |
| | | |
| | | if (status_reg & SYS_STATUS_RXFCG)//æåæ¥æ¶ |
| | | { |
| | | u16 tag_recv_interval,send_i=0,remain_i=0; |
| | | /* Clear good RX frame event in the DW1000 status register. */ |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);//æ¸
餿 å¿ä½ |
| | | |
| | | /* A frame has been received, read it into the local buffer. */ |
| | | frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFL_MASK_1023;//è·å¾æ¥æ¶æ°æ®é¿åº¦ |
| | | g_Resttimer = 0; |
| | | dwt_readrxdata(rx_buffer, frame_len, 0);//è¯»åæ¥æ¶æ°æ® |
| | | if (rx_buffer[MESSAGE_TYPE_IDX] == DATA_POLL ) //å¤ææ¥æ¶å°çæ°æ®æ¯å¦æ¯responseæ°æ® |
| | | { |
| | | recdata_len = frame_len-14; |
| | | memcpy(rec_gpsdata,&rx_buffer[DATA_IDX],recdata_len); |
| | | // if(gpsdataready_flag) |
| | | { |
| | | gpsdataready_flag = 0; |
| | | tx_sync_msg[MESSAGE_TYPE_IDX]=DATA_RESPONSE; |
| | | remain_i = gps_packlen; |
| | | currentpack_num = 0; |
| | | totalpack_num = gps_packlen/110; |
| | | while(remain_i>0) |
| | | { |
| | | if(remain_i>=110) |
| | | { |
| | | tx_sync_msg[CURENTPACKNUM_IDX] = 0; |
| | | memcpy(&tx_sync_msg[DATA_IDX],&RTCMdata[send_i],110); |
| | | send_i+=110; |
| | | remain_i-=110; |
| | | dwt_writetxdata(110+14, tx_sync_msg, 0);//å°Pollå
æ°æ®ä¼ ç»DW1000ï¼å°å¨å¼å¯åéæ¶ä¼ åºå» |
| | | dwt_writetxfctrl(110+14, 0);//设置è¶
宽带åéæ°æ®é¿åº¦ |
| | | dwt_starttx(DWT_START_TX_IMMEDIATE); |
| | | sendtimes++; |
| | | }else{ |
| | | tx_sync_msg[CURENTPACKNUM_IDX] = 1; |
| | | memcpy(&tx_sync_msg[DATA_IDX],&RTCMdata[send_i],remain_i); |
| | | dwt_writetxdata(remain_i+14, tx_sync_msg, 0);//å°Pollå
æ°æ®ä¼ ç»DW1000ï¼å°å¨å¼å¯åéæ¶ä¼ åºå» |
| | | dwt_writetxfctrl(remain_i+14, 0);//设置è¶
宽带åéæ°æ®é¿åº¦ |
| | | dwt_starttx(DWT_START_TX_IMMEDIATE); |
| | | remain_i = 0; |
| | | sendtimes++; |
| | | } |
| | | delay_us(1000); |
| | | } |
| | | } |
| | | LED0_BLINK; |
| | | |
| | | extern HIDO_DataStruct stPosState[4]; |
| | | |
| | | GPS_ParseGGA(rec_gpsdata,recdata_len); |
| | | |
| | | const char *fmt = "{\"battery\":4.2,\"dev_type\":\"11\",\"device_sn\":\"15625394\",\"gps_type\":%d,\"high\":%.8lf,\"lat\":%.8lf,\"lng\":%.8lf}"; |
| | | |
| | | double lat = 0; |
| | | double lon = 0; |
| | | double high = 0; |
| | | uint8_t gps_type; |
| | | gps_type = HIDO_UtilStrBufToInt(stPosState[2].m_pData,1); |
| | | if(gps_type!=0) |
| | | { |
| | | GPS_ParseLon(&stPosState[1], &lon); |
| | | GPS_ParseLat(&stPosState[0], &lat); |
| | | GPS_ParseHeight(&stPosState[3], &high); |
| | | } |
| | | printf(fmt,gps_type, high, lat, lon); |
| | | //USART_puts(rec_gpsdata,recdata_len); |
| | | } |
| | | }else{ |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | |
| | | } |