Ejemplo n.º 1
0
int test_receive_max_sized_message() {
    IT("receives an max-sized message");
    reset_callback();
    
    ShimClient shimClient;
    shimClient.setAllowConnect(true);
    
    byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
    shimClient.respond(connack,4);
    
    PubSubClient client(server, 1883, callback, shimClient);
    int rc = client.connect((char*)"client_test1");
    IS_TRUE(rc);
    
    byte length = MQTT_MAX_PACKET_SIZE;
    byte publish[] = {0x30,length-2,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x70,0x61,0x79,0x6c,0x6f,0x61,0x64};
    byte bigPublish[length];
    memset(bigPublish,'A',length);
    bigPublish[length] = 'B';
    memcpy(bigPublish,publish,16);
    shimClient.respond(bigPublish,length);
    
    rc = client.loop();
    
    IS_TRUE(rc);
    
    IS_TRUE(callback_called);
    IS_TRUE(strcmp(lastTopic,"topic")==0);
    IS_TRUE(lastLength == length-9);
    IS_TRUE(memcmp(lastPayload,bigPublish+9,lastLength)==0);
    
    IS_FALSE(shimClient.error());

    END_IT
}
Ejemplo n.º 2
0
int test_receive_stream() {
    IT("receives a streamed callback message");
    reset_callback();
    
    Stream stream;
    stream.expect((uint8_t*)"payload",7);
    
    ShimClient shimClient;
    shimClient.setAllowConnect(true);
    
    byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
    shimClient.respond(connack,4);
    
    PubSubClient client(server, 1883, callback, shimClient, stream);
    int rc = client.connect((char*)"client_test1");
    IS_TRUE(rc);
    
    byte publish[] = {0x30,0xe,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x70,0x61,0x79,0x6c,0x6f,0x61,0x64};
    shimClient.respond(publish,16);
    
    rc = client.loop();

    IS_TRUE(rc);
    
    IS_TRUE(callback_called);
    IS_TRUE(strcmp(lastTopic,"topic")==0);
    IS_TRUE(lastLength == 7);
    
    IS_FALSE(stream.error());
    IS_FALSE(shimClient.error());

    END_IT
}
Ejemplo n.º 3
0
int test_receive_qos1() {
    IT("receives a qos1 message");
    reset_callback();
    
    ShimClient shimClient;
    shimClient.setAllowConnect(true);
    
    byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
    shimClient.respond(connack,4);
    
    PubSubClient client(server, 1883, callback, shimClient);
    int rc = client.connect((char*)"client_test1");
    IS_TRUE(rc);
    
    byte publish[] = {0x32,0x10,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x12,0x34,0x70,0x61,0x79,0x6c,0x6f,0x61,0x64};
    shimClient.respond(publish,18);
    
    byte puback[] = {0x40,0x2,0x12,0x34};
    shimClient.expect(puback,4);
    
    rc = client.loop();
    
    IS_TRUE(rc);
    
    IS_TRUE(callback_called);
    IS_TRUE(strcmp(lastTopic,"topic")==0);
    IS_TRUE(memcmp(lastPayload,"payload",7)==0);
    IS_TRUE(lastLength == 7);
    
    IS_FALSE(shimClient.error());

    END_IT
}
Ejemplo n.º 4
0
void spi_write_reg(SPI_CONTROLLER spi_controller, uint8_t reg, uint8_t value)
{
    DRIVER_API_RC ret = DRV_RC_OK;
    uint8_t buffer[2] = {0};

    buffer[0] = reg & WRITE_CMD;
    buffer[1] = value;

    reset_callback();
    ret = ss_spi_transfer(spi_controller, buffer, sizeof(buffer), NULL , 0, spi_cfg.slave_enable);
    CU_ASSERT ("SPI write failure", ret == DRV_RC_OK);
    wait_xfer_or_err();
}
Ejemplo n.º 5
0
void read_block_spi(SPI_CONTROLLER spi_controller)
{
    uint8_t read_buffer[HUM_LSB - CALLIB_0] = {0xff};
    DRIVER_API_RC ret = 0;
    //uint32_t idx;
    cu_print("read block 2 : %d bytes\n", sizeof(read_buffer));
    reset_callback();
    ret = ss_spi_transfer(spi_controller, 0, 0, read_buffer, \
                          sizeof(read_buffer), spi_cfg.slave_enable);
    wait_xfer_or_err();
    CU_ASSERT("Sending block bytes TX buffer failed\n", (ret == DRV_RC_OK));
#ifdef DEBUG
    dump_data(read_buffer, sizeof(read_buffer));
#endif
}
Ejemplo n.º 6
0
void spi_read_reg(SPI_CONTROLLER spi_controller, uint8_t reg, uint8_t expected_val)
{
    DRIVER_API_RC ret = DRV_RC_OK;
    uint8_t read_data = 0;

    reset_callback();

    ret = ss_spi_transfer(spi_controller, &reg, 1, &read_data , 1, spi_cfg.slave_enable);
    CU_ASSERT ("SPI read failure", ret == DRV_RC_OK);
    wait_xfer_or_err();
#ifdef DEBUG
    cu_print("read value %x expected value %x\n", read_data, expected_val);
#endif
    CU_ASSERT ("SPI expected value differs from the read value", expected_val == read_data);
}
Ejemplo n.º 7
0
void transfer_block_spi(SPI_CONTROLLER spi_controller)
{
    uint8_t write_buffer[1] = {CALLIB_0};
    uint8_t read_buffer[HUM_LSB - CALLIB_0] = {0};
    DRIVER_API_RC ret = 0;
    //uint32_t idx;
    cu_print("read %d bytes\n", sizeof(read_buffer));
    reset_callback();
    ret = ss_spi_transfer(spi_controller, write_buffer, 1, read_buffer, \
                          sizeof(read_buffer), spi_cfg.slave_enable);
    CU_ASSERT("Sending block bytes TX buffer failed\n", (ret == DRV_RC_OK));
    wait_xfer_or_err();
#ifdef DEBUG
    dump_data(read_buffer, sizeof(read_buffer));
#endif
    CU_ASSERT("ss spi written value differs from the read value", read_buffer[CTRL_MEAS - CALLIB_0] == 0x04);
    CU_ASSERT("ss spi written value differs from the read value", read_buffer[CONFIG - CALLIB_0] == 0x40);
}