Tange Cloud for Device
 Rev.345
载入中...
搜索中...
未找到
TgCloudApi.h
浏览该文件的文档.
1/**
2 * @file TgCloudApi.h
3 * @brief 探鸽云SDK接口申明
4 */
5#ifndef __TgCloudApi_h__
6#define __TgCloudApi_h__
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <stdint.h>
13#include <time.h>
14#include "TgCloudConst.h"
15#include "TgCloudCmd.h"
16#include "TgCloudCmdEx.h"
17#include "ec_const.h"
18#include "TgCloudUtil.h"
19
20
21/** \addtogroup api_const
22 * @{*/
23/** sim 卡类型 */
24typedef enum {
25 SIMT_PHY, ///< 物理卡
26 SIMT_ESIM, ///< ESIM
27 SIMT_VSIM ///< vsim卡
29
30/** 低功耗设备的工作模式 */
31typedef enum {
32 PM_ALLON, ///< 常电模式。非低功耗设备的默认模式
33 PM_SLEEPABLE, ///< 系统可休眠(会收到STATUS_IDLE状态回调。这是低功耗设备的默认模式)
34 PM_NETDOWN ///< 主控正常工作,网络模块进入休眠模式
36
37/** 传输内容 */
38typedef enum {
39 TRANS_SERVICE_LIVE_AV = 0,
40 TRANS_SERVICE_AUDIO_PIC = 1,
41 TRANS_SERVICE_PIC_ONLY = 2,
42 TRANS_SERVICE_MAX
44
45/** SDK选项常数 */
46typedef enum {
47 /** 有人观看时禁止上传
48 * 类型: int*
49 * - 1 disable
50 * - 0 Allow parallel operation
51 */
53
54 /** 云存储缓冲文件数.
55 * 类型: int*: 1~6
56 */
58
59 /** 传输内容
60 * 类型: int*:
61 * - 0 live video/audio
62 * - 1 picture+audio
63 * - 2 picture only.
64 * @ref ETRANSSERVICE.
65 */
67
68#if 0
69 /** tcp连接方式
70 * 类型 int*:
71 * - 0 default
72 * - 1 并发
73 */
74 TCOPT_TCP_CONNECTOR = 4,
75#endif
76
77 /** backstore 存储天数
78 * 类型 int*:
79 * - 0 同云服务保存天数
80 * - >0 自定义的存储天数.不超过服务规定的天数
81 */
83
84 /** 最大云存data文件。超出的帧会丢弃.
85 * 类型: int*
86 */
88
89 /** 仅上报AI事件.
90 * 类型: int*
91 */
93
94 /** 用户没有应答不能拉流. 用于楼宇对讲
95 * 类型: int *
96 */
98
99 /** 事件云存预录时间长度, 单位:秒.
100 * 类型: int *
101 * 说明: 默认为5\". 实际长度受云存缓存大小限制。记住录像总时长是不变的.
102 */
104
105 /* Don't genera event&record for wxvoip */
106 TCOPT_NO_WX_EVENT = 10,
108
109/** @anchor sdk_state_flags */
110/** @name SDK状态标志
111 * @{*/
112#define TGSS_F_CS_INSERVICE 0x00000001 ///< 云文件正在上传或者新文件正在打包
113#define TGSS_F_P2P_CONNECTED 0x00000002 ///< 有用户连接
114#define TGSS_F_P2P_STREAMING 0x00000004 ///< 用户正在拉流
115#define TGSS_F_P2P_INSETTING 0x00000008 ///< 用户处在设置界面
116#define TGSS_F_BS_UPLOADING 0x00000010 ///< 后备存储正在上传
117#define TGSS_F_CALL_PENDING 0x00000020 ///< 呼叫正在等待处理
118#define TGSS_F_IN_CONVERSATION 0x00000040 ///< 呼叫通话中
119/**@}*/
120
121/**@}*/ //group api_const
122
123/** \defgroup api_structure API数据结构
124 * API接口用到的数据结构
125 * @{*/
126/** 设备基本信息 */
127typedef struct TCIDEVICEINFO {
128 char device_type[16]; ///< Not used
129 char vendor[16]; ///<设备生产厂商 OEM
130 char firmware_id[32]; ///<ota 升级用的固件标识, 平台唯一. 两款设备,如果升级包一样,就有相同的 firmware_id。
131 ///< 可以按 "公司_方案_设备类型_其它信息" 的规则自己定义一个字符串, 例如: "TANGE_HISI_IPC_001".
132 ///< 标识里不能有"."。
133 ///< 平台按字符串比较,不关心具体内容.
134 char firmware_ver[10]; ///< 固件主版本,8个数字组成的字符串。like: "03020201", means 3.2.2.1.
135 char model[32]; ///< 产品型号
137
138/** 云服务信息 */
139typedef struct TCISERVICEINFO {
140 ECSERVICETYPE serviceType; ///< 云服务类型
141 time_t expiration; ///< 过期时间(utc)
142 union {
143 uint32_t sub_type;
144 /**< 当 serviceType = @ref ECGS_TYPE_STORAGE, sub_type 为云存服务子类型:
145 * - EC_SVC_EVENT: 事件录像
146 * - EC_SVC_CONTINUOUS: 全天录像
147 * - EC_SVC_FOR_AI: 仅为ai服务提供短录像,其它事件不录像
148 * - EC_SVC_IMAGE_N: 保存N张图片
149 */
150
151 char *objects;
152 /**< 当 serviceType = @ref ECGS_TYPE_AI, objects 为
153 * '\0'结尾并以一个额外 '\0'结束的允许检测的ai对象列表。例如: "body\0car\0cry\0"
154 */
155 };
157
158/** p2p连接句柄. A opaque pointer */
159typedef void *p2phandle_t;
160/** 命令回调类型 */
161typedef int (*TGCMDHANDLER)(p2phandle_t handle, int cmd, const void *data, int len);
162
163/*
164typedef uint64_t feature_map_t;
165void FEATURE_ZERO(feature_map_t *fm);
166int FEATURE_SET(feature_map_t *fm, feature_t f);
167int HAS_FEATURE(const feature_map_t *fm, feature_t f);
168*/
169
170/** P2P发送统计数据结构 */
172 short id; ///< 用户(连接)标识
173 short vchannel; ///< 视频通道
174 short vstream; ///< 码流
175 short is_igop; ///< 1:统计间隔为一个I帧间隔; 0:周期约为~1s
176 int nBytesInBuff; ///< 位于发送缓冲区的字节数
177 int nBytesSent; ///< 已经发送的字节数
178 int nBytesTotal; ///< 总共收到的字节数
179 int nBytesThrow; ///< 丢掉的字节数。丢包会持续到到一个I帧,这期间即使网络恢复也会丢,所以其值只能作为参考, 不能用于计算网速
180 int msStatInterval; ///< 统计周期(单位: ms)
181};
182
183/** sdk 回调函数结构 */
184struct TciCB {
185 /** 获取设备基本信息 */
186 int (*get_info)(TCIDEVICEINFO *info);
187
188 //int (*on_get_features)(feature_map_t *features);
189
190/** 设备能力. 参见 @ref DeviceFeatures
191 \param key 能力名
192 \param buf 返回能力描述的缓冲区
193 \param size 缓冲区大小
194 \retval 0 ok
195 \retval <0 failed(not recognize)
196*/
197 int (*get_feature)(const char *key, char *buf, int size);
198
199 /** 取设备当前状态或初始默认设置.
200 *
201 * \param key 状态名
202 * \li \c CVideoQuality 云录像清晰度. 格式: <tt>stream:channel</tt>
203 * \li \c streamQuality 实时视频默认码流. 格式: <tt>stream:channel</tt>
204 * - \c stream 码流: 0-高清; 1-标清
205 * - \c channel 视频通道号: 0, 1, ...
206 *
207 * \li \c mac 设备mac地址, null结尾的12个十六进制字符
208 * \li \c versions 版本号的json数组。格式: ["main_ver", "sub_ver1", ...]. 版本号为8个数字级成的字符串如"01000208"(=1.0.2.8)
209 *
210 * \param buf 返回值缓冲区
211 * \param size 缓冲区大小
212 *
213 */
214 int (*get_state)(const char *key, char *buf, int size);
215
216 /** 直连模式下用户登录帐号检查
217 * \param user 用户名, 目前未使用
218 * \param key 用户密码加密
219 * \retval 1 验证成功
220 * \retval 0 失败
221 */
222 int (*on_apmode_login)(const char *user, const char *key);
223
224/**
225 * @name OTA接口
226 * @{
227 */
228 /** OTA升级开始
229 * \param new_version 升级包版本
230 * \param size 升级包大小
231 * \return 0 升级继续; -1 升级中止
232 */
233 int (*on_ota_download_start)(const char *new_version, unsigned int size);
234
235 /** 升级包数据
236 * 升级包下载过程中,sdk调用此回调将数据传给应用层
237 * \param buff 数据
238 * \param size 数据长度
239 * \return 0 继续; -1 传输中止
240 */
241 int (*on_ota_download_data)(const uint8_t *buff, int size);
242
243 /** 升级包下载结束
244 * \param status 完成状态: 0-ok, 可以执行升级; 1-下载中断; 2-数据校验错
245 * \retval -1 应用中止升级过程
246 * \retval 0 如果应用可以立即执行升级,可以返回0表示升级成功
247 * \retval 1 如果应用要退出进程再升级,返回1通知APP等待.
248 * @note 因为返回0/1后应用会退出,不保证APP端一定能收到应答
249 */
250 int (*on_ota_download_finished)(int status);
251/**@}*/
252
253
254/**
255 * @name 二维码扫描
256 * @{
257 */
258 /** 二维码扫描开始
259 * 应用层在此开启取Y数据的通道
260 * \return 0 ok; -1 failed
261 */
262 int (*qrcode_start)(void);
263
264 /** 获取Y图片
265 * \param[in,out] ppYBuff
266 * \param[out] width 返回图片宽度
267 * \param[out] height 返回图片高度
268 * \return 0 ok; -1 停止扫描
269 * @note 第一次调用时 *ppYBuff为NULL. 应用层在此分配一个缓冲区, 填入Y数据,并把缓冲区指针保存到*ppYBuff.
270 * 之后的调用 *ppYBuff为之前设置的值
271 */
272 int (*qrcode_get_y_data)(uint8_t **ppYBuff, int *width, int *height);
273
274 /** 结束二维码扫描
275 * \param ppYBuff *ppYBuff中为最后一次在on_get_y_data中返回的值
276 * @note 应用层在此释放前面分配的内存(free(*ppYBuff)), 关闭Y通道
277 */
278 void (*qrcode_end)(uint8_t *pYBuff);
279/**@}*/
280
281 /** 抓取图片. 目前只支持jpeg格式
282 * \param type @ref pic_type "图片类型" in TciCloudConst.h
283 * \param ppJgp *ppJpg为图片地址或用于返回图片的址.见note
284 * \param size 返回时*size为图片字节数
285 * \return 0 ok; @ref TCE_BUFFER_TOO_SMALL; -1 其它错误
286 * @note 如果*ppJpg为NULL,应用层分配图片空间, 空间指针和图片大小分别保存在*ppJpg和*size. sdk内部负责释放空间。
287 * 如果*ppJpg为非空,*ppJpg为SDK内分配的空间地址,*size为空间大小。返回时*size为实际图片大小
288 */
289 int (*snapshot)(int type, uint8_t **ppJpg, int *size); //??
290
291 /** 设置wifi参数
292 * \param is_switching 0:配网; 1:添加成功后修改wifi
293 * \return 0 配置ok; -1 配置不对
294 * \note 返回时, wifi处在station模式
295 */
296 int (*set_wifi)(int is_switching, const char *ssid, const char *key);
297
298 /** 设置时区
299 * \param tzs 时区字符串. Refer to man page of tzset().
300 */
301 int (*set_timezone)(const char *tzs);
302
303 /** 设置时间
304 * \param time utc 时间
305 */
306 int (*set_time)(time_t time);
307
308 /** sdk内部状态
309 * \param status 状态. Refer to @ref status_code "Status Code" in TgCloudConst.h
310 * \param pData 状态相关数据
311 * \return 返回值同event的值有关. 请查看 @ref status_code 。默认返回0
312 */
313 int (*on_status)(int event, const void *pData, int len);
314
315
316/**
317 * @name 对讲
318 * @{
319 */
320 /** 开始对讲
321 * \return 0 ok; -1 中断
322 */
323 int (*on_talkback_start)(void);
324
325 /** 对讲数据回调
326 * 格式在前面已经协商过
327 * \return 0 if played
328 */
329 int (*talkback)(TCMEDIA at, const uint8_t *audio, int len);
330
331 /** 结束对讲 */
332 void (*on_talkback_stop)(void);
333/**@}*/
334
335 /** @deprecated
336 * 请求I帧. 请使用 request_iframe_ex
337 * \param vstream 视频流. 0-主码流; 1-辅码流
338 * \return 0
339 */
340 int (*request_iframe)(int vstream);
341
342 /** 当AI识别成功,通过本回调通知应用. (本回调未使用,设为NULL)
343 * \param type \ref pic_type "图片类别指示"
344 * \param pJpg 正识别图片
345 * \param len 图片长度
346 */
347 void (*ai_result)(int type, const uint8_t* pJpg, int len);
348
349 /** 在平台端采集设备日志
350 * \param action
351 * - 0-开始长日志采集;
352 * - 1-停止长日志采集;
353 * - 2-获取日志文件用于上传云端. 文件路径不能有空格
354 * - 102-获取日志文件用于传给app。文件只支持文本格式, 路径不能有空格
355 *
356 * \param logfile 同action有关。
357 * - action为0或1时, logfile为NULL
358 * - 当action为2时, logfile用于应用层返回日志文件路径. 多个路径用';'分隔,总长不超过256
359 *
360 * \return 0:ok; -1:failed
361 */
362 int (*log)(int action, char *logfile);
363
364 /** 请求指定图像通道的I帧
365 * \param channel 图像通道
366 * \param vstream 视频流. 0-主码流; 1-辅码流
367 * \return 0
368 */
369 int (*request_iframe_ex)(int channel, int vstream);
370
371 /** 网络传输统计回调 */
372 void (*trans_stat)(const struct TransStatUser *_stat);
373
374 /** 切换图像质量
375 * @param channel 图像通道。目前为0
376 * @param stream 码流 0,1,..., 在"Resolutions"能力中返回
377 * @param qstr 质量描述串, 例如 HD/SD/FHD/..., 在"Resolutions"能力中返回.
378 */
379 void (*switch_quality)(int channel, int stream, const char *qstr);
380
381 void (*talkback_ex)(int mt, unsigned int ts, const void *data, int len, unsigned int uFrameFlags);
382};
383
384/** IPv4 地址表示(网络字节顺序) */
385typedef struct Ipv4Addr {
386 unsigned int ip; ///< ip, network byte-order
387 unsigned short port; ///< port, network byte-order
388} Ipv4Addr;
389
390/** Simple Buffer */
391typedef struct SIMPLEBUFFER {
392 uint8_t *data; ///< 数据缓冲区指针
393 int size; ///< 缓冲区大小
394 int len; ///< 数据长度
396
397/** 参数文件读写函数据指针结构 */
399 /** 分配缓冲区,并读出参数文件.
400 * @param buff 缓冲区结构指针. 由实现填充结构成员。缓冲区大小为参数文件大小加上 cbExtra
401 * @param cbExtra 额外分配的字节数
402 * @retval 1 ok
403 * @retval 0 failed
404 */
405 int (*alloc_and_readall)(SIMPLEBUFFER *buff, int cbExtra);
406
407 /** 写参数文件
408 * @param buff 参数缓冲区指针
409 * @retval 1 ok
410 * @retval 0 failed
411 */
412 int (*save_buff)(const SIMPLEBUFFER *buff);
413
414 /** 释放参数缓冲区 */
415 void (*free_buff)(SIMPLEBUFFER *buff);
416
417 /** 删除参数文件(或者清空参数文件)。下一次读出时 len为0 */
418 void (*remove)(void);
419};
420
421/** 用户文件下载目的地.
422 * @ref TciGetUserFile() */
423union TgfDest {
424 /** 数据下载到文件 */
425 struct to_file {
426 char *path; ///< IN: file path
427 } file;
428 /** 数据下载到内存 */
429 struct to_mem {
430 void *mem; ///< OUT: 指向sdk分配的内存
431 int size; ///< OUT: 数据长度
432 } mem;
433};
434
435/** 设备升级包信息 */
436typedef struct DEVICEOTAINFO {
437 int size; ///< 升级包大小
438 char ver[16]; ///< 升级包版本
439 char md5[36]; ///< md5 检验字符串
440 char url[256]; ///< 下载地址
442
443/** 4G 设备信息 */
444typedef struct TG4GINFO {
445 char imei[24]; ///< 4g模块标识
446 char iccid[24]; ///< sim卡号
447 SIMCARDTYPE sim_type; ///< sim卡类型
448} TG4GINFO;
449
450
451/**@}*///{group api_structure}
452
453/** \defgroup api_reference API参考
454 * @{*/
455
456/** \name 核心API
457 * @{*/
458
459/** 获取SDK版本号
460 * TciInit()之后调用
461 * \return SDK版本号字符串。如:"rev. nn"
462 */
463const char *TciGetVersion(void);
464
465/** 配置基本参数
466 * 在TciStart()之前调用
467 * \param path 用于保存sdk私有数据的目录, 需要有读写权限
468 * \param uuid 设备id. 新的id参数为 \"<i>uuid</i>,<i>key</i>\" 的形式, 烧号时由服务器分配
469 * \return 0
470 */
471int TciInit(const char *path, const char *uuid);
472
473/** 启动服务
474 * @pre 调用本接口前需要保证网络已经配置好
475 * 本调用阻塞直到内部完成初始化或操作失败
476 * \param isBound 设备本地记录的绑定状态. 复位或在TciCB::on_status()里 @ref STATUS_DELETED 时清除。收到 @ref STATUS_LOGON 时设置并保存
477 * \param uCloudBuffSize 云存储缓冲区大小(单位:字节). 要求能缓存3~5秒音视频数据, 为0会禁用云存
478 * \retval 0 启动成功
479 * \retval others. Refer to @ref error_code "错误码"
480 * @ref TgCloudConst.h
481 */
482int TciStart(int isBound, unsigned int uCloudBuffSize);
483
484/** 启动服务.
485 * @param uuid 设备id. 新的id参数为 \"<i><uuid></i>,<i><key></i>" 的形式, 烧号时由服务器分配
486 * @note
487 * 这个接口用于 TciInit() 没有传 uuid 参数的情形. 例如工厂生产测试烧号后立即 \n
488 * 启动服务。烧号前调用TciInit()时uuid为NULL, 烧号后可以在这里传入uuid。
489 * 其它参数和返回值同 TciStart()
490 */
491int TciStart2(int isBound, unsigned int uCloudBuffSize, const char *uuid);
492
493
494/** 停止服务
495 * @pre TciStart() 返回0
496 * @return 0(成功), 或 @ref TCE_SERVER_IS_DOWN, @ref TCE_INVALID_UUID
497 * @ref TgCloudConst.h
498 */
499int TciStop(void);
500
501/** 释放资源
502 * @pre TciStop()
503 * @return Always return 0
504 */
505int TciCleanup(void);
506
507/** 注册回调 -- sdk内部事件
508 * \param cb 非局部TciCB结构指针
509 * \return 0
510 * @note 在 TciInit() 前调用
511 */
512int TciSetCallback(const struct TciCB *cb);
513
514/** 注册通用命令回调
515 * 在回调里处理APP发来的命令请求
516 * @note 在 TciInit() 前调用
517 */
519
520/** 绑定应用私有数据指针到p2p handle
521 * @param[in] handle P2P句柄, 来自命令回调
522 * @param[in] pUser 应用私有数据指针
523 */
524void TciSetSessionUserData(p2phandle_t handle, void *pUser);
525
526/** 返回由TciSetSessionUserData()设置的应用私有数据指针
527 * @param[in] handle P2P句柄
528 * @retval 返回P2P句柄绑定的应用私有数据,没有则返回NULL
529 */
531
532/** 控制日志输出. 应该在TciInit()前调用
533 * @param b_output_to_console 是否输出到控制台
534 * @param log_path log文件路径。应该是一个全局或静态的字符串指针. 为NULL时不创建日志文件
535 * @param max_log_size 日志文件最大尺寸(单位:byte)
536 */
537void TciSetLogOption(int b_output_to_console, const char *log_path, int max_log_size);
538
539/** 设置SDK日志输出等级.
540 * @param level 3:Information(default); 5:verbose; 6:debug
541 */
542void TciSetLogLevel(int level);
543
544/** 设置云存储录像通道的码流
545 * @param channel 视频通道
546 * @param stream 码流: 0-主; 1-辅
547 * @note 本接口拟用于画中画设备. \n
548 * 当收到 @ref TCI_CMD_SET_PRIMARY_VIEW 命令时,设备可能希望云录像通道与实时画面一致,就可以调用此接口. \n
549 * 非此情形,用户可以通过App发送 @ref TCI_CMD_SET_CLOUD_VIDEO_QUALITY_REQ 来显式设置云录像通道和码流。这一命令在sdk内部处理, 不会回调给应用层.
550 */
551void TciSetCloudStream(int channel, int stream);
552
553/** 通用sdk工作选项设置接口.
554 * @param opt 选项名. @ref TCSYSOPTION
555 * @param pVal 传入选项值
556 * @return >=0:ok; <0:错误
557 */
558int TciSetSysOption(TCSYSOPTION opt, const void *pVal);
559
560/** 通用sdk工作选项获取接口.
561 * @param opt 选项名. @ref TCSYSOPTION
562 * @param pVal 返回选项的值
563 * @return >=0:ok; <0:错误
564 */
565int TciGetSysOption(TCSYSOPTION opt, void *pVal);
566
567/** 开启p2p功能,进入厂测状态.
568 * @param key_path key 文件路径
569 * @retval 0 ok
570 * @retval -1 failed
571 */
572int TciStartInTestMode(const char *key_path);
573
574/**@}*/ //name 核心API
575
576/** \name 上报事件/状态/其它数据到平台
577 * @{*/
578/** 上报事件。本版本允许附带事件特定参数.
579 * @param evtp 事件参数指针
580 * @return 0:事件已经排队等待发送; non-zeor:错误码
581 * @note 本操作是异步的,返回0后要求evtp->jpg_pic仍然有效。 \n
582 * 如果evtp->evtp_flags 最低位非0, 上传结束后sdk会释放空间. \n
583 * evtp->evtp_flags最低位为0,用于jpg_pic为全局空间的情形. \n
584 * 返回非0时,调用者要自己释放图片空间.
585 */
587
588/** 停止事件, 仅少数事件才有意义.
589 * @param evt ECEVENT_DOORBELL 为取消呼叫.
590 * @note 取消呼叫时, sdk内部自动取呼叫的时间
591 */
593
594/** 门锁事件上报。图片和录像都在内部处理了.
595 * 参数见外部文档
596 */
597int TciSetLockEvent(int cls, int msg, int usrtyp, int usrid);
598
599/** 包装了门铃事件 */
601
602/** @deprecated
603 * 上报4G设备信息. 请使用 TciReport4GInfoEx()
604 * @param imei
605 * @param iccid
606 * @param state G4STATE_xxx
607 * @return 0:成功; <0:错误码
608 */
609int TciReport4GInfo(const char *imei, const char *iccid, ECG4STATE state);
610
611/** 上报4G设备信息,代替 TciReport4GInfo()
612 * @param info 指向4G信息结构
613 * @param state 4G联网状态
614 * @return 0:成功; <0:错误码
615 */
616int TciReport4GInfoEx(const TG4GINFO *info, ECG4STATE state);
617
618/** 上报GPS信息
619 * @param time 当前时间
620 * @param longitude 当前经度值(单位:度). >0 东经,<0 西经
621 * @param latitude 当前纬度值(单位:度). >0 北纬,<0 南纬
622 * @param speed 速度 km/h
623 * @param angle 对正北方向的夹角: 0~359
624 * @param signal_strength 0:未知(忽略); 1:弱; 2:中; 3:强
625 * @return 0:ok; non-zero: error code
626*/
627int TciReportGpsInfo(const unsigned int time, const double longitude, const double latitude,
628 double speed, int angle , int signal_strength);
629
630/** 上报电池状态
631 * @param qoe 电池电量百分比(0~100); -1:未知
632 * @param qoe_low
633 * - 1: 电量低;
634 * - 0: 电量正常;
635 * - -1:未知
636 * @param charging 1-正在充电; 0-放电状态
637 * @return 0-成功; 非0-错误码
638 */
639int TciReportBatteryStatus(int qoe, int qoe_low, int charging);
640
641/** 报告系统运行时状态
642 @param state 状态名. @ref ENUMRTSTATE
643 * @param pData state 相关参数。具体见
644 */
645void TciSetRtState(ENUMRTSTATE state, void *pData);
646
647/** 发送用户自定义数据到第三方平台.
648 * 需要平台间对接
649 */
650int TciSendUserData(const unsigned char *data, int len);
651
652/**@}*/ //name 上报事件
653
654/** \name 发送音视频和消息
655 * 这个数据通过p2p通道传给App。或者,如果有服务,音视频会上传云端
656 * @{*/
657
658/** 发送p2p命令请求
659 * @param handle 连接句柄,由 TciSetCmdHandler()设置的回调被调用时会收到此句柄
660 * @param cmd 命令标识
661 * @param data 指向命令参数
662 * @param dataSize 参数长度
663 * @return 0 或 \ref error_code "错误码"
664 */
665int TciSendCmd(p2phandle_t handle, unsigned int cmd, const void *data, int dataSize);
666
667/** 发送p2p命令应答
668 * @param handle 连接句柄,由 TciSetCmdHandler()设置的回调被调用时会收到此句柄
669 * @param cmd 命令标识
670 * @param data 指向命令参数
671 * @param dataSize 参数长度
672 * @return 0 或 \ref error_code "错误码"
673 */
674int TciSendCmdResp(p2phandle_t handle, unsigned int cmd, const void *data, int dataSize);
675
676/** 发送一个 Tcis_ErrorResp 结构作应答.
677 * 这个应答用于只需要简单地通知客户端命令执行成功或失败的情形.
678 * @param handle P2P句柄
679 * @param cmd 命令标识
680 * @param status @ref TCI_OK 或 TCI_E_xxx, 参见 @ref generic_err_code "通用错误码"
681 * @return 0 或 \ref error_code "错误码"
682 */
683int TciSendCmdRespStatus(p2phandle_t handle, unsigned int cmd, unsigned int status);
684
685/** 回放时发送数据帧.
686 * @param handle 连接句柄
687 * @param id_mt 低16位:媒体数据类型 @ref TCMEDIA ; 高16位:视频通道号(0~N-1)
688 * @param frame 帧数据指针
689 * @param len 帧数据长度
690 * @param timestamp 帧的时间戳
691 * @param uFrameFlags 视频:关键帧标志(1:关键帧;0:非关键帧); 音频: @ref audio_sample_fmt "音频采样格式"
692 * @retval >0 ok
693 * @retval 0 当前为回放暂停状态。
694 * @retval TCE_NETWORK_BUSY @ref TCE_NETWORK_BUSY :网络拥堵,应用层要延迟一会儿(例如300ms)后重新发送
695 * @retval -1 其它错误,通常意味着连接无效
696 * @note 每次设备在文件内或文件间重新定位, 或者自动跳到下一个文件,要通过 TciSendPbSyncFrame 先发一个绝对时间同步帧.
697 *
698 * @see TciSendPbSyncFrame
699 */
700int TciSendPbFrame(p2phandle_t handle, uint32_t id_mt, const uint8_t *frame, int len, uint32_t timestamp, int uFrameFlags);
701
702/** 在回放流中插入消息.
703 * @param handle p2p连接句柄。
704 * @param type 消息类型
705 * @param data1 @ref RTMSGHEAD_t::data1
706 * @param data2 @ref RTMSGHEAD_t::data2
707 * @param data_len 额外数据长度 @ref RTMSGHEAD_t::frame_size
708 * @param data 指向额外数据
709 */
710int TciSendPbMessage(p2phandle_t handle, RTMTYPE type, unsigned int data1, unsigned int data2, const void *data, int data_len);
711
712/** \def TciSendPbSyncFrame
713 * 发送回放时间同步帧.
714 * @param handle p2p 连接句柄
715 * @param utc_time 下一帧的生成时间(utc, 单位s)
716 * @param is_response_to_PLAY_START 1:响应 @ref TCI_CMD_RECORD_PLAYCONTROL; 0:自动跳到下一个文件
717 */
718#define TciSendPbSyncFrame(handle, utc_time, is_response_to_PLAY_START) TciSendPbMessage(handle, is_response_to_PLAY_START?RTM_SYNCTIME_RESPONSE_TO_USER:RTM_SYNCTIME, 0, utc_time, NULL, 0)
719
720/** \def TciSendPbTimelapseFlag
721 * 发送缩时录像回放标志。在进入和退出时发送.
722 * @param handle p2p 连接句柄
723 * @param flag 1:进入缩时回放; 0:退出缩时回放
724 */
725#define TciSendPbTimelapseFlag(handle, flag) TciSendPbMessage(handle, RTM_TIME_LAPSED, flag, 0, NULL, 0)
726
727/** \def TciSendPbEndOfEvent
728 * 在事件回放结束时发送此标志通知App.
729 */
730#define TciSendPbEndOfEvent(handle) TciSendPbMessage(handle, RTM_END_OF_EVENT, 0, 0, NULL, 0)
731
732
733/** 发送实时音视频帧, SDK内部会将数据分发到云端和APP.
734 * @param channel 视频通道号: 0|1|...
735 * @param stream 视频码流. 0: 高清; 1: 标清
736 * @param mt 媒体类型 @ref TCMEDIA
737 * @param pFrame 指向数据帧。视频要带4个前导字节 00 00 00 01
738 * @param length 数据帧长度
739 * @param ts timestamp. 单位为ms
740 * @param uFrameFlags 帧标志(低16位)
741 * - 视频: 0或 @ref video_frame_flags "FF_KEYFRAME/FF_TIMELAPSE/..." 的组合
742 * - 音频: @ref audio_sample_fmt "音频采样格式" (0(默认)或2: 8k16bmono; 10:16k16bmono)
743 *
744 * @note 该操作不会阻塞调用。如果没有消费者(没有云服务,没有人访问),实际不会做任何事情
745 */
746int TciSendFrameEx(int channel, int stream, TCMEDIA mt, const uint8_t *pFrame, int length, uint32_t ts, int uFrameFlags);
747
748/* @deprecated */
749//#define TciSendFrame(stream_, mt, pFrame, length, ts, uFrameFlags) TciSendFrameEx(0, stream_, mt, pFrame, length, ts, uFrameFlags)
750
751/** 发送实时流消息.
752 * @param channel 通道。为-1时在全部通道上发送
753 * @param stream 码流。为-1时在全部码流上发送
754 * @param type 消息类型. 参见 @ref RTMTYPE
755 * @param data1 消息相关数据
756 * @param data2 消息相关数据
757 * @param data_len 额外数据长度 @ref RTMSGHEAD_t::frame_size
758 * @param data 指向额外数据
759 */
760int TciSendLiveMessage(int channel, int stream, RTMTYPE type, unsigned int data1, unsigned int data2, const void *data, int data_len);
761
762/** \def TciSendLiveMsg_ReachPsp
763 * 发送预置位到位通知. */
764#define TciSendLiveMsg_ReachPsp(channel, psp_num) TciSendLiveMessage(channel, -1, RTM_REACH_PSP, channel, psp_num, NULL, 0)
765
766/** \def TciSendLiveMsg_LensSwitch
767 * 多目摄像机镜头切换时发送的标志帧, 要求在新镜头的第一帧前发送. */
768#define TciSendLiveMsg_LensSwitch(channel, stream) TciSendLiveMessage(channel, stream, RTM_LENS_SWITCH, channel, stream, NULL, 0)
769
770/** @deprecated
771 * \def TciSendLensSwitchFlag
772 * 发送镜头切换通知, 旧的名字. */
773#define TciSendLensSwitchFlag(channel, stream) TciSendLiveMsg_LensSwitch(channel, stream)
774
775/** 在命令通道上发送通知.
776 * @param handle 指定连接。如果为NULL,则发广播.
777 * @param type 消息类型
778 * @param type 消息类型. 参见 @ref RTMTYPE
779 * @param data1 消息相关数据
780 * @param data2 消息相关数据
781 * @param extra_data 指向额外数据, 可以为NULL
782 * @param extra_len 额外数据长度
783 */
784int TciSendRtMsg(p2phandle_t handle, RTMTYPE type, unsigned int data1, unsigned data2, const void *extra_data, int extra_len);
785
786/**@}*/ //name 发送数据
787
788
789/** @name 配网和注册
790 * @{*/
791
792/** 开始配置WIFI.
793 * 支持AP热点或设备扫描手机上的二维码的方式配置WIFI. AP热点名称为 \"<b>AICAM_</b><I>uuid</I>\" 的形式. \n
794 * 该调用会一直阻塞直到获得了正确的wifi配置.
795 * \param mode 配网方式. @ref GWM_QRCODE, @ref GWM_AP 的组合。
796 */
797int TciConfigWifi(int mode);
798
799/** 在sdk外部扫二维码. 调用此接口验证
800 * @return 有效时返回SA_TRUE, 否则返回 SA_FALSE
801 */
802int TciCheckRegString(const char *s);
803
804/** 中止配网.
805 * \param mode 要中止的配网方式. @ref GWM_QRCODE: 只中止qrcode; @ref GWM_AP 会中止全部配网方式。
806 */
807int TciStopConfigWifi(int mode);
808
809/** 保存wifi注册信息.
810 * 用于wifi模块从AP模式切换到STA模式必须重启的情形。 \n
811 * @return 要保存的数据的地址。 *len 为要保存的数据的长度
812 *
813 * @note 在 TciConfigWifi()返回后调用 TciGetRegisterConfiguration() 操作并且保存返回的数据。\n
814 * 重启后不调用 TciConfigWifi(), 而是用保存的内容调用 TciSetRegisterConfiguration()。
815 * 然后执行 TciStart() 完成注册过程。
816 */
817const void *TciGetRegisterConfiguration(int *len);
818
819/** 恢复wifi注册信息.
820 * \return 非0表示成功
821 */
822SA_BOOL TciSetRegisterConfiguration(const void *data, int len);
823
824/** @deprecated 设置p2p信息.
825 * @param sss 从平台获取的p2p信息字符串
826 * @return 0:ok; -1:内容错误
827 * @note 在 TciStart()前调用
828 */
829int TciSetP2pInfo(const char *sss);
830
831/** 处理从蓝牙收到的注册数据
832 * @param data 命令0x8006的数据
833 * @note 参看《蓝牙的应用层协议.md》文档
834 * */
835int TciProcessRegInfo(const void *data);
836
837/** 手动处理注册信息
838 * @param s 另一台设备通过 STATUS_GOT_REGINFO 获取到的注册信息
839 */
840int TciSetRegInfo(const char *s);
841
842/**@}*/ //name 配网和注册
843
844
845/** @name 低功耗相关
846 * @{*/
847/** 预分配云存储帧缓存空间.
848 * 本功能用于对上传时间敏感的事件唤醒类设备录像。
849 * 可以在网络初始化前就调用本接口,之后调用 TciSendFrameEx()就会向缓冲写入帧。
850 * 设备TciStart()成功后调用TciSetEventEx(),已经缓存的帧得以上传。
851 *
852 * 不调用本接口,TciStart()内部会在设备注册成功后执行同样功能.
853 *
854 * \param uCloudBuffSize 云存储缓冲区大小(单位:字节),最小1M
855 *
856 * @return 内存不足时返回-1, 否则返回0
857 *
858 * @note TciStart()会通过回调修改系统时间,设备要保证 TciStart()前后帧的时间戳时连续的。 \n
859 * * 要在 TciInit() 之后调用
860 * * 要在调用前从RTC恢复系统时间和设置时区
861 */
862int TciAllocCloudBuffer(unsigned int uCloudBuffSize);
863
864/** 等待录像缓冲区中的所有数据被消耗掉.
865 * @note 本功能用在缩时录像时缓存周期结束时通知sdk结束打包并立即上传. \n
866 * 操作会阻塞直到打包上传完成. 操作期间不要向sdk送入新的帧.
867 */
869
870/** 告诉SDK下一个视频关键帧的实际发生时间(UTC).
871 * @param channel/stream 云存的通道和码流
872 * @param t 下一个关键帧的发生时间
873 * @note 默认情况下SDK以调用 TciSendFrameEx()时的时间作为帧的产生时间, 这个时间用于确定云 \n
874 * 存储的开始时间和回放定位.
875 * 当应用层存在缓存行为(帧在时间 T0 时产生, 但在n秒后的 T0+n 时发送), 需要调用本接口 \n
876 * 告诉SDK传入的时间(T0)才是帧的实际发生时间。\n
877 * 调用本接口后,下一次事件时间如果等于或早于T0, 录像从缓冲区中的第一帧开始; 否则执行 \n
878 * 普通的5秒预录。\n
879 * 这种情形一般发生在低功耗设备.
880 */
881int TciSetKeyVideoTime(int channel, int stream, time_t t);
882
883/** 准备休眠
884 * 本api建立到唤醒服务器的tcp连接,并且返回连接数.
885 * 调用者对返回的socket调用getpeername()/getsockname()取得与唤醒服务器的连接信息,
886 * 并使用此信息配置wifi模组,然后对主芯片下电。在模组里每50\"向唤醒
887 * 服务器发送64字节的心跳包,包内容任意。
888 *
889 * 注意: 设备如果要进入休眠,应用层不能关闭返回的socket.
890 *
891 * @param socks 接收连接socket
892 * @param size socks数组大小
893 * @retval >=0 number of sockets connected to wakeup-servers
894 * @retval <0 failed
895 */
896int TciPrepareHiberation(int *socks, int size);
897
898/** 获取唤醒服务器ip地址
899 * @param servers 接收服务器地址。最多返回3个地址
900 * @return 服务器个数
901 */
903
904/** 生成唤醒服务器登录命令.
905 * 本接口用于到唤醒服务器的tcp连接不由主机创建的情形.
906 *
907 * @param randKey 服务器生成的随机串
908 * @param len_of_authstring 登录命令长度
909 * @return 登录字节串指针。如果失败返回 NULL
910 *
911 * @note 应用要按以下步骤建立到唤醒服务器的有效连接:
912 * 1. 应用调用 TciGetWakeupServers() 获取唤醒服务器的地址
913 * 2. 通信模块建立到唤醒服务器的连接, 接收由服务器返回的randkey
914 * 3. 应用使用此randkey调用本接口
915 * 4. 通信模块向服务器发送本接口生成的认证字符串
916 * 6. 主控下电. 通信模块每50\"向服务器发送64字节的心跳包,包内容任意。
917 */
918const uint8_t *TciPrepareAuthString(const char *randKey, int *len_of_authstring);
919
920/** 设置低功耗设备的工作模式.
921 *
922 * @note 需要在TciStart()之后调用. 调用逻辑一定参看文档 @ref a21_ManuallyPowerManagement
923 */
925
926/** 从NETDOWN模式下恢复网络后,调用本api使p2p快速上线 */
928
929/** 设置低功耗设备唤醒原因, 设备进入休眠时会上报给服务器.
930 * @param t_wakeup 唤醒时间
931 * @param r <0:异常唤醒; 0:远程唤醒; >0:唤醒事件类型(ECEVENT)
932 * @param user_reason 当r=ECEVENT_USER_DEFINED, user_reason为用户定义的唤醒理由字符串,长度不超过15个字符. \n
933 * 其它情形下传NULL
934 * @param sig_lvl wifi或4G信号强度: 0~100. 传负数时由用户自己解释
935 * @param sdc_rec SD卡录像长度
936 * @note 要在 STATUS_IDLE 返回0的时候调用,因为随此上报的还有别的信息。
937 */
938void TciSetWakeupReason(time_t t_wakeup, int r, const char *user_reason, int sig_lvl, int sdc_rec);
939
940
941/** 设备端准备强制休眠.
942 * 本操作会先通知实时用户(app端收到通知后要停止视频),然后停止云上传、退出p2p、断开长连接等. \n
943 * 返回后设备可以立即下电。
944 * @param bDiscardFilesInQueue 是否放弃上传队列中未处理的文件. \n
945 * 如果为 SA_FALSE, 会尝试上传队列中的所有文件. \n
946 * 建议在开启了后备存储并且存储路径有效时 SA_TRUE,这样在网络不好,队列中文件多时可以加速返回. \n
947 * 其它情况下的设置由应用自行载定.
948 */
949int TciForceSleeping(SA_BOOL bDiscardFilesInQueue);
950/**@}*/
951
952/** @name 云存储自动补录
953 * @{*/
954/** 设置云存储后备存储目录和缓存策略.
955 * 当设置后备存储目录后,SDK会利用此目录暂存上传失败的录像和图片,
956 * 并在合适的时机重传. \n
957 * 本功能要在 TciStart() 前调用
958 * @param sd_path 用于后备存储的目录
959 * @param buffer_hint 内存缓存策略.
960 * @retval 0
961 * @note 缓存策略影响用于云存储的内存大小。参看 @ref ECBUFFERHINT 的说明
962 */
963int TciSetBackStore(const char *sd_path, ECBUFFERHINT buffer_hint);
964
965/** 允许或禁止后备上传.
966 * @param en 1:enable; 0:disable
967 * @note 默认由sdk根据网络情况决定上传时间。如果应用层要临时禁止上传,可调用此接口
968 */
970
971/** 这个接口用于sd卡格式化前释放backstore, 和格式化后重新开启后备存储
972 * @param en 0-释放; 非0-重新打开
973 */
975/**@}*/
976
977
978/** @name 用户定义云上传
979 * @{*/
980/** 开始一个用户定义上传.
981 * 自定义上传主要用于sdk本身预录时间不足或不能录像,要从SD卡录像上传的情形. \n
982 * 必须在 TciStart() 成功后调用
983 *
984 * @param evt 事件类型. @ref ECEVENT (作为参数传入时要强传为 const char *型), 或长度小于16的字符串。 \n
985 * 目前仅支持行车记录仪的事件(@ref ECEVENT_DR_BEGIN ~ @ref ECEVENT_DR_END) \n
986 * 或者 TciCB::on_status(@ref STATUS_SDER, SDER *, ...) 回调的平台定义事件( SDER::event )
987 * @param tRecordStart 录像起始时间
988 * @param jpg_pic 图片数据(如果有的话)指针(SDK不会take图片缓冲区的所有权)
989 * @param pic_len 图片数据长度
990 * @return 如果允许上传,返回一个用户上传句柄。否则返回NULL
991 * @note 用户自定义上传只能是事件上传,长度限制在30秒内. \n
992 * 自定义上传的是事后发觉的事件,这个时候录像已经保存到sd卡了。\n
993 * 自定义上传的时间范围不能与TciSetEvent 的时间重叠,也不能与另一个自定义事件的时间范围重叠
994 */
995void *TciUduBegin2(const char *evt, time_t tRecordStart, const char *jpg_pic, int pic_len);
996#define TciUduBegin(evt, tRecordStart) TciUduBegin2(evt, tRecordStart, NULL, 0)
997
998/** 自定义上传过程,写入帧.
999 * @param hUdu TciUduBegin() 返回的上传句柄
1000 * @param mt 媒体类型. 参见 TciSendPbFrame() 的 id_mt 参数
1001 * @param ts 时间戳
1002 * @param pFrame 帧数据指针
1003 * @param size 帧数据大小
1004 * @param uFrameFlags 视频:关键帧标志(1:关键帧;0:非关键帧); 音频: @ref audio_sample_fmt "音频采样格式"
1005 * @return 0:ok; 非0:录像长度超限,用户要调用 TciUduEnd()
1006 */
1007int TciUduPutFrame(void *hUdu, TCMEDIA mt, uint32_t ts, const uint8_t *pFrame, int size, int uFrameFlags);
1008
1009/** 结束自定义上传
1010 * @param hUdu TciUduBegin() 返回的上传句柄
1011 */
1012void TciUduEnd(void *hUdu);
1013/**@}*///name 用户定义云上传
1014
1015/** 上报错误 */
1016int TciReportError(const char *name, const char *detail);
1017
1018/** 用于选择调试环境
1019 * @param env 1:测试环境; 0:正式环境
1020 * @note 在 TciStart() 之前调用
1021 */
1023
1024typedef void (*TCIONLIVEFRAMECB)(int channel, int stream, TCMEDIA mt, const uint8_t *pFrame, uint32_t size, uint32_t ts, int uFrameFlags);
1025void TciRegisterLiveFrameCB(TCIONLIVEFRAMECB cb);
1026void TciUnregisterLiveFrameCB(TCIONLIVEFRAMECB cb);
1027
1028/** 设置参数文件操作指针.
1029 * SDK会保存工作参数到flash. 小系统设备在flash上没有标准文件I/O支持时,需要提供载入和写参数的操作。本操作要在 TciInit() 之前调用 \n
1030 * linux和有文件系统的liteos不需要设置
1031 * @param ops 参数文件操作结构指针
1032 */
1034
1035/** 设置最大p2p连接数.
1036 * @param num 要设置的最大连接数
1037 * @return 最大连接数有效值
1038 * @note 只能在 TciStart()和TciConfigWifi()前调用
1039 */
1041
1042char *TciGetDeviceInfoString(void);
1043
1044/** \name 手动OTA&文件上传下载
1045 * @{*/
1046/** 下载升级包
1047 * @param subdev NULL或子设备id. 用于选择相应的固件
1048 * @return 0:ok; <0:error code
1049 */
1050int TciUpgradeOnTheAir(const char *subdev);
1051
1052
1053/** 查询升级包.
1054 * @param uuid
1055 * @param ota 返回升级包信息
1056 * @note 先要调用 TciStart()
1057 */
1058int TciQueryForOTA(const char *uuid, DEVICEOTAINFO *ota);
1059
1060/** 查询第三方升级包.
1061 * @param fw_id 第三方设备的 firmware id
1062 * @param fw_ver 第三方设备的当前版本号。版本号在平台上是以8位数字("01010101")的方式记录. \n
1063 * 如果第三方固件的版本有不同表示方式,需要在上传固件时自行维护一个映射关系.
1064 * @param ota 返回升级包信息
1065 * @return 0:查询成功, 是否有可用升级包看 *ota 内容; <0:错误码
1066 * @note 先要调用 TciStart()
1067 */
1068int TciQueryForOta2(const char *fw_id, const char *fw_ver, DEVICEOTAINFO *ota);
1069
1070/** 执行下载过程,会调用回调里的 ota 接口.
1071 * @return 0:下载完成; -1:没有设置回调; 其它<0:通信错误
1072 */
1074/**@}*/ //手动OTA
1075
1076
1077/** \name 下载用户文件
1078 * @{*/
1079/** 查询并下载用户文件.
1080 * @param name 文件上传到服务器端时确定的文件标识
1081 * @param bToFile 1:下载到文件; 0:下载到内存
1082 * @param dest 下载到文件时,设置 dest->file.path 为本地文件路径; 下载到内存时,内容在dest->mem中返回
1083 */
1084int TciGetUserFile(const char *name, SA_BOOL bToFile, union TgfDest *dest);
1085
1086/** 获取用户文件的下载地址.
1087 * @param name 文件上传到服务器端时确定的文件标识
1088 * @param flnk 成功时返回文件信息
1089 * @return 0:成功; 非0:错误码
1090 */
1091int TciQueryUserFile(const char *name, EcFileLink *flnk);
1092
1093/** 下载用户文件.
1094 * @param flink 用户文件信息
1095 * @param bToFile 1:下载到文件; 0:下载到内存
1096 * @param dest 下载到文件时,设置 dest->file.path 为本地文件路径; 下载到内存时,内容在dest->mem中返回
1097 * @param timeout 超时值。单位:秒
1098 * @return 0:成功; 非0:错误码
1099 */
1100int TciDownloadUserFile(const EcFileLink *flink, SA_BOOL bToFile, union TgfDest *dest, int timeout);
1101/**@}*/
1102
1103/** \name 日志上传工具
1104 * 以查询的方式上传日志,主要用于低功耗设备.
1105 * @{*/
1106/** 查询日志上传请求
1107 * @param uuid
1108 * @param model_id may be NULL
1109 * @param ppUrl 如果有请求,返回上传地址
1110 * @return 0:ok; none-zero: error code
1111 * @note 如果有请求,用返回的地址调用 TgPostMultiparts()
1112 */
1113int TgQueryUploadReq(const char* uuid, const char *model_id, char **ppUrl);
1114
1115/** 传日志文件
1116 * @param url TgQueryUploadReq() 返回的上传地址
1117 * @param uuid
1118 * @param path 本地文件名
1119 * @param timeout 超时值(ms)
1120 * @return 0:ok; otherwise error
1121 */
1122int TgPostLogFile(const char *url, const char *uuid, const char *path, int timeout);
1123
1124/** 上传内存中的日志
1125 * @param url TgQueryUploadReq() 返回的上传地址
1126 * @param uuid
1127 * @param mem 内存地址
1128 * @param size 数据长度
1129 * @param name 保存为文件名name
1130 * @param timeout 超时值(ms)
1131 * @return 0:ok; otherwise error
1132 */
1133int TgPostLogMem(const char *url, const char *uuid, const void *mem, int size, const char *name, int timeout);
1134
1135/**@}*/ //name 上传下载
1136
1137/** \name MCU配网api
1138 * 低功耗设备在MCU端进行配网.
1139 * @{*/
1140/** 获取设备属性字符串。调用者把该字符串传给MCU,用于在MCU端激活设备.
1141 * 调用者要 free() 返回的字符串.
1142 */
1144
1145/** 返回要同步到MCU的数据.
1146 \param pLen 用于返回数据长度.
1147 \return 要同步到MCU的数据缓冲区地址。调用者要负责释放(free())
1148 */
1149unsigned char *TciGetPlatConfig(int *pLen);
1150
1151/** 同步从MCU来的数据.
1152 \param pData 从MCU收到的同步数据
1153 \param len 数据长度
1154 \return 0:成功; <0:失败
1155 */
1156int TciSyncPlatConfig(const unsigned char *pData, int len);
1157/**@}*/// name register_in_mcu
1158
1159
1160/** \name 其它功能
1161 * @{*/
1162/** 设备上线后IP发生变化时通知SDK, 用于立即更新长连接 */
1164
1165typedef struct _IceConfig {
1166 char *ip;
1167 int port;
1168 char *username;
1169 char *password;
1170 int is_turn;
1171} ICECONFIG;
1172
1173/** 开启本地工作模式.
1174 * 该模式用于仅在局域网工作的设备. 有需要先要同我们联系.
1175 * @param url
1176 * @param cfg webrtc 服务配置数组
1177 * @param size 数组大小
1178 * @return 0:成功; <0:错误码
1179 * @note 函数内部会复制cfg信息, 返回后用户可以释放cfg引用或间接引用的空间
1180 */
1181int TciLocalStart(const char *url, const ICECONFIG *cfg, int size);
1182
1183/** 获取SDK内部状态.
1184 * @return 0 或 @ref sdk_state_flags "SDK状态标志" 的组合
1185 * @note 本函数只是用来告诉用户当前用什么事件在处理. \n
1186 * 不能用来代替 STATUS_IDLE 状态回调.
1187 */
1188unsigned int TciGetSdkState(void);
1189
1190
1191/** 设置用户定义低功耗设备的事件云录像时长.
1192 * @param erl 录像时长,可取值 -1/10/20/30. <=0时录像时长由sdk决定.
1193 * @note 非低功耗设备该设置无效. 在TciInit()后调用.
1194 * @return 0(ok) 或 TCI_E_NOT_ALLOWED
1195 */
1197/**@}*/ //misc
1198
1199/** \name 呼入处理
1200 * @{*/
1201/** 接听.
1202 * @param flavor 通话类型 @ref VIDEO_CALL 或 @ref VOICE_CALL
1203 * @return 0:成功; 非0为错误码。如果呼叫来自微信小程序, 错误码定义在 wx_err.h
1204 * @note flavor是对从@ref STATUS_INCALL2 收到的@ref INCALLINFO::flavor 的响应, \n
1205 * 不得高于请求的值. \n
1206 * 不要在回调中调用本接口。
1207 */
1209
1210/** 拒接.
1211 * @return 0:成功; 非0为错误码。如果呼叫来自微信小程序, 错误码定义在 wx_err.h
1212 */
1214
1215/** 挂断当前通话 */
1216int TciHangup(void);
1217/**@}*/ //name 呼入
1218
1219/**@}*/ //api_reference
1220
1221#ifdef __cplusplus
1222}
1223#endif
1224
1225#endif
P2p Commands and Structures
P2p Commands and Structures
ENUMRTSTATE
运行时状态
探鸽云SDK常数定义
ECALLFLAVOR
通话类型
常数和错误码定义
ECBUFFERHINT
云上传文件队列长度.
PMODE
低功耗设备的工作模式
ECEVENT
上报事件类型.
SIMCARDTYPE
sim 卡类型
RTMTYPE
插入到媒体流(实时或回放)或命令通道中的消息类型.
ECG4STATE
4G状态
ECSERVICETYPE
云服务类型
TCMEDIA
媒体类型枚举常数
ETRANSSERVICE
传输内容
TCSYSOPTION
SDK选项常数
@ PM_ALLON
常电模式。非低功耗设备的默认模式
@ PM_NETDOWN
主控正常工作,网络模块进入休眠模式
@ PM_SLEEPABLE
系统可休眠(会收到STATUS_IDLE状态回调。这是低功耗设备的默认模式)
@ SIMT_ESIM
ESIM
@ SIMT_VSIM
vsim卡
@ SIMT_PHY
物理卡
@ TCOPT_PRERECORD_LENGTH
事件云存预录时间长度, 单位:秒.
@ TCOPT_MAX_DATAFILE_SIZE
最大云存data文件。超出的帧会丢弃.
@ TCOPT_ONLY_REPORT_AI_EVENT
仅上报AI事件.
@ TCOPT_NO_STREAMING_WITHOUT_ACCEPTING_CALL
用户没有应答不能拉流.
@ TCOPT_TRANS_MEDIA_TYPE
传输内容 类型: int*:
@ TCOPT_DISABLE_UPLOAD_WHEN_VIEWING
有人观看时禁止上传 类型: int*
@ TCOPT_BUFFER_QUEUE_SIZE
云存储缓冲文件数.
@ TCOPT_BACKSTORE_SAVEDAYS
backstore 存储天数 类型 int*:
int TciCheckRegString(const char *s)
在sdk外部扫二维码.
int TciRejectInCall2()
拒接.
int TciSendCmdResp(p2phandle_t handle, unsigned int cmd, const void *data, int dataSize)
发送p2p命令应答
void TciBackStoreEnableUpload(int en)
允许或禁止后备上传.
int TciProcessRegInfo(const void *data)
处理从蓝牙收到的注册数据
unsigned int TciGetSdkState(void)
获取SDK内部状态.
int TciInit(const char *path, const char *uuid)
配置基本参数 在TciStart()之前调用
void * TciGetSessionUserData(p2phandle_t handle)
返回由TciSetSessionUserData()设置的应用私有数据指针
int TciGetUserFile(const char *name, SA_BOOL bToFile, union TgfDest *dest)
查询并下载用户文件.
int TciSetKeyVideoTime(int channel, int stream, time_t t)
告诉SDK下一个视频关键帧的实际发生时间(UTC).
const void * TciGetRegisterConfiguration(int *len)
保存wifi注册信息.
void TciBackStoreEnable(int en)
这个接口用于sd卡格式化前释放backstore, 和格式化后重新开启后备存储
int TciSetCallback(const struct TciCB *cb)
注册回调 – sdk内部事件
int TciSetLockEvent(int cls, int msg, int usrtyp, int usrid)
门锁事件上报。图片和录像都在内部处理了.
void TciSetSessionUserData(p2phandle_t handle, void *pUser)
绑定应用私有数据指针到p2p handle
int TciQueryForOta2(const char *fw_id, const char *fw_ver, DEVICEOTAINFO *ota)
查询第三方升级包.
int TciGetWakeupServers(Ipv4Addr servers[3])
获取唤醒服务器ip地址
void TciSetLogOption(int b_output_to_console, const char *log_path, int max_log_size)
控制日志输出.
void TciSelectEnvironment(int env)
用于选择调试环境
int TciStart(int isBound, unsigned int uCloudBuffSize)
启动服务
char * TciGetActivationAttrs(void)
获取设备属性字符串。调用者把该字符串传给MCU,用于在MCU端激活设备.
int TciReport4GInfo(const char *imei, const char *iccid, ECG4STATE state)
int TciSetMaxP2pClientsNum(int num)
设置最大p2p连接数.
int TciDownloadUserFile(const EcFileLink *flink, SA_BOOL bToFile, union TgfDest *dest, int timeout)
下载用户文件.
int TciPrepareHiberation(int *socks, int size)
准备休眠 本api建立到唤醒服务器的tcp连接,并且返回连接数.
void TciSetLogLevel(int level)
设置SDK日志输出等级.
int TciQueryForOTA(const char *uuid, DEVICEOTAINFO *ota)
查询升级包.
void TciSetPowerMode(PMODE mode)
设置低功耗设备的工作模式.
int TciReportBatteryStatus(int qoe, int qoe_low, int charging)
上报电池状态
int TciStopEvent(ECEVENT evt)
停止事件, 仅少数事件才有意义.
int TciSendPbMessage(p2phandle_t handle, RTMTYPE type, unsigned int data1, unsigned int data2, const void *data, int data_len)
在回放流中插入消息.
int TciStopConfigWifi(int mode)
中止配网.
int TciSetEventRecordLength(int erl)
设置用户定义低功耗设备的事件云录像时长.
int TciSendPbFrame(p2phandle_t handle, uint32_t id_mt, const uint8_t *frame, int len, uint32_t timestamp, int uFrameFlags)
回放时发送数据帧.
int TciGetSysOption(TCSYSOPTION opt, void *pVal)
通用sdk工作选项获取接口.
const uint8_t * TciPrepareAuthString(const char *randKey, int *len_of_authstring)
生成唤醒服务器登录命令.
int TciConfigWifi(int mode)
开始配置WIFI.
int TciSendLiveMessage(int channel, int stream, RTMTYPE type, unsigned int data1, unsigned int data2, const void *data, int data_len)
发送实时流消息.
int TciLocalStart(const char *url, const ICECONFIG *cfg, int size)
开启本地工作模式.
int TciUduPutFrame(void *hUdu, TCMEDIA mt, uint32_t ts, const uint8_t *pFrame, int size, int uFrameFlags)
自定义上传过程,写入帧.
int TciReport4GInfoEx(const TG4GINFO *info, ECG4STATE state)
上报4G设备信息,代替 TciReport4GInfo()
int TciSetSysOption(TCSYSOPTION opt, const void *pVal)
通用sdk工作选项设置接口.
int TciSetP2pInfo(const char *sss)
int TciStartInTestMode(const char *key_path)
开启p2p功能,进入厂测状态.
int TciUpgradeOnTheAir(const char *subdev)
下载升级包
int TciSendFrameEx(int channel, int stream, TCMEDIA mt, const uint8_t *pFrame, int length, uint32_t ts, int uFrameFlags)
发送实时音视频帧, SDK内部会将数据分发到云端和APP.
int TciSetEventEx(EVENTPARAM *evtp)
上报事件。本版本允许附带事件特定参数.
int TciForceSleeping(SA_BOOL bDiscardFilesInQueue)
设备端准备强制休眠.
void * TciUduBegin2(const char *evt, time_t tRecordStart, const char *jpg_pic, int pic_len)
开始一个用户定义上传.
int TciStart2(int isBound, unsigned int uCloudBuffSize, const char *uuid)
启动服务.
int TciSendUserData(const unsigned char *data, int len)
发送用户自定义数据到第三方平台.
void TciSetCloudStream(int channel, int stream)
设置云存储录像通道的码流
void TciSetRtState(ENUMRTSTATE state, void *pData)
报告系统运行时状态
void TciUduEnd(void *hUdu)
结束自定义上传
void TciSetParamFileOps(struct paramf_ops *ops)
设置参数文件操作指针.
unsigned char * TciGetPlatConfig(int *pLen)
返回要同步到MCU的数据.
int TciSendCmd(p2phandle_t handle, unsigned int cmd, const void *data, int dataSize)
发送p2p命令请求
int TciSetCmdHandler(const TGCMDHANDLER cb)
注册通用命令回调 在回调里处理APP发来的命令请求
int TciSetRegInfo(const char *s)
手动处理注册信息
int TciPerformOTA(DEVICEOTAINFO *ota)
执行下载过程,会调用回调里的 ota 接口.
int TgQueryUploadReq(const char *uuid, const char *model_id, char **ppUrl)
查询日志上传请求
int TciAllocCloudBuffer(unsigned int uCloudBuffSize)
预分配云存储帧缓存空间.
int TciSendRtMsg(p2phandle_t handle, RTMTYPE type, unsigned int data1, unsigned data2, const void *extra_data, int extra_len)
在命令通道上发送通知.
int TgPostLogFile(const char *url, const char *uuid, const char *path, int timeout)
传日志文件
int TciCleanup(void)
释放资源
const char * TciGetVersion(void)
获取SDK版本号 TciInit()之后调用
int TciSendCmdRespStatus(p2phandle_t handle, unsigned int cmd, unsigned int status)
发送一个 Tcis_ErrorResp 结构作应答.
int TciReportError(const char *name, const char *detail)
上报错误
void TcnIpChanged()
设备上线后IP发生变化时通知SDK, 用于立即更新长连接
int TciReportGpsInfo(const unsigned int time, const double longitude, const double latitude, double speed, int angle, int signal_strength)
上报GPS信息
int TgPostLogMem(const char *url, const char *uuid, const void *mem, int size, const char *name, int timeout)
上传内存中的日志
void TciFlushCsCache()
等待录像缓冲区中的所有数据被消耗掉.
void TciSetWakeupReason(time_t t_wakeup, int r, const char *user_reason, int sig_lvl, int sdc_rec)
设置低功耗设备唤醒原因, 设备进入休眠时会上报给服务器.
int TciStop(void)
停止服务
int TciSyncPlatConfig(const unsigned char *pData, int len)
同步从MCU来的数据.
int TciQueryUserFile(const char *name, EcFileLink *flnk)
获取用户文件的下载地址.
int TciHangup(void)
挂断当前通话
int TciSetDoorbellEvent()
包装了门铃事件
void TciFastRecoverP2p(void)
从NETDOWN模式下恢复网络后,调用本api使p2p快速上线
int TciAcceptInCall2(ECALLFLAVOR flavor)
接听.
SA_BOOL TciSetRegisterConfiguration(const void *data, int len)
恢复wifi注册信息.
int TciSetBackStore(const char *sd_path, ECBUFFERHINT buffer_hint)
设置云存储后备存储目录和缓存策略.
int(* on_ota_download_finished)(int status)
升级包下载结束
short id
用户(连接)标识
int(* snapshot)(int type, uint8_t **ppJpg, int *size)
抓取图片.
unsigned short port
port, network byte-order
char ver[16]
升级包版本
int size
升级包大小
void(* trans_stat)(const struct TransStatUser *_stat)
网络传输统计回调
int msStatInterval
统计周期(单位: ms)
int(* get_feature)(const char *key, char *buf, int size)
设备能力.
void(* on_talkback_stop)(void)
结束对讲
short vstream
码流
unsigned int ip
ip, network byte-order
int(* set_time)(time_t time)
设置时间
int(* qrcode_get_y_data)(uint8_t **ppYBuff, int *width, int *height)
获取Y图片
int(* request_iframe_ex)(int channel, int vstream)
请求指定图像通道的I帧
int nBytesInBuff
位于发送缓冲区的字节数
int(* on_talkback_start)(void)
开始对讲
int(* log)(int action, char *logfile)
在平台端采集设备日志
int(* qrcode_start)(void)
二维码扫描开始 应用层在此开启取Y数据的通道
int(* talkback)(TCMEDIA at, const uint8_t *audio, int len)
对讲数据回调 格式在前面已经协商过
int(* on_ota_download_start)(const char *new_version, unsigned int size)
OTA升级开始
int(* set_wifi)(int is_switching, const char *ssid, const char *key)
设置wifi参数
char firmware_ver[10]
固件主版本,8个数字组成的字符串。like: "03020201", means 3.2.2.1.
int(* on_status)(int event, const void *pData, int len)
sdk内部状态
char * path
IN: file path
char md5[36]
md5 检验字符串
void * mem
OUT: 指向sdk分配的内存
uint8_t * data
数据缓冲区指针
char url[256]
下载地址
void(* free_buff)(SIMPLEBUFFER *buff)
释放参数缓冲区
time_t expiration
过期时间(utc)
int size
OUT: 数据长度
int(* on_ota_download_data)(const uint8_t *buff, int size)
升级包数据 升级包下载过程中,sdk调用此回调将数据传给应用层
int len
数据长度
int nBytesSent
已经发送的字节数
char iccid[24]
sim卡号
short is_igop
1:统计间隔为一个I帧间隔; 0:周期约为~1s
SIMCARDTYPE sim_type
sim卡类型
int nBytesTotal
总共收到的字节数
char imei[24]
4g模块标识
int size
缓冲区大小
int(* get_state)(const char *key, char *buf, int size)
取设备当前状态或初始默认设置.
int(* request_iframe)(int vstream)
char vendor[16]
设备生产厂商 OEM
char device_type[16]
Not used
short vchannel
视频通道
int(* save_buff)(const SIMPLEBUFFER *buff)
写参数文件
ECSERVICETYPE serviceType
云服务类型
int(* set_timezone)(const char *tzs)
设置时区
void(* switch_quality)(int channel, int stream, const char *qstr)
切换图像质量
void(* remove)(void)
删除参数文件(或者清空参数文件)。下一次读出时 len为0
int(* alloc_and_readall)(SIMPLEBUFFER *buff, int cbExtra)
分配缓冲区,并读出参数文件.
void(* qrcode_end)(uint8_t *pYBuff)
结束二维码扫描
char firmware_id[32]
ota 升级用的固件标识, 平台唯一.
char model[32]
产品型号
void(* ai_result)(int type, const uint8_t *pJpg, int len)
当AI识别成功,通过本回调通知应用.
int(* on_apmode_login)(const char *user, const char *key)
直连模式下用户登录帐号检查
int(* get_info)(TCIDEVICEINFO *info)
获取设备基本信息
int nBytesThrow
丢掉的字节数。丢包会持续到到一个I帧,这期间即使网络恢复也会丢,所以其值只能作为参考, 不能用于计算网速
void * p2phandle_t
p2p连接句柄.
int(* TGCMDHANDLER)(p2phandle_t handle, int cmd, const void *data, int len)
命令回调类型
设备升级包信息
事件上报参数.
IPv4 地址表示(网络字节顺序)
Simple Buffer
设备基本信息
云服务信息
4G 设备信息
sdk 回调函数结构
数据下载到文件
数据下载到内存
P2P发送统计数据结构
参数文件读写函数据指针结构
用户文件下载目的地.