配置工程 最后更新时间: 2025年07月11日
第一步,初始化
1
构建创建及运行地图所需的环境变量,主要需要实现内存、文件、系统、网络、渲染等适配器所需能力接口和提供一些基础参数(设备id、key等)。
awk_context_t context;
memset(&context, 0, sizeof(awk_context_t)); // 务必先memset
context.device_id = "设备id";
context.key = "开平key";
context.root_dir = "文件路径"; // SDK内部文件夹根路径
context.tile_mem_cache_max_size = 0; // 栅格图内存缓存限值,单位:MB
context.tile_disk_cache_max_size = 200; // 栅格图磁盘缓存限值,单位:MB
#if 0
//在线模式配置
context.tile_load_mode = AWK_MAP_TILE_LOAD_ONLINE;
#else
// 离线模式配置
context.tile_load_mode = AWK_MAP_TILE_LOAD_OFFLINE;
context.offline_map_dir = "offline_map_path"; // 离线文件路径
#endif
// 内存相关适配
context.memory_adapter.mem_malloc = awk_mem_malloc_adapter;
context.memory_adapter.mem_free = awk_mem_free_adapter;
context.memory_adapter.mem_calloc = awk_mem_calloc_adapter;
context.memory_adapter.mem_realloc = awk_mem_realloc_adapter;
// 文件相关适配
context.file_adapter.file_open = awk_file_open_adapter;
context.file_adapter.file_close = awk_file_close_adapter;
context.file_adapter.file_read = awk_file_read_adapter;
context.file_adapter.file_write = awk_file_write_adapter;
context.file_adapter.file_mkdir = awk_file_mkdir_adapter;
context.file_adapter.file_exists = awk_file_exists_adapter;
context.file_adapter.file_remove = awk_file_remove_adapter;
context.file_adapter.file_opendir = awk_file_opendir_adapter;
context.file_adapter.file_closedir = awk_file_closedir_adapter;
context.file_adapter.file_readdir = awk_file_readdir_adapter;
context.file_adapter.file_seek = awk_file_seek_adapter;
context.file_adapter.file_flush = awk_file_flush_adapter;
context.file_adapter.file_rmdir = awk_file_rmdir_adapter;
context.file_adapter.file_dir_exists = awk_file_dir_exists_adapter;
context.file_adapter.file_get_size = awk_file_get_size_adapter;
context.file_adapter.file_get_last_access = awk_file_get_last_access_adapter;
context.file_adapter.file_rename = awk_file_rename_adapter;
context.file_adapter.file_unzip = awk_file_unzip_adapter;
// 网络相关适配
context.network_adapter.send = awk_aos_network_adapter_send_adapter;
context.network_adapter.cancel = awk_aos_network_adapter_cancel_adapter;
// 渲染绘制相关适配
context.render_adapter.begin_drawing = awk_render_begin_drawing_adapter;
context.render_adapter.commit_drawing = awk_render_commit_drawing_adapter;
context.render_adapter.draw_point = awk_render_point_adapter;
context.render_adapter.draw_polyline = awk_render_polyline_adapter;
context.render_adapter.draw_polygon = awk_render_polygon_adapter;
context.render_adapter.draw_bitmap = awk_render_bitmap_adapter;
context.render_adapter.draw_color = awk_render_color_adapter;
// 其他系统相关适配
context.system_adapter.get_system_time = awk_get_system_time_adapter;
context.system_adapter.log_printf = awk_printf_adapter;
awk_init(&context);2
POSIX标准适配层头文件:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>3
POSIX标准-内存相关适配层代码示例:
static void awk_mem_free_adapter(void *ptr)
{
free(ptr);
}
static void *awk_mem_malloc_adapter(size_t size)
{
void *ptr = malloc(size);
return ptr;
}
static void *awk_mem_calloc_adapter(size_t count, size_t size)
{
void *ptr = calloc(count, size);
return ptr;
}
static void *awk_mem_realloc_adapter(void *ptr, size_t size)
{
void *r_ptr = realloc(ptr, size);
return r_ptr;
}4
POSIX标准-文件相关适配层代码示例:
static void *awk_file_open_adapter(const char *filename, const char *mode)
{
FILE *file = fopen(filename, mode);
return (void *)file;
}
static int awk_file_close_adapter(void *handler)
{
FILE *file = (FILE *)handler;
return fclose(file);
}
static int awk_file_seek_adapter(void *handler, long offset, int where)
{
FILE *file = (FILE *)handler;
return fseek(file, offset, where);
}
static int awk_file_flush_adapter(void *handler)
{
FILE *file = (FILE *)handler;
return fflush(file);
}
static size_t awk_file_read_adapter(void *ptr, size_t size, void *handler)
{
return fread(ptr, size, 1, (FILE *)handler);
}
static size_t awk_file_write_adapter(void *ptr, size_t size, void *handler)
{
return fwrite(ptr, size, 1, (FILE *)handler);
}
static bool awk_file_exists_adapter(const char *path)
{
int ret = access(path, 0);
return ret == 0;
}
static bool awk_file_dir_exists_adapter(const char *path)
{
struct stat fileStat;
memset(&fileStat, 0, sizeof(struct stat));
return (stat(path, &fileStat) == 0) && S_ISDIR(fileStat.st_mode);
}
static int awk_file_remove_adapter(const char *path)
{
return remove(path);
}
static int awk_file_mkdir_adapter(const char *path, uint16_t model)
{
return mkdir(path, model);
}
static int awk_file_rmdir_adapter(const char *path)
{
return rmdir(path);
}
static void *awk_file_opendir_adapter(const char *path)
{
DIR *dir = opendir(path);
return (void *)dir;
}
static int awk_file_closedir_adapter(void *dir)
{
return closedir((DIR *)dir);
}
static void awk_file_readdir_adapter(void *dir, awk_file_dir_foreach foreach, void *user_data)
{
struct dirent *entry = NULL;
while ((entry = readdir((DIR *)dir)) != NULL)
{
awk_file_dir_entry dir_entry = {
.file_name = entry->d_name};
foreach (dir_entry, user_data)
;
}
}
static size_t awk_file_get_size_adapter(const char *path)
{
struct stat statbuf;
int ret = stat(path, &statbuf);
return ret == 0 ? statbuf.st_size : 0;
}
static long awk_file_get_last_access_adapter(const char *path)
{
struct stat statbuf;
int ret = stat(path, &statbuf);
return ret == 0 ? statbuf.st_atimespec.tv_nsec : 0;
}
static int awk_file_rename_adapter(const char *old_name, const char *new_name)
{
return rename(old_name, new_name);
}第二步,激活设备
激活设备,设备初次使用时调用,需要保证网络可用,未激活会导致SDK不可用。
awk_activate_device(callback);
