Example #1
0
//
// AT command handle
//
void at_command_handle(CStream *p_serial, CString &str) {
	str.makeUpper();

	// finds command with command list. and return the index of the command list, if found.
	switch( str.find(at_cmd_list, ATCMD_COUNT) ) {
	case 0: // set interval in millisecond.
		m_beacon.interval = str.parseInt(10);
		str = "OK\n";
		break;

	case 1: // get interval
		str.printf("%dms\n", m_beacon.interval);
		break;

	case 2: // set tx power
		m_beacon.tx_power =(BLE_TX_POWER_T) str.parseInt(9);
		str = "OK\n";
		break;

	case 3: // get tx power
		str.printf("%ddBm\n", m_beacon.tx_power);
		break;

	case 4:	// set company id
		m_beacon.company_id = str.parseHex(6);
		str = "OK\n";
		break;

	case 5:	// get company id
		str.printf("0x%04X\n", m_beacon.company_id);
		break;

	case 6:	// set major value
		msb_value_set(m_beacon.data.major, str.parseInt(7));
		str = "OK\n";
		break;

	case 7: // get major value
		str.printf("%d\n", msb_value_get(m_beacon.data.major));
		break;

	case 8: // set minor value
		msb_value_set(m_beacon.data.minor, str.parseInt(7));
		str = "OK\n";
		break;

	case 9:	// get minor value
		str.printf("%d\n", msb_value_get(m_beacon.data.minor));
		break;

	case 10:// set measure rssi
		m_beacon.data.meas_rssi = str.parseInt(6);
		str = "OK\n";
		break;

	case 11:// get measure rssi
		str.printf("%d\n", m_beacon.data.meas_rssi);
		break;

	case 12:// save
		m_p_sgBeacon->write(&m_beacon, sizeof(m_beacon));
		str = "OK\n";
		break;

	case 13:// reset
		system_reset();
		break;

	case 14:// goto DFU
		gotoDFU();
		break;

	default:// command not found
		str = "ERROR\n";
		break;
	}

	// response to stream
	p_serial->write(str.getBuffer(), str.length());
}
Example #2
0
void CChihlee::runAnalysis(const char *szInput, JSONObject &jsonResp)
{
	CFileHandler file;
	CString strWord = szInput;
	CResponsePacket respPacket;
	CString strText;
	CString strSound;
	CString strScreen;

	strWord.replace("笑訊", "校訓");
	strWord.replace("校去", "校訓");
	strWord.replace("治理", "致理");

	ofstream csWordFile("/chihlee/jetty/webapps/chihlee/Text.txt", ios::trunc);
	strText.format("%s\n          \n          ", szInput);
	csWordFile << strText.getBuffer() << endl;
	csWordFile.close();
	remove("/chihlee/jetty/webapps/chihlee/map.jpg");

	//=============== 校園導覽 =================================//
	if (0 <= strWord.find("導覽") || 0 <= strWord.find("地圖") || 0 <= strWord.find("參觀") || 0 <= strWord.find("校園"))
	{
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_1.wav";
		strScreen = "/chihlee/jetty/webapps/chihlee/img/map.jpg";
	}

	//=============== 廁所怎麼走 =================================//
	if (0 <= strWord.find("廁所") || 0 <= strWord.find("洗手間") || 0 <= strWord.find("大便") || 0 <= strWord.find("小便")
			|| 0 <= strWord.find("方便間"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/wc_map.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_2.wav";
	}

	//=============== 我想找電動輪椅充電 =================================//
	if (0 <= strWord.find("電動輪椅") || 0 <= strWord.find("輪椅充電") || 0 <= strWord.find("充電") || 0 <= strWord.find("沒電"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/wc_map.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_3.wav";
	}

	//=============== 圖書館怎麼走 =================================//
	if (0 <= strWord.find("圖書館") || 0 <= strWord.find("圖館") || 0 <= strWord.find("書館") || 0 <= strWord.find("看書"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/wc_map.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_4.wav";
	}

	//=============== 校訓 =================================//
	if (0 <= strWord.find("校訓") || 0 <= strWord.find("誠信") || 0 <= strWord.find("致理科大"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/motto.png";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_5.wav";
	}

	//=============== 吉祥物 =================================//
	if (0 <= strWord.find("吉祥物") || 0 <= strWord.find("喜鵲"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/character.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_6.wav";
	}

	//=============== 校歌 =================================//
	if (0 <= strWord.find("校歌") || 0 <= strWord.find("學生活動"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/song.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_7.wav";
	}

	//================ 謝謝你的解說=====================//
	if (0 <= strWord.find("謝謝") || 0 <= strWord.find("感謝") || 0 <= strWord.find("掰掰") || 0 <= strWord.find("拜拜")
			|| 0 <= strWord.find("謝啦") || 0 <= strWord.find("謝拉"))
	{
		remove("/chihlee/jetty/webapps/chihlee/map.jpg");
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_8.wav";
	}

	file.copyFile(strScreen.getBuffer(), "/chihlee/jetty/webapps/chihlee/map.jpg");
	playSound(strSound.getBuffer());

	respPacket.setActivity<int>("type", RESP_TTS).setActivity<const char*>("lang", "zh").setActivity<const char*>("tts",
			"").format(jsonResp);
}