Skip to content

Commit

Permalink
update codes, upgrade NBIOT support codes
Browse files Browse the repository at this point in the history
  • Loading branch information
i3water committed Nov 10, 2018
1 parent 741ad4a commit faa1e04
Show file tree
Hide file tree
Showing 3 changed files with 517 additions and 309 deletions.
300 changes: 205 additions & 95 deletions src/Adapters/BlinkerNB73.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,99 @@ enum BlinkerNB73Status{
NB_INIT_SUCCESS
};

class NBdata
{
public :
NBdata()
: _isReq(false)
{}

bool update(String data) {
// _data = data;
// BLINKER_LOG2(BLINKER_F("update data: "), data);
_isReq = serialize(data);
return _isReq;
}

bool isReq() { return _isReq; }

String reqName() { return _reqName; }

uint8_t paramNum() { return _paramNum; }

private :
bool _isReq;
uint8_t _paramNum;
// String _data;
String _reqName;
String _param[11];

bool serialize(String _data) {
#ifdef BLINKER_DEBUG_ALL
BLINKER_LOG2(BLINKER_F("serialize _data: "), _data);
#endif
int addr_start = _data.indexOf("+");
int addr_end = 0;

// BLINKER_LOG2(BLINKER_F("serialize addr_start: "), addr_start);
// BLINKER_LOG2(BLINKER_F("serialize addr_end: "), addr_end);

if ((addr_start != -1) && STRING_contains_string(_data, ":")) {
addr_start = 0;
addr_end = _data.indexOf(":");

if (addr_end == -1) {
return false;
}
else {
_reqName = _data.substring(addr_start, addr_end);
#ifdef BLINKER_DEBUG_ALL
BLINKER_LOG2(BLINKER_F("serialize _reqName: "), _reqName);
#endif
}

// BLINKER_LOG2(BLINKER_F("serialize _data: "), _data);

String serData;
uint16_t dataLen = _data.length();

for (_paramNum = 0; _paramNum < 11; _paramNum++) {
addr_start += addr_end;
addr_start += 1;
serData = _data.substring(addr_start, dataLen);

addr_end = serData.indexOf(",");

// BLINKER_LOG2(BLINKER_F("serialize serData: "), serData);
// BLINKER_LOG2(BLINKER_F("serialize addr_start: "), addr_start);
// BLINKER_LOG2(BLINKER_F("serialize addr_end: "), addr_end);

if (addr_end == -1) {
if (addr_start >= dataLen) return false;
_param[_paramNum] = serData;
#ifdef BLINKER_DEBUG_ALL
BLINKER_LOG2(BLINKER_F("_param[_paramNum]: "), _param[_paramNum]);
#endif
_paramNum++;
return true;
}
else {
_param[_paramNum] = serData.substring(0, addr_end);
}
#ifdef BLINKER_DEBUG_ALL
BLINKER_LOG2(BLINKER_F("_param[_paramNum]: "), _param[_paramNum]);
#endif
}
return true;
}
else {
return false;
}
}
};

static class NBdata * _nbDataManager;

class BlinkerTransportStream
{
public :
Expand All @@ -53,6 +146,23 @@ class BlinkerTransportStream
#ifdef BLINKER_DEBUG_ALL
BLINKER_LOG2(BLINKER_F("handleSerial: "), streamData);
#endif

if (!_nbDataManager) {
_nbDataManager = new NBdata();

_nbDataManager->update(STRING_format(streamData));

BLINKER_LOG2(BLINKER_F("isReq: "), _nbDataManager->isReq());
BLINKER_LOG2(BLINKER_F("reqName: "), _nbDataManager->reqName());
BLINKER_LOG2(BLINKER_F("paramNum: "), _nbDataManager->paramNum());
}
else {
_nbDataManager->update(STRING_format(streamData));
BLINKER_LOG2(BLINKER_F("isReq: "), _nbDataManager->isReq());
BLINKER_LOG2(BLINKER_F("reqName: "), _nbDataManager->reqName());
BLINKER_LOG2(BLINKER_F("paramNum: "), _nbDataManager->paramNum());
}

return true;
}
else {
Expand All @@ -70,7 +180,7 @@ class BlinkerTransportStream
}

if (stream->available()) {
strcpy(streamData, (stream->readString()).c_str());
strcpy(streamData, (stream->readStringUntil('\n')).c_str());
#ifdef BLINKER_DEBUG_ALL
BLINKER_LOG2(BLINKER_F("handleSerial: "), streamData);
#endif
Expand All @@ -89,100 +199,100 @@ class BlinkerTransportStream

connect();

BlinkerNB73Status init_status = NB_INIT;

while (init_status != NB_INIT_SUCCESS) {
// available();

switch (init_status)
{
case NB_INIT :
if (_available()) {
// if (lastRead() == BLINKER_CMD_NB_NB73) {
if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_NB73)) {
init_status = NB_POWER_ON;
print(BLINKER_CMD_NB_CGATT);

BLINKER_LOG1("NB_POWER_ON");
}
}
break;
case NB_POWER_ON :
if (_available()) {
// if (lastRead() == BLINKER_CMD_NB_CGATT_SUCCESSED) {
if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_CGATT_SUCCESSED)) {
init_status = NB_CGATT_SUCCESS;
print(BLINKER_CMD_NB_CREATE);

BLINKER_LOG1("NB_CGATT_SUCCESS");
}
// else if (lastRead() == BLINKER_CMD_NB_CGATT_FAILED) {
else if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_CGATT_FAILED)) {
init_status = NB_CGATT_FAIL;

BLINKER_LOG1("NB_CGATT_FAIL");
}
}
break;
case NB_CGATT_SUCCESS :
if (_available()) {
// if (lastRead() == BLINKER_CMD_NB_CREATE_SUCCESSED) {
if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_CREATE_SUCCESSED)) {
init_status = NB_CREAT_SUCCESS;
print(BLINKER_CMD_NB_ADDOBJ);

BLINKER_LOG1("NB_CREAT_SUCCESS");
}
}
break;
case NB_CREAT_SUCCESS :
if (_available()) {
// if (lastRead() == BLINKER_CMD_OK) {
if (STRING_contains_string(lastRead(), BLINKER_CMD_OK)) {
init_status = NB_ADDOBJ_SUCCESS;
print(BLINKER_CMD_NB_OPEN);

BLINKER_LOG1("NB_ADDOBJ_SUCCESS");
}
}
break;
case NB_ADDOBJ_SUCCESS :
if (_available()) {
// if (lastRead() == BLINKER_CMD_NB_EVENT_6) {
if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_EVENT_6)) {
init_status = NB_OPEN_SUCCESS;
// print(BLINKER_CMD_NB_ADDOBJ);

BLINKER_LOG1("NB_OPEN_SUCCESS");
}
}
break;
case NB_OPEN_SUCCESS :
if (_available()) {
// if (lastRead() == BLINKER_CMD_NB_OBSERVE) {
if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_OBSERVE)) {
init_status = NB_OBSERVE;
print(BLINKER_CMD_NB_OBSERVERSP);

BLINKER_LOG1("NB_OBSERVERSP");
}
}
break;
case NB_OBSERVE :
if (_available()) {
// if (lastRead() == BLINKER_CMD_OK) {
if (STRING_contains_string(lastRead(), BLINKER_CMD_OK)) {
init_status = NB_INIT_SUCCESS;
// print(BLINKER_CMD_NB_OBSERVERSP);

BLINKER_LOG1("NB_INIT_SUCCESS");
}
}
break;
default :
break;
}
}
// BlinkerNB73Status init_status = NB_INIT;

// while (init_status != NB_INIT_SUCCESS) {
// // available();

// switch (init_status)
// {
// case NB_INIT :
// if (_available()) {
// // if (lastRead() == BLINKER_CMD_NB_NB73) {
// if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_NB73)) {
// init_status = NB_POWER_ON;
// print(BLINKER_CMD_NB_CGATT);

// BLINKER_LOG1("NB_POWER_ON");
// }
// }
// break;
// case NB_POWER_ON :
// if (_available()) {
// // if (lastRead() == BLINKER_CMD_NB_CGATT_SUCCESSED) {
// if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_CGATT_SUCCESSED)) {
// init_status = NB_CGATT_SUCCESS;
// print(BLINKER_CMD_NB_CREATE);

// BLINKER_LOG1("NB_CGATT_SUCCESS");
// }
// // else if (lastRead() == BLINKER_CMD_NB_CGATT_FAILED) {
// else if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_CGATT_FAILED)) {
// init_status = NB_CGATT_FAIL;

// BLINKER_LOG1("NB_CGATT_FAIL");
// }
// }
// break;
// case NB_CGATT_SUCCESS :
// if (_available()) {
// // if (lastRead() == BLINKER_CMD_NB_CREATE_SUCCESSED) {
// if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_CREATE_SUCCESSED)) {
// init_status = NB_CREAT_SUCCESS;
// print(BLINKER_CMD_NB_ADDOBJ);
// BLINKER_LOG1("NB_CREAT_SUCCESS");
// }
// }
// break;
// case NB_CREAT_SUCCESS :
// if (_available()) {
// // if (lastRead() == BLINKER_CMD_OK) {
// if (STRING_contains_string(lastRead(), BLINKER_CMD_OK)) {
// init_status = NB_ADDOBJ_SUCCESS;
// print(BLINKER_CMD_NB_OPEN);
// BLINKER_LOG1("NB_ADDOBJ_SUCCESS");
// }
// }
// break;
// case NB_ADDOBJ_SUCCESS :
// if (_available()) {
// // if (lastRead() == BLINKER_CMD_NB_EVENT_6) {
// if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_EVENT_6)) {
// init_status = NB_OPEN_SUCCESS;
// // print(BLINKER_CMD_NB_ADDOBJ);

// BLINKER_LOG1("NB_OPEN_SUCCESS");
// }
// }
// break;
// case NB_OPEN_SUCCESS :
// if (_available()) {
// // if (lastRead() == BLINKER_CMD_NB_OBSERVE) {
// if (STRING_contains_string(lastRead(), BLINKER_CMD_NB_OBSERVE)) {
// init_status = NB_OBSERVE;
// print(BLINKER_CMD_NB_OBSERVERSP);

// BLINKER_LOG1("NB_OBSERVERSP");
// }
// }
// break;
// case NB_OBSERVE :
// if (_available()) {
// // if (lastRead() == BLINKER_CMD_OK) {
// if (STRING_contains_string(lastRead(), BLINKER_CMD_OK)) {
// init_status = NB_INIT_SUCCESS;
// // print(BLINKER_CMD_NB_OBSERVERSP);

// BLINKER_LOG1("NB_INIT_SUCCESS");
// }
// }
// break;
// default :
// break;
// }
// }
}

String lastRead() { return STRING_format(streamData); }
Expand Down
Loading

0 comments on commit faa1e04

Please sign in to comment.