You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
4.6 KiB
142 lines
4.6 KiB
#include "MEKOROT_Kernel.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "KRNL", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X )
|
|
|
|
mekorotKernel::mekorotKernel(config_setting_t* ptr) : protocolLGS_CLIENT(), basicThread(), basicEngine() {
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(ptr, (CSTR)"KERNEL");
|
|
m_bStage = MEKOROT_KRNL_STG_INIT;
|
|
m_pSerial = NULL;
|
|
m_pSerialDevice[0] = (char)0;
|
|
m_nSerialSpeed = 19200;
|
|
m_bDeviceID[0] = m_bDeviceID[1] = m_bDeviceID[2] = -1;
|
|
m_bDeviceFlags[0] = m_bDeviceFlags[1] = m_bDeviceFlags[2] = false;
|
|
};
|
|
|
|
mekorotKernel::~mekorotKernel() {
|
|
if (m_pSerial != NULL) delete( m_pSerial );
|
|
};
|
|
|
|
bool mekorotKernel::init(void){
|
|
config_setting_t *pSetting;
|
|
pSetting = config_setting_get_member(m_pSettings, MEKOROT_KRNL_SERIAL_LINE_TAG);
|
|
if (pSetting != NULL) {
|
|
sprintf(m_pSerialDevice, "%s", config_setting_get_string(pSetting));
|
|
} else {
|
|
sprintf(m_pSerialDevice, "\\\\.\\COM2");
|
|
pSetting = config_setting_add(m_pSettings, MEKOROT_KRNL_SERIAL_LINE_TAG, CONFIG_TYPE_STRING);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
if (pSetting == NULL) {
|
|
LOG_ERROR("Failure while adding setting!");
|
|
return -1;
|
|
};
|
|
config_setting_set_string(pSetting, m_pSerialDevice);
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, MEKOROT_KRNL_SERIAL_SPEED_TAG);
|
|
if (pSetting != NULL) {
|
|
m_nSerialSpeed = config_setting_get_int(pSetting);
|
|
} else {
|
|
pSetting = config_setting_add(m_pSettings, MEKOROT_KRNL_SERIAL_SPEED_TAG, CONFIG_TYPE_INT);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
if (pSetting == NULL) {
|
|
LOG_ERROR("Failure while adding setting!");
|
|
return -1;
|
|
};
|
|
config_setting_set_int(pSetting, m_nSerialSpeed );
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, MEKOROT_KRNL_DEVICE_0_ID_TAG);
|
|
if (pSetting != NULL) {
|
|
m_bDeviceID[0] = config_setting_get_int(pSetting);
|
|
} else {
|
|
pSetting = config_setting_add(m_pSettings, MEKOROT_KRNL_DEVICE_0_ID_TAG, CONFIG_TYPE_INT);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
if (pSetting == NULL) {
|
|
LOG_ERROR("Failure while adding setting!");
|
|
return -1;
|
|
};
|
|
config_setting_set_int(pSetting, m_bDeviceID[0]);
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, MEKOROT_KRNL_DEVICE_1_ID_TAG);
|
|
if (pSetting != NULL) {
|
|
m_bDeviceID[1] = config_setting_get_int(pSetting);
|
|
} else {
|
|
pSetting = config_setting_add(m_pSettings, MEKOROT_KRNL_DEVICE_1_ID_TAG, CONFIG_TYPE_INT);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
if (pSetting == NULL) {
|
|
LOG_ERROR("Failure while adding setting!");
|
|
return -1;
|
|
};
|
|
config_setting_set_int(pSetting, m_bDeviceID[1]);
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, MEKOROT_KRNL_DEVICE_2_ID_TAG);
|
|
if (pSetting != NULL) {
|
|
m_bDeviceID[2] = config_setting_get_int(pSetting);
|
|
} else {
|
|
pSetting = config_setting_add(m_pSettings, MEKOROT_KRNL_DEVICE_2_ID_TAG, CONFIG_TYPE_INT);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
if (pSetting == NULL) {
|
|
LOG_ERROR("Failure while adding setting!");
|
|
return -1;
|
|
};
|
|
config_setting_set_int(pSetting, m_bDeviceID[2]);
|
|
};
|
|
|
|
basicSettingsProvider::getInstance()->validate();
|
|
m_bStage = MEKOROT_KRNL_STG_CONNECT;
|
|
return basicThread::init();
|
|
};
|
|
|
|
void mekorotKernel::m_fThreadProc(void){
|
|
m_bThreadStatus = TH_WORKING;
|
|
while (m_bThreadStatus < TH_ENDED) {
|
|
switch( m_bStage ) {
|
|
case MEKOROT_KRNL_STG_CONNECT:{
|
|
if (m_pSerial == NULL) {
|
|
m_pSerial = new serialPort(m_pSerialDevice, m_nSerialSpeed);
|
|
if (m_pSerial != NULL) {
|
|
setTransport( m_pSerial );
|
|
m_bStage = MEKOROT_KRNL_STG_PING_DEVICES;
|
|
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
case MEKOROT_KRNL_STG_PING_DEVICES: {
|
|
bool LB = true;
|
|
for (uint8_t index = 0; index < 3; index++) {
|
|
if (m_bDeviceID[index] != -1 && !m_bDeviceFlags[index]){
|
|
LB = false;
|
|
if (setDeviceID(m_bDeviceID[index])) {
|
|
if (!getState2()) {
|
|
LOG_ERROR("Get STATE FAILURE!");
|
|
};
|
|
} else {
|
|
LOG_ERROR("Set DevID FAILURE!");
|
|
};
|
|
m_bDeviceTO[index] = getMilliseconds();
|
|
};
|
|
};
|
|
if (LB) {
|
|
m_bStage = MEKOROT_KRNL_STG_WORKING;
|
|
} else {
|
|
SLEEP(1000); // wait responce
|
|
};
|
|
break;
|
|
};
|
|
case MEKOROT_KRNL_STG_WORKING: {
|
|
|
|
break;
|
|
};
|
|
};
|
|
SLEEP(DEFAULT_THREAD_SLEEP_TIME);
|
|
};
|
|
};
|
|
|
|
bool mekorotKernel::packetHandler(protocolPackage* Package) {
|
|
LOG("PROTO HANDLER!");
|
|
return false;
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|