/*Start up the wifi network*/
bool ATTDevice::StartWifi(bool forceReset)
{
    #ifdef DEBUG
    Serial.println("starting wifi");
    #endif
	bool res = false;
	if(!forceReset)								
	{
		_stream->println(CMD_AT);                   //first send the at command to synchronize: we have something to wait for an 'ok' ->could be that the wifi chip is still processing a prev command and returns 'ok', in which case the new 'init' is lost.
		res = expectString(CMD_AT_OK, 1000, true);	//if response, wifi is already set ok, otherwise wifi switched to router, we show the correct message to the user (otherwise the wifi module has to do 2 things: it's most likely already started the wifi server, but we want to send commands to it, which doesn't work		
		if(res == false)									//try the command 1 more time, could be that user did reset, in which case the wifi module might wake up a little too late to see that AT command
			res = expectString(CMD_AT_OK, 1000, true);
	}
	else{
		_stream->println(CMD_AT_RESET_WIFI);                   //first send the at command to synchronize: we have something to wait for an 'ok' ->could be that the wifi chip is still processing a prev command and returns 'ok', in which case the new 'init' is lost.
		res = expectString(CMD_AT_RESET_WIFI, 2000, true);	
	}
	if(res == false){
		Serial.println();
		if(!forceReset)
			Serial.println("The wifi module could not connect to the wifi router. The module will now switch to router mode");
		else
			Serial.println("The credentials for the wifi module has been reset. The module will now switch to router mode");
		Serial.println("Please use another device to connect to 'ESP8266 wifi'");
		Serial.println("Browse to 192.168.4.1 and set the SSID and password");
		res = expectString(CMD_AT_OK, 0, false);
	}
	return res;
}
// Sends a reset command to the module and waits for the success response (or timeout).
// Returns true on success.
bool Sodaq_RN2483::resetDevice()
{
    debugPrintLn("[resetDevice]");

    this->loraStream->print(STR_CMD_RESET);
    this->loraStream->print(CRLF);

    if (expectString(STR_DEVICE_TYPE_RN)) {
        if (strstr(this->inputBuffer, STR_DEVICE_TYPE_RN2483) != NULL) {
            debugPrintLn("The device type is RN2483");

            return true;
        }
        else if (strstr(this->inputBuffer, STR_DEVICE_TYPE_RN2903) != NULL) {
            debugPrintLn("The device type is RN2903");
            // TODO move into init once it is decided how to handle RN2903-specific operations
            setFsbChannels(DEFAULT_FSB);

            return true;
        }
        else {
            debugPrintLn("Unknown device type!");

            return false;
        }
    }

    return false;
}
Beispiel #3
0
bool DbcParser::parseSectionVersion(CanDb &candb, DbcTokenList &tokens)
{
    QString version;
    if (!expectString(tokens, &version)) { return false; }
    candb.setVersion(version);
    return expectSectionEnding(tokens);
}
Beispiel #4
0
/**
* @brief Sends a join command to the network
* @param Type of join, OTAA or ABP
* @return Returns true on success or false if fail.
*/
bool RN2483::joinNetwork(const char* type)
{
    _RN2483.printf(STR_CMD_JOIN);
    _RN2483.printf(type);
    _RN2483.printf(CRLF);

    return expectOK() && expectString(STR_ACCEPTED, 30000);
}
void ScannerTestBase::scanAndExpectString(const char *expected_value, const unsigned short expected_length)
{
  ASSERT_EQ(LITERAL_STRING, yylex());
  ASSERT_TRUE(yylval);

  expectString(yylval->data.string_data, expected_value, expected_length);
  free(yylval);
}
Beispiel #6
0
// Sends a reset command to the module and waits for the success response (or timeout).
// Returns true on success.
bool Sodaq_RN2483::resetDevice()
{
    debugPrintLn("[resetDevice]");

    this->loraStream->print(STR_CMD_RESET);
    this->loraStream->print(CRLF);

    return expectString(STR_DEVICE_TYPE);
}
Beispiel #7
0
// Sends a join network command to the device and waits for the response (or timeout).
// Returns true on success.
bool Sodaq_RN2483::joinNetwork(const char* type)
{
    debugPrintLn("[joinNetwork]");

    this->loraStream->print(STR_CMD_JOIN);
    this->loraStream->print(type);
    this->loraStream->print(CRLF);

    return expectOK() && expectString(STR_ACCEPTED, 10000);
}
void InText::readAngle(Angle& d, PhysicalInStream& stream)
{
  static const std::string degString = "deg";
  static const std::string radString = "rad";
  static const std::string piRadString = "pi";

  float value = d;
  readFloat(value, stream);

  bool isDeg = false;
  bool isPiRad = false;
  if(!isEof(stream))
  {
    if(theChar == 'd')
      isDeg = expectString(degString, stream);
    else if(theChar == 'p')
      isPiRad = expectString(piRadString, stream);
    else if(theChar == 'r')
      expectString(radString, stream);
  }
  d = isDeg ? Angle::fromDegrees(value) : isPiRad ? Angle(value * pi) : Angle(value);
}
//send a data value to the cloud server for the sensor with the specified id.
bool ATTDevice::Send(String value, int id)
{
	String idStr = String(id);
    writeCommand(CMD_SEND, value, idStr);
    bool res = expectString(CMD_SEND_OK);
    #ifdef DEBUG
    if(res == false)
        Serial.println("Failed to send value");
    else
        Serial.println("value sent");
    #endif
    return res;
}
//connect with the http server
bool ATTDevice::Connect(char httpServer[])
{
    String param = String(httpServer);
    writeCommand(CMD_CONNECT, param);
    bool res = expectString(CMD_CONNECT_OK, 0);
    #ifdef DEBUG
    if(res == false){
        Serial.print(HTTPSERVTEXT);
        Serial.println(FAILED);
    }
    #endif
    return res;
}
//connect with the broker
bool ATTDevice::Subscribe(char broker[], mqttCallback callback)
{
    _callback = callback;
    bool res = false;
    String param = String(broker);
	writeCommand(CMD_SUBSCRIBE, param);
	res = expectString(CMD_SUBSCRIBE_OK);
	#ifdef DEBUG
	if(res == false){
		Serial.print(MQTTSERVTEXT);
		Serial.println(FAILED);
	}
	#endif
	return res;
}
//connect with the http server
bool ATTDevice::Init(String deviceId, String clientId, String clientKey)
{
    #ifdef DEBUG
	Serial.println();
    Serial.println(F("setting device credentials"));
    #endif
		
    writeCommand(CMD_INIT, deviceId, clientId, clientKey);
    bool res = expectString(CMD_INIT_OK, 2000);		//for init, we use a shorter wait period, so that the main application can retry quickly (resend the AT, so that the remote wifi can sync).
    #ifdef DEBUG	
    if(res == false){
        Serial.print(UARTINITTEXT);
        Serial.println(FAILED);
    }
    #endif
    return res;
}
Beispiel #13
0
// Gets the digital state of a pin
// Returns the state of a GPIO ( true or false ), returns false if pin not set up
uint8_t Sodaq_RN2483::digitalRead(uint8_t gpio) {
	//sanitize inputs,
	// only handle GPIO0-13
	debugPrintLn("digitalRead");
	if (gpio >13) {
		return false;
		debugPrintLn("GPIO out of bounds : 0-13 only");
	}
	// sys get pindig <pinname>
	this->loraStream->print(STR_SYS_GET);
	this->loraStream->print(STR_GPIO_DIG);
	this->loraStream->print(STR_GPIO);
	this->loraStream->print(gpio);
	this->loraStream->print(CRLF);

	// parse response 
	// "1" means pin is High, so return true
	// will return false / 0 otherwise
	return expectString("1"); 

}
//create or update the specified asset.
bool ATTDevice::AddAsset(int id, String name, String description, bool isActuator, String type)
{
    #ifdef DEBUG
    Serial.println(F("adding asset"));
    #endif

    String isAct;
    if(isActuator)
		isAct = "true";
	else
		isAct = "false";
	String idStr = String(id);
	writeCommand(CMD_ADDASSET, idStr, name, description, isAct, type);
	bool res = expectString(CMD_ADDASSET_OK);
	#ifdef DEBUG
	if(res == false)
		Serial.println("Failed to add asset");
	else
		Serial.println("asset added");
	#endif
	return res;
}
Beispiel #15
0
/**
* @brief Sends a reset command to the module
* Also sets-up some initial parameters like power index, SF and FSB channels.
* @return Waits for sucess reponse or timeout.
*/
bool RN2483::resetDevice()
{
    printf("RN2483: Reset\n");
    _RN2483.printf(STR_CMD_RESET);
    _RN2483.printf(CRLF);
    if (expectString(STR_DEVICE_TYPE_RN, 2000)) {
        if (strstr(this->inputBuffer, STR_DEVICE_TYPE_RN2483) != NULL) {
            isRN2903 = false;
            return setPowerIndex(DEFAULT_PWR_IDX_868) &&
                   setSpreadingFactor(DEFAULT_SF_868);
        } else if (strstr(this->inputBuffer, STR_DEVICE_TYPE_RN2903) != NULL) {
            // TODO move into init once it is decided how to handle RN2903-specific operations
            isRN2903 = true;

            return setFsbChannels(DEFAULT_FSB) &&
                   setPowerIndex(DEFAULT_PWR_IDX_915) &&
                   setSpreadingFactor(DEFAULT_SF_915);
        } else {
            return false;
        }
    }
    return false;
}
Beispiel #16
0
/**
* @brief Looks for an 'OK' response from the RN2483
* @param Timeout Period
* @return Returns true if the string is received before a timeout.
* Returns false if a timeout occurs or if another string is received.
*/
bool RN2483::expectOK(uint16_t timeout)
{
    return expectString(STR_RESULT_OK, timeout);
}
Beispiel #17
0
// Provides a quick test of several methods as a pseudo-unit test.
void Sodaq_RN2483::runTestSequence(Stream& stream)
{
    debugPrint("free ram: ");
    debugPrintLn(freeRam());

    init(stream);

    this->loraStream = &stream;
    this->diagStream = &stream;

    // expectString
    debugPrintLn("write \"testString\" and then CRLF");
    if (expectString("testString", 5000)) {
        debugPrintLn("[expectString] positive case works!");
    }

    debugPrintLn("");
    debugPrintLn("write something other than \"testString\" and then CRLF");
    if (!expectString("testString", 5000)) {
        debugPrintLn("[expectString] negative case works!");
    }

    debugPrint("free ram: ");
    debugPrintLn(freeRam());

    // setMacParam(array)
    debugPrintLn("");
    debugPrintLn("");
    uint8_t testValue[] = {0x01, 0x02, 0xDE, 0xAD, 0xBE, 0xEF};
    setMacParam("testParam ", testValue, ARRAY_SIZE(testValue));

    // macTransmit
    debugPrintLn("");
    debugPrintLn("");
    uint8_t testValue2[] = {0x01, 0x02, 0xDE, 0xAD, 0xBE, 0xEF};
    macTransmit(STR_CONFIRMED, 1, testValue2, ARRAY_SIZE(testValue2));

    debugPrint("free ram: ");
    debugPrintLn(freeRam());

    // receive
    debugPrintLn("");
    debugPrintLn("==== receive");
    char mockResult[] = "303132333435363738";
    memcpy(this->receivedPayloadBuffer, mockResult, strlen(mockResult) + 1);
    uint8_t payload[64];
    debugPrintLn("* without having received packet");
    uint8_t length = receive(payload, sizeof(payload));
    debugPrintLn(reinterpret_cast<char*>(payload));
    debugPrint("Length: ");
    debugPrintLn(length);
    debugPrintLn("* having received packet");
    this->packetReceived = true;
    length = receive(payload, sizeof(payload));
    debugPrintLn(reinterpret_cast<char*>(payload));
    debugPrint("Length: ");
    debugPrintLn(length);

    // onMacRX
    debugPrintLn("");
    debugPrintLn("==== onMacRX");
    char mockRx[] = "mac_rx 1 303132333435363738";
    memcpy(this->inputBuffer, mockRx, strlen(mockRx) + 1);
    this->packetReceived = false;// reset
    debugPrint("Input buffer now is: ");
    debugPrintLn(this->inputBuffer);
    debugPrint("onMacRX result code: ");
    debugPrintLn(onMacRX());
    uint8_t payload2[64];
    if (receive(payload2, sizeof(payload2)) != 9) {
        debugPrintLn("len is wrong!");
    }
    debugPrintLn(reinterpret_cast<char*>(payload2));
    if (receive(payload2, sizeof(payload2), 2) != 7) {
        debugPrintLn("len is wrong!");
    }
    debugPrintLn(reinterpret_cast<char*>(payload2));
    if (receive(payload2, sizeof(payload2), 3) != 6) {
        debugPrintLn("len is wrong!");
    }
    debugPrintLn(reinterpret_cast<char*>(payload2));

    debugPrint("free ram: ");
    debugPrintLn(freeRam());

    // lookup error
    debugPrintLn("");
    debugPrintLn("");

    debugPrint("empty string: ");
    debugPrintLn((lookupMacTransmitError("") == NoResponse) ? "passed" : "wrong");

    debugPrint("\"random\": ");
    debugPrintLn((lookupMacTransmitError("random") == NoResponse) ? "passed" : "wrong");

    debugPrint("\"invalid_param\": ");
    debugPrintLn((lookupMacTransmitError("invalid_param") == InternalError) ? "passed" : "wrong");

    debugPrint("\"not_joined\": ");
    debugPrintLn((lookupMacTransmitError("not_joined") == NotConnected) ? "passed" : "wrong");

    debugPrint("\"busy\": ");
    debugPrintLn((lookupMacTransmitError("busy") == Busy) ? "passed" : "wrong");

    debugPrint("\"invalid_param\": ");
    debugPrintLn((lookupMacTransmitError("invalid_param") == InternalError) ? "passed" : "wrong");

    debugPrint("free ram: ");
    debugPrintLn(freeRam());
}
Beispiel #18
0
static void
readTix(void) {
  unsigned int i;
  HpcModuleInfo *tmpModule;
  const HpcModuleInfo *lookup;

  ws();
  expect('T');
  expect('i');
  expect('x');
  ws();
  expect('[');
  ws();

  while(tix_ch != ']') {
    tmpModule = (HpcModuleInfo *)stgMallocBytes(sizeof(HpcModuleInfo),
                                                "Hpc.readTix");
    tmpModule->from_file = true;
    expect('T');
    expect('i');
    expect('x');
    expect('M');
    expect('o');
    expect('d');
    expect('u');
    expect('l');
    expect('e');
    ws();
    tmpModule -> modName = expectString();
    ws();
    tmpModule -> hashNo = (unsigned int)expectWord64();
    ws();
    tmpModule -> tickCount = (int)expectWord64();
    tmpModule -> tixArr = (StgWord64 *)calloc(tmpModule->tickCount,sizeof(StgWord64));
    ws();
    expect('[');
    ws();
    for(i = 0;i < tmpModule->tickCount;i++) {
      tmpModule->tixArr[i] = expectWord64();
      ws();
      if (tix_ch == ',') {
        expect(',');
        ws();
      }
    }
    expect(']');
    ws();

    lookup = lookupHashTable(moduleHash, (StgWord)tmpModule->modName);
    if (lookup == NULL) {
        debugTrace(DEBUG_hpc,"readTix: new HpcModuleInfo for %s",
                   tmpModule->modName);
        insertHashTable(moduleHash, (StgWord)tmpModule->modName, tmpModule);
    } else {
        ASSERT(lookup->tixArr != 0);
        ASSERT(!strcmp(tmpModule->modName, lookup->modName));
        debugTrace(DEBUG_hpc,"readTix: existing HpcModuleInfo for %s",
                   tmpModule->modName);
        if (tmpModule->hashNo != lookup->hashNo) {
            fprintf(stderr,"in module '%s'\n",tmpModule->modName);
            failure("module mismatch with .tix/.mix file hash number");
            if (tixFilename != NULL) {
                fprintf(stderr,"(perhaps remove %s ?)\n",tixFilename);
            }
            stg_exit(EXIT_FAILURE);
        }
        for (i=0; i < tmpModule->tickCount; i++) {
            lookup->tixArr[i] = tmpModule->tixArr[i];
        }
        stgFree(tmpModule->tixArr);
        stgFree(tmpModule->modName);
        stgFree(tmpModule);
    }

    if (tix_ch == ',') {
      expect(',');
      ws();
    }
  }
  expect(']');
  fclose(tixFile);
}
Beispiel #19
0
bool Sodaq_RN2483::expectOK()
{
    return expectString(STR_RESULT_OK);
}