Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of Inp_Fiber_Logo_FOTA by
Diff: main.cpp
- Revision:
- 10:867018503cd3
- Parent:
- 9:4363af5affba
- Child:
- 11:8301a86310c9
--- a/main.cpp Fri Jul 07 02:13:18 2017 +0000 +++ b/main.cpp Fri Jul 07 02:42:28 2017 +0000 @@ -1,3 +1,5 @@ +// 20170703 BRIGHTNESS_MAXを100に変更 +// シリアル通信のプロトコルを、文字列→バイト列に変更 // 20170619 DeviceInformationのSerialNumberにIND+Macアドレスを適用し、DEVICENAMEはINUPATHYとした // 20170617 ストレス値を"R"(relax)から"S"(stress)に変更し、(1.0 - relaxRatio)を送るよう改変 // 20170617 輝度調整の方法をrgbの合計値を基準にするように調整した。 @@ -294,6 +296,7 @@ int main(void) { +/* char msgIBI[100]; int nMsgIBILen = 0; char msgHappy[10]; @@ -302,9 +305,11 @@ int nMsgConcentrationLen = 0; char msgRelax[10]; int nMsgRelaxLen = 0; +*/ + byte_t msgHeader[3] = {0x49,0x4e,0x50}; - char msg[256]; - int nMsgLen = 0; + byte_t msg[19]; +// int nMsgLen = 0; float Brightness = 1.0; bool brighten = true; @@ -583,7 +588,7 @@ // nMsgLen = sprintf(msg,"B%d\0", BPM); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); - nMsgIBILen = sprintf(msgIBI,"Q%d\0", IBI); +// nMsgIBILen = sprintf(msgIBI,"Q%d\0", IBI); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); // 平均値算出用配列に値を詰める @@ -654,7 +659,7 @@ // リラックスの係数を算出する relaxRatio = diffRatio; - nMsgRelaxLen = sprintf(msgRelax,"S%0.2f\0", (1-relaxRatio)); +// nMsgRelaxLen = sprintf(msgRelax,"S%0.2f\0", (1-relaxRatio)); // nMsgLen = sprintf(msg,"R%0.2f\0", relaxRatio); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); @@ -797,7 +802,7 @@ conRatio = averageConRatio; conRatio = 1 - conRatio; - nMsgConcentrationLen = sprintf(msgConcentration,"C%0.2f\0", conRatio); +// nMsgConcentrationLen = sprintf(msgConcentration,"C%0.2f\0", conRatio); // nMsgLen = sprintf(msg,"C%0.2f\0", conRatio); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); @@ -909,7 +914,7 @@ // happyRatio = averageStressRatio ;// @@@ - nMsgHappyLen = sprintf(msgHappy,"H%0.2f\0", happyRatio); +// nMsgHappyLen = sprintf(msgHappy,"H%0.2f\0", happyRatio); // nMsgLen = sprintf(msg,"H%0.2f\0", happyRatio); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); @@ -966,9 +971,18 @@ // printf("R%d\n", rval); // printf("C%d\n", cval); - sprintf(msg,"%s%s%s%s\0", msgIBI, msgHappy, msgRelax, msgConcentration); +// sprintf(msg,"%s%s%s%s\0", msgIBI, msgHappy, msgRelax, msgConcentration); + + float relaxRatioFloat = float(1-relaxRatio); + + memcpy(msg, msgHeader, sizeof(msgHeader)); + memcpy(&(msg[ 3]), &IBI , sizeof(IBI) ); + memcpy(&(msg[ 7]), &happyRatio , sizeof(happyRatio)); + memcpy(&(msg[11]), &relaxRatioFloat, sizeof(relaxRatioFloat)); + memcpy(&(msg[15]), &conRatio , sizeof(conRatio) ); ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), - (uint8_t*)msg, nMsgIBILen + nMsgHappyLen + nMsgRelaxLen + nMsgConcentrationLen); + (uint8_t*)msg, sizeof(msg)); +// (uint8_t*)msg, nMsgIBILen + nMsgHappyLen + nMsgRelaxLen + nMsgConcentrationLen); // (uint8_t*)msg, nMsgIBILen + 1 + nMsgHappyLen + 1 + nMsgRelaxLen + 1 + nMsgConcentrationLen); // determine color range @@ -1067,3 +1081,4 @@ wait_ms(10); // 500usまで下げてもセンサー共振は起こらないことを確認 } } +