Embedded Pthreads在嵌入式ARM中不工作
您好,我正在使用AM1808 ARM9微处理器。 我有一个GSM加密狗接口。我想让GSM加密狗连接,以及所有的数据传输以及在后台使用pthreads接收 当我试图在后台连接加密狗时,它一直闪烁绿灯,我无法连接到服务器 我找不到问题 这是我的数据卡初始化代码以及通信例程。 我正在初始化主线程中的线程Embedded Pthreads在嵌入式ARM中不工作,embedded,pthreads,embedded-linux,Embedded,Pthreads,Embedded Linux,您好,我正在使用AM1808 ARM9微处理器。 我有一个GSM加密狗接口。我想让GSM加密狗连接,以及所有的数据传输以及在后台使用pthreads接收 当我试图在后台连接加密狗时,它一直闪烁绿灯,我无法连接到服务器 我找不到问题 这是我的数据卡初始化代码以及通信例程。 我正在初始化主线程中的线程 int InitializeDataCard(void) { static int connect_ret = 0; pthread_t pro
int InitializeDataCard(void)
{
static int connect_ret = 0;
pthread_t processing_th;
pthread_create(&processing_th, NULL, Datacard_Connection_Thread, &db_mc_object);
pthread_detach(processing_th);
ShowMessageBox(msgbox_text[136], MB_TASKMODAL);
if(connect_ret)
{
ShowMessageBox(msgbox_text[163], MB_ICONERROR);
return -1;`enter code here`
}
else
{
return 0;
}
}
int ConnectToServer(void)
{
int connect_ret = 0;
Dprintf(__func__,"Trying to connect ....");
DPUUtilsLib_RetrieveParameter(PID_DATACARD_INFO,(UCHAR *)&datacard_info,sizeof(datacard_info));
connect_ret = DataCardConnect(datacard_info);
sleep(3);
//g_do_process = 0;
Dprintf(__func__,"DataCardConnect ret=%d",connect_ret);
return connect_ret;
}
void * Datacard_Connection_Thread(void *tempdata)
{
int ret=0,response = -1,enc_ret=0;
static int g_gsm_response = 0;
dpu_csv_file_param_t fileparam;
dpu_db_export_search_params_t tempparams;
dpu_db_milk_collection_t *livedata,*updatedata;
dpu_db_user_master_t CreatedBy,UpdatedBy;
dpu_db_society_master_t soc_info;
char filename[50]={0};
livedata = (dpu_db_milk_collection_t *)tempdata;
//Connect to the Network
create_connection :
ret = ConnectToServer();
//connected successfully
if(!ret)
{
//Get the SocietyCode from the Database
if(g_data_available)
{
g_data_available=0;
soc_info.SocietyId = g_society_list[g_selected_society].SocietyId;
DPUDBLib_search_society_master(&soc_info);
strncpy(livedata->SocietyCode,soc_info.SocietyCode,5);
Dprintf(__func__,"%04d\n %5.2f\n %5.2f\n %5.2f\n %5.2f\n %5.2f\n %5.2f\n %7.2f\n %7.2f\n %03d\n %c\n %d\n %5.2d\n %s\n %d",
livedata->MemberCode,livedata->Fat,livedata->LRCLR,livedata->SNF,livedata->Solid,
livedata->FatKG,livedata->SNFKG,livedata->Rate,livedata->Amount,
livedata->CanNumber,livedata->EntryMode,livedata->MC_RateChartId,livedata->Water,livedata->SocietyCode,__LINE__);
sprintf(tempparams.FileName,"%s/%s",DATA_TEMP,MT_MILKLIVEFILE);
memcpy(fileparam.FilePath,tempparams.FileName,sizeof(tempparams.FileName));
fileparam.Type = DPU_CSV_EXPORT;
fileparam.FileType = DPU_CSV_MILK_LIVE_DATA_FILE;
//open a csv file
DPUCSVLib_open_csv_file(&fileparam);
memset(&CreatedBy,0,sizeof(dpu_db_user_master_t));
memset(&UpdatedBy,0,sizeof(dpu_db_user_master_t));
strncpy(CreatedBy.Username,TempUser,5);
//write the live data into the file
DPUCSVLib_write_csv_file(&fileparam,livedata,&CreatedBy,&UpdatedBy);
//encrypt the file
enc_ret = DPUEncryptFile(tempparams.FileName,filename);
if(!enc_ret)
{
//send file request to server for the accepting the data
response = SendFileRequest(g_gsm_response,filename,9);
if(!response)
{
//receive the response of the server
response = GetResponceFromServer(g_gsm_response,&response,9);
if(response || g_gsm_response) response = -1;
else
{
//If record is successfully sent to the server then update the FlagGSM flag of the record as well as
//Update the database
g_update_record = 1;
livedata->FlagGSM = 1;
updatedata->MilkCollectionId = livedata->MilkCollectionId;
DPUDBLib_search_milk_collection_entry_by_record(&updatedata);
DPUDBLib_edit_milk_collection_entry(&updatedata,&livedata);
g_update_record = 0;
}
}
//remove the temp file generated
remove(filename);
}
}
}
else
{
//if connection is not successfully done then try to reconnect the server
ShowMessageBox(msgbox_text[156], MB_ICONERROR);
goto create_connection;
}
}
我认为这是一个基本的错误。通过在
InitializeDataCard
中声明静态变量connect_ret
,并不意味着它将与ConnectToServer
中声明的变量相同。因此,第一个函数将始终具有相同的行为
我认为您需要一个全局变量(即未在函数中定义)和某种同步,因为当您创建线程时,它可能不会立即执行,所以即使您有一个全局变量,在知道它已正确设置之前,您无法对其进行检查。您是否尝试过制作一个简单的示例,尝试生成一个线程,例如闪烁一个led?您进行了哪些调试,发现了什么?是否输入了线程代码,如果输入了,它将填充在哪一行?是的,我已经完成了它在线程中输入的调试。我的服务器也在运行,但我的加密狗仍在闪烁绿灯,我无法连接。我的ConnectToServer函数的返回值是完美的。我发现了一个问题,如下所示。因为我需要在数据卡是否连接的情况下继续处理。当我尝试发送数据时,即使数据卡未连接,在这种情况下,我的机器将重新启动,这意味着我无法退出线程。然后我使用了thread_join()函数而不是thread_detach()然后我的目标得到了解决,但我的系统变得很慢,因为这是不可接受的。请检查我的代码如下:void LiveCollectionDataSend(dpu_db_milk_collection_MCdata){dpu_db_milk_collection_*tempdata=malloc(sizeof(dpu_db_milk_collection_t));pthread_t processing_th;int temp;int*ret_val;memcpy(tempdata,MCdata,sizeof(dpu_db_milk_collection_t));pthread_create(&processing_th,NULL,LiveDataTransferThread,tempdata);//pthread_join(processing_th,(void*)&ret val);pthread_exit((void**)&ret val);}