int bip_send_pdu( BACNET_ADDRESS * dest, /* destination address */ BACNET_NPDU_DATA * npdu_data, /* network information */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len) { /* number of bytes of data */ struct sockaddr_in bip_dest; int mtu_len = 0; int bytes_sent = 0; /* addr and port in host format */ struct in_addr address; uint16_t port = 0; // (void) npdu_data; /* assumes that the driver has already been initialized */ if (BIP_Socket < 0) { return BIP_Socket; } mtu[0] = BVLL_TYPE_BACNET_IP; bip_dest.sin_family = AF_INET; if ((dest->net == BACNET_BROADCAST_NETWORK) || ((dest->net > 0) && (dest->len == 0)) || (dest->mac_len == 0)) { /* broadcast */ address.s_addr = BIP_Broadcast_Address.s_addr; port = BIP_Port; mtu[1] = BVLC_ORIGINAL_BROADCAST_NPDU; } else if (dest->mac_len == 6) { bip_decode_bip_address(dest, &address, &port); mtu[1] = BVLC_ORIGINAL_UNICAST_NPDU; } else { /* invalid address */ return -1; } bip_dest.sin_addr.s_addr = address.s_addr; bip_dest.sin_port = port; memset(&(bip_dest.sin_zero), '\0', 8); mtu_len = 2; mtu_len += encode_unsigned16(&mtu[mtu_len], (uint16_t) (pdu_len + 4 /*inclusive */ )); memcpy(&mtu[mtu_len], pdu, pdu_len); mtu_len += pdu_len; if(newsocket != 0) { TCPIP_UdpSend(newsocket, 0, 0, mtu, mtu_len); } else { TCPIP_UdpSend(BIP_Socket/*bip_Conns[0].UdpSocket*/, 0, 0, mtu, mtu_len); } flagLED_ether_tx = 1; Test[13]++; return bytes_sent; }
/* * ---------------------------------------------------------------------------- * Function Name: sntpc_Send * Purpose: * Params: * Returns: * Note: * ---------------------------------------------------------------------------- */ void sntpc_Send(U8_T InterUdpId) { U8_T len = 48; U8_T i; sntp_Buf[0] = 0x0b; for (i = 1; i < len; i++) sntp_Buf[i] = 0; TCPIP_UdpSend(InterUdpId, 0, 0, sntp_Buf, len); // printd("sntp send...\n\r"); } /* End of sntpc_Send() */
//U8_T IDATA fwAutoUpdated[4] _at_ 0x31; void GUDPBC_Receive(U8_T XDATA* pData, U16_T length, U8_T id) { U8_T opcode = 0xFF; BOOL bValidReq = FALSE; U16_T i; U8_T n = 0; if(pData[0] == 0x64) { // flag_udp_scan = 1; // udp_scan_count = 0; state = 1; for(n = 0;n < (U8_T)length / 4;n++) { if((pData[4*n + 1] == Modbus.ip_addr[0]) && (pData[4*n+2] == Modbus.ip_addr[1]) &&(pData[4*n + 3] == Modbus.ip_addr[2]) && (pData[4*n+4] == Modbus.ip_addr[3])) { // scanstart=0; state=0; // break; } } if(state) { //use broadcast when scan UdpData(0); //serialnumber 4 bytes Scan_Infor.master_sn[0] = 0; Scan_Infor.master_sn[1] = 0; Scan_Infor.master_sn[2] = 0; Scan_Infor.master_sn[3] = 0; memcpy(&Scan_Infor.panelname,panelname,20); // if(cSemaphoreTake( xSemaphore_tcp_send, ( portTickType ) 10 ) == pdTRUE) { TCPIP_UdpSend(gudpbc_Conns[id].UdpSocket, 0, 0, &Scan_Infor, sizeof(STR_SCAN_CMD)); // cSemaphoreGive( xSemaphore_tcp_send ); } // for MODBUS device for(i = 0;i < sub_no;i++) { if((scan_db[i].product_model >= CUSTOMER_PRODUCT) || (current_online[scan_db[i].id / 8] & (1 << (scan_db[i].id % 8)))) // in database but not on_line { if(scan_db[i].product_model != PRODUCT_MINI_BIG) { Scan_Infor.own_sn[0] = (U16_T)scan_db[i].sn << 8; Scan_Infor.own_sn[1] = (U16_T)(scan_db[i].sn >> 8) << 8; Scan_Infor.own_sn[2] = (U16_T)(scan_db[i].sn >> 16) << 8; Scan_Infor.own_sn[3] = (U16_T)(scan_db[i].sn >> 24) << 8; Scan_Infor.product = (U16_T)scan_db[i].product_model << 8; Scan_Infor.address = (U16_T)scan_db[i].id << 8; Scan_Infor.master_sn[0] = Modbus.serialNum[0]; Scan_Infor.master_sn[1] = Modbus.serialNum[1]; Scan_Infor.master_sn[2] = Modbus.serialNum[2]; Scan_Infor.master_sn[3] = Modbus.serialNum[3]; memcpy(&Scan_Infor.panelname,tstat_name[i],20); { // if(cSemaphoreTake( xSemaphore_tcp_send, ( portTickType ) 10 ) == pdTRUE) {// Test[11]++; TCPIP_UdpSend(gudpbc_Conns[id].UdpSocket, 0, 0, &Scan_Infor, sizeof(STR_SCAN_CMD)); // cSemaphoreGive( xSemaphore_tcp_send ); } } } } } // if id confict, send it to T3000 if(conflict_num == 1) { if(conflict_product != PRODUCT_MINI_BIG) { Scan_Infor.own_sn[0] = (U16_T)conflict_sn_old << 8; Scan_Infor.own_sn[1] = (U16_T)(conflict_sn_old >> 8) << 8; Scan_Infor.own_sn[2] = (U16_T)(conflict_sn_old >> 16) << 8; Scan_Infor.own_sn[3] = (U16_T)(conflict_sn_old >> 24) << 8; Scan_Infor.product = (U16_T)conflict_product << 8; Scan_Infor.address = (U16_T)conflict_id << 8; Scan_Infor.master_sn[0] = Modbus.serialNum[0]; Scan_Infor.master_sn[1] = Modbus.serialNum[1]; Scan_Infor.master_sn[2] = Modbus.serialNum[2]; Scan_Infor.master_sn[3] = Modbus.serialNum[3]; { // if(cSemaphoreTake( xSemaphore_tcp_send, ( portTickType ) 10 ) == pdTRUE) { TCPIP_UdpSend(gudpbc_Conns[id].UdpSocket, 0, 0, &Scan_Infor, sizeof(STR_SCAN_CMD)); // cSemaphoreGive( xSemaphore_tcp_send ); } } Scan_Infor.own_sn[0] = (U16_T)conflict_sn_new << 8; Scan_Infor.own_sn[1] = (U16_T)(conflict_sn_new >> 8) << 8; Scan_Infor.own_sn[2] = (U16_T)(conflict_sn_new >> 16) << 8; Scan_Infor.own_sn[3] = (U16_T)(conflict_sn_new >> 24) << 8; { // if(cSemaphoreTake( xSemaphore_tcp_send, ( portTickType ) 10 ) == pdTRUE) { TCPIP_UdpSend(gudpbc_Conns[id].UdpSocket, 0, 0, &Scan_Infor, sizeof(STR_SCAN_CMD)); // cSemaphoreGive( xSemaphore_tcp_send ); } } } }