gnokii:API错误?
我对以下代码有问题:gnokii:API错误?,api,config,gnokii,Api,Config,Gnokii,我对以下代码有问题: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <gnokii.h> #define CONFIG_FILE "config" struct gn_statemachine *state; void terminate(void) { gn_lib_phone_close(state); gn_lib_phonep
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnokii.h>
#define CONFIG_FILE "config"
struct gn_statemachine *state;
void terminate(void) {
gn_lib_phone_close(state);
gn_lib_phoneprofile_free(&state);
gn_lib_library_free();
}
int main() {
gn_data data;
gn_error error;
gn_sms_folder_list folderlist;
atexit(terminate);
if((error = gn_lib_phoneprofile_load(CONFIG_FILE,&state))
!= GN_ERR_NONE)
{
fprintf(stderr,"%s\n",gn_error_print(error));
exit(1);
}
memset(&folderlist,0,sizeof(gn_sms_folder_list));
gn_data_clear(&data);
data.sms_folder_list = &folderlist;
error = gn_sm_functions(GN_OP_GetSMSFolders, &data, state);
printf("ada %d sms dun\n",folderlist.number);
return 0;
}
因为我将配置文件包含在主输出的一个文件夹中:
$ cat config
[global]
connection = bluetooth
port = 24:22:AB:AB:C1:F8
model = AT
rfcomm_channel = 2
那有什么问题吗?首先,以下几点会导致问题:
if((error = gn_lib_phoneprofile_load(CONFIG_FILE,&state))
状态
变量未在此处初始化。这将导致传递随机指针,很可能是segfault
接下来,gn\u lib\u phoneprofile\u load()
的第一个参数不是配置文件名,而是配置中提供连接详细信息的phone部分。假设您将config
作为此参数传递,则需要:
[phone_config]
connection = bluetooth
port = 24:22:AB:AB:C1:F8
model = AT
rfcomm_channel = 2
但是放在标准gnokii配置文件位置。要使用不同的位置,请使用:
gn_lib_phoneprofile_load_from_file(CONFIG_FILE, NULL, &state);
第二个参数是电话段名称。如果为空,则将使用[global]
另外,gn\u lib\u phoneprofile\u load()
只读取配置文件。您需要运行gn\u lib\u phone\u open()
来初始化连接
最后,已经编写了类似的代码,无需重新设计轮子:这是一个很好的解释:D,我想知道如何在变量中设置配置,而不是从文件中获取,这是可能的吗?无论如何,是否有一些手动库API为gnokii API编写了文档?如果有一些配置变量处理的合适API在TODO列表中,那该有多好。可能会在2-3个gnokii版本中发布。现在,您可以查看如何在没有配置文件的情况下处理gnokii配置。没有合适的API文档。我的建议是阅读gnokii的源代码和一些使用示例,我不知道您(作为开发人员)对gnokii it自身未来开发的
没有合适的API文档的期望是什么,但我期待着进一步的发布,不管是什么:D
gn_lib_phoneprofile_load_from_file(CONFIG_FILE, NULL, &state);