Skip to content

Commit d88c238

Browse files
authored
refactor cyton status check, add log message (#269)
Signed-off-by: Andrey Parfenov <[email protected]>
1 parent 8c4b913 commit d88c238

File tree

1 file changed

+16
-34
lines changed

1 file changed

+16
-34
lines changed

src/board_controller/openbci/openbci_serial_board.cpp

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -127,47 +127,29 @@ int OpenBCISerialBoard::set_port_settings ()
127127
return (int)BrainFlowExitCodes::SET_PORT_ERROR;
128128
}
129129
safe_logger (spdlog::level::trace, "set port settings");
130-
return send_to_board ("v");
130+
return (int)BrainFlowExitCodes::STATUS_OK;
131131
}
132132

133133
int OpenBCISerialBoard::status_check ()
134134
{
135-
unsigned char buf[1];
136-
int count = 0;
137-
int max_empty_seq = 5;
138-
int num_empty_attempts = 0;
135+
if (is_streaming)
136+
{
137+
return (int)BrainFlowExitCodes::STREAM_ALREADY_RUN_ERROR;
138+
}
139139

140-
for (int i = 0; i < 500; i++)
140+
std::string response = "";
141+
int res = send_to_board ("v", response);
142+
if (res != (int)BrainFlowExitCodes::STATUS_OK)
141143
{
142-
int res = serial->read_from_serial_port (buf, 1);
143-
if (res > 0)
144-
{
145-
num_empty_attempts = 0;
146-
// board is ready if there are '$$$'
147-
if (buf[0] == '$')
148-
{
149-
count++;
150-
}
151-
else
152-
{
153-
count = 0;
154-
}
155-
if (count == 3)
156-
{
157-
return (int)BrainFlowExitCodes::STATUS_OK;
158-
}
159-
}
160-
else
161-
{
162-
num_empty_attempts++;
163-
if (num_empty_attempts > max_empty_seq)
164-
{
165-
safe_logger (spdlog::level::err, "board doesnt send welcome characters!");
166-
return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
167-
}
168-
}
144+
return res;
169145
}
170-
return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
146+
safe_logger (spdlog::level::info, "Message from the board : {}", response.c_str ());
147+
std::size_t found = response.find ("$$$");
148+
if (found == std::string::npos)
149+
{
150+
return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
151+
}
152+
return (int)BrainFlowExitCodes::STATUS_OK;
171153
}
172154

173155
int OpenBCISerialBoard::prepare_session ()

0 commit comments

Comments
 (0)