int8_t socket_write(uint8_t id , uint8_t *sendData , uint16_t length , uint32_t timeout )
{
int ret = GSOCKET_OK;
gsockeArryType *socket = socket_read_obj(id);//绑定关系
if(!devCom->isOK())//------------------它可以提前返回
{
printy("socket_write 直接返回id = %d\n" , id);
return SOCKERT_STATUS_ERR;
}
if(socket == NULL)
{
log_err("SOCKET_SEND_NOID id = %d\n" , id);
return SOCKET_SEND_NOID ;
}
if( socket->useFlag == FALSE)
{
return SOCKET_SEND_NOCON;
}
//开始发送
if( xSemaphoreTake( xSocketSemaphore, timeout ) == pdTRUE )
{
if( ( ret = devCom->send(id , sendData , length )) == TRUE)
{
xSemaphoreGive(xSocketSemaphore);
return GSOCKET_OK;
}
xSemaphoreGive(xSocketSemaphore);
return ret;
}
else
{
printy("socket %d GETFAIL xSocketSemaphore ->SOCKET_SEND_BUSY\n" , id);
return SOCKET_SEND_BUSY;
}
}
int8_t gsm_write_data(uint8_t socketId , uint8_t *msg , uint16_t length)
{
uint8_t comm[64] , cmdLength =0,sendAck=0;
memset(comm , 0x00 , sizeof(comm));
if(GSM_INIT_OK==0) { printy("gsm_write_data GSM_INIT_OK==0 直接返回\r\n"); return SOCKET_SEND_FAIL;}//------------------它可以提前返回 已经不要了
cmdLength = sprintf((char *)comm , "AT+CIPSEND=%d,%d\r\n" , socketId , length);
// printf("SIM send :%s",comm);
modesim_send(comm , cmdLength);
if( xSemaphoreTake( xSocketATACKSemaphore, 60000 ) == pdTRUE )
{
//printf("SIM send AT 拿到>成功 继续\r\n");
// log_arry("SIM send :" ,msg , length );
modesim_send(msg ,length );
if(xQueueReceive( xSIM800CTALKQueue, &sendAck, 60000 ) == pdTRUE)
{
// printf("SIM send MAG 拿到反馈%d[9-ok 10-fail]\r\n",sendAck);
if(sendAck == GSM_SEND_OK_TYPE)
return 0;
else if(sendAck == GSM_SEND_FAIL_TYPE)
return SOCKET_SEND_FAIL;
}
log_err("SIM send MAG 没有拿到反馈\n" );
return SOCKET_SEND_NOREADY;
}
log_err("SIM send AT 没有拿到>\r\n" );
return SOCKET_SEND_NOREADY;
}