这是我在这里的第一个问题,我希望我不会做错任何事。
目前我正在为Cyanogenmod进行设备调试,但由于标题中提到的问题,我似乎无法使gps正常工作。
在gps驱动程序中,有以下代码:
state->thread = callback_backup.create_thread_cb(gps_native_thread, gps_state_thread, state);
产生此错误: D / gps_mtk(598):无法创建gps线程:[再试一次]
可以在此处找到启动过程的完整日志: https://paste.ee/p/UsYy4
gps_state_thread函数是这样的:
void
gps_state_thread(void *arg)
{
static float count = 0;
GpsState* state = (GpsState*) arg;
state->test_time += 1;
// state->thread_exit_flag=0;
NmeaReader reader[1];
#if NEED_IPC_WITH_CODEC
char buf_for_codec[2048];
#endif
int gps_fd = state->fd;
int control_fd = state->control[1];
int epoll_fd = state->epoll_hd;
int test_started = 0;
nmea_reader_init( reader );
int mnld_fd = bind_udp_socket(MTK_MNLD2HAL);
DBG("WARNING: mnld_fd=%d\n", mnld_fd);
if(mnld_fd >= 0) {
if(epoll_register( epoll_fd, mnld_fd ) < 0)
ERR("ERR: epoll register control_fd error, error num is %d\n, message is %s\n", errno, strerror(errno));
else
DBG("WARNING: epoll_register successfully\n");
}
#if NEED_IPC_WITH_CODEC
int sock_codec, size_codec;
struct sockaddr_un un;
socklen_t client_addr_len;
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
strcpy(un.sun_path, EVDO_CODEC_SOC);
if ((state->sock_codec = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
ERR("create socket for communicate with codec error, message %s\n", strerror(errno));
return;
}
unlink(EVDO_CODEC_SOC);
size_codec = sizeof(un.sun_family)+strlen(un.sun_path);
if(bind(state->sock_codec, (struct sockaddr *)&un, size_codec) < 0)
{
ERR("bind fail, message = %s\n", strerror(errno));
return;
}
if(listen(state->sock_codec, 5) == -1)
{
ERR("listern error, message is %s\n", strerror(errno));
return;
}
DBG("listen done\n");
int a = chmod(EVDO_CODEC_SOC, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP);
DBG("chmod res = %d\n", a); //770<--mode
if(chown(EVDO_CODEC_SOC, -1, AID_INET))
{
ERR("chown error: %s", strerror(errno));
}
epoll_register(epoll_fd, state->sock_codec);
#endif
// register control file descriptors for polling
if(epoll_register( epoll_fd, control_fd ) < 0)
ERR("epoll register control_fd error, error num is %d\n, message is %s\n", errno, strerror(errno));
if(epoll_register( epoll_fd, gps_fd) < 0)
ERR("epoll register gps_fd error, error num is %d\n, message is %s\n", errno, strerror(errno));
DBG("gps thread running: PPID[%d], PID[%d]\n", getppid(), getpid());
release_condition(&lock_for_sync[M_INIT]);
DBG("HAL thread is ready, realease lock, and CMD_START can be handled\n");
#if SEM
sem_t *sem;
sem = sem_open("/data/misc/read_dev_gps", O_CREAT, S_IRWXU|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH,1);
if(sem == SEM_FAILED)
{
ERR("init semaphore FAIL, error message is %s \n", strerror(errno));
return ;
}
else
DBG("create semaphore ok\n");
#endif
// now loop
for (;;) {
#if NEED_IPC_WITH_CODEC
struct epoll_event events[3];
#else
struct epoll_event events[4];
#endif
int ne, nevents;
#if NEED_IPC_WITH_CODEC
nevents = epoll_wait( epoll_fd, events, 3, -1 );
#else
nevents = epoll_wait( epoll_fd, events, 4, -1 );
#endif
if (nevents < 0) {
if (errno != EINTR)
ERR("epoll_wait() unexpected error: %s", strerror(errno));
continue;
}
VER("gps thread received %d events", nevents);
for (ne = 0; ne < nevents; ne++) {
if ((events[ne].events & (EPOLLERR|EPOLLHUP)) != 0) {
ERR("EPOLLERR or EPOLLHUP after epoll_wait() !?");
goto Exit;
}
if ((events[ne].events & EPOLLIN) != 0) {
int fd = events[ne].data.fd;
if (fd == control_fd)
{
char cmd = 255;
int ret;
DBG("gps control fd event");
do {
ret = read( fd, &cmd, 1 );
} while (ret < 0 && errno == EINTR);
if (cmd == CMD_QUIT) {
DBG("gps thread quitting on demand");
goto Exit;
}
else if (cmd == CMD_START) {
if (!started) {
DBG("gps thread starting location_cb=%p", &callback_backup);
started = 1;
nmea_reader_set_callback( reader, &state->callbacks);
}
}
#ifdef GPS_AT_COMMAND
else if (cmd == CMD_TEST_START) {
if ((!test_started)&&(1 == test_mode_flag)) {
// DBG("**AT Command test_start: test_cb=%p", state->callbacks.test_cb);
test_started = 1;
nmea_reader_set_callback(reader, &state->callbacks);
}
}
else if (cmd == CMD_TEST_STOP) {
if(test_started) {
DBG("**AT Command test_stop");
test_started = 0;
nmea_reader_set_callback(reader, NULL);
}
}
else if (cmd == CMD_TEST_SMS_NO_RESULT) {
DBG("**CMD_TEST_SMS_NO_RESULT, update result!!");
sms_airtest_no_signal_report(Err_Code,0,0,0,0);
//nmea_reader_update_at_test_result(reader, Err_Code, 0, 0, 0, 0);
}
#endif
#if EPO_SUPPORT
else if (cmd == CMD_DOWNLOAD){
DBG("Send download request in HAL.");
mGpsXtraCallbacks.download_request_cb();
}
#endif
else if (cmd == CMD_STOP) {
if (started) {
DBG("gps thread stopping");
started = 0;
nmea_reader_set_callback( reader, NULL );
DBG("CMD_STOP has been receiving from HAL thread, release lock so can handle CLEAN_UP\n");
}
}
else if (cmd == CMD_RESTART) {
reader->fix_mode = 0;
}
}
else if (fd == gps_fd)
{
if(!flag_unlock)
{
release_condition(&lock_for_sync[M_START]);
flag_unlock = 1;
DBG("got first NMEA sentence, release lock to set state ENGINE ON, SESSION BEGIN");
}
VER("gps fd event");
if(report_time_interval > ++count){
DBG("[trace]count is %f\n", count);
int ret = read( fd, buff, sizeof(buff) );
continue;
}
count = 0;
for (;;) {
int nn, ret;
#if SEM
if(sem_wait(sem) != 0)
{
ERR("sem wait error, message is %s \n", strerror(errno));
close(fd);
return ;
}
else
DBG("get semaphore, can read now\n");
#endif
ret = read( fd, buff, sizeof(buff) );
#if NEED_IPC_WITH_CODEC
memset(buf_for_codec, 0, sizeof(buf_for_codec));
memcpy(buf_for_codec, buff, sizeof(buff));
#endif
#if SEM
if(sem_post(sem) != 0)
{
ERR("sem post error, message is %s\n", strerror(errno));
close(fd);
return ;
}
else
DBG("post semaphore, read done\n");
#endif
if (ret < 0) {
if (errno == EINTR)
continue;
if (errno != EWOULDBLOCK)
ERR("error while reading from gps daemon socket: %s: %p", strerror(errno), buff);
break;
}
DBG("received %d bytes:\n", ret);
gps_nmea_end_tag = 0;
for (nn = 0; nn < ret; nn++)
{
if(nn == (ret-1))
gps_nmea_end_tag = 1;
nmea_reader_addc( reader, buff[nn] );
}
}
VER("gps fd event end");
}
else if(fd == mnld_fd) {
mnld_to_gps_handler(mnld_fd,state);
}
#if NEED_IPC_WITH_CODEC
else if(fd == state->sock_codec)
{
client_addr_len = sizeof(un);
int accept_ret = accept(state->sock_codec, (struct sockaddr*)&un, &client_addr_len);
if(accept_ret == -1)
{
ERR("accept error, message is %s\n", strerror(errno));
continue;
}
DBG("accept done\n");
int cmd, write_len;
GpsLocation tLocation;
if(recv(accept_ret, &cmd, sizeof(cmd),0)<0)
{
ERR("read from codec error, message = %s\n", strerror(errno));
close(accept_ret);
continue;
}
DBG("read done, cmd: %d\n", cmd);
switch(cmd)
{
case 1://need NMEA sentences
write_len = send(accept_ret, buf_for_codec, sizeof(buff),0);
DBG("write %d bytes to codec\n", write_len);
break;
case 2: //For AGPS location froward
DBG("Snd to UI");
char ack_buf[10] = {0};
strcpy(ack_buf, "cmd2_ack");
write_len = send(accept_ret, ack_buf, sizeof(ack_buf), 0);
DBG("wait rcv location data");
if(recv(accept_ret, &tLocation, sizeof(tLocation), 0) < 0)
{
ERR("read from codec error, message = %s\n", strerror(errno));
}else{
if(callback_backup.location_cb){
DBG("Update location data to UI");
callback_backup.location_cb(&tLocation);
}else{
DBG("Location CB is null");
}
}
break;
default:
ERR("unknonwn codec message, codec send %d to me\n", cmd);
break;
}
close(accept_ret);
}
#endif
else
{
ERR("epoll_wait() returned unkown fd %d ?", fd);
}
}
}
}
Exit:
DBG("HAL thread is exiting, release lock to clean resources\n");
close(mnld_fd);
release_condition(&lock_for_sync[M_CLEANUP]);
return;
}
如果您还需要了解其他信息,请告诉我。