//////////////////////////////////////////////////////////////////////////////
// Includes
//////////////////////////////////////////////////////////////////////////////
-#include "autoconf.h"
+#include <stdint.h>
#include <stdio.h>
-#include "runtime.h"
-#include <stdlib.h>
-#include <math.h>
-#include "mphalport.h"
-#include "compile.h"
-#include "repl.h"
-#include "mperrno.h"
-#include "binary.h"
-
-#include <string.h>
-#if 0
+#include "obj.h"
+#include "runtime.h"
+#include "helios.h"
+#include "helios_debug.h"
+#include "helios_datacall.h"
+// #include "jc_prv.h"
+// #include "jc_aes.h"
+#if CONFIG_juphoon
+#include "jrtc.h"
+#include "jrtc0.h"
+#include "callbackdeal.h"
#include "helios_debug.h"
#include "autoconf.h"
//////////////////////////////////////////////////////////////////////////////
-#include "helios_extint.h"
-#include "jrtc.h"
+#define HELIOS_JRTC_LOG(msg, ...) custom_log("JRTC", msg, ##__VA_ARGS__)
+#define datacall_debug(fmt, ...) custom_log(APP, fmt, ##__VA_ARGS__)
+/** 通话错误值 */
-/* 定义juphoon_obj_t结构体 */
-typedef struct _juphoon_obj_t
+struct jrtc_t
{
- mp_obj_base_t base; //定义的对象结构体要包含该成员
-}juphoon_obj_t;
+ void* task; //必须放在头部
+ struct jrtc_t *next;
+ volatile unsigned char state, error;
+ char room[65], uid[65], vid[65], screen[65];
+ unsigned short srvIdx, gop, istats;//统计周期,默认5s
+ unsigned short video_cs_threshold;//卡顿阀值,默认300毫秒
+ unsigned short auto_req_slen;
+ struct AES_ctx *aes_ctx;
+ struct net_sock *tcpfd, *udpfd;
+ struct net_addr *udp_addr, *srv_addr;
+ unsigned char *recv_buf, *ared_buf, *vfec_buf;
+ unsigned short recv_off, ared_off;
+ unsigned hash, vfec_size, role, status;
+ struct jrtc_image_t *camera, *video;
+ unsigned audio_ssrc, video_ssrc;//local ssrc
+ unsigned char udp_fail_count;
+ char audio_pt, ared_pt;
+ char video_pt, vfec_pt;
+ unsigned short audio_seqno, video_seqno, vfec_seqno;
+ unsigned char audio_ptime;
+ unsigned char req_cam:2;
+ unsigned char req_batch:2;
+ unsigned char req_event:3;//1:status,2:role,3:video,4:index
+ unsigned char audio_received:1;
+ unsigned char video_started:1, audio_started:1, leave_called:1, video_changed:1;
+ unsigned char aenc_idx:2, adec_idx:2, venc_idx:2, vdec_idx:2;
+ char netst_pt, volu_pt;
+ signed char index;
+ unsigned char video_index;
+ unsigned char recv_types;//RECV_TYPE
+ unsigned recv_ms, send_ms, stats_ms, last_ms;
+ struct rtp_lostr_t* audio_lostR, *video_lostR;
+ struct rtp_stats_t* audio_stats, *video_stats;
+ unsigned recv_frame_count, recv_frame_ms;//fps
+ unsigned video_cs;//统计周期内(istats)卡顿毫秒数和
+ void (*effect_cb)(struct jrtc_photo_t* frame);
+ //发送请求处理
+ void* req_sem;
+ char req_id[65];
+ unsigned req_mask, req_value;
+};
+
+// enum jrtc_error err;
+int protect = 0;
-const mp_obj_type_t juphoon_type;
-juphoon_obj_t *single_juphoon = NULL;
+static struct jrtc_image_t send = {0};
+static struct jrtc_image_t recieve = {0};
-#define CONFIG_STR_LEN 40
-//void jrtc_config (const char* appkey, const char* uid, const char key[16], const char* tokens);
-STATIC mp_obj_t Juphoon_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
+
+/* 定义jrtc_obj_t结构体 */
+typedef struct _jrtc_obj_t
{
- mp_arg_check_num(n_args, n_kw, 0, 4, false); //检查参数个数
- if( single_juphoon == NULL ) {
- single_juphoon = m_new_obj_with_finaliser(juphoon_obj_t); //创建对象,分配空间
- }
- juphoon_obj_t *self = single_juphoon;
- self->base.type = &juphoon_type; //定义对象的类型
+ mp_obj_base_t base; //定义的对象结构体要包含该成员
+}jrtc_obj_t;
- int ret = 0;
+const mp_obj_type_t jrtc_type;
- char appkey[CONFIG_STR_LEN + 1] = {0}; /*appkey 当前APP特有的标识, 需向Juphoon申请获得*/
- char uid[CONFIG_STR_LEN + 1] = {0}; /*uid 账户*/
- char key[CONFIG_STR_LEN + 1] = {0}; /*key 通讯密钥, 必须与appkey匹配, 需向Juphoon申请或注册*/
- char tokens[CONFIG_STR_LEN + 1] = {0}; /*用于鉴权的tokens,默认为""*/
-
- switch(n_args){
- case 4:{
- mp_buffer_info_t tokens_info;
- mp_get_buffer_raise(args[3], &tokens_info, MP_BUFFER_READ);
- if( tokens_info.len > CONFIG_STR_LEN ) {
- juphoon_LOG("tokens length error");
- ret = -1;
- break;
- }
- memcpy(tokens, tokens_info.buf,tokens_info.len);
- juphoon_LOG("tokens = %s\n\r",tokens);
- //no break
- }
-
- case 3:{
- mp_buffer_info_t key_info;
- mp_get_buffer_raise(args[2], &key_info, MP_BUFFER_READ);
- if(key_info.len != 16 ) {
- juphoon_LOG("key length error\n\r");
- ret = -1;
- break;
- }
- memcpy(key, key_info.buf,key_info.len);
- juphoon_LOG(" key = %s\n\r",key);
- //no break;
- }
-
- case 2:{
- mp_buffer_info_t uid_info;
- mp_get_buffer_raise(args[1], &uid_info, MP_BUFFER_READ);
- if(uid_info.len == 0 || uid_info.len > CONFIG_STR_LEN) {
- juphoon_LOG("uid length error\n\r");
- ret = -1;
- break;
- }
- memcpy(uid,uid_info.buf,key_info.len);
- juphoon_LOG("uid = %s\n\r",uid);
- //no break
- }
-
- case 1:{
- mp_buffer_info_t appkey_info;
- mp_get_buffer_raise(args[0], &appkey_info, MP_BUFFER_READ);
- if(appkey_info.len == 0 || appkey_info.len > CONFIG_STR_LEN) {
- juphoon_LOG("appkey length error\n\r");
- ret = -1;
- break;
+/** 当前的版本号 */
+#define JRTC_VERTION "1.4.0"
+
+
+static Helios_MsgQ_t int_happen_q = 0;
+static Helios_Thread_t int_handle_task_id = 0;
+
+//mp_buffer_info_t roomid, ticket;
+static struct jrtc_t* test = NULL;
+int self_close_sta = 0;
+static c_callback_t *usr_callback = NULL;
+static c_callback_t cb = {0};
+
+char *ticket_temp = NULL;
+char *roomid_temp = NULL;
+
+
+void jrtc_handle(void * argv) {
+ uint8_t open_state = 0;
+ int ret = -1;
+ while (1) {
+ ret = Helios_MsgQ_Get(int_happen_q, (void *)&open_state, sizeof(uint8_t), HELIOS_WAIT_FOREVER);
+ if (ret != 0)
+ {
+ HELIOS_JRTC_LOG("interrupt handle thread failed to get queue\n");
+ continue;
+ }
+ if (open_state == 1) {
+ if (jrtc_state(test) == JRTC_CLOSED) {
+ //jrtc_open(roomid_temp, ticket_temp, &recieve, &send);
+ // mp_get_buffer_raise(args[ARG_roomid], &roomid, MP_BUFFER_READ);
+ // mp_get_buffer_raise(args[ARG_ticket], &ticket, MP_BUFFER_READ);
+ HELIOS_JRTC_LOG("105\n");
+ test = jrtc_open(roomid_temp, ticket_temp, &recieve, &send);
+ HELIOS_JRTC_LOG("107\n");
+ jrtc_activate(test, JRTC_AUDIO|JRTC_CAMERA);
+ // 等待对方视频对讲结束
+ while(jrtc_state(test) != JRTC_CLOSED)
+ {
+ Helios_msleep(1000);
+ }
+ if (self_close_sta == 0) {
+ // 判断是对方挂断,产生回调
+ st_CallBack_jrtc *jrtc_int = malloc(sizeof(st_CallBack_jrtc));
+ if(NULL != jrtc_int) {
+ jrtc_int->result = self_close_sta;
+ jrtc_int->callback = cb;
+ qpy_send_msg_to_callback_deal_thread(CALLBACK_TYPE_ID_JRTC, jrtc_int);
+ }
+ }
}
- memcpy(appkey, appkey_info.buf, appkey_info.len);
- juphoon_LOG("appkey = %s\n\r",appkey);
- break;
- }
-
- default:
- juphoon_LOG(" info error");
- ret = -1;
- break;
+ }
}
+}
- if(ret != 0){
- return mp_obj_new_int(ret);
- }
- juphoon_LOG("ret = %d\n\r",ret);
- //配置全局参数,只需调用一次.
- jrtc_config (appkey, uid, key, tokens);
- return MP_OBJ_FROM_PTR(self); //返回对象的指针
+// 注册回调函数
+STATIC mp_obj_t set_callback(const mp_obj_t handler)
+{
+ usr_callback = &cb;
+ mp_sched_schedule_callback_register(usr_callback, handler);
+
+ return mp_obj_new_int(1);
}
-struct jrtc_t* jrtc_open (const char* id, const char* ticket, struct jrtc_image_t* video, struct jrtc_image_t* camera);
-struct jrtc_image_t
-{/* 可强转为 jrtc_photo_t 使用 */
- void* data;
- unsigned bytes;
- unsigned short width, height;
- char format;/*< enum jrtc_dtype */
- char fps;
- unsigned short kbps;
- volatile char put, get;
- char reserve[2];
-};
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_set_callback_obj, set_callback);
-STATIC const mp_arg_t alipay_pay_config_args[] =
-{
- { MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL} },
- { MP_QSTR_ticket, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL} },
- { MP_QSTR_bind_interval, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
- { MP_QSTR_payment_interval, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
- { MP_QSTR_msg_task_priority, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
- { MP_QSTR_msg_task_stacksize, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
- { MP_QSTR_notifier_cb, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL} },
- { MP_QSTR_sync_mode, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
-};
-STATIC mp_obj_t juphoon_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
+STATIC mp_obj_t mp_jrtc_init(void) {
+ Helios_ThreadAttr attr = {0};
+ if (int_happen_q == 0) {
+ int_happen_q = Helios_MsgQ_Create(1, sizeof(uint8_t));
+ }
+ if(int_handle_task_id == 0)
+ {
+ attr.name = "jrtc_handle";
+ attr.stack_size = 1024*4;
+ attr.priority = 90;
+ attr.entry = jrtc_handle;
+
+ int_handle_task_id = Helios_Thread_Create(&attr);
+ if (0 == int_handle_task_id)
+ {
+ mp_raise_ValueError("create interrupt handle task failed\n");
+ }
+ }
+
+
+ return mp_obj_new_int(1);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_jrtc_init_obj, mp_jrtc_init);
+
+STATIC mp_obj_t mp_jrtc_config_server (mp_obj_t config_server)
{
- enum {ARG_bind_timeout, ARG_payment_timeout, ARG_bind_interval, ARG_payment_interval, ARG_msg_task_priority, ARG_msg_task_stacksize,
- ARG_notifier_cb, ARG_sync_mode,};
-
- mp_arg_val_t args[MP_ARRAY_SIZE(alipay_pay_config_args)];
- mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,MP_ARRAY_SIZE(alipay_pay_config_args), alipay_pay_config_args, args);
-
- ALIPAY_obj_t *self = (ALIPAY_obj_t *)MP_OBJ_TO_PTR(pos_args[0]);
+ char *config_s= (char*)mp_obj_str_get_str(config_server);
+ jrtc_config_server(config_s);
+
+ return mp_obj_new_int(1);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_jrtc_config_server_obj, mp_jrtc_config_server);
- helios_pay_config_t pay_config = {0};
+
+STATIC mp_obj_t mp_jrtc_config (size_t n_args, const mp_obj_t *args, mp_map_t *kw_args)
+{
int ret = 0;
+ static Helios_DataCallInfoStruct datacall_info = {0};
+ Helios_DataCall_GetInfo(1, 0, &datacall_info);
+ enum { ARG_appkey, ARG_uid, ARG_srvURL, ARG_key};
+ //jrtc_image_t temp_image_config = {0};
- pay_config.query_bind_result_timeout = args[ARG_bind_timeout].u_int;
- pay_config.query_payment_result_timeout = args[ARG_payment_timeout].u_int;
- pay_config.query_bind_result_interval = args[ARG_bind_interval].u_int;
- pay_config.query_payment_result_interval = args[ARG_payment_interval].u_int;
- pay_config.msg_task_priority = args[ARG_msg_task_priority].u_int;
- pay_config.msg_task_stacksize = args[ARG_msg_task_stacksize].u_int;
- if (args[ARG_notifier_cb].u_obj != mp_const_none) {
- static c_callback_t cb = {0};
- memset(&cb, 0, sizeof(c_callback_t));
- pay_init_callback = &cb;
- mp_sched_schedule_callback_register(pay_init_callback, args[ARG_notifier_cb].u_obj);
+ static const mp_arg_t allowed_args[] =
+ {
+ { MP_QSTR_appkey, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ { MP_QSTR_uid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ { MP_QSTR_srvURL, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ { MP_QSTR_key, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ };
+ mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args , args , kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals);
+ //mp_buffer_info_t appkey, uid, srvURL, key;
+ // mp_get_buffer_raise(args[ARG_appkey], &appkey, MP_BUFFER_READ);
+ // mp_get_buffer_raise(args[ARG_uid], &uid, MP_BUFFER_READ);
+ // mp_get_buffer_raise(args[ARG_srvURL], &srvURL, MP_BUFFER_READ);
+ // mp_get_buffer_raise(args[ARG_key], &key, MP_BUFFER_READ);
+
+ char *appkey_temp = (char *)mp_obj_str_get_str(vals[ARG_appkey].u_obj);
+ char *uid_temp = (char *)mp_obj_str_get_str(vals[ARG_uid].u_obj);
+ char *srvURL_temp = (char *)mp_obj_str_get_str(vals[ARG_srvURL].u_obj);
+ char *key_temp = (char *)mp_obj_str_get_str(vals[ARG_key].u_obj);
+ // char *appkey_temp = (char *)mp_obj_str_get_str(ARG_appkey);
+ // char *uid_temp = (char *)mp_obj_str_get_str(ARG_uid);
+ // char *srvURL_temp = (char *)mp_obj_str_get_str(ARG_srvURL);
+ // char *key_temp = (char *)mp_obj_str_get_str(ARG_key);
+ // jrtc_config(appkey_temp, uid_temp, srvURL_temp, key_temp);
+ //jrtc_config(appkey.buf, uid.buf, srvURL.buf, key.buf);
+
+ jrtc_config(appkey_temp, uid_temp, srvURL_temp, key_temp);
+ _jrtc_net_info = &datacall_info;
+ protect = 1;
+ ret = 1;
+ return mp_obj_new_int(ret);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mp_jrtc_config_obj, 4 ,mp_jrtc_config);
+
+
+STATIC mp_obj_t mp_jrtc_open (size_t n_args, const mp_obj_t *args, mp_map_t *kw_args)
+{
+ int ret = 0;
+ if(protect != 1){
+ HELIOS_JRTC_LOG("Not config\n");
+ ret = -1;
+ return mp_obj_new_int(-1);
}
- pay_config.notifier_cb = helios_callback_to_pay_init;
- pay_config.sync_mode = args[ARG_sync_mode].u_int;
+ enum { ARG_roomid, ARG_ticket, ARG_recieve, ARG_send};
+ static const mp_arg_t allowed_args[] =
+ {
+ { MP_QSTR_roomid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ { MP_QSTR_ticket, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ { MP_QSTR_recieve, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ { MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ };
+ mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args , args , kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals);
+ /*mp_get_buffer_raise(vals[ARG_roomid].u_obj, &roomid, MP_BUFFER_READ);
+ mp_get_buffer_raise(vals[ARG_ticket].u_obj, &ticket, MP_BUFFER_READ);*/
- MP_THREAD_GIL_EXIT();
- ret = Helios_upay_init(&pay_config);
- MP_THREAD_GIL_ENTER();
+ roomid_temp = (char *)mp_obj_str_get_str(vals[ARG_roomid].u_obj);
+ ticket_temp = (char *)mp_obj_str_get_str(vals[ARG_ticket].u_obj);
+ size_t len;
+ mp_obj_t *elem;
+ mp_obj_get_array(vals[ARG_send].u_obj, &len, &elem);
+ recieve.fps = mp_obj_get_int(elem[0]);
+ recieve.kbps = mp_obj_get_int(elem[1]);
+ recieve.width = mp_obj_get_int(elem[2]);
+ recieve.height= mp_obj_get_int(elem[3]);
+ mp_obj_get_array(vals[ARG_recieve].u_obj, &len, &elem);
+ send.fps = mp_obj_get_int(elem[0]);
+ send.kbps = mp_obj_get_int(elem[1]);
+ send.width = mp_obj_get_int(elem[2]);
+ send.height = mp_obj_get_int(elem[3]);
+
+ uint8_t int_happen = 1;
+ Helios_MsgQ_Put(int_happen_q, (const void *)&int_happen, sizeof(uint8_t), HELIOS_NO_WAIT);
+
+ // ret = jrtc_open(roomid_temp, ticket_temp, &recieve, &send);
+ // jrtc_activate(test, JRTC_AUDIO|JRTC_CAMERA);
return mp_obj_new_int(ret);
}
+STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mp_jrtc_open_obj, 4, mp_jrtc_open);
+
+
+STATIC mp_obj_t mp_jrtc_close (mp_obj_t err_j)
+{
+ int ret = 0;
+ HELIOS_JRTC_LOG("257");
+ int err = mp_obj_get_int(err_j);
+ if((err != 0) && (err != 1) && (err != 64) && (err != 71) && (err != 90) && (err != 104) &&
+ (err != 101) && (err != 111) && (err != 128) && (err != 129) && (err != 130) && (err != 131) &&
+ (err != 132) && (err != 133) && (err != 134) && (err != 135) && (err != 136) && (err != 137) &&
+ (err != 138) && (err != 252) && (err != 253) && (err != 254) &&(err != 255))
+ {
+ HELIOS_JRTC_LOG("err_j is invalid\n");
+ ret = -1;
+ return mp_obj_new_int(ret);
+ }
+ else {
+ //err = err_j;
+ if (test == NULL) {
+ mp_raise_ValueError("point fail\n");
+ }
+ MP_THREAD_GIL_EXIT();
+ jrtc_close(test, err);
+ MP_THREAD_GIL_ENTER();
+ test = NULL;
+ ret = 1;
+ self_close_sta = 1;
+ //Helios_DataCall_Stop(1, 0, 0);
+ return mp_obj_new_int(ret);
+ }
+
+}
+
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_jrtc_close_obj, mp_jrtc_close);
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_init_HX3918_obj, mp_HX3918_init);//初始化
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_deinit_HX3918_obj, mp_HX3918_deinit);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_activate_HX3918_obj, mp_activate_HX3918);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_blood_oxygen_obj, mp_HX3918_get_blood_oxygen);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_heart_obj, mp_HX3918_get_heart);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_blood_pressure_obj, mp_HX3918_get_blood_pressure);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_wear_obj, mp_HX3918_get_wear);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_open_heart_obj, mp_HX3918_open_heart);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_open_blood_oxygen_obj, mp_HX3918_open_blood_oxygen);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_open_hrv_obj, mp_HX3918_open_hrv);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_hrv_obj, mp_HX3918_get_hrv);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_all_data_obj, mp_HX3918_get_all_data);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_close_obj, mp_HX3918_close);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_set_sleep_obj, mp_HX3918_set_sleep);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_HX3918_open_test_obj, mp_HX3918_open_test);
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_HX3918_set_sar_obj, mp_HX3918_set_sar);
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_test_data_obj, mp_HX3918_get_test_data);//
-
-STATIC const mp_rom_map_elem_t HX3918_locals_dict_table[] = {
- { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&mp_init_HX3918_obj) },
- { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&mp_deinit_HX3918_obj) },
- { MP_ROM_QSTR(MP_QSTR_activate), MP_ROM_PTR(&mp_activate_HX3918_obj) },
- { MP_ROM_QSTR(MP_QSTR_get_blood_oxygen), MP_ROM_PTR(&mp_HX3918_get_blood_oxygen_obj)},
- { MP_ROM_QSTR(MP_QSTR_get_heart), MP_ROM_PTR(&mp_HX3918_get_heart_obj)},
- { MP_ROM_QSTR(MP_QSTR_get_blood_pressure), MP_ROM_PTR(&mp_HX3918_get_blood_pressure_obj)},
- { MP_ROM_QSTR(MP_QSTR_get_wear), MP_ROM_PTR(&mp_HX3918_get_wear_obj)},
- { MP_ROM_QSTR(MP_QSTR_open_heart), MP_ROM_PTR(&mp_HX3918_open_heart_obj)},
- { MP_ROM_QSTR(MP_QSTR_open_blood_oxygen), MP_ROM_PTR(&mp_HX3918_open_blood_oxygen_obj)},
- { MP_ROM_QSTR(MP_QSTR_open_hrv), MP_ROM_PTR(&mp_HX3918_open_hrv_obj)},
- { MP_ROM_QSTR(MP_QSTR_get_hrv), MP_ROM_PTR(&mp_HX3918_get_hrv_obj)},
- { MP_ROM_QSTR(MP_QSTR_get_all_data), MP_ROM_PTR(&mp_HX3918_get_all_data_obj)},
- { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_HX3918_close_obj)},
- { MP_ROM_QSTR(MP_QSTR_set_sleep), MP_ROM_PTR(&mp_HX3918_set_sleep_obj)},
- { MP_ROM_QSTR(MP_QSTR_open_test), MP_ROM_PTR(&mp_HX3918_open_test_obj)},
- { MP_ROM_QSTR(MP_QSTR_set_sar), MP_ROM_PTR(&mp_HX3918_set_sar_obj)},
- { MP_ROM_QSTR(MP_QSTR_get_test_data), MP_ROM_PTR(&mp_HX3918_get_test_data_obj)},
-};
-STATIC MP_DEFINE_CONST_DICT(HX3918_locals_dict, HX3918_locals_dict_table);
-const mp_obj_type_t Hsensor_HX3918_type = {
- { &mp_type_type },
- .name = MP_QSTR_HX3918,
- .make_new = HX3918_make_new,
- .locals_dict = (mp_obj_dict_t*)&HX3918_locals_dict,
+
+
+/* 定义的modjrtc本地字典 */
+STATIC const mp_rom_map_elem_t jrtc_globals_table[] = {
+ {MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jrtc)}, //这个对应python层面的__name__ 属性
+ {MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&mp_jrtc_config_obj)}, //新增的modtest_obj_func_withargs对象注册到modtest中
+ {MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_jrtc_open_obj)},
+ {MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_jrtc_close_obj)},
+ {MP_ROM_QSTR(MP_QSTR_set_callback), MP_ROM_PTR(&mp_set_callback_obj)},
+ {MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&mp_jrtc_init_obj)},
+ {MP_ROM_QSTR(MP_QSTR_config_server), MP_ROM_PTR(&mp_jrtc_config_server_obj)},
};
+/* 把modjrtc_globals_table注册到 mp_module_modjrtc_globals里面去 */
+//STATIC MP_DEFINE_CONST_DICT(jrtc_locals_dict, jrtc_locals_dict_table);
+STATIC MP_DEFINE_CONST_DICT(mp_module_jrtc_globals, jrtc_globals_table);
+
+/* 定义mp_obj_type_t类型的结构体;注意这里和定义module使用的类型是不一样的 */
+const mp_obj_module_t mp_module_jrtc = {
+ .base={ &mp_type_module },
+ //.name = MP_QSTR_jrtc, //type类的name属性是放在这里定义,而不是放在DICT中
+ //.make_new = can_mcp2515_make_new, //添加的make new属性
+ .globals = (mp_obj_dict_t*)&mp_module_jrtc_globals, //注册jrtc_locals_dict
+};
#endif
"""
// ic type: cst8xx
-// proj name: CSW_2309233_CST816D_COB_DWS_HY_LFY203G_C06_AKL_G3.hex
-// check sum: 0xcd16
-// create time: 2023/9/15 11:47:32
+// proj name: CSW_2311097_CST816D_COB_DWS_HY_HTY1384183CG_C06_AKL_G3.hex
+// check sum: 0xa796
+// create time: 2023/11/8 10:14:38
"""
app_bin_816d = [
-0x00, 0x00, 0x00, 0x3c, 0x16, 0xcd,
+0x00, 0x00, 0x00, 0x3c, 0x96, 0xa7,
0x02, 0x2b, 0x9a, 0x75, 0x91, 0xcc, 0x75, 0x91, 0x00, 0x32, 0x32, 0x22, 0x02, 0x00, 0x03, 0x02,
0x2e, 0xea, 0x74, 0xb7, 0x2f, 0xf5, 0x82, 0xe4, 0x34, 0x02, 0xf5, 0x83, 0xe0, 0xff, 0x22, 0x22,
0x00, 0x02, 0x32, 0x2b, 0xe4, 0x7b, 0x02, 0xfa, 0xf9, 0xf8, 0xaf, 0x00, 0xae, 0x00, 0xad, 0x00,
0x05, 0x0b, 0x28, 0xff, 0xff, 0xff, 0x78, 0x2e, 0x90, 0x01, 0x00, 0x08, 0x08, 0x85, 0x00, 0xc8,
0x00, 0x14, 0x02, 0x58, 0x09, 0x09, 0x85, 0x00, 0xc8, 0x00, 0x28, 0x02, 0x58, 0x0a, 0x02, 0x85,
0x00, 0xc8, 0x00, 0x3c, 0x02, 0x58, 0x0a, 0x02, 0x85, 0x00, 0xc8, 0x00, 0x3c, 0x02, 0x58, 0x05,
-0x00, 0xf0, 0x01, 0x1c, 0x00, 0x2d, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8,
+0x00, 0xf0, 0x01, 0x1c, 0x00, 0x1e, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8,
0x00, 0xfa, 0x00, 0xfa, 0x05, 0x01, 0x0a, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x9c,
0x00, 0x0a, 0x14, 0x02, 0x03, 0x07, 0x06, 0x00, 0xc8, 0x04, 0x00, 0x01, 0x08, 0x09, 0x00, 0xc8,
0x04, 0x02, 0x03, 0x07, 0x06, 0x00, 0xc8, 0x04, 0x02, 0x03, 0x07, 0x06, 0x00, 0xc8, 0x04, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0xb6, 0x02, 0x30, 0x92, 0x33, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xcd,
-
+0xb6, 0x02, 0x30, 0x92, 0x33, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0xa7,
]
self.hsensor.init()
self.hsensor.close()
try :
- self.hsensor.set_sar(1)
+ self.hsensor.set_sar(0)
except Exception as e:
print("Hsensor none set_sar:{}".format(e))
self.old_temp_time = 0
self.lpm_fd = pm.create_wakelock("test_lock", len("test_lock"))
pm.wakelock_lock(self.lpm_fd)
print("location_thread:1")
- EventMesh.publish(constants.EVENT.GPSOPEN)
+ # EventMesh.publish(constants.EVENT.GPSOPEN)
print("location_thread:2")
#self.timer_read_GPS_info.start(1000, 1, self.location_timer)
print("location_thread:3")
#print(self.location_timer_count)
GSV_dict= {}
- #检查GNSS数据
- if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
-
- pass
- tmp_ok_count = 0
- tmp_very_ok_count = 0
- gsv_data = quecgnss.get_gsv()
- rmc_data = quecgnss.get_rmc()
- gga_data = quecgnss.get_gga()
- vtg_data = quecgnss.get_vtg()
- # print("gsv:{}".format(quecgnss.get_gsv()))
- # print("gga:{}".format(quecgnss.get_gga()))
- # print("rmc:{}".format(quecgnss.get_rmc()))
- # print("vtg:{}".format(quecgnss.get_vtg()))
- for i in range(len(gsv_data)) :
+ # #检查GNSS数据
+ # if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
+
+ # pass
+ # tmp_ok_count = 0
+ # tmp_very_ok_count = 0
+ # gsv_data = quecgnss.get_gsv()
+ # rmc_data = quecgnss.get_rmc()
+ # gga_data = quecgnss.get_gga()
+ # vtg_data = quecgnss.get_vtg()
+ # # print("gsv:{}".format(quecgnss.get_gsv()))
+ # # print("gga:{}".format(quecgnss.get_gga()))
+ # # print("rmc:{}".format(quecgnss.get_rmc()))
+ # # print("vtg:{}".format(quecgnss.get_vtg()))
+ # for i in range(len(gsv_data)) :
- if i % 2 == 0:
- if i+1 >= len(gsv_data) :
- print("gsv_data num error!!")
- break
- GSV_dict[gsv_data[i]] = gsv_data[i+1]
- #print("type:gsv_data{}".format(type(gsv_data[i+1])))
- try:
- #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
- if gsv_data[i+1] :
- if (gsv_data[i+1])>=20:
- tmp_ok_count +=1
- if (gsv_data[i+1])>=30:
- tmp_very_ok_count +=1
+ # if i % 2 == 0:
+ # if i+1 >= len(gsv_data) :
+ # print("gsv_data num error!!")
+ # break
+ # GSV_dict[gsv_data[i]] = gsv_data[i+1]
+ # #print("type:gsv_data{}".format(type(gsv_data[i+1])))
+ # try:
+ # #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
+ # if gsv_data[i+1] :
+ # if (gsv_data[i+1])>=20:
+ # tmp_ok_count +=1
+ # if (gsv_data[i+1])>=30:
+ # tmp_very_ok_count +=1
- except Exception as e:
- usys.print_exception(e)
+ # except Exception as e:
+ # usys.print_exception(e)
- if(tmp_ok_count > self.GSV_sig_ok_count ):
- self.GSV_sig_ok_count = tmp_ok_count
- if(tmp_very_ok_count > self.GSV_sig_very_ok_count ):
- self.GSV_sig_very_ok_count = tmp_very_ok_count
- match_rmc_data = rmc_data.split(",")
- if len (match_rmc_data)>3: #有rmc数据
- if match_rmc_data[2] == 'A':
- match_gga_data = gga_data.split(",")
- if len(match_gga_data) >4: #数据全
- match_vtg_data = vtg_data.split(",")
- gps_date = "%s,%s"%(match_rmc_data[9],match_rmc_data[1][:6])#日期
- #gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
- latitude = "0,N" #纬度
- latitude_tmp = str(self.GxGGA_latitude(gga_data)).split(".")
- if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
- latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
- latitude = "%s,%s"%(latitude,match_rmc_data[4] )
-
- longitude = "0,E"#经度
- longitude_tmp = str(self.GxGGA_longitude(gga_data)).split(".")
- if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
- longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
- longitude = "%s,%s"%(longitude,match_rmc_data[6] ) #match_rmc_data[6] + str(gnss_r_data[1])
+ # if(tmp_ok_count > self.GSV_sig_ok_count ):
+ # self.GSV_sig_ok_count = tmp_ok_count
+ # if(tmp_very_ok_count > self.GSV_sig_very_ok_count ):
+ # self.GSV_sig_very_ok_count = tmp_very_ok_count
+ # match_rmc_data = rmc_data.split(",")
+ # if len (match_rmc_data)>3: #有rmc数据
+ # if match_rmc_data[2] == 'A':
+ # match_gga_data = gga_data.split(",")
+ # if len(match_gga_data) >4: #数据全
+ # match_vtg_data = vtg_data.split(",")
+ # gps_date = "%s,%s"%(match_rmc_data[9],match_rmc_data[1][:6])#日期
+ # #gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
+ # latitude = "0,N" #纬度
+ # latitude_tmp = str(self.GxGGA_latitude(gga_data)).split(".")
+ # if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
+ # latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
+ # latitude = "%s,%s"%(latitude,match_rmc_data[4] )
+
+ # longitude = "0,E"#经度
+ # longitude_tmp = str(self.GxGGA_longitude(gga_data)).split(".")
+ # if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
+ # longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
+ # longitude = "%s,%s"%(longitude,match_rmc_data[6] ) #match_rmc_data[6] + str(gnss_r_data[1])
- high = "0"#高度
- high = str(self.GxGGA_altitude(gga_data))
- number = "0"#可用卫星
- precision = "5.8"#精度
- if len(match_gga_data)>5 :
- if match_gga_data[7]:
- number = match_gga_data[7]
- if match_gga_data[8]:
- precision = match_gga_data[8]
- direction = "249.5" #方向
- speed = '0.00' #速度
- if(len(match_vtg_data)>5 ):
- if match_vtg_data[1]:
- direction = match_vtg_data[1]
- if match_vtg_data[7]:
- speed = match_vtg_data[7]
- self.gps_data = {
- "latitude": latitude,
- "longitude": longitude,
- "high": high,
- "direction": direction,
- "speed": speed,
- "number": number,
- "date": gps_date,
- "precision": precision
- }
+ # high = "0"#高度
+ # high = str(self.GxGGA_altitude(gga_data))
+ # number = "0"#可用卫星
+ # precision = "5.8"#精度
+ # if len(match_gga_data)>5 :
+ # if match_gga_data[7]:
+ # number = match_gga_data[7]
+ # if match_gga_data[8]:
+ # precision = match_gga_data[8]
+ # direction = "249.5" #方向
+ # speed = '0.00' #速度
+ # if(len(match_vtg_data)>5 ):
+ # if match_vtg_data[1]:
+ # direction = match_vtg_data[1]
+ # if match_vtg_data[7]:
+ # speed = match_vtg_data[7]
+ # self.gps_data = {
+ # "latitude": latitude,
+ # "longitude": longitude,
+ # "high": high,
+ # "direction": direction,
+ # "speed": speed,
+ # "number": number,
+ # "date": gps_date,
+ # "precision": precision
+ # }
# ***********************************************************************************
# self.location_timer_count = 0
# self.GSV_sig_ok_count = 0
-
- # if (self.GGA_count < 3 and self.GSV_sig_ok_count < 2) and self.wifi_data and self.cell_data and self.location_timer_count > 30 and self.location_timer_count < 40: #超过20秒且有效卫星个数少于3
- # EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- # EventMesh.txt_log("GGA_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
- # self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
-
- if self.GSV_sig_ok_count <= 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过40秒且信号大于30的不足3个
+
+ if self.wifi_data != [] and self.cell_data != [] : #
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+ # if self.GSV_sig_ok_count <= 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过40秒且信号大于30的不足3个
+ # EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ # EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
+ # self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
#break
# if self.location_type != 1 and self.location_timer_count >= 60*4 : #4分钟关闭
# EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位