void NCD32Relay::turnOffAllRelays(int bank){
	if(numberOfRelays <= 8){
		if(!i2cWrite(address1, 0x0A, 0)){
			Serial.println("Turn Off all relays in bank failed");
			initialized = false;
		}
		initialized = true;
		readStatus(address1);
		return;
	}

	byte addr = 0;
	if(bank == 1 || bank == 2){
		addr = address1;
	}else{
		if(bank == 3 || bank == 4){
			addr = address2;
		}else{
			//Bad bank value
			return;
		}
	}

	bank = 17+bank;

	if(!i2cWrite(addr, bank, 0)){
		Serial.println("Turn Off all relays in bank failed");
		initialized = false;
	}
	initialized = true;
	readStatus(addr);
	return;
}
Exemple #2
0
bool checkWen() {
    uint8_t s1, s2, s3;

    s1 = readStatus();

    spiEnable();
    spiReadWriteByte(SPICMD_WREN);
    spiDisable();

    s2 = readStatus();

    spiEnable();
    spiReadWriteByte(SPICMD_WRDIS);
    spiDisable();

    s3 = readStatus();

    if (!(s1 & FSR_WEN)
            && (s2 & FSR_WEN)
            && !(s3 & FSR_WEN)) {
        return true;
    }

    return false;
}
Exemple #3
0
usbMsgLen_t nrfTest() {
    if (!waitForReady()) {
        usbOutputBuffer[0] = ERROR_READY_WAIT;
        usbOutputBuffer[1] = usbOutputBuffer[2] = usbOutputBuffer[3] = readStatus();
        return 4;
    }

    spiEnable();
    usbOutputBuffer[1] = readStatus();
    spiDisable();

    spiEnable();
    spiReadWriteByte(SPICMD_WREN);
    spiDisable();

    spiEnable();
    usbOutputBuffer[2] = readStatus();
    spiDisable();

    spiEnable();
    spiReadWriteByte(SPICMD_WRDIS);
    spiDisable();

    spiEnable();
    usbOutputBuffer[3] = readStatus();
    spiDisable();

    if (!(usbOutputBuffer[1] & FSR_WEN) && (usbOutputBuffer[2] & FSR_WEN) && !(usbOutputBuffer[3] & FSR_WEN)) {
        usbOutputBuffer[0] = ERROR_OK;
    } else {
        usbOutputBuffer[0] = ERROR_WEN_TEST_FAILED;
    }

    return 4;
}
Exemple #4
0
/** Called when asyn clients call pasynFloat64->write().
  * This function sends a signal to the simTask thread if the value of P_UpdateTime has changed.
  * For all  parameters it  sets the value in the parameter library and calls any registered callbacks.
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Value to write. */
asynStatus drvQuadEM::writeFloat64(asynUser *pasynUser, epicsFloat64 value)
{
    int function = pasynUser->reason;
    int status = asynSuccess;
    int channel;
    const char *paramName;
    const char* functionName = "writeFloat64";

    getAddress(pasynUser, &channel);
    
    /* Set the parameter in the parameter library. */
    status |= setDoubleParam(channel, function, value);

    /* Fetch the parameter string name for possible use in debugging */
    getParamName(function, &paramName);

    if (function == P_AveragingTime) {
        status |= setAveragingTime(value);
        epicsRingBytesFlush(ringBuffer_);
        ringCount_ = 0;
        status |= readStatus();
    }
    else if (function == P_BiasVoltage) {
        status |= setBiasVoltage(value);
        status |= readStatus();
    }
    else if (function == P_IntegrationTime) {
        status |= setIntegrationTime(value);
        status |= readStatus();
    } 
    else {
        /* All other parameters just get set in parameter list, no need to
         * act on them here */
    }
    
    /* Do callbacks so higher layers see any changes */
    status |= (asynStatus) callParamCallbacks();
    
    if (status) 
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d, name=%s, value=%f", 
                  driverName, functionName, status, function, paramName, value);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, name=%s, value=%f\n", 
              driverName, functionName, function, paramName, value);
    return (asynStatus)status;
}
bool
xpcc::At45db0x1d<Spi, Cs>::initialize()
{
	Cs::set();
	Cs::setOutput();

	uint8_t status = readStatus();
	if (status == 0xff || status == 0) {
		// no device present
		return false;
	}

	if ((status & PAGE_SIZE) == 0)
	{
		// Page size is 264 (the default)
		// => set page size from 264 to 256 bytes
		Cs::reset();

		// send page size change sequence (fixed sequence)
		Spi::transferBlocking(0x3d);
		Spi::transferBlocking(0x2a);
		Spi::transferBlocking(0x80);
		Spi::transferBlocking(0xa6);

		Cs::set();
	}

	waitUntilReady();

	return true;
}
void NCD32Relay::setBankStatus(int status, int bank){
	byte addr;
	if(bank == 1 || bank == 2){
		addr = address1;
	}else{
		if(bank == 3 || bank == 4){
			addr = address2;
		}else{
			//Bad bank value
			return;
		}
	}
	setBankStatusRetry:
	Wire.beginTransmission(addr);
	if(numberOfRelays <= 8){
		bank = 0x0A;
	}else{
		bank = 17+bank;
	}

	if(!i2cWrite(addr, bank, status)){
		initialized = false;
		Serial.println("Set Bank Status failed");
		return;
	}
	initialized = true;
	readStatus(addr);
}
void flash25spi::waitForWrite() {
    while (true) {
        if (0==readStatus()&1)
            break;
        wait_us(10);
    }
}
Exemple #8
0
LWDAQ_Client::LWDAQ_Client(QString host, quint16 port, QObject *parent) : QObject(parent),
                                  hostName(host),
                                  portNo(port),
                                  currentState(UNSET),
                                  cmdNo(0),
                                  error(false),
                                  errorText("") {

    tcpSocket = new QTcpSocket(this);

    connect(tcpSocket, SIGNAL(connected()), this, SLOT(gotConnected()));
    connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(gotDisconnected()));
    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readStatus()));
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
                this, SLOT(displayError(QAbstractSocket::SocketError)));

    connectTimer = new QTimer(this);
    connectTimer->setInterval(RECONNECT_TIME*1000);
    connectTimer->setSingleShot(true);
    connect(connectTimer, SIGNAL(timeout()), this, SLOT(init()));

    statusTimer = new QTimer(this);
    statusTimer->setInterval(SLOW_UPDATE_TIME*1000);
    statusTimer->setSingleShot(false);
    connect(statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));

    runTimer = new QTimer(this);
    runTimer->setInterval(DEFAULT_RUN_TIME*1000);
    runTimer->setSingleShot(true);
    connect(runTimer, SIGNAL(timeout()), this, SLOT(stopRun()));
}
BYTE
Z47Interface::in(BYTE addr)
{
    debugss(ssH47, ALL, "(%d)\n", addr);
    BYTE offset = getPortOffset(addr);
    BYTE data   = 0;

    switch (offset)
    {
        case StatusPort_Offset_c:
            readStatus(data);
            debugss(ssH47, ALL, "StatusPort - 0x%02x\n", data);
            break;

        case DataPort_Offset_c:
            readData(data);
            debugss(ssH47, ALL, "DataPort - 0x%02x\n", data);
            break;

        default:
            debugss(ssH47, ERROR, "Unknown Port offset - %d\n", offset);
            break;
    }

    return data;
}
Exemple #10
0
int KmxController::Initialize(){

  int type = BOARD_TYPE_UNKNOWN;

  if(km->CheckKMotionVersion(&type,false)){
    //enter simulation mode?
    log_info("CheckKMotionVersion failed. Simulation mode active.");
    setSimulationMode(true);
  }


  if(Setup()){
    printf("Setup failed.\n");
    return -1;
  }

  UpdateMotionParams();

  //Try without simulation on startup
  setSimulationMode(false);

  if(!readStatus()){
  //if (FirstStartup)
  //{
    //FirstStartup=false;
    if (Interpreter->InvokeAction(ACTION_PROG_START,FALSE))  // Special Command
    {
      AfxMessageBox("Unable to perform Startup Action");
    }
  //}

  }
  return 0;
}
// Check to see if message is available
uint8_t CAN_MCP2515::available()
{
  uint8_t msgStatus = readStatus();
  // (msgStatus & 0x01) means message in RX buffer 0
  // (msgStatus & 0x02) means message in RX buffer 1
  // Returns number of messages available
  return (msgStatus & MCP2515_STATUS_CANINTF_RXnIF);
}
Exemple #12
0
//[hdt] reversed meaning of boolean: isrunning TRUE ==> is running
// returns the Oscillator Stop Flag (OSF) bit of the status reg
// to confirm that the clock is running (1 ==> running)
uint8_t Chronodot::isrunning(void) {
  uint8_t ss=0;

  if ( readStatus(CD_STATUS, &ss, (char *) "CD::isrunning()") == 0 ) 
    return 1;
  else
    return 0;

}
Exemple #13
0
bool EasyVR::hasFinished()
{
  int8_t rx = recv(NO_TIMEOUT);
  if (rx < 0)
    return false;
  
  readStatus(rx);
  return true;
}
//1, 2, 4, 8, or 16 relays
void NCD32Relay::setAddress(int a0, int a1, int a2){
	address1 = 0x20;
	if(a0 == 1){
		address1 = address1 | 1;
	}
	if(a1 == 1){
		address1 = address1 | 2;
	}
	if(a2 == 1){
		address1 = address1 | 4;
	}
	Wire.begin();

	if(numberOfRelays == 16 || numberOfRelays ==8){
		byte writeData[2] = {0,0};
		if(numberOfRelays == 16){
			if(!i2cWrite(address1, 0, writeData, 2)){
				Serial.println("Initialization of relay controller failed");
				return;
			}

		}else{
			if(!i2cWrite(address1, 0, writeData, 1)){
				Serial.println("Initialization of relay controller failed");
				return;
			}
		}
	}else{
		byte writeData[1];
		byte writeData2[1];
		switch(numberOfRelays){
		case 1:
			writeData[0] = oneRelayMux;
			writeData2[0] = oneRelayMux;
			break;
		case 2:
			writeData[0] = twoRelayMux;
			writeData2[0] = twoRelayMux;
			break;
		case 4:
			writeData[0] = fourRelayMux;
			writeData2[0] = fourRelayMux;
			break;
		}
		if(!i2cWrite(address1, 0x00, writeData, 1)){
			Serial.println("Initialization of relay controller failed");
			return;
		}
		if(!i2cWrite(address1, 0x06, writeData2, 1)){
			Serial.println("Initialization of relay controller failed");
			return;
		}
	}
	initialized = true;
	readStatus(address1);
}
Exemple #15
0
bool EasyVR::checkMessages()
{
  sendCmd(CMD_VERIFY_RP);
  sendArg(-1);
  sendArg(0);

  int rx = recv(STORAGE_TIMEOUT);
  readStatus(rx);
  return (_status.v == 0);
}
Exemple #16
0
bool
HttpClient::perform()
{
    writeRequest();
    if (!_conn->fresh() && (_conn->stream().obtain().size == 0)) {
        _conn.reset(new HttpConnection(_conn->server()));
        writeRequest();
    }
    return (readStatus() && readHeaders() && readContent());
}
Exemple #17
0
int SoapyRemoteDevice::readStreamStatus(
    SoapySDR::Stream *stream,
    size_t &chanMask,
    int &flags,
    long long &timeNs,
    const long timeoutUs)
{
    auto data = (ClientStreamData *)stream;
    auto ep = data->endpoint;
    if (not ep->waitStatus(timeoutUs)) return SOAPY_SDR_TIMEOUT;
    return ep->readStatus(chanMask, flags, timeNs);
}
void NCD32Relay::setAllRelayStatus(int bank1, int bank2, int bank3, int bank4){
	if(numberOfRelays <=8){
		setBankStatus(bank1, 1);
		return;
	}
	byte writeData1[2] = {bank1, bank2};
	if(!i2cWrite(address1, 18, writeData1, 2)){
		Serial.println("Set All Relay Status failed");
		initialized = false;
		return;
	}
	readStatus(address1);

	byte writeData2[2] = {bank3, bank4};
	if(!i2cWrite(address2, 18, writeData2, 2)){
		Serial.println("Set All Relay Status failed");
		initialized = false;
		return;
	}
	readStatus(address2);
	initialized = true;
}
//24 or 32 relays
void NCD32Relay::setAddress(int a0, int a1){
	address1 = 0x20;
	address2 = 0x21;
	if(a0 == 1){
		address1 = address1 | 2;
		address2 = address2 | 2;
	}
	if(a1 == 1){
		address1 = address1 | 4;
		address2 = address2 | 4;
	}
	//Start I2C port
	Wire.begin();
	byte writeData[2] = {0,0};
	if(!i2cWrite(address1, 0, writeData, 2)){
		initialized = false;
		Serial.println("Initialization of relay controller failed on first address");
		return;
	}else{
		readStatus(address1);
	}

	byte writeData2[2];
	if(numberOfRelays == 32){
		writeData2[0] = 0;
		writeData2[1] = 0;
	}else{
		writeData2[0] = 0;
		writeData2[1] = 255;
	}
	if(!i2cWrite(address2, 0, writeData2, 2)){
		initialized = false;
		Serial.println("Initialization of relay controller failed on second address");
		return;
	}else{
		readStatus(address2);
	}
	initialized = true;
}
Exemple #20
0
static bool unWriteProtect() {
    static uint8_t cmd[]={CMD_WRITESTATUS,0};

    uint8_t status;
    if(!readStatus(&status))
        return false;
    if(!(status & 0x1c))    //already unlocked
        return true;
    if(!writeEnable())
        return false;
    if(!dev_spiWrite(cmd,2,1,0))
        return false;
    return writeWait(50);
}
Exemple #21
0
void *heaproutine(void *v)
{
  struct stackheap *stuff = (struct stackheap*)v;
  struct statusStuff s = stuff->statusstuff;
  while(1 && highheap == 0){
  readStatus(stuff->pid, &s);
  if(s.VmData > 4000)
    {
      highheap++;
      kill(stuff->pid, 9);
      fprintf(stderr, "Heap memory is above 4 MB\n");
    }
  }
}
Exemple #22
0
void *stackroutine(void *v)
{
  struct stackheap *stuff = (struct stackheap*)v;
  struct statusStuff s = stuff->statusstuff;
  while(1 && highstack == 0){
  readStatus(stuff->pid, &s);
  if(s.VmStk > 4000)
    {
      highstack++;
      kill(stuff->pid, 9);
      fprintf(stderr, "Stack memory is above 4 MB\n");
    }
 }
}
void NCD32Relay::turnOffAllRelays(){
	if(numberOfRelays <= 8){
		if(!i2cWrite(address1, 0x0A, 0)){
			Serial.println("Turn Off all relays failed");
			initialized = false;
		}
		initialized = true;
		readStatus(address1);
		return;
	}
	byte writeData[2] = {0, 0};
	if(!i2cWrite(address1, 18, writeData, 2)){
		Serial.println("Turn Off all relays failed");
		initialized = false;
	}
	readStatus(address1);
	if(!i2cWrite(address2, 18, writeData, 2)){
		Serial.println("Turn Off all relays failed");
		initialized = false;
	}
	readStatus(address2);
	initialized = true;
}
Exemple #24
0
bool waitWenIsCleared() {
    uint8_t status;
    uint8_t attempts;

    for (attempts = 0; attempts < 10; ++attempts) {
        status = readStatus();

        if (!(status & FSR_WEN)) {
            return true;
        }

        _delay_ms(2);
    }

    return false;
}
Exemple #25
0
bool waitForReady() {
    uint8_t status;
    uint8_t attempt;

    for (attempt = 0; attempt < 10; ++attempt) {
        status = readStatus();

        if (!(status & FSR_RDYN)) {
            return true;
        }

        _delay_ms(2);
    }

    return false;
}
Exemple #26
0
RedisProto::ParseState RedisProto::parse(char *s, int len, RedisProtoParseResult *result)
{
    int ret = 0;
    switch (s[0]) {
    case '+':
        result->type = RedisProtoParseResult::Status;
        ret = readStatus(s, len, &(result->tokens[0]));
        break;
    case '-':
        result->type = RedisProtoParseResult::Error;
        ret = readError(s, len, &(result->tokens[0]));
        break;
    case ':':
        result->type = RedisProtoParseResult::Integer;
        ret = readInteger(s, len, &result->integer);
        break;
    case '$':
        result->type = RedisProtoParseResult::Bulk;
        ret = readBulk(s, len, &(result->tokens[0]));
        break;
    case '*':
        result->type = RedisProtoParseResult::MultiBulk;
        ret = readMultiBulk(s, len, result->tokens, &result->tokenCount);
        break;
    default: {
        int stringlen = 0;
        result->type = RedisProtoParseResult::Bulk;
        ret = readTextEndByCRLF(s, len, &stringlen);
        if (ret > 0) {
            result->tokens[0].s = s;
            result->tokens[0].len = stringlen;
        }
    }
        break;
    }

    switch (ret) {
    case READ_AGAIN:
        return ProtoIncomplete;
    case READ_ERROR:
        return ProtoError;
    default:
        result->protoBuff = s;
        result->protoBuffLen = ret;
        return ProtoOK;
    }
}
bool
xpcc::Scp1000<Spi, Cs, Int>::setOperation(scp1000::Operation opMode)
{
	writeRegister(scp1000::REGISTER_OPERATION, opMode);
	
	uint8_t retries = 16;
	// wait for the sensor to complete setting the operation
	while (--retries && (readStatus(true) & scp1000::OPERATION_STATUS_RUNNING)) {
		xpcc::delayMilliseconds(1);
	}
	
	// The sensor took too long to complete the operation
	if (retries)
		return true;
	
	return false;
}
Exemple #28
0
/** Downloads all of the current EPICS settings to the electrometer.  
  * Typically used after the electrometer is power-cycled.
  */
asynStatus drvQuadEM::reset() 
{
    epicsInt32 iValue;
    epicsFloat64 dValue;

    getIntegerParam(P_Range, &iValue);
    setRange(iValue);

    getIntegerParam(P_ValuesPerRead, &iValue);
    setValuesPerRead(iValue);

    getDoubleParam(P_AveragingTime, &dValue);
    setAveragingTime(dValue);

    getIntegerParam(P_TriggerMode, &iValue);
    setTriggerMode(iValue);
    
    getIntegerParam(P_NumChannels, &iValue);
    setNumChannels(iValue);
    
    getIntegerParam(P_BiasState, &iValue);
    setBiasState(iValue);
    
    getIntegerParam(P_BiasInterlock, &iValue);
    setBiasInterlock(iValue);
    
    getDoubleParam(P_BiasVoltage, &dValue);
    setBiasVoltage(dValue);
    
    getIntegerParam(P_Resolution, &iValue);
    setResolution(iValue);

    getIntegerParam(P_ReadFormat, &iValue);
    setReadFormat(iValue);
    
    getDoubleParam(P_IntegrationTime, &dValue);
    setIntegrationTime(dValue);
    
    readStatus();
    
    getIntegerParam(P_Acquire, &iValue);
    setAcquire(iValue);

    return asynSuccess;
}
Exemple #29
0
void GameDatas::read(QString path){
    readVariablesSwitches(path);
    m_commonEventsDatas->read(path);
    readSystem(path);
    readItems(path);
    readSkills(path);
    readBattleSystem(path);
    readWeapons(path);
    readArmors(path);
    readHeroes(path);
    readMonsters(path);
    readTroops(path);
    readClasses(path);
    readTilesets(path);
    readAnimations(path);
    readStatus(path);
    readTitleScreenGameOver(path);

    m_isDatasRead = true;
}
Exemple #30
0
void LOW_compTwinSwitch::handleAlarm()
{
  LOW_devDS2406::cmd_ChannelAccess::channelInfo_t  chInfoRead, chInfoReset;

  // two steps needed here, otherwise latch status cannot be read
  readStatus( chInfoRead);
  resetLatches( chInfoReset);
  
  // switch A
  if ( chInfoRead.activityLatch_pioA )
    // using current status after latch reset (and not the one of read status)
    // enables us to detect a button release during latch reset
    doSwitchAction( 0, chInfoReset.sensedLevel_pioA);

  // switch B if present
  if ( pioDevice.getHasPioB() && chInfoRead.activityLatch_pioB )
    // using current status after latch reset (and not the one of read status)
    // enables us to detect a button release during latch reset
    doSwitchAction( 1, chInfoReset.sensedLevel_pioB);
}