void ySafeTrace(const char *file,u32 line,void *ptr) { u32 i; YMEM_ENTRY *entry; yEnterCriticalSection(&yMapCS); for(i=0, entry=yMap; i< yMapUsed ; i++,entry++){ YASSERT(entry->state != YMEM_NOT_USED); if(entry->ptr == ptr) break; } if(i == yMapUsed){ dbglog("Update trace of unallocated pointer 0x%x at %s:%d\n\n",ptr,file,line); ymemdump(); YASSERT(0); } if(entry->state == YMEM_FREED){ dbglog("Update trace of allready freed pointer (0x%x) at %s:%d\n",ptr,file,line); dbglog("was allocated at %s:%d size =%d freed at %s:%d\n\n", entry->malloc_file, entry->malloc_line, entry->malloc_size, entry->free_file,entry->free_line); ymemdump(); YASSERT(0); } ymemdumpentry(entry,"trace"); entry->malloc_file = file; entry->malloc_line = line; yLeaveCriticalSection(&yMapCS); }
//return 0 if a read is still pending int yyyReadIdle(yInterfaceSt *iface,char *errmsg) { yEnterCriticalSection(&iface->yyyCS); if(iface->devref==NULL){ yLeaveCriticalSection(&iface->yyyCS); return YERR(YAPI_DEVICE_NOT_FOUND); } yLeaveCriticalSection(&iface->yyyCS); return YAPI_SUCCESS; }
void ySafeMemoryInit(u32 nbentry) { YASSERT(yMap==NULL && yMapSize==0); yInitializeCriticalSection(&yMapCS); yEnterCriticalSection(&yMapCS); yMap = malloc(nbentry *sizeof(YMEM_ENTRY)); if(yMap){ yMapSize = nbentry; memset(yMap,0,nbentry *sizeof(YMEM_ENTRY)); yMapUsed=0; } yLeaveCriticalSection(&yMapCS); }
/** * Changes the primary unit for measuring humidity. That unit is a string. * If that strings starts with the letter 'g', the primary measured value is the absolute * humidity, in g/m3. Otherwise, the primary measured value will be the relative humidity * (RH), in per cents. * * Remember to call the saveToFlash() method of the module if the modification * must be kept. * * @param newval : a string corresponding to the primary unit for measuring humidity * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YHumidity::set_unit(const string& newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { rest_val = newval; res = _setAttr("unit", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the PWM duty cycle at device power on. Remember to call the matching * module saveToFlash() method, otherwise this call will have no effect. * * @param newval : a floating point number corresponding to the PWM duty cycle at device power on * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YPwmOutput::set_dutyCycleAtPowerOn(double newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%" FMTs64, (s64)floor(newval * 65536.0 + 0.5)); rest_val = string(buf); res = _setAttr("dutyCycleAtPowerOn", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the state of the PWM at device power on. Remember to call the matching module saveToFlash() * method, otherwise this call will have no effect. * * @param newval : either Y_ENABLEDATPOWERON_FALSE or Y_ENABLEDATPOWERON_TRUE, according to the state * of the PWM at device power on * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YPwmOutput::set_enabledAtPowerOn(Y_ENABLEDATPOWERON_enum newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { rest_val = (newval>0 ? "1" : "0"); res = _setAttr("enabledAtPowerOn", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
static void Handle_IOHIDDeviceIOHIDReportCallback( void * inContext, // context from IOHIDDeviceRegisterInputReportCallback IOReturn inResult, // completion result for the input report operation void * inSender, // IOHIDDeviceRef of the device this report is from IOHIDReportType inType, // the report type uint32_t inReportID, // the report ID uint8_t * inReport, // pointer to the report data CFIndex InReportLength) // the actual size of the input report { yInterfaceSt *iface= (yInterfaceSt*) inContext; yEnterCriticalSection(&iface->yyyCS); yyPushNewPkt(iface,&iface->tmprxpkt); memset(&iface->tmprxpkt,0xff,sizeof(USB_Packet)); yLeaveCriticalSection(&iface->yyyCS); }
/** * Changes the current expected position of the quadrature decoder. * Invoking this function implicitely activates the quadrature decoder. * * @param newval : a floating point number corresponding to the current expected position of the quadrature decoder * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YQuadratureDecoder::set_currentValue(double newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%" FMTs64, (s64)floor(newval * 65536.0 + 0.5)); rest_val = string(buf); res = _setAttr("currentValue", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the activation state of the quadrature decoder. * * @param newval : either Y_DECODING_OFF or Y_DECODING_ON, according to the activation state of the * quadrature decoder * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YQuadratureDecoder::set_decoding(Y_DECODING_enum newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { rest_val = (newval>0 ? "1" : "0"); res = _setAttr("decoding", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the electric signal sampling method to use. * The HIGH_RATE method uses the highest sampling frequency, without any filtering. * The HIGH_RATE_FILTERED method adds a windowed 7-sample median filter. * The LOW_NOISE method uses a reduced acquisition frequency to reduce noise. * The LOW_NOISE_FILTERED method combines a reduced frequency with the median filter * to get measures as stable as possible when working on a noisy signal. * * @param newval : a value among Y_SIGNALSAMPLING_HIGH_RATE, Y_SIGNALSAMPLING_HIGH_RATE_FILTERED, * Y_SIGNALSAMPLING_LOW_NOISE, Y_SIGNALSAMPLING_LOW_NOISE_FILTERED and Y_SIGNALSAMPLING_HIGHEST_RATE * corresponding to the electric signal sampling method to use * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YGenericSensor::set_signalSampling(Y_SIGNALSAMPLING_enum newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf); res = _setAttr("signalSampling", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Preset the state of the watchdog at device startup (A for the idle position, * B for the active position, UNCHANGED for no modification). Remember to call the matching module saveToFlash() * method, otherwise this call will have no effect. * * @param newval : a value among Y_STATEATPOWERON_UNCHANGED, Y_STATEATPOWERON_A and Y_STATEATPOWERON_B * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YWatchdog::set_stateAtPowerOn(Y_STATEATPOWERON_enum newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf); res = _setAttr("stateAtPowerOn", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the loop current at device start up. Remember to call the matching * module saveToFlash() method, otherwise this call has no effect. * * @param newval : a floating point number corresponding to the loop current at device start up * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YCurrentLoopOutput::set_currentAtStartUp(double newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%" FMTs64, (s64)floor(newval * 65536.0 + 0.5)); rest_val = string(buf); res = _setAttr("currentAtStartUp", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the sensibility for the input (between 1 and 1000) for triggering user callbacks. * The sensibility is used to filter variations around a fixed value, but does not preclude the * transmission of events when the input value evolves constantly in the same direction. * Special case: when the value 1000 is used, the callback will only be thrown when the logical state * of the input switches from pressed to released and back. * Remember to call the saveToFlash() method of the module if the modification must be kept. * * @param newval : an integer corresponding to the sensibility for the input (between 1 and 1000) for * triggering user callbacks * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YAnButton::set_sensitivity(int newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf); res = _setAttr("sensitivity", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the physical value range measured by the sensor. As a side effect, the range modification may * automatically modify the display resolution. Default value is "-999999.999...999999.999". * * @param newval : a string corresponding to the physical value range measured by the sensor * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YGenericSensor::set_valueRange(const string& newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { rest_val = newval; res = _setAttr("valueRange", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the number of seconds between current time and UTC time (time zone). * The timezone is automatically rounded to the nearest multiple of 15 minutes. * * @param newval : an integer corresponding to the number of seconds between current time and UTC time (time zone) * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YRealTimeClock::set_utcOffset(int newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf); res = _setAttr("utcOffset", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
int YCurrentLoopOutput::set_currentTransition(const string& newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { rest_val = newval; res = _setAttr("currentTransition", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
int YGps::set_command(const string& newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { rest_val = newval; res = _setAttr("command", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the current time. Time is specifid in Unix format (number of elapsed seconds since Jan 1st, 1970). * * @param newval : an integer corresponding to the current time * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YRealTimeClock::set_unixTime(s64 newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%u", (u32)newval); rest_val = string(buf); res = _setAttr("unixTime", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the number of child nodes expected in normal conditions. * If the value is zero, no check is performed. If it is non-zero, the number * child nodes is checked on startup and the status will change to error if * the count does not match. * * @param newval : an integer corresponding to the number of child nodes expected in normal conditions * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YDaisyChain::set_requiredChildCount(int newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf); res = _setAttr("requiredChildCount", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the representation system used for positioning data. * * @param newval : a value among Y_COORDSYSTEM_GPS_DMS, Y_COORDSYSTEM_GPS_DM and Y_COORDSYSTEM_GPS_D * corresponding to the representation system used for positioning data * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YGps::set_coordSystem(Y_COORDSYSTEM_enum newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf); res = _setAttr("coordSystem", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the duration of resets caused by the watchdog, in milliseconds. * * @param newval : an integer corresponding to the duration of resets caused by the watchdog, in milliseconds * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YWatchdog::set_triggerDuration(s64 newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%u", (u32)newval); rest_val = string(buf); res = _setAttr("triggerDuration", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
int YAnButton::set_pulseCounter(s64 newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%u", (u32)newval); rest_val = string(buf); res = _setAttr("pulseCounter", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Starts or stops the calibration process. Remember to call the saveToFlash() * method of the module at the end of the calibration if the modification must be kept. * * @param newval : either Y_ANALOGCALIBRATION_OFF or Y_ANALOGCALIBRATION_ON * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YAnButton::set_analogCalibration(Y_ANALOGCALIBRATION_enum newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { rest_val = (newval>0 ? "1" : "0"); res = _setAttr("analogCalibration", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the running state of the watchdog. * * @param newval : either Y_RUNNING_OFF or Y_RUNNING_ON, according to the running state of the watchdog * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YWatchdog::set_running(Y_RUNNING_enum newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { rest_val = (newval>0 ? "1" : "0"); res = _setAttr("running", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the watchdog running state at module power on. Remember to call the * saveToFlash() method and then to reboot the module to apply this setting. * * @param newval : either Y_AUTOSTART_OFF or Y_AUTOSTART_ON, according to the watchdog running state * at module power on * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YWatchdog::set_autoStart(Y_AUTOSTART_enum newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { rest_val = (newval>0 ? "1" : "0"); res = _setAttr("autoStart", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
int YWatchdog::set_delayedPulseTimer(YDelayedPulse newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buff[64]; sprintf(buff,"%d:%d",newval.target,newval.ms); rest_val = string(buff); res = _setAttr("delayedPulseTimer", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
/** * Changes the electric signal bias for zero shift adjustment. * If your electric signal reads positive when it should be zero, setup * a positive signalBias of the same value to fix the zero shift. * * @param newval : a floating point number corresponding to the electric signal bias for zero shift adjustment * * @return YAPI_SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ int YGenericSensor::set_signalBias(double newval) { string rest_val; int res; yEnterCriticalSection(&_this_cs); try { char buf[32]; sprintf(buf, "%" FMTs64, (s64)floor(newval * 65536.0 + 0.5)); rest_val = string(buf); res = _setAttr("signalBias", rest_val); } catch (std::exception) { yLeaveCriticalSection(&_this_cs); throw; } yLeaveCriticalSection(&_this_cs); return res; }
void ySafeMemoryDump(void *discard) { u32 i; YMEM_ENTRY *entry; yEnterCriticalSection(&yMapCS); for(i=0, entry=yMap; i< yMapUsed ; i++,entry++){ if(entry->state == YMEM_MALLOCED && entry->ptr!=discard){ break; } } if(i< yMapUsed){ ymemdump(); } yLeaveCriticalSection(&yMapCS); }
void *ySafeMalloc(const char *file,u32 line,u32 size) { u32 i; YMEM_ENTRY *entry; void *ptr; yEnterCriticalSection(&yMapCS); if(yMapUsed < yMapSize){ //use a new one entry=yMap+yMapUsed; }else{ // find a freed entry for(i=0; i< yMapSize;i++){ if(yMap[i].state == YMEM_FREED) break; } if(i==yMapSize){ dbglog("No more entry available for ySafeMalloc\n\n"); ymemdump(); yLeaveCriticalSection(&yMapCS); return NULL; } entry = yMap+i; } ptr=malloc(size); if(!ptr){ dbglog("No more memory available (unable to allocate %d bytes)\n\n",size); ymemdump(); yLeaveCriticalSection(&yMapCS); return NULL; } memset(entry,0,sizeof(YMEM_ENTRY)); entry->state = YMEM_MALLOCED; entry->malloc_file = file; entry->malloc_line = line; entry->ptr = ptr; entry->malloc_size = size; if(yMapUsed < yMapSize) yMapUsed++; yLeaveCriticalSection(&yMapCS); return ptr; }
void yyyPacketShutdown(yInterfaceSt *iface) { yEnterCriticalSection(&iface->yyyCS); if(iface->devref!=NULL){ IOHIDDeviceRegisterInputReportCallback( iface->devref, // IOHIDDeviceRef for the HID device (u8*) &iface->tmprxpkt, // pointer to the report data (uint8_t's) USB_PKT_SIZE, // number of bytes in the report (CFIndex) NULL, // the callback routine iface); // context passed to callback IOHIDDeviceClose(iface->devref, kIOHIDOptionsTypeNone); iface->devref=NULL; } yLeaveCriticalSection(&iface->yyyCS); yDeleteCriticalSection(&iface->yyyCS); yyyFreePktQueue(iface); }