updated iris-kit to 1.4.0 supportted remote study

This commit is contained in:
strawmanbobi
2024-11-22 15:25:31 +08:00
parent 03fa31a9c0
commit adf7f61e7d
7 changed files with 80 additions and 68 deletions

View File

@@ -27,6 +27,7 @@ build_flags =
-DLOG_DEBUG=1 -DLOG_DEBUG=1
-DLOG_INFO=1 -DLOG_INFO=1
-DLOG_ERROR=1 -DLOG_ERROR=1
-DSTORE_RECEIVED_IR_DATA=1
-I${common.workspace}/lib/irext/include -I${common.workspace}/lib/irext/include
[env:esp8266-1m-base] [env:esp8266-1m-base]

View File

@@ -35,7 +35,7 @@ StaticJsonDocument<512> mqtt_upstream_topic_msg_doc;
StaticJsonDocument<512> mqtt_upstream_topic_rsp_doc; StaticJsonDocument<512> mqtt_upstream_topic_rsp_doc;
// out unsolicited message // out unsolicited message
StaticJsonDocument<512> mqtt_upstream_topic_ind_doc; StaticJsonDocument<2048> mqtt_upstream_topic_ind_doc;
// out heartbeat message // out heartbeat message
StaticJsonDocument<512> mqtt_upstream_topic_hbt_doc; StaticJsonDocument<512> mqtt_upstream_topic_hbt_doc;

View File

@@ -33,7 +33,7 @@ extern StaticJsonDocument<1024> http_request_doc;
extern StaticJsonDocument<1024> http_response_doc; extern StaticJsonDocument<1024> http_response_doc;
extern StaticJsonDocument<512> mqtt_upstream_topic_msg_doc; extern StaticJsonDocument<512> mqtt_upstream_topic_msg_doc;
extern StaticJsonDocument<512> mqtt_upstream_topic_rsp_doc; extern StaticJsonDocument<512> mqtt_upstream_topic_rsp_doc;
extern StaticJsonDocument<512> mqtt_upstream_topic_ind_doc; extern StaticJsonDocument<2048> mqtt_upstream_topic_ind_doc;
extern StaticJsonDocument<512> mqtt_upstream_topic_hbt_doc; extern StaticJsonDocument<512> mqtt_upstream_topic_hbt_doc;
extern StaticJsonDocument<512> mqtt_downstream_topic_msg_doc; extern StaticJsonDocument<512> mqtt_downstream_topic_msg_doc;
extern StaticJsonDocument<512> status_notify_doc; extern StaticJsonDocument<512> status_notify_doc;

View File

@@ -172,7 +172,9 @@ void sendStatus(String file, t_remote_ac_status status) {
} }
void prepareStudyIR() { void prepareStudyIR() {
#if defined STORE_RECEIVED_IR_DATA
removeReceived(); removeReceived();
#endif
enableIRIn(); enableIRIn();
} }
@@ -183,19 +185,39 @@ void cancelStudyIR() {
int completeStudyIR(String &ir_data) { int completeStudyIR(String &ir_data) {
// called unsolicited // called unsolicited
disableIRIn(); disableIRIn();
return loadReceived(ir_data); #if defined STORE_RECEIVED_IR_DATA
loadReceived(ir_data);
#else
ir_data = g_recv_ir_code_str;
#endif
DEBUGF("loaded received code : %s\n", ir_data.c_str());
return ir_data.length();
} }
void recvIR() { void recvIR() {
int max_time_slice = 0;
int time_slice = 0;
if (ir_recv->decode(&g_recv_results)) { if (ir_recv->decode(&g_recv_results)) {
INFOF("Recv IR, raw length = %d\n", g_recv_results.rawlen - 1); INFOF("Recv IR, raw length = %d\n", g_recv_results.rawlen - 1);
String raw_data; g_recv_ir_code_str.clear();
for (int i = 1; i < g_recv_results.rawlen; i++) { for (int i = 1; i < g_recv_results.rawlen; i++) {
raw_data += String(*(g_recv_results.rawbuf + i) * kRawTick) + ","; time_slice = *(g_recv_results.rawbuf + i) * kRawTick;
if (time_slice > max_time_slice) {
max_time_slice = time_slice;
}
g_recv_ir_code_str += String(time_slice) + ",";
} }
g_recv_ir_code_str += String(3 * max_time_slice);
ir_recv->resume(); ir_recv->resume();
INFOLN(raw_data.c_str());
saveReceived(g_recv_results); DEBUGLN(g_recv_ir_code_str.c_str());
#if defined STORE_RECEIVED_IR_DATA
saveReceived(g_recv_ir_code_str);
#endif
processStatusChange(IRIS_KIT_STATUS_STUDIED, processStatusChange(IRIS_KIT_STATUS_STUDIED,
g_iris_kit_status.console_id, g_iris_kit_status.console_id,
g_iris_kit_status.remote_index, g_iris_kit_status.remote_index,
@@ -204,17 +226,14 @@ void recvIR() {
} }
} }
bool saveReceived(decode_results& results) { bool saveReceived(String& ir_data) {
String save_path = SAVE_PATH; String save_path = SAVE_PATH;
String file_name = ""; String file_name = "";
uint16_t max_time_slice = 0;
char time_slice[16] = { 0 };
if (g_iris_kit_status.remote_index.isEmpty()) { if (g_iris_kit_status.remote_index.isEmpty()) {
return false; return false;
} }
#if defined STORE_RECEIVED_TO_TMP_FILE
file_name = "ir_" + g_iris_kit_status.remote_index + RECEIVED_SUFFIX; file_name = "ir_" + g_iris_kit_status.remote_index + RECEIVED_SUFFIX;
save_path += file_name; save_path += file_name;
INFOF("Save received code to: %s\n", save_path.c_str()); INFOF("Save received code to: %s\n", save_path.c_str());
@@ -223,25 +242,9 @@ bool saveReceived(decode_results& results) {
ERRORF("Failed to create file\n"); ERRORF("Failed to create file\n");
return false; return false;
} }
#endif
for (size_t i = 0; i < results.rawlen; i++) { cache.write(ir_data.c_str(), ir_data.length());
memset(time_slice, 0, sizeof(time_slice));
if (*(results.rawbuf + i) > max_time_slice) {
max_time_slice = *(results.rawbuf + i);
}
snprintf(time_slice, 15, "%d", *(results.rawbuf + i));
g_recv_ir_code_str += String(time_slice) + ",";
}
// append tail code
max_time_slice = 2 * max_time_slice;
snprintf(time_slice, 15, "%d", max_time_slice);
g_recv_ir_code_str += String(time_slice);
#if defined STORE_RECEIVED_TO_TMP_FILE
cache.write(g_recv_ir_code_str.c_str(), g_recv_ir_code_str.length());
cache.close(); cache.close();
#endif
return true; return true;
} }
@@ -254,12 +257,10 @@ bool removeReceived() {
return false; return false;
} }
#if defined STORE_RECEIVED_TO_TMP_FILE
file_name = "ir_" + g_iris_kit_status.remote_index + RECEIVED_SUFFIX; file_name = "ir_" + g_iris_kit_status.remote_index + RECEIVED_SUFFIX;
save_path += file_name; save_path += file_name;
INFOF("Delete received code file: %s\n", save_path.c_str()); INFOF("Delete received code file: %s\n", save_path.c_str());
LittleFS.remove(save_path); LittleFS.remove(save_path);
#endif
return true; return true;
} }
@@ -272,10 +273,9 @@ int loadReceived(String &ir_data) {
return -1; return -1;
} }
#if defined STORE_RECEIVED_TO_TMP_FILE
file_name = "ir_" + g_iris_kit_status.remote_index + RECEIVED_SUFFIX; file_name = "ir_" + g_iris_kit_status.remote_index + RECEIVED_SUFFIX;
save_path += file_name; save_path += file_name;
INFOF("Load received code from: %s\n", save_path.c_str()); DEBUGF("Load received code from: %s\n", save_path.c_str());
File cache = LittleFS.open(save_path, "r"); File cache = LittleFS.open(save_path, "r");
if (!cache) { if (!cache) {
@@ -284,9 +284,8 @@ int loadReceived(String &ir_data) {
} }
ir_data = cache.readString(); ir_data = cache.readString();
cache.close(); cache.close();
#else
ir_data = g_recv_ir_code_str; DEBUGF("received code : %s\n", ir_data.c_str());
#endif
return ir_data.length(); return ir_data.length();
} }

View File

@@ -54,7 +54,7 @@ int completeStudyIR(String &ir_data);
void recvIR(); void recvIR();
bool saveReceived(decode_results &results); bool saveReceived(String &results);
bool removeReceived(); bool removeReceived();

View File

@@ -57,11 +57,12 @@ static String buildConnect();
static String buildHeartBeat(); static String buildHeartBeat();
static void buildGeneralResponse(String notify_name); static void buildGeneralResponse(String notify_name);
static void buildGeneralIndication(String notify_name); static void buildGeneralIndication(String notify_name);
static String buildTestResponse(); static String buildTestResponse(int console_id);
static String buildStudyPreparedResponse(); static String buildStudyPreparedResponse(int console_id, String remote_index, int key_id, String key_name);
static String buildStudyCompletedIndication(String ir_data); static String buildStudyCompletedIndication(String ir_data,
static String buildStudyErrorIndication(); int console_id, String remote_index, int key_id, String key_name);
static String buildStudyCancelledResponse(); static String buildStudyErrorIndication(int console_id, String remote_index, int key_id, String key_name);
static String buildStudyCancelledResponse(int console_id, String remote_index, int key_id, String key_name);
static int handleConnected(String product_key, String device_name, String content); static int handleConnected(String product_key, String device_name, String content);
static int handleHartBeat(String product_key, String device_name, String content); static int handleHartBeat(String product_key, String device_name, String content);
static int handleEmit(String product_key, String device_name, String content); static int handleEmit(String product_key, String device_name, String content);
@@ -249,7 +250,7 @@ int processStatusChange(int status, int console_id, String remote_index, int key
// enter into IR receive mode and send response // enter into IR receive mode and send response
updateIrisKitStatus(IRIS_KIT_STATUS_READY_TO_STUDY, console_id, remote_index, key_id, key_name); updateIrisKitStatus(IRIS_KIT_STATUS_READY_TO_STUDY, console_id, remote_index, key_id, key_name);
prepareStudyIR(); prepareStudyIR();
String recvPreparedResponseData = buildStudyPreparedResponse(); String recvPreparedResponseData = buildStudyPreparedResponse(console_id, remote_index, key_id, key_name);
sendData(g_upstream_topic.c_str(), (uint8_t*) recvPreparedResponseData.c_str(), recvPreparedResponseData.length()); sendData(g_upstream_topic.c_str(), (uint8_t*) recvPreparedResponseData.c_str(), recvPreparedResponseData.length());
break; break;
} }
@@ -260,9 +261,9 @@ int processStatusChange(int status, int console_id, String remote_index, int key
String ir_data = ""; String ir_data = "";
String studyCompletedIndicationData = ""; String studyCompletedIndicationData = "";
if (completeStudyIR(ir_data) > 0) { if (completeStudyIR(ir_data) > 0) {
studyCompletedIndicationData = buildStudyCompletedIndication(ir_data); studyCompletedIndicationData = buildStudyCompletedIndication(ir_data, console_id, remote_index, key_id, key_name);
} else { } else {
studyCompletedIndicationData = buildStudyErrorIndication(); studyCompletedIndicationData = buildStudyErrorIndication(console_id, remote_index, key_id, key_name);
} }
sendData(g_upstream_topic.c_str(), (uint8_t*) studyCompletedIndicationData.c_str(), studyCompletedIndicationData.length()); sendData(g_upstream_topic.c_str(), (uint8_t*) studyCompletedIndicationData.c_str(), studyCompletedIndicationData.length());
updateIrisKitStatus(IRIS_KIT_STATUS_UPLOADED, console_id, remote_index, key_id, key_name); updateIrisKitStatus(IRIS_KIT_STATUS_UPLOADED, console_id, remote_index, key_id, key_name);
@@ -272,7 +273,7 @@ int processStatusChange(int status, int console_id, String remote_index, int key
{ {
// cancel IR receiving and reset // cancel IR receiving and reset
cancelStudyIR(); cancelStudyIR();
String studyCancelledResponseData = buildStudyCancelledResponse(); String studyCancelledResponseData = buildStudyCancelledResponse(console_id, remote_index, key_id, key_name);
sendData(g_upstream_topic.c_str(), (uint8_t*) studyCancelledResponseData.c_str(), studyCancelledResponseData.length()); sendData(g_upstream_topic.c_str(), (uint8_t*) studyCancelledResponseData.c_str(), studyCancelledResponseData.length());
resetIrisKitStatus(); resetIrisKitStatus();
break; break;
@@ -281,7 +282,7 @@ int processStatusChange(int status, int console_id, String remote_index, int key
{ {
// send response for test notification // send response for test notification
updateIrisKitStatus(IRIS_KIT_STATUS_TEST, console_id, remote_index, key_id, key_name); updateIrisKitStatus(IRIS_KIT_STATUS_TEST, console_id, remote_index, key_id, key_name);
String testResponseData = buildTestResponse(); String testResponseData = buildTestResponse(console_id);
sendData(g_upstream_topic.c_str(), (uint8_t*) testResponseData.c_str(), testResponseData.length()); sendData(g_upstream_topic.c_str(), (uint8_t*) testResponseData.c_str(), testResponseData.length());
resetIrisKitStatus(); resetIrisKitStatus();
break; break;
@@ -342,64 +343,75 @@ static String buildHeartBeat() {
return heartBeatMessage; return heartBeatMessage;
} }
static void buildGeneralMessageBody(String notify_name, StaticJsonDocument<512> &json_doc) { static void buildGeneralResponse(String notify_name, StaticJsonDocument<512> &json_doc,
int console_id, String remote_index, int key_id, String key_name) {
json_doc.clear(); json_doc.clear();
json_doc["productKey"] = g_product_key; json_doc["productKey"] = g_product_key;
json_doc["deviceName"] = g_device_name; json_doc["deviceName"] = g_device_name;
json_doc["appId"] = g_app_id; json_doc["appId"] = g_app_id;
json_doc["consoleId"] = g_iris_kit_status.console_id; json_doc["consoleId"] = console_id;
json_doc["remoteIndex"] = g_iris_kit_status.remote_index; json_doc["remoteIndex"] = remote_index;
json_doc["keyId"] = g_iris_kit_status.key_id; json_doc["keyId"] = key_id;
json_doc["keyName"] = g_iris_kit_status.key_name; json_doc["keyName"] = key_name;
json_doc["resp"] = String(notify_name); json_doc["resp"] = String(notify_name);
}
static void buildGeneralResponse(String notify_name, StaticJsonDocument<512> &json_doc) {
buildGeneralMessageBody(notify_name, json_doc);
json_doc["eventName"] = String(EVENT_NOTIFY_RESP); json_doc["eventName"] = String(EVENT_NOTIFY_RESP);
} }
static void buildGeneralIndication(String notify_name, StaticJsonDocument<512> &json_doc) { static void buildGeneralIndication(String notify_name, StaticJsonDocument<2048> &json_doc,
buildGeneralMessageBody(notify_name, json_doc); int console_id, String remote_index, int key_id, String key_name) {
json_doc.clear();
json_doc["productKey"] = g_product_key;
json_doc["deviceName"] = g_device_name;
json_doc["appId"] = g_app_id;
json_doc["consoleId"] = console_id;
json_doc["remoteIndex"] = remote_index;
json_doc["keyId"] = key_id;
json_doc["keyName"] = key_name;
json_doc["resp"] = String(notify_name);
json_doc["eventName"] = String(EVENT_INDICATION); json_doc["eventName"] = String(EVENT_INDICATION);
} }
static String buildTestResponse() { static String buildTestResponse(int console_id) {
String testReponse = ""; String testReponse = "";
buildGeneralResponse(NOTIFY_RESP_TEST, mqtt_upstream_topic_rsp_doc); buildGeneralResponse(NOTIFY_RESP_TEST, mqtt_upstream_topic_rsp_doc, console_id, "", 0, "");
serializeJson(mqtt_upstream_topic_rsp_doc, testReponse); serializeJson(mqtt_upstream_topic_rsp_doc, testReponse);
return testReponse; return testReponse;
} }
static String buildStudyPreparedResponse() { static String buildStudyPreparedResponse(int console_id, String remote_index, int key_id, String key_name) {
String studyPreparedResponse = ""; String studyPreparedResponse = "";
buildGeneralResponse(NOTIFY_STUDY_PREPARED, mqtt_upstream_topic_rsp_doc); buildGeneralResponse(NOTIFY_STUDY_PREPARED, mqtt_upstream_topic_rsp_doc,
console_id, remote_index, key_id, key_name);
serializeJson(mqtt_upstream_topic_rsp_doc, studyPreparedResponse); serializeJson(mqtt_upstream_topic_rsp_doc, studyPreparedResponse);
return studyPreparedResponse; return studyPreparedResponse;
} }
static String buildStudyCompletedIndication(String ir_data) { static String buildStudyCompletedIndication(String ir_data,
int console_id, String remote_index, int key_id, String key_name) {
String studyCompletedIndication = ""; String studyCompletedIndication = "";
buildGeneralIndication(NOTIFY_STUDY_COMPLETED, mqtt_upstream_topic_ind_doc); buildGeneralIndication(NOTIFY_STUDY_COMPLETED, mqtt_upstream_topic_ind_doc,
console_id, remote_index, key_id, key_name);
mqtt_upstream_topic_ind_doc["payload"] = ir_data; mqtt_upstream_topic_ind_doc["payload"] = ir_data;
serializeJson(mqtt_upstream_topic_ind_doc, studyCompletedIndication); serializeJson(mqtt_upstream_topic_ind_doc, studyCompletedIndication);
return studyCompletedIndication; return studyCompletedIndication;
} }
static String buildStudyErrorIndication() { static String buildStudyErrorIndication(int console_id, String remote_index, int key_id, String key_name) {
String studyErrorIndication = ""; String studyErrorIndication = "";
buildGeneralIndication(NOTIFY_STUDY_ERROR, mqtt_upstream_topic_ind_doc); buildGeneralIndication(NOTIFY_STUDY_ERROR, mqtt_upstream_topic_ind_doc,
console_id, remote_index, key_id, key_name);
serializeJson(mqtt_upstream_topic_ind_doc, studyErrorIndication); serializeJson(mqtt_upstream_topic_ind_doc, studyErrorIndication);
return studyErrorIndication; return studyErrorIndication;
} }
static String buildStudyCancelledResponse() { static String buildStudyCancelledResponse(int console_id, String remote_index, int key_id, String key_name) {
String studyCancelledResponse = ""; String studyCancelledResponse = "";
buildGeneralResponse(NOTIFY_STUDY_CANCELLED, mqtt_upstream_topic_rsp_doc); buildGeneralResponse(NOTIFY_STUDY_CANCELLED, mqtt_upstream_topic_rsp_doc,
console_id, remote_index, key_id, key_name);
serializeJson(mqtt_upstream_topic_rsp_doc, studyCancelledResponse); serializeJson(mqtt_upstream_topic_rsp_doc, studyCancelledResponse);
return studyCancelledResponse; return studyCancelledResponse;

View File

@@ -100,7 +100,7 @@ void setup() {
INFOF("██║██╔══██╗██║╚════██║\n"); INFOF("██║██╔══██╗██║╚════██║\n");
INFOF("██║██║ ██║██║███████║\n"); INFOF("██║██║ ██║██║███████║\n");
INFOF("╚═╝╚═╝ ╚═╝╚═╝╚══════╝\n"); INFOF("╚═╝╚═╝ ╚═╝╚═╝╚══════╝\n");
INFOF("== IRIS Kit [1.3.1_r1] Powered by AliyunIoT ==\n"); INFOF("== IRIS Kit [1.4.0_r1] Powered by AliyunIoT ==\n");
// try loading saved iriskit settings // try loading saved iriskit settings
iriskit_settings.credential_token.clear(); iriskit_settings.credential_token.clear();