mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
update
- Completed Serial Manager
This commit is contained in:
parent
1529b8b335
commit
4a8ebffa82
@ -39,8 +39,8 @@ public:
|
|||||||
|
|
||||||
struct TrackerConfig_t
|
struct TrackerConfig_t
|
||||||
{
|
{
|
||||||
DeviceConfig_t device{};
|
DeviceConfig_t device;
|
||||||
CameraConfig_t camera{};
|
CameraConfig_t camera;
|
||||||
std::vector<WiFiConfig_t> networks;
|
std::vector<WiFiConfig_t> networks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -6,24 +6,32 @@ SerialManager::SerialManager() : serialManagerActive(false),
|
|||||||
serialBuffer{0},
|
serialBuffer{0},
|
||||||
device_config_name{0},
|
device_config_name{0},
|
||||||
device_config_OTAPassword{0},
|
device_config_OTAPassword{0},
|
||||||
device_config_OTAPort(0) {}
|
device_config_OTAPort(0),
|
||||||
|
camera_config_vflip{0},
|
||||||
|
camera_config_href{0},
|
||||||
|
camera_config_framesize{0},
|
||||||
|
camera_config_quality{0},
|
||||||
|
wifi_config_name{0},
|
||||||
|
wifi_config_ssid{0},
|
||||||
|
wifi_config_password{0} {}
|
||||||
|
|
||||||
SerialManager::~SerialManager() {}
|
SerialManager::~SerialManager() {}
|
||||||
|
|
||||||
void SerialManager::listenToSerial(int timeout)
|
void SerialManager::listenToSerial(unsigned long timeout)
|
||||||
{
|
{
|
||||||
log_d("Listening to serial");
|
log_d("Listening to serial");
|
||||||
serialManagerActive = true;
|
serialManagerActive = true;
|
||||||
Serial.setTimeout(timeout);
|
Serial.setTimeout(timeout);
|
||||||
|
|
||||||
static boolean recvInProgress = false;
|
static bool recvInProgress = false;
|
||||||
static byte index = 0; // index
|
static uint8_t index = 0; // index
|
||||||
char startDelimiter = '<';
|
char startDelimiter = '<'; //! we need to decide on a delimiter for the start of a message
|
||||||
char endDelimiter = '>';
|
char endDelimiter = '>'; //! we need to decide on a delimiter for the end of a message
|
||||||
char receivedChar; // to test for received data on the line
|
char receivedChar; // to test for received data on the line
|
||||||
|
|
||||||
while (serialManagerActive)
|
while ((Serial.available() > 0) && !newData)
|
||||||
{
|
{
|
||||||
|
serialManagerActive = true;
|
||||||
receivedChar = Serial.read();
|
receivedChar = Serial.read();
|
||||||
if (recvInProgress)
|
if (recvInProgress)
|
||||||
{
|
{
|
||||||
@ -53,11 +61,6 @@ void SerialManager::listenToSerial(int timeout)
|
|||||||
recvInProgress = true;
|
recvInProgress = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Serial.available() > 0)
|
|
||||||
{
|
|
||||||
Serial.readBytesUntil('\n', this->serialBuffer, sizeof(this->serialBuffer));
|
|
||||||
}
|
|
||||||
delay(timeout);
|
delay(timeout);
|
||||||
serialManagerActive = false;
|
serialManagerActive = false;
|
||||||
}
|
}
|
||||||
@ -68,36 +71,64 @@ void SerialManager::parseData()
|
|||||||
log_d("Parsing data");
|
log_d("Parsing data");
|
||||||
char *strtokIndx; // this is used by strtok() as an index
|
char *strtokIndx; // this is used by strtok() as an index
|
||||||
|
|
||||||
strtokIndx = strtok(tempBuffer, ","); // get the first part - the string
|
//! Parse the data
|
||||||
|
//* Device Config *//
|
||||||
|
strtokIndx = strtok(tempBuffer, ","); // get the first part
|
||||||
strcpy(device_config_name, strtokIndx); // copy it to buffer
|
strcpy(device_config_name, strtokIndx); // copy it to buffer
|
||||||
|
|
||||||
strtokIndx = strtok(NULL, ","); // get the second part - the string
|
strtokIndx = strtok(NULL, ","); // get the second part
|
||||||
strcpy(device_config_OTAPassword, strtokIndx); // copy it to buffer
|
strcpy(device_config_OTAPassword, strtokIndx);
|
||||||
|
|
||||||
strtokIndx = strtok(NULL, ","); // get the first part - the string
|
strtokIndx = strtok(NULL, ",");
|
||||||
device_config_OTAPort = atoi(strtokIndx); // convert this part to an integer
|
device_config_OTAPort = atoi(strtokIndx);
|
||||||
|
|
||||||
projectConfig.setDeviceConfig( ); // get the second part - the value
|
//* Camera Config *//
|
||||||
if (newData)
|
strtokIndx = strtok(NULL, ",");
|
||||||
|
camera_config_vflip = atoi(strtokIndx);
|
||||||
|
|
||||||
|
strtokIndx = strtok(NULL, ",");
|
||||||
|
camera_config_framesize = atoi(strtokIndx);
|
||||||
|
|
||||||
|
strtokIndx = strtok(NULL, ",");
|
||||||
|
camera_config_href = atoi(strtokIndx);
|
||||||
|
|
||||||
|
strtokIndx = strtok(NULL, ",");
|
||||||
|
camera_config_quality = atoi(strtokIndx);
|
||||||
|
|
||||||
|
//* Wifi Config *//
|
||||||
|
strtokIndx = strtok(tempBuffer, ",");
|
||||||
|
strcpy(wifi_config_name, strtokIndx);
|
||||||
|
|
||||||
|
strtokIndx = strtok(NULL, ",");
|
||||||
|
strcpy(wifi_config_ssid, strtokIndx);
|
||||||
|
|
||||||
|
strtokIndx = strtok(NULL, ",");
|
||||||
|
strcpy(wifi_config_password, strtokIndx);
|
||||||
|
|
||||||
|
/* if (newData)
|
||||||
{
|
{
|
||||||
log_d("New data");
|
log_d("New data");
|
||||||
newData = false;
|
newData = false;
|
||||||
char *token = strtok(serialBuffer, ",");
|
char *token = strtok(tempBuffer, ",");
|
||||||
while (token != NULL)
|
while (token != NULL)
|
||||||
{
|
{
|
||||||
log_d("Token: %s", token);
|
log_d("Token: %s", token);
|
||||||
token = strtok(NULL, ",");
|
token = strtok(NULL, ",");
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialManager::moveData()
|
void SerialManager::handleSerial()
|
||||||
{
|
{
|
||||||
listenToSerial(30000); // test for serial input for 30 seconds
|
listenToSerial(30000L); // test for serial input for 30 seconds
|
||||||
if (newData) // input received
|
if (newData) // input received
|
||||||
{
|
{
|
||||||
strcpy(tempBuffer, serialBuffer); // this temporary copy is necessary to protect the original data because strtok() used in parseData() replaces the commas with \0
|
strcpy(tempBuffer, serialBuffer); // this temporary copy is necessary to protect the original data because strtok() used in parseData() replaces the commas with \0
|
||||||
parseData(); // split the data into tokens and store them in the data structure
|
parseData(); // split the data into tokens and store them in the data structure
|
||||||
newData = false; // reset new data
|
newData = false; // reset new data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
projectConfig.setDeviceConfig(device_config_name, device_config_OTAPassword, &device_config_OTAPort, true); // set the values in the project config
|
||||||
|
projectConfig.setCameraConfig(&camera_config_vflip, &camera_config_framesize, &camera_config_href, &camera_config_quality, true); // set the values in the project config
|
||||||
|
projectConfig.setWifiConfig(wifi_config_name, wifi_config_ssid, wifi_config_password, true); // set the values in the project config
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,17 +9,30 @@ public:
|
|||||||
SerialManager();
|
SerialManager();
|
||||||
virtual ~SerialManager();
|
virtual ~SerialManager();
|
||||||
|
|
||||||
void listenToSerial(int timeout);
|
void handleSerial();
|
||||||
void parseData();
|
|
||||||
void moveData();
|
|
||||||
|
|
||||||
bool serialManagerActive;
|
bool serialManagerActive;
|
||||||
|
|
||||||
|
/* Device Config Variables */
|
||||||
char device_config_name[32];
|
char device_config_name[32];
|
||||||
char device_config_OTAPassword[100];
|
char device_config_OTAPassword[100];
|
||||||
int device_config_OTAPort;
|
int device_config_OTAPort;
|
||||||
|
|
||||||
|
/* Camera Config Variables */
|
||||||
|
uint8_t camera_config_vflip;
|
||||||
|
uint8_t camera_config_framesize;
|
||||||
|
uint8_t camera_config_href;
|
||||||
|
uint8_t camera_config_quality;
|
||||||
|
|
||||||
|
/* Wifi Config Variables */
|
||||||
|
char wifi_config_name[32];
|
||||||
|
char wifi_config_ssid[100];
|
||||||
|
char wifi_config_password[100];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void listenToSerial(unsigned long timeout);
|
||||||
|
void parseData();
|
||||||
enum DataTypes_e
|
enum DataTypes_e
|
||||||
{
|
{
|
||||||
DataType_Unknown,
|
DataType_Unknown,
|
||||||
@ -30,8 +43,8 @@ private:
|
|||||||
DataType_Debug
|
DataType_Debug
|
||||||
};
|
};
|
||||||
|
|
||||||
char tempBuffer[sizeof(serialBuffer) / sizeof(serialBuffer[0])];
|
|
||||||
char serialBuffer[100000]; //! Need to find the appropriate size for this - count the maximum possible size of a message
|
char serialBuffer[100000]; //! Need to find the appropriate size for this - count the maximum possible size of a message
|
||||||
|
char tempBuffer[sizeof(serialBuffer) / sizeof(serialBuffer[0])];
|
||||||
bool newData;
|
bool newData;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user