// Software Initialization: // input parameter: // void : nothing // return type: // int : return SUCCESS, init Software int init(void) { int level; double actual, desired; char sensorTempData[5]; initLogging("temp_log"); initCSVFile("temp_csv"); initConfigFile("temp_config"); logging(INFO, "\nStarting CliConWARE Software...."); // Printing current hour: printf(" -- Current hour : %d:%02d\n", getHour(), getMin()); // Printing actual temperature: readData("/dev/temp_sensor", sensorTempData); actual = (double) atof(sensorTempData)/ 1000; printf(" -- Actual temperature : %.2f°C\n", actual); // Printing desired temperature: desired = getDesired("temp_config"); printf(" -- Desired temperature : %.2f°C\n", desired); // Printing current knob level: level = map(actual); printf(" -- Current knob level : %d\n", level); logging(INFO, "The Software will start in 3 seconds.....\n"); sleep(3); return SUCCESS; }
// Software Initialization: // input parameter: // void : nothing // return type: // int : return SUCCESS int init(void) { // TODO: MESSY int command; double actual; char sensorTempData[5]; initLogging("G44/log"); initCSVFile(); initConfigFile(); if (extern_argc != 2) { logging(WARN, "Error running software!, Mismatch number of argument!!!"); logging(WARN, "E.g run as follow: ./climateControlSoftware 22.5"); logging(WARN, "Terminating program.........."); logging(ERROR, "Terminating program..........Done"); } logging(INFO, "Initializing Climate Control Software...."); sleep(1); logging(INFO, "Initializing Climate Control Software....Done"); sleep(1); logging(INFO, "Checking sensor device file...."); sleep(1); logging(INFO, "Openning /dev/temp_sensor...."); FILE* file = openFile("/dev/temp_sensor", "r"); readData("/dev/temp_sensor", sensorTempData); actual = (double) atof(sensorTempData)/ 1000; sleep(1); //logging(INFO, "Initializing Climate Control Software....Done"); printf("Current sensor data is.... %.2f°C\n", actual); sleep(1); fclose(file); logging(INFO, "Checking sensor device file....Done"); sleep(1); logging(INFO, "Checking knob device file...."); sleep(1); logging(INFO, "Openning /dev/temp_knob...."); file = openFile("/dev/temp_knob", "r"); command = map(actual); sleep(1); //logging(INFO, "Initializing Climate Control Software....Done"); printf("Current knob level is.... %d\n", command); sleep(1); fclose(file); logging(INFO, "Checking knob device file....Done"); sleep(1); logging(INFO, "The PID Controller will start in 5 seconds....."); sleep(5); logging(INFO, "The PID Controller will start in 5 seconds.....Done"); return SUCCESS; }
void ConfigManager::initConfig() { try { configMap = loadConfigMap(configFilePath); } catch (...) { // if we can't parse the document, throw the values out FBLOG_WARN("ConfigManager", "Could not read document from " << configFilePath); initConfigFile(); } }
/** \brief A demo task to show the use of the SPI. */ static void spiTask(void* unused) { INT8U i; dn_error_t dnErr; INT8U osErr; dn_spi_open_args_t spiOpenArgs; INT8U sendStatus; INT8U pkBuf[sizeof(loc_sendtoNW_t) + APP_DATA_BUF_SIZE]; loc_sendtoNW_t* pkToSend; dn_ioctl_spi_transfer_t spiTransfer; //===== initialize the configuration file initConfigFile(); //===== initialize packet variables pkToSend = (loc_sendtoNW_t*)pkBuf; //===== initialize SPI // open the SPI device spiOpenArgs.maxTransactionLenForCPHA_1 = 0; dnErr = dn_open( DN_SPI_DEV_ID, &spiOpenArgs, sizeof(spiOpenArgs) ); if ((dnErr < DN_ERR_NONE) && (dnErr != DN_ERR_STATE)) { dnm_cli_printf("unable to open SPI device, error %d\n\r",dnErr); } // initialize spi communication parameters spiTransfer.txData = spiNetApp_vars.spiTxBuffer; spiTransfer.rxData = spiNetApp_vars.spiRxBuffer; spiTransfer.transactionLen = sizeof(spiNetApp_vars.spiTxBuffer); spiTransfer.numSamples = 1; spiTransfer.startDelay = 0; spiTransfer.clockPolarity = DN_SPI_CPOL_0; spiTransfer.clockPhase = DN_SPI_CPHA_0; spiTransfer.bitOrder = DN_SPI_MSB_FIRST; spiTransfer.slaveSelect = DN_SPI_SSn0; spiTransfer.clockDivider = DN_SPI_CLKDIV_16; //===== wait for the mote to have joined OSSemPend(spiNetApp_vars.joinedSem,0,&osErr); ASSERT(osErr == OS_ERR_NONE); while(1) { // this is a task, it executes forever //===== step 1. write over SPI // set bytes to send for (i=0;i<sizeof(spiNetApp_vars.spiTxBuffer);i++) { spiNetApp_vars.spiTxBuffer[i] = i; } // send bytes dnErr = dn_ioctl( DN_SPI_DEV_ID, DN_IOCTL_SPI_TRANSFER, &spiTransfer, sizeof(spiTransfer) ); if (dnErr < DN_ERR_NONE) { dnm_cli_printf("Unable to communicate over SPI, err=%d\r\n",dnErr); } //===== step 2. print over CLI dnm_cli_printf("SPI sent: "); for (i=0;i<sizeof(spiNetApp_vars.spiTxBuffer);i++) { dnm_cli_printf(" %02x",spiNetApp_vars.spiTxBuffer[i]); } dnm_cli_printf("\r\n"); dnm_cli_printf("SPI received:"); for (i=0;i<sizeof(spiNetApp_vars.spiRxBuffer);i++) { dnm_cli_printf(" %02x",spiNetApp_vars.spiRxBuffer[i]); } dnm_cli_printf("\r\n"); //===== step 3. send data to manager // fill in packet "header" // Note: sendto->header is filled in dnm_loc_sendtoCmd pkToSend->locSendTo.socketId = loc_getSocketId(); pkToSend->locSendTo.destAddr = DN_MGR_IPV6_MULTICAST_ADDR; // IPv6 address pkToSend->locSendTo.destPort = WKP_SPI_NET; pkToSend->locSendTo.serviceType = DN_API_SERVICE_TYPE_BW; pkToSend->locSendTo.priority = DN_API_PRIORITY_MED; pkToSend->locSendTo.packetId = 0xFFFF; // fill in the packet payload memcpy(&pkToSend->locSendTo.payload[0],&spiNetApp_vars.spiRxBuffer[0],APP_DATA_BUF_SIZE); // send the packet dnErr = dnm_loc_sendtoCmd(pkToSend, APP_DATA_BUF_SIZE, &sendStatus); ASSERT (dnErr == DN_ERR_NONE); //===== step 4. pause until next iteration // this call blocks the task until the specified timeout expires (in ms) OSTimeDly(spiNetApp_vars.period); } }