void DeviceConfig::load(DataNode *node) { busy_lock.lock(); if (node->hasAnother("name")) { deviceName = node->getNext("name")->element()->toString(); } if (node->hasAnother("ppm")) { DataNode *ppm_node = node->getNext("ppm"); int ppmValue = 0; ppm_node->element()->get(ppmValue); setPPM(ppmValue); std::cout << "Loaded PPM for device '" << deviceId << "' at " << ppmValue << "ppm" << std::endl; } if (node->hasAnother("offset")) { DataNode *offset_node = node->getNext("offset"); long long offsetValue = 0; offset_node->element()->get(offsetValue); setOffset(offsetValue); std::cout << "Loaded offset for device '" << deviceId << "' at " << offsetValue << "Hz" << std::endl; } if (node->hasAnother("streamOpts")) { DataNode *streamOptsNode = node->getNext("streamOpts"); for (int i = 0, iMax = streamOptsNode->numChildren(); i<iMax; i++) { DataNode *streamOptNode = streamOptsNode->child(i); std::string keyName = streamOptNode->getName(); std::string strSettingValue = streamOptNode->element()->toString(); if (keyName != "") { setStreamOpt(keyName, strSettingValue); } } } if (node->hasAnother("settings")) { DataNode *settingsNode = node->getNext("settings"); for (int i = 0, iMax = settingsNode->numChildren(); i<iMax; i++) { DataNode *settingNode = settingsNode->child(i); std::string keyName = settingNode->getName(); std::string strSettingValue = settingNode->element()->toString(); if (keyName != "") { setSetting(keyName, strSettingValue); } } } if (node->hasAnother("rig_ifs")) { DataNode *rigIFNodes = node->getNext("rig_ifs"); while (rigIFNodes->hasAnother("rig_if")) { DataNode *rigIFNode = rigIFNodes->getNext("rig_if"); if (rigIFNode->hasAnother("model") && rigIFNode->hasAnother("sdr_if")) { int load_model; long long load_freq; rigIFNode->getNext("model")->element()->get(load_model); rigIFNode->getNext("sdr_if")->element()->get(load_freq); rigIF[load_model] = load_freq; } } } busy_lock.unlock(); }
void DataNode::releaseDependencyList(){ DataNode* iNode = this; while (iNode != 0){ DataNode* tmp = iNode->getNext(); delete iNode; iNode = tmp; } }
static void mdlTerminate(SimStruct *S) { rtsys = (RTsys*) ssGetUserData(S); if (rtsys == NULL) { return; } if (rtsys->taskList != NULL) { // write logs to the MATLAB workspace DataNode *dn = (DataNode*) rtsys->taskList->getFirst(); while (dn != NULL) { UserTask *task = (UserTask*) dn->data; for (int j=0; j<NBRLOGS; j++) { Log *log = task->logs[j]; if (log) { // printf("Dumping log %d for task %s\n", j, task->name); mxArray *ptr = mxCreateDoubleMatrix(log->entries, 1, mxREAL); for (int n=0; n<log->entries; n++) { mxGetPr(ptr)[n] = log->vals[n]; } mexMakeArrayPersistent(ptr); mexPutVariable("base",log->variable,ptr); } } dn = (DataNode*) dn->getNext(); } } #ifdef KERNEL_MATLAB if (!destroyed) { mxDestroyArray(segArray); destroyed = true; } #else cleanup(); #endif // Delete rtsys and all data structures within delete rtsys; #ifdef KERNEL_MATLAB mxArray* rhs[2]; rhs[0] = mxCreateString("global"); rhs[1] = mxCreateString("_rtsys"); mexCallMATLAB(0, NULL, 2, rhs, "clear"); #endif }
DataNode *getNode(const char *name, List* list) { DataNode* n; if (strcmp(name, "")==0) { return NULL; } n = (DataNode*) list->getFirst(); while (n != NULL) { if (n->name != NULL) { if (strcmp(n->name, name) == 0) break; } n = (DataNode*) n->getNext(); } if (n == NULL) { return NULL; } else { return n; } }
double hellocode(int seg, void* data) { Hello_Data *d = (Hello_Data*) data; int activeroute = 0; int k, m, n; double now; double period; HelloMsg *hellomsg; GenericNwkMsg *nwkmsg; RERRMsg *rerrmsg; DataNode *dn; DataNode *tmp; switch (seg) { case 1: now = ttCurrentTime(); if (VERBOSE) { mexPrintf("Time: %f Node#%d running periodic HELLO task\n", now, d->nodeID); } // Determine if any active routes exist for (k=0; k<NBR_AODV; k++) { if (d->routing_table[k].valid) { activeroute = 1; } } period = ttGetPeriod(); if (activeroute && (d->lastRREQ < now - period)) { if (VERBOSE) { mexPrintf("Broadcasting HELLO msg\n"); } hellomsg = new HelloMsg; hellomsg->hopCnt = 0; hellomsg->dest = d->nodeID; hellomsg->destSeqNbr = d->seqNbrs[d->nodeID]; hellomsg->src = 0; hellomsg->lifetime = DELETE_PERIOD; nwkmsg = new GenericNwkMsg; nwkmsg->type = HELLO; nwkmsg->intermed = d->nodeID; nwkmsg->msg = hellomsg; ttSendMsg(1, 0, nwkmsg, 24); } // Determine local connectivity for (k=0; k<NBR_AODV; k++) { if (d->nbors[k]) { // Node k is a neighbor if (now - d->lastHello[k] > DELETE_PERIOD) { mexPrintf("Node#%d lost connection to Node#%d\n", d->nodeID, k+1); d->nbors[k] = 0; // remove from neighbor list // Send RERRs for (m=0; m<NBR_AODV; m++) { // Find routes that use node k as next hop if (d->routing_table[m].valid) { if (d->routing_table[m].nextHop == k+1) { // Should send RERR to all nodes in precursor list for (n=0; n<NBR_AODV; n++) { if (d->routing_table[m].prec[n]) { // Node n uses this node as next hop towards node k rerrmsg = new RERRMsg; rerrmsg->dest = m + 1; rerrmsg->destSeqNbr = d->routing_table[m].destSeqNbr; rerrmsg->receiver = n + 1; d->RERRlist->appendNode(new DataNode(rerrmsg, "")); } } // Invalidate route if (VERBOSE) { mexPrintf("Node#%d invalidating route to Node#%d through unreachable Node#%d\n", d->nodeID, m+1, k+1); } d->routing_table[m].valid = 0; } } } } } } return 0.0001;; case 2: ttSleep(0.001); return 0.0001; case 3: // Send all RERRs dn = (DataNode*) d->RERRlist->getFirst(); if (dn != NULL) { rerrmsg = (RERRMsg*) dn->data; nwkmsg = new GenericNwkMsg; nwkmsg->type = RERR; nwkmsg->intermed = d->nodeID; nwkmsg->msg = rerrmsg; ttSendMsg(1, rerrmsg->receiver, nwkmsg, 12); tmp = dn; dn = (DataNode*) dn->getNext(); tmp->remove(); delete tmp; ttSleep(0.001); return 0.0001; } else { return FINISHED; } case 4: ttSetNextSegment(3); return 0.0001; } return FINISHED; // to supress compilation warnings }
void ttCreateTimeTriggeredDispatcher(const char *name, double Ts, double *tSeq, int size) { char errbuf[MAXERRBUF]; UserTask *userTask; DataNode *dn; TimeTriggeredDispatcher *dispatcher, *ndispatcher; if (strcmp(name,"") == 0) { TT_MEX_ERROR("ttCreateTimeTriggeredDispatcher: Name should be a non-empty string!"); return; } if (rtsys->prioFcn == NULL) { TT_MEX_ERROR("ttCreateTimeTriggeredDispatcher: Kernel must be initialized before creation of TT Dispatcher!"); return; } dn = getNode(name, rtsys->ttdispList); if (dn!=NULL) { TT_MEX_ERROR("ttCreateTimeTriggeredDispatcher: Name of TimeTriggeredDispatcher Object not unique!"); return; } // Check for invalid task identifiers for(int i = 0;i<size;i++) { if((int)*(tSeq+i)>0) { bool taskFound = false; dn = (DataNode*) rtsys->taskList->getFirst(); while (dn != NULL) { userTask = (UserTask*) dn->data; if (userTask->taskIdentifier == (int)*(tSeq+i)) // task idenifiers match { taskFound = true; break; } dn = (DataNode*) dn->getNext(); } if (!taskFound) { snprintf(errbuf, MAXERRBUF, "Task identifier %d not found!", (int)*(tSeq+i)); TT_MEX_ERROR(errbuf); return; } } else if ((int)*(tSeq+i)<0) { TT_MEX_ERROR("Task identifiers must be greater than 0. No negative integers allowed."); return; } } dispatcher = new TimeTriggeredDispatcher(name,Ts,tSeq,size); rtsys->ttdispList->appendNode(new DataNode(dispatcher, dispatcher->name)); // Create time-triggered handler and timer to activate dispatcher at the slot boundaries InterruptHandler *hdl = new InterruptHandler("ttdispatcher"); hdl->codeFcn = ttDispatcherCodeFcn; hdl->priority = -1000.0; hdl->display = false; hdl->nonpreemptible = true; hdl->data = (void *)dispatcher; Timer *timer = new Timer("ttdispatcher"); timer->period = Ts; timer->isPeriodic = true; timer->isOverrunTimer = true; // = do not delete after expiry timer->task = hdl; dispatcher->slotTimer = timer; // Schedule dispatcher timer at start dispatcher->slotTimer->time = 0.0; dispatcher->slotTimer->moveToList(rtsys->timeQ); // Attach tasks defined in the table to the dispatcher dn = (DataNode*) rtsys->taskList->getFirst(); while (dn != NULL) { userTask = (UserTask*) dn->data; for(int i = 0;i<size;i++) { if((int)*(tSeq+i) == userTask->taskIdentifier) { ttAttachTimeTriggeredDispatcher(userTask->name, name); //sprintf(errbuf, "disp(\'Task %s attached to TTdispatcher\')", userTask->name); //mexEvalString(errbuf); break; } } dn = (DataNode*) dn->getNext(); } // Make sure that existing TTDispatchers have no overlapping with current dispatcher dn = (DataNode*) rtsys->ttdispList->getFirst(); while (dn != NULL) { ndispatcher = (TimeTriggeredDispatcher*) dn->data; if (ndispatcher->affinity == dispatcher->affinity && dispatcher != ndispatcher) { if (ndispatcher->schedulingTable.size() != size) { TT_MEX_ERROR("All TTDispatchers must have same scheduling table lengths! Check for hyperperiod of the dispatchers will be implemented in the next version."); return; } if (fabs(ndispatcher->slotLength - Ts) > 0.0000000001f) { TT_MEX_ERROR("All TTDispatchers must have same slot lengths."); return; } for (unsigned slotIter = 0; slotIter < size; slotIter++) { if ((int)*(tSeq+slotIter) > 0 && ndispatcher->schedulingTable[slotIter] > 0) { TT_MEX_ERROR("Two tasks can not execute on a single processor at the same time."); return; } } } dn = (DataNode*) dn->getNext(); } }
static void mdlOutputs(SimStruct *S, int_T tid) { //printf("mdlOutputs at %g\n", ssGetT(S)); rtsys = (RTsys*) ssGetUserData(S); if (rtsys->init_phase) { /* Failure during initialization */ return; } real_T *y = ssGetOutputPortRealSignal(S,0); real_T *n = ssGetOutputPortRealSignal(S,1); real_T *s = ssGetOutputPortRealSignal(S,2); real_T *m = ssGetOutputPortRealSignal(S,3); real_T *energyConsumption = ssGetOutputPortRealSignal(S,4); int i, j, k, detected; double dTime; DataNode *dn; Task* task; UserTask* t; InterruptHandler* hdl; Monitor *mon; if (!rtsys->started && ssGetT(S) == 0.0) { rtsys->started = true; return; } if (!rtsys->mdlzerocalled) { printf("Zero crossing detection must be turned on in order to run TrueTime!\n"); ssSetErrorStatus(S, "Zero crossing detection must be turned on in order to run TrueTime!"); return; } /* Storing the time */ rtsys->time = ssGetT(S) * rtsys->clockDrift + rtsys->clockOffset; detected = 0; /* Check interrupts */ i = 0; dn = (DataNode*) rtsys->triggerList->getFirst(); while (dn != NULL) { if (fabs(rtsys->interruptinputs[i]-rtsys->oldinterruptinputs[i]) > 0.1) { hdl = (InterruptHandler*) dn->data; Trigger* trig = hdl->trigger; if (rtsys->time - trig->prevHit > trig->latency) { // Trigger interrupt handler if (hdl->myList == rtsys->readyQ) { // handler serving older interrupts hdl->pending++; } else { hdl->moveToList(rtsys->readyQ); detected = 1; } trig->prevHit = rtsys->time; } else { //printf("Call to interrupt handler %s ignored at time %f. Within interrupt latency!\n", hdl->name, rtsys->time); } rtsys->oldinterruptinputs[i] = rtsys->interruptinputs[i]; } i++; dn = (DataNode*) dn->getNext(); } /* Check network */ dn = (DataNode*) rtsys->networkList->getFirst(); while (dn != NULL) { hdl = (InterruptHandler*) dn->data; Network* network = hdl->network; i = network->networkID - 1; //printf("mdlOutputs: checking network #%d inp: %d oldinp: %d\n",i,rtsys->networkinputs[i],rtsys->oldnetworkinputs[i]); if (fabs(rtsys->networkinputs[i] - rtsys->oldnetworkinputs[i]) > 0.1) { hdl->moveToList(rtsys->readyQ); detected = 1; rtsys->oldnetworkinputs[i] = rtsys->networkinputs[i]; } dn = (DataNode*) dn->getNext(); } /* Run kernel? */ double externTime = (rtsys->time- rtsys->clockOffset) / rtsys->clockDrift; if ((externTime >= rtsys->nextHit) || (detected > 0)) { dTime = runKernel(ssGetT(S)); if (rtsys->error) { // Something went wrong executing a code function mxArray *bn[1]; mexCallMATLAB(1, bn, 0, 0, "gcs"); // get current system char buf[200]; mxGetString(bn[0], buf, 200); for (unsigned int i=0; i<strlen(buf); i++) if (buf[i]=='\n') buf[i]=' '; printf("In block ==> '%s'\nSimulation aborted!\n", buf); ssSetStopRequested(S, 1); } else { rtsys->nextHit = (rtsys->time + dTime - rtsys->clockOffset) / rtsys->clockDrift; } } /* Outputs */ for (i=0; i<rtsys->nbrOfOutputs; i++) { y[i] = rtsys->outputs[i]; } /* Network send */ for (i=0; i<rtsys->nbrOfNetworks; i++) { n[i] = rtsys->nwSnd[i]; } /* Task schedule */ i = 0; j = 0; dn = (DataNode*) rtsys->taskList->getFirst(); while (dn != NULL) { t = (UserTask*) dn->data; rtsys->taskSched[i] = (double) (j+1); if (t->display) j++; dn = (DataNode*) dn->getNext(); i++; } task = (Task*) rtsys->readyQ->getFirst(); while (task != NULL) { if (task->isUserTask()) { t = (UserTask*) task; rtsys->taskSched[t->taskID - 1] += 0.25; } task = (Task*) task->getNext(); } if ((rtsys->running != NULL) && (rtsys->running->isUserTask())) { t = (UserTask*) rtsys->running; rtsys->taskSched[t->taskID - 1] += 0.25; } i = 0; j = 0; dn = (DataNode*) rtsys->taskList->getFirst(); while (dn != NULL) { t = (UserTask*) dn->data; if (t->display) { s[j] = rtsys->taskSched[i]; j++; } dn = (DataNode*) dn->getNext(); i++; } /* Handler schedule */ i = 0; j = 0; dn = (DataNode*) rtsys->handlerList->getFirst(); while (dn != NULL) { rtsys->handlerSched[i] = (double) (j+rtsys->nbrOfSchedTasks+2); if (i==0 && rtsys->contextSwitchTime > EPS) { // Context switch schedule, move graph down to task level rtsys->handlerSched[i] = rtsys->handlerSched[i] - 1; } hdl = (InterruptHandler*) dn->data; if (hdl->display) j++; dn = (DataNode*) dn->getNext(); i++; } task = (Task*) rtsys->readyQ->getFirst(); while (task != NULL) { if (!(task->isUserTask())) { hdl = (InterruptHandler*) task; rtsys->handlerSched[hdl->handlerID - 1] += 0.25; } task = (Task*) task->getNext(); } if ((rtsys->running != NULL) && (!(rtsys->running->isUserTask()))) { hdl = (InterruptHandler*) rtsys->running; rtsys->handlerSched[hdl->handlerID - 1] += 0.25; } i = 0; j = 0; dn = (DataNode*) rtsys->handlerList->getFirst(); while (dn != NULL) { hdl = (InterruptHandler*) dn->data; if (hdl->display) { s[j+rtsys->nbrOfSchedTasks] = rtsys->handlerSched[i]; j++; } dn = (DataNode*) dn->getNext(); i++; } /* Monitor graph */ k = 0; dn = (DataNode*) rtsys->monitorList->getFirst(); while (dn != NULL) { mon = (Monitor*) dn->data; for (j=0; j<rtsys->nbrOfTasks; j++) rtsys->monitorGraph[j] = (double) (j+1+k*(1+rtsys->nbrOfTasks)); t = (UserTask*) mon->waitingQ->getFirst(); while (t != NULL) { i = t->taskID; rtsys->monitorGraph[i-1] += 0.25; t = (UserTask*) t->getNext(); } if (mon->heldBy != NULL) { i = mon->heldBy->taskID; rtsys->monitorGraph[i-1] += 0.5; } if (mon->display) { for (j=0; j<rtsys->nbrOfTasks; j++) m[j+k*rtsys->nbrOfTasks] = rtsys->monitorGraph[j]; k++; } dn = (DataNode*) dn->getNext(); } /* Energy consumption */ energyConsumption[0] = rtsys->energyConsumption; }
void DeviceConfig::load(DataNode *node) { std::lock_guard < std::mutex > lock(busy_lock); if (node->hasAnother("name")) { deviceName = node->getNext("name")->element()->toString(); } if (node->hasAnother("ppm")) { DataNode *ppm_node = node->getNext("ppm"); int ppmValue = 0; ppm_node->element()->get(ppmValue); setPPM(ppmValue); } if (node->hasAnother("offset")) { DataNode *offset_node = node->getNext("offset"); long long offsetValue = 0; offset_node->element()->get(offsetValue); setOffset(offsetValue); } if (node->hasAnother("agc_mode")) { DataNode *agc_node = node->getNext("agc_mode"); int agcModeValue = 0; agc_node->element()->get(agcModeValue); setAGCMode(agcModeValue?true:false); } if (node->hasAnother("sample_rate")) { DataNode *sample_rate_node = node->getNext("sample_rate"); long sampleRateValue = 0; sample_rate_node->element()->get(sampleRateValue); setSampleRate(sampleRateValue); } if (node->hasAnother("antenna")) { DataNode *antenna_node = node->getNext("antenna"); std::string antennaNameValue; antenna_node->element()->get(antennaNameValue); setAntennaName(antennaNameValue); } if (node->hasAnother("streamOpts")) { DataNode *streamOptsNode = node->getNext("streamOpts"); for (int i = 0, iMax = streamOptsNode->numChildren(); i<iMax; i++) { DataNode *streamOptNode = streamOptsNode->child(i); std::string keyName = streamOptNode->getName(); std::string strSettingValue = streamOptNode->element()->toString(); if (keyName != "") { setStreamOpt(keyName, strSettingValue); } } } if (node->hasAnother("settings")) { DataNode *settingsNode = node->getNext("settings"); for (int i = 0, iMax = settingsNode->numChildren(); i<iMax; i++) { DataNode *settingNode = settingsNode->child(i); std::string keyName = settingNode->getName(); std::string strSettingValue = settingNode->element()->toString(); if (keyName != "") { setSetting(keyName, strSettingValue); } } } if (node->hasAnother("rig_ifs")) { DataNode *rigIFNodes = node->getNext("rig_ifs"); while (rigIFNodes->hasAnother("rig_if")) { DataNode *rigIFNode = rigIFNodes->getNext("rig_if"); if (rigIFNode->hasAnother("model") && rigIFNode->hasAnother("sdr_if")) { int load_model; long long load_freq; rigIFNode->getNext("model")->element()->get(load_model); rigIFNode->getNext("sdr_if")->element()->get(load_freq); rigIF[load_model] = load_freq; } } } if (node->hasAnother("gains")) { DataNode *gainsNode = node->getNext("gains"); while (gainsNode->hasAnother("gain")) { DataNode *gainNode = gainsNode->getNext("gain"); std::string keyName; float fltSettingValue; gainNode->getNext("id")->element()->get(keyName); gainNode->getNext("value")->element()->get(fltSettingValue); if (keyName != "" && !(fltSettingValue!=fltSettingValue)) { setGain(keyName, fltSettingValue); } } } }
static void mdlOutputs(SimStruct *S, int_T tid) { debugPrintf("'%s': mdlOutputs at %.16f\n", rtsys->blockName, ssGetT(S)); rtsys = (RTsys*) ssGetUserData(S); if (rtsys->init_phase) { /* Failure during initialization */ return; } real_T *y = ssGetOutputPortRealSignal(S,0); real_T *n = ssGetOutputPortRealSignal(S,1); real_T *s = ssGetOutputPortRealSignal(S,2); real_T *e = ssGetOutputPortRealSignal(S,3); int i, shouldRunKernel = 0; double timestep; DataNode *dn; UserTask* t; InterruptHandler* hdl; if (!rtsys->started && ssGetT(S) == 0.0) { rtsys->started = true; } else { /* Storing the time */ rtsys->time = ssGetT(S) * rtsys->clockDrift + rtsys->clockOffset; shouldRunKernel = 0; /* Run kernel? */ double externTime = (rtsys->time- rtsys->clockOffset) / rtsys->clockDrift; if ((externTime >= rtsys->nextHit) || (shouldRunKernel > 0)) { timestep = runKernel(ssGetT(S)); if (rtsys->error) { mexPrintf("In block ==> '%s'\n", ssGetBlockName(S)); mexPrintf("Simulation aborted!\n"); ssSetErrorStatus(S, errbuf); return; } else { rtsys->nextHit = (rtsys->time + timestep - rtsys->clockOffset) / rtsys->clockDrift; } } } /* Analog outputs */ for (i=0; i<rtsys->nbrOfOutputs; i++) { y[i] = rtsys->outputs[i]; } /* Network send outputs */ for (i=0; i<rtsys->nbrOfNetworks; i++) { n[i] = rtsys->nwSnd[i]; rtsys->oldnwSnd[i] = rtsys->nwSnd[i]; } /* Usertask schedule outputs */ i = 0; dn = (DataNode*) rtsys->taskList->getFirst(); while (dn != NULL) { t = (UserTask*) dn->data; if (t->display) { double val = (double) (i+1); for (int j = 0; j < rtsys->nbrOfCPUs; j++) { s[i + j * rtsys->nbrOfSchedTasks] = val; } if (t->state == RUNNING) { val += 0.5; } else if (t->state == READY) { val += 0.25; } else if (t->state == WAITING) { val += 0.125; } s[i + t->affinity * rtsys->nbrOfSchedTasks] = val; i++; if (i > rtsys->nbrOfSchedTasks) { mexPrintf("FATAL ERROR: schedule output port out of bounds!\n"); ssSetErrorStatus(S, "error"); return; } } dn = (DataNode*) dn->getNext(); } /* Handler schedule outputs */ dn = (DataNode*) rtsys->handlerList->getFirst(); while (dn != NULL) { hdl = (InterruptHandler*) dn->data; if (hdl->display) { double val = (double) (i+1); if (hdl->state == RUNNING) { val += 0.5; } else if (hdl->state == READY) { val += 0.25; } s[i + hdl->affinity * rtsys->nbrOfSchedTasks] = val; i++; if (i > rtsys->nbrOfSchedTasks) { mexPrintf("FATAL ERROR: schedule output port out of bounds!\n"); ssSetErrorStatus(S, "error"); return; } } dn = (DataNode*) dn->getNext(); } /* Energy consumption output */ e[0] = rtsys->energyConsumption; }
static void mdlTerminate(SimStruct *S) { debugPrintf("'%s': mdlTerminate\n", S->path); rtsys = (RTsys*) ssGetUserData(S); if (rtsys == NULL) { return; } // Write task execution logs to the MATLAB workspace if (rtsys->taskList != NULL) { DataNode *dn = (DataNode*) rtsys->taskList->getFirst(); while (dn != NULL) { UserTask *task = (UserTask*) dn->data; for (int j=0; j<NBRLOGS; j++) { Log *log = task->logs[j]; if (log) { mxArray *ptr = mxCreateDoubleMatrix(log->entries, 1, mxREAL); for (int n=0; n<log->entries; n++) { mxGetPr(ptr)[n] = log->vals[n]; } mexMakeArrayPersistent(ptr); mexPutVariable("base",log->variable,ptr); } } dn = (DataNode*) dn->getNext(); } } // Write user-defined logs to the MATLAB workspace if (rtsys->logList != NULL) { DataNode *dn = (DataNode*) rtsys->logList->getFirst(); while (dn != NULL) { Log *log = (Log*) dn->data; mxArray *ptr = mxCreateDoubleMatrix(log->entries, 1, mxREAL); for (int n=0; n<log->entries; n++) { mxGetPr(ptr)[n] = log->vals[n]; } mexMakeArrayPersistent(ptr); mexPutVariable("base",log->variable,ptr); dn = (DataNode*) dn->getNext(); } } #ifdef KERNEL_MATLAB mxDestroyArray(rtsys->segArray); #else cleanup(); #endif // Delete rtsys and all data structures within delete rtsys; #ifdef KERNEL_MATLAB mxArray* rhs[2]; rhs[0] = mxCreateString("global"); rhs[1] = mxCreateString("_rtsys"); mexCallMATLAB(0, NULL, 2, rhs, "clear"); #endif }
bool AppFrame::loadSession(std::string fileName) { DataTree l; if (!l.LoadFromFileXML(fileName)) { return false; } wxGetApp().getDemodMgr().terminateAll(); try { DataNode *header = l.rootNode()->getNext("header"); std::string version(*header->getNext("version")); long long center_freq = *header->getNext("center_freq"); std::cout << "Loading " << version << " session file" << std::endl; std::cout << "\tCenter Frequency: " << center_freq << std::endl; wxGetApp().setFrequency(center_freq); DataNode *demodulators = l.rootNode()->getNext("demodulators"); while (demodulators->hasAnother("demodulator")) { DataNode *demod = demodulators->getNext("demodulator"); if (!demod->hasAnother("bandwidth") || !demod->hasAnother("frequency")) { continue; } long bandwidth = *demod->getNext("bandwidth"); long long freq = *demod->getNext("frequency"); int type = demod->hasAnother("type") ? *demod->getNext("type") : DEMOD_TYPE_FM; float squelch_level = demod->hasAnother("squelch_level") ? (float) *demod->getNext("squelch_level") : 0; int squelch_enabled = demod->hasAnother("squelch_enabled") ? (int) *demod->getNext("squelch_enabled") : 0; int stereo = demod->hasAnother("stereo") ? (int) *demod->getNext("stereo") : 0; std::string output_device = demod->hasAnother("output_device") ? string(*(demod->getNext("output_device"))) : ""; float gain = demod->hasAnother("gain") ? (float) *demod->getNext("gain") : 1.0; DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().newThread(); newDemod->setDemodulatorType(type); newDemod->setBandwidth(bandwidth); newDemod->setFrequency(freq); newDemod->setGain(gain); newDemod->updateLabel(freq); if (squelch_enabled) { newDemod->setSquelchEnabled(true); newDemod->setSquelchLevel(squelch_level); } if (stereo) { newDemod->setStereo(true); } bool found_device = false; std::map<int, RtAudio::DeviceInfo>::iterator i; for (i = outputDevices.begin(); i != outputDevices.end(); i++) { if (i->second.name == output_device) { newDemod->setOutputDevice(i->first); found_device = true; } } if (!found_device) { std::cout << "\tWarning: named output device '" << output_device << "' was not found. Using default output."; } newDemod->run(); newDemod->setActive(false); wxGetApp().bindDemodulator(newDemod); std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl; std::cout << "\t\tBandwidth: " << bandwidth << std::endl; std::cout << "\t\tSquelch Level: " << squelch_level << std::endl; std::cout << "\t\tSquelch Enabled: " << (squelch_enabled ? "true" : "false") << std::endl; std::cout << "\t\tStereo: " << (stereo ? "true" : "false") << std::endl; std::cout << "\t\tOutput Device: " << output_device << std::endl; } } catch (DataInvalidChildException &e) { std::cout << e.what() << std::endl; return false; } catch (DataTypeMismatchException &e) { std::cout << e.what() << std::endl; return false; } currentSessionFile = fileName; std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator) + 1); GetStatusBar()->SetStatusText(wxString::Format(wxT("Loaded session file: %s"), currentSessionFile.c_str())); SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str())); return true; }