/** * Инициализация COM порта */ int FtdiDevices::Initialization() { int state = 0; if ( !openDSUSession() ) state = 1; if ( !reset() ) state = 1; if ( !setSpeed(115200) ) state = 1; if ( !setDataCharacteristics() ) state = 1; if ( !getModemStatus() ) state = 1; setEventNotification(); setDtrRts(); purge(); if ( !setFlowControl() ) state = 1; QString msg; int type; if ( state == 1 ) { msg = "Не могу открыть устройство( COM порт A )!" ; type = appLogger.ERROR_MSG_TYPE; } else { msg = "Устройство открыто успешно( COM порт A )!"; type = appLogger.INFO_MSG_TYPE; } /* Запись в лог сообщения */ appLogger.sendDataToViewer( type, msg, appLogger.SYSTEM_LOGGER ); return state; }
void SP5K_statusFunction(void) { RtcTimeType rtcDateTime; u08 pos, channel; u16 dialTimer; u08 mStatus; frameDataType frame; u08 gprsState, gprsSubState, dataState; rtcGetTime(&rtcDateTime); getDataFrame(&frame); dialTimer = getTimeToNextDial(); memset( &cmd_printfBuff, '\0', CHAR128); if (xSemaphoreTake( sem_CmdUart, MSTOTAKECMDUARTSEMPH ) == pdTRUE ) { snprintf_P( cmd_printfBuff,CHAR128,PSTR("\r\nSpymovil %s %s\0"), SP5K_MODELO, SP5K_VERSION); rprintfStr(CMD_UART, cmd_printfBuff ); snprintf_P( cmd_printfBuff,CHAR128,PSTR(" %d-%s-%s\0"), NRO_CHANNELS, EE_TYPE, FTYPE); rprintfStr(CMD_UART, cmd_printfBuff ); snprintf_P( cmd_printfBuff,CHAR128,PSTR(" %s %s\r\n\0"), SP5K_REV, SP5K_DATE ); rprintfStr(CMD_UART, cmd_printfBuff ); /* DlgId */ snprintf_P( cmd_printfBuff,CHAR128,PSTR("dlgid: %s\r\n\0"), systemVars.dlgId ); rprintfStr(CMD_UART, cmd_printfBuff ); /* Fecha y Hora */ snprintf_P( cmd_printfBuff,CHAR128,PSTR("rtc: %02d/%02d/%04d \0"),rtcDateTime.day,rtcDateTime.month, rtcDateTime.year ); rprintfStr(CMD_UART, cmd_printfBuff ); snprintf_P( cmd_printfBuff,CHAR128,PSTR("%02d:%02d:%02d\r\n\0"),rtcDateTime.hour,rtcDateTime.min, rtcDateTime.sec ); rprintfStr(CMD_UART, cmd_printfBuff ); // SERVER --------------------------------------------------------------------------------------- snprintf_P( cmd_printfBuff,CHAR128,PSTR(">Server:\r\n\0")); rprintfStr(CMD_UART, cmd_printfBuff ); /* APN */ snprintf_P( cmd_printfBuff,CHAR128,PSTR(" apn: %s\r\n\0"), systemVars.apn ); rprintfStr(CMD_UART, cmd_printfBuff ); /* SERVER IP:SERVER PORT */ snprintf_P( cmd_printfBuff,CHAR128,PSTR(" server ip:port: %s:%s\r\n\0"), systemVars.serverAddress,systemVars.serverPort ); rprintfStr(CMD_UART, cmd_printfBuff ); /* SERVER SCRIPT */ snprintf_P( cmd_printfBuff,CHAR128,PSTR(" server script: %s\r\n\0"), systemVars.serverScript ); rprintfStr(CMD_UART, cmd_printfBuff ); /* SERVER PASSWD */ snprintf_P( cmd_printfBuff,CHAR128,PSTR(" passwd: %s\r\n\0"), systemVars.passwd ); rprintfStr(CMD_UART, cmd_printfBuff ); // MODEM --------------------------------------------------------------------------------------- snprintf_P( cmd_printfBuff,CHAR128,PSTR(">Modem:\r\n\0")); rprintfStr(CMD_UART, cmd_printfBuff ); /* Modem status */ mStatus = getModemStatus(); switch (mStatus) { case M_OFF: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" modem: OFF\r\n\0")); break; case M_OFF_IDLE: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" modem: OFF Idle\r\n\0")); break; case M_ON_CONFIG: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" modem: ON & configurating.\r\n\0")); break; case M_ON_READY: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" modem: ON & ready(apn,ip).\r\n\0")); break; default: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" modem: ERROR\r\n\0")); break; } rprintfStr(CMD_UART, cmd_printfBuff ); /* DLGIP */ snprintf_P( cmd_printfBuff,CHAR128,PSTR(" dlg ip: %s\r\n\0"), systemVars.dlgIp ); rprintfStr(CMD_UART, cmd_printfBuff ); /* CSQ */ snprintf_P( cmd_printfBuff,CHAR128,PSTR(" signalQ: csq=%d, dBm=%d\r\n\0"), systemVars.csq, systemVars.dbm ); rprintfStr(CMD_UART, cmd_printfBuff ); // DCD/RI/TERMSW if ( systemVars.dcd == 0 ) { pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR(" pines: dcd=ON,\0")); } if ( systemVars.dcd == 1 ) { pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR(" pines: dcd=OFF,\0"));} if ( systemVars.ri == 0 ) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("ri=ON,\0")); } if ( systemVars.ri == 1 ) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("ri=OFF,\0"));} if ( systemVars.termsw == 1 ) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("term=ON\r\n\0")); } if ( systemVars.termsw == 0 ) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("term=OFF\r\n\0"));} rprintfStr(CMD_UART, cmd_printfBuff ); // SYSTEM --------------------------------------------------------------------------------------- snprintf_P( cmd_printfBuff,CHAR128,PSTR(">System:\r\n\0")); rprintfStr(CMD_UART, cmd_printfBuff ); /* Memoria */ snprintf_P( cmd_printfBuff,CHAR128,PSTR(" memory: wrPtr=%d, rdPtr=%d, usedRec=%d, freeRecs=%d\r\n\0"), BD_getWRptr(), BD_getRDptr(), BD_getRcsUsed(), BD_getRcsFree() ); rprintfStr(CMD_UART, cmd_printfBuff ); /* WRK mode (NORMAL / SERVICE) */ switch (systemVars.wrkMode) { case WK_NORMAL: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" wrkmode: normal\r\n\0")); break; case WK_SERVICE: snprintf_P( &cmd_printfBuff,CHAR128,PSTR(" wrkmode: service\r\n\0")); break; case WK_MONITOR: snprintf_P( &cmd_printfBuff,CHAR128,PSTR(" wrkmode: monitor\r\n\0")); break; default: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" wrkmode: ERROR\r\n\0")); break; } rprintfStr(CMD_UART, cmd_printfBuff ); /* PWR mode (CONTINUO / DISCRETO) */ switch (systemVars.pwrMode) { case PWR_CONTINUO: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" pwrmode: continuo\r\n\0")); break; case PWR_DISCRETO: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" pwrmode: discreto\r\n\0")); break; default: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" pwrmode: ERROR\r\n\0")); break; } rprintfStr(CMD_UART, cmd_printfBuff ); #ifdef CHANNELS_3 /* Consigna */ switch (systemVars.consigna.tipo) { case CONS_NONE: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" consigna: none\r\n\0")); break; case CONS_DOBLE: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" consigna: doble (dia->%02d:%02d, noche->%02d:%02d)\r\n\0"), systemVars.consigna.hh_A,systemVars.consigna.mm_A,systemVars.consigna.hh_B,systemVars.consigna.mm_B ); break; default: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" consigna: ERROR\r\n\0")); break; } rprintfStr(CMD_UART, cmd_printfBuff ); #endif /* Timers */ snprintf_P( cmd_printfBuff,CHAR128,PSTR(" timerPoll: %d/%d\r\n\0"),systemVars.timerPoll, getTimeToNextPoll() ); rprintfStr(CMD_UART, cmd_printfBuff ); if (systemVars.pwrMode == PWR_CONTINUO ) { pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR(" timerDial: -1(%d)/\0"),systemVars.timerDial ); } else { pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR(" timerDial: %d/\0"),systemVars.timerDial ); } pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("%d\r\n\0"), dialTimer ); rprintfStr(CMD_UART, cmd_printfBuff ); snprintf_P( cmd_printfBuff,CHAR128,PSTR(" khTimer: %d\r\n\0"),houseKeepingTimer ); rprintfStr(CMD_UART, cmd_printfBuff ); // Debug Options. pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR(" debugLevel: \0")); if ( systemVars.debugLevel == D_NONE) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("none") ); } else { if ( (systemVars.debugLevel & D_DATA) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+data")); } if ( (systemVars.debugLevel & D_GPRS) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+gprs")); } if ( (systemVars.debugLevel & D_BD) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+bd")); } if ( (systemVars.debugLevel & D_I2C) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+i2c")); } if ( (systemVars.debugLevel & D_DIGITAL) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+digital")); } } snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("\r\n\0")); rprintfStr(CMD_UART, cmd_printfBuff ); // Log Options pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR(" logLevel: \0")); if ( systemVars.logLevel == LOG_NONE) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("none")); } if ( systemVars.logLevel == LOG_INFO) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("info")); } if ( systemVars.logLevel == LOG_WARN) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("warn")); } if ( systemVars.logLevel == LOG_ALERT) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("alert")); } snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("\r\n\0")); rprintfStr(CMD_UART, cmd_printfBuff ); getStatusGprsSM( &gprsState, &gprsSubState); getStatusDataSM( &dataState ); snprintf_P( cmd_printfBuff,CHAR128,PSTR(" tkGprs:%d/%d, tkData:%d\r\n\0"), gprsState, gprsSubState, dataState); rprintfStr(CMD_UART, cmd_printfBuff ); // CONFIG --------------------------------------------------------------------------------------- snprintf_P( cmd_printfBuff,CHAR128,PSTR(">Config:\r\n\0")); rprintfStr(CMD_UART, cmd_printfBuff ); /* Configuracion del sistema */ switch (mcpDevice) { case MCP23008: snprintf_P( cmd_printfBuff,CHAR128,PSTR(" analog=%d, digital=2.\r\n\0"),NRO_CHANNELS); break; case MCP23018: pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR(" analog=%d, digital=2, valves=4.\r\n\0"),NRO_CHANNELS); break; default: snprintf_P( cmd_printfBuff,CHAR128,PSTR("ERROR !! No analog system detected\r\n\0")); break; } rprintfStr(CMD_UART, cmd_printfBuff ); #ifdef CHANNELS_3 snprintf_P( cmd_printfBuff,CHAR128,PSTR(" batt{0-15V}\r\n\0")); rprintfStr(CMD_UART, cmd_printfBuff ); #endif for ( channel = 0; channel < NRO_CHANNELS; channel++) { snprintf_P( cmd_printfBuff,CHAR128,PSTR(" a%d{%d-%dmA/%d-%d, %.2f/%.2f}(%s)\r\n\0"),channel, systemVars.Imin[channel],systemVars.Imax[channel],systemVars.Mmin[channel],systemVars.Mmax[channel], systemVars.offmmin[channel], systemVars.offmmax[channel], systemVars. aChName[channel] ); rprintfStr(CMD_UART, cmd_printfBuff ); } /* Configuracion de canales digitales */ snprintf_P( cmd_printfBuff,CHAR128,PSTR(" d0{%.2f p/p} (%s)\r\n\0"), systemVars.magPP[0],systemVars.dChName[0]); rprintfStr(CMD_UART, cmd_printfBuff ); snprintf_P( cmd_printfBuff,CHAR128,PSTR(" d1{%.2f p/p} (%s)\r\n\0"), systemVars.magPP[1],systemVars.dChName[1]); rprintfStr(CMD_UART, cmd_printfBuff ); // VALUES --------------------------------------------------------------------------------------- snprintf_P( cmd_printfBuff,CHAR128,PSTR(">Values:\r\n\0")); rprintfStr(CMD_UART, cmd_printfBuff ); pos = 0; // Armo el frame memset( &cmd_printfBuff, NULL, CHAR128); pos += snprintf_P( &cmd_printfBuff[pos], CHAR128,PSTR( " %04d%02d%02d,"),frame.rtc.year,frame.rtc.month, frame.rtc.day ); pos += snprintf_P( &cmd_printfBuff[pos], CHAR128, PSTR("%02d%02d%02d,"),frame.rtc.hour,frame.rtc.min, frame.rtc.sec ); // Valores analogicos for ( channel = 0; channel < NRO_CHANNELS; channel++) { pos += snprintf_P( &cmd_printfBuff[pos], CHAR128, PSTR("%s=%.2f,"),systemVars.aChName[channel],frame.analogIn[channel] ); } // Valores digitales. pos += snprintf_P( &cmd_printfBuff[pos], CHAR128, PSTR("%sP=%.2f,"),systemVars.dChName[0], frame.din0_pCount ); pos += snprintf_P( &cmd_printfBuff[pos], CHAR128,PSTR( "%sP=%.2f"), systemVars.dChName[1], frame.din1_pCount ); #ifdef CHANNELS_3 // Bateria pos += snprintf_P( &cmd_printfBuff[pos], CHAR128, PSTR(",bt=%.2f%"),frame.batt ); #endif pos += snprintf_P( &cmd_printfBuff[pos], CHAR128,PSTR("\r\n\0") ); // Imprimo rprintfStr(CMD_UART, &cmd_printfBuff ); xSemaphoreGive( sem_CmdUart ); } }