Пример #1
0
I2C_RESULT i2c_Write(unsigned char addr, unsigned char* pData, unsigned char len)
{
  //printf("i2c_write(%d %d %d)\n", (int)addr, (int)*pData, (int)len);

#if !defined(I2C_CFGEN_CALLTRACE)
  I2C_RESULT result;

  if (config.start)
  {
    _START();
  }

  addr <<= 1; /* address is in high 7 bits */
  /* low bit 0 is now zero, indicating a write */

  //printf("send addr %d\n", (int) addr);
  result = i2c_TxByte(addr);
  if (I2C_RESULT_IS_ERROR(result))
  { /* probably a NACK */
    //printf("nack addr\n");
    if (config.stop)
    {
      _STOP();
    }
    return result;
  }

  while (len != 0)
  {
    //printf("send data %d\n", (int)*pData);

    result = i2c_TxByte(*pData);
    if (I2C_RESULT_IS_ERROR(result))
    {
      //printf("nak data\n");
      if (config.stop)
      {
        _STOP();
      }
      return result;
    }
    pData++;
    len--;
  }

  if (config.stop)
  {
    //printf("STOP\n");
    _STOP();
  }
#else
  printf("i2c_Write(%d,%d,%d)\n",(int)addr, (int)*pData, (int)len);
#endif
  return I2C_RESULT_OK;
}
Пример #2
0
I2C_RESULT i2c_Read(unsigned char addr, unsigned char* pData, unsigned char len)
{
#if !defined(I2C_CFGEN_CALLTRACE)
  I2C_RESULT result = I2C_RESULT_OK;

  if (config.start)
  {
    _START();
  }

  addr <<= 1;   /* address goes into high 7 bits */
  addr |= 0x01; /* READ */

  result = i2c_TxByte(addr);
  if (I2C_RESULT_IS_ERROR(result))
  {
    if (config.stop)
    {
      _STOP();
    }
    return result;
  }
  
  while (len != 0)
  {
    /* Don't send ACK on last byte */
    result = i2c_RxByte(pData, (len != 1));
    if (I2C_RESULT_IS_ERROR(result))
	  {
      if (config.stop)
      {
	      _STOP();
      }
	    return result;
	  }
    pData++;
    len--;
  }

  if (config.stop)
  {
    _STOP();
  }
#else
  printf("i2c_Read(%d,%d,%d)\n",(int)addr, (int)*pData,(int)len);
#endif
  return I2C_RESULT_OK;
}
Пример #3
0
void test_image_manager::test1(void)
{
    _START();
    _INFO("Verify of internal class nnImageManager: method  read configuration and load images");
    _AUTHOR("Coppi Angelo n2draw library ");
    _STOP();
    miniXmlNode  node;
#ifdef _UNICODE
    bool res = miniXmlNode::load(X("..\\..\\conf_utf16.xml"),&node);
#else
    bool res = miniXmlNode::load(X("..\\..\\conf_utf8.xml"),&node);
#endif
    CA_ASSERT(res == true);
    STRING s;
    nnImageManager im(s);
    res = im.readConfiguration(&node);
    CA_ASSERT(res == true);
    res = im.loadImages();
    CA_ASSERT(res == true);
    /*
    const listImage *images = im.getImageList();
    if (images != nullptr)
    {
        listImage::const_iterator it = images->begin();
        listImage::const_iterator _end = images->end();
        while (it != _end)
        {
            draw((it->second));
            it++;
        }
    }
    */
}
Пример #4
0
I2C_RESULT i2c_Stop(void)
{
#if !defined(I2C_CFGEN_CALLTRACE)
  _STOP();
#else
  printf("i2c_Stop\n");
#endif
  return I2C_RESULT_OK;
}
Пример #5
0
void test_bmpImage_class::test2(void)
{
    _START();
    _INFO("verifica interna alla classe: metodo create");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    CA_ASSERT(s.create(100, 100,24,  255) == true);
    CA_ASSERT((LPBITMAPFILEHEADER)s != nullptr);
}
Пример #6
0
void _F90_STOP( char *str1,
	        int  len1 )
{
    fcd_t  fcd1;

    fcd1.ptr = str1;
    fcd1.len = len1;

    _STOP( fcd1 );
}
Пример #7
0
void test_bmpImage_class::test7(void)
{
    _START();
    _INFO("verifica interrna alla classe : metodo isValid()");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.create(100, 100,24, 255);
    CA_ASSERT(s.isValid()==true);
}
Пример #8
0
void test_bmpImage_class::test14(void)
{
    _START();
    _INFO("verifica interrna alla classe:dimensioni");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.copyFromFile("./old/BORDER.BMP");
    s.copyToFile("BORDER.BMP");
}
Пример #9
0
void test_bmpImage_class::test13(void)
{
    _START();
    _INFO("verifica interrna alla classe:dimensioni");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.create(50, 100,24,  255);
    CA_ASSERT(s.check(50, 100)==true);
    CA_ASSERT(s.check(150, 100)==false);
}
Пример #10
0
void test_bmpImage_class::test9(void)
{
    _START();
    _INFO("verifica interrna alla classe:metodo detach");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.create(100, 100,24,  255);
    LPBITMAPFILEHEADER v = (LPBITMAPFILEHEADER)s;
    CA_ASSERT(s.detach()==true);
    CA_ASSERT((LPBITMAPFILEHEADER)(s)==nullptr);
    delete [](v);
}
Пример #11
0
void test_bmpImage_class::test3(void)
{
    _START();
    _INFO("verifica interrna alla classe : verifica struttura bitmapfileheader");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.create(100, 100,24, 255);
    LPBITMAPFILEHEADER v = (LPBITMAPFILEHEADER)s;
    CA_ASSERT(v->bfType == 0x4d42);
    CA_ASSERT(v->bfOffBits == ((int)(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER))));
    CA_ASSERT(v->bfSize == ((int)(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (100 * 100 * 3))));
}
Пример #12
0
void test_app_manager::test1(void)
{
    _START();
    _INFO("Verify of internal class nnAppManager:load and display a draw");
    _AUTHOR("Coppi Angelo n2draw library ");
    _STOP();
    nnAppManager app;
#ifdef _UNICODE
    STRING name(X("conf_utf16.xml"));
#else
    STRING name(X("conf_utf8.xml"));
#endif
    STRING path("./");
    IChild *childs = app.createObjects(name,path);
    CA_ASSERT(childs != nullptr);
    bool res;
    nnPoint p=childs->getView()->getConstPhy();
    CA_ASSERT(p.x != 0 );
    CA_ASSERT(p.y != 0);
    res=childs->getImage()->loadImages();
    CA_ASSERT(res == true);
    nnContactNO *v = new nnContactNO();
    nnObjManager *mn = dynamic_cast<nnObjManager *>(childs->getManager());
    res = mn->addContact(10, 0, v);
    CA_ASSERT(res == true);
    CA_ASSERT((int)mn->size() == (int)1);
    nnGenericCoil *u = new nnGenericCoil();
    res = mn->addCoil(10, u);
    CA_ASSERT(res == true);
    CA_ASSERT((int)mn->size() == (int)20);
    nnContactNC *v1 = new nnContactNC();
    res = mn->addContact(12, 0, v1);
    CA_ASSERT(res == true);
    nnPoint p1(12, 0);
    nnPoint p2(10, 0);
    nnConnection::connectComponent(childs->getManager(), p1, p2);
    res = childs->getView()->updateDraw();
    CA_ASSERT(res == true);
    bmpImage &bdraw = childs->getView()->getDraw();
    for(unsigned int i=0;i<bdraw.getWidth();i+=100)
        bdraw.line(i,0,i,bdraw.getHeight(),255,0,0,0xfefefefe);
    for(unsigned int u=0;u<bdraw.getHeight();u+=100)
        bdraw.line(0,u,bdraw.getWidth(),u,0,0,255,0xfefefefe);
        bdraw.line(0,0,bdraw.getWidth(),bdraw.getHeight(),0,255,0,0xfefefefe);
        bdraw.line(0,0,200,bdraw.getHeight(),0,255,255,0xfefefefe);
    bdraw.frameRect(10,10,300,300,128,128,64,0xfefefefe);
    bdraw.frameRect(50,50,250,250,128,128,64,0xfefefefe);
    draw(&bdraw);
    MKDIR(".\\bmp",S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    bdraw.copyToFile(X(".\\bmp\\test1_app.bmp"));
}
Пример #13
0
void test_bmpImage_class::test1(void)
{
    _START();
    _INFO("verifica interrna alla classe: metodo attach");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    CA_ASSERT_M("Pointer to bitmapfileheader test is  null", (nullptr == (LPBITMAPFILEHEADER)s));
    LPBITMAPFILEHEADER p;
    p= (LPBITMAPFILEHEADER) new unsigned char[sizeof(BITMAPFILEHEADER)];
    CA_ASSERT_M("Test Attach method", s.attach(p) == true);
    CA_ASSERT_M("Pointer to bitmapfileheader is valid", (nullptr != (LPBITMAPFILEHEADER)s));

}
Пример #14
0
void test_bmpImage_class::test12(void)
{
    _START();
    _INFO("verifica interrna alla classe:metodo landscape");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.create(50, 100,24,  255);
    CA_ASSERT((int)s.getWidth()==50);
    CA_ASSERT((int)s.getHeight() == 100);
    s.landscape(false);
    CA_ASSERT((int)s.getWidth()== 100);
    CA_ASSERT((int)s.getHeight()== 50);
}
Пример #15
0
void test_app_manager::test2(void)
{
    _START();
    _INFO("Verify of internal class nnAppManager:load and display a draw, and scroll it");
    _AUTHOR("Coppi Angelo n2draw library ");
    _STOP();
    nnAppManager app;
#ifdef _UNICODE
    STRING name(X("conf_utf16.xml"));
#else
    STRING name(X("conf_ut8.xml"));
#endif
    STRING path("./");
    IChild *childs = app.createObjects(name,path);
    CA_ASSERT(childs != nullptr);
    bool res;

    res = childs->getImage()->loadImages();
    CA_ASSERT(res == true);
    nnContactNO *v = new nnContactNO();
    nnObjManager *mn = dynamic_cast<nnObjManager *>(childs->getManager());
    res = mn->addContact(10, 0, v);
    CA_ASSERT(res == true);
    CA_ASSERT((int)mn->size() == (int)1);
    nnGenericCoil *u = new nnGenericCoil();
    res = mn->addCoil(10, u);
    CA_ASSERT(res == true);
    CA_ASSERT((int)mn->size() == (int)20);
    nnContactNC *v1 = new nnContactNC();
    res = mn->addContact(12, 0, v1);
    CA_ASSERT(res == true);
    nnPoint p1(12, 0);
    nnPoint p2(10, 0);
    nnConnection::connectComponent(childs->getManager(), p2, p1);
    res = childs->getView()->updateDraw();
    CA_ASSERT(res == true);
    bmpImage &bdraw = childs->getView()->getDraw();
    draw(&bdraw);
    childs->getView()->handlerScrollHorz(2);
    res = childs->getView()->updateDraw();
    //CA_ASSERT(res == true);
    bdraw = childs->getView()->getDraw();
    draw(&bdraw);
    childs->getView()->handlerScrollVert(2);
    res = childs->getView()->updateDraw();
    CA_ASSERT(res == true);
    bdraw = childs->getView()->getDraw();
    draw(&bdraw);
}
Пример #16
0
void test_bmpImage_class::test10(void)
{
    _START();
    _INFO("verifica interrna alla classe: create attach clear");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.create(100, 100,24,  255);
    bmpImage t;
    t.create(100, 100,24, 255);
    LPBITMAPFILEHEADER v = (LPBITMAPFILEHEADER)s;
    t.clear();
    t.attach(s);
    CA_ASSERT(v == (LPBITMAPFILEHEADER)t);
}
Пример #17
0
void test_bmpImage_class::test6(void)
{
    _START();
    _INFO("verifica interrna alla classe: metodo copyfrom bmpImage");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.create(100, 100,24,  255);
    bmpImage v;
    v.copyFrombmpImage(s);
    int res = memcmp((LPBITMAPFILEHEADER)s, (LPBITMAPFILEHEADER)v, ((LPBITMAPFILEHEADER)(s))->bfSize);
    CA_ASSERT(res== 0);
    draw(&v);

}
Пример #18
0
void test_bmpImage_class::test4(void)
{
    _START();
    _INFO("verifica interrna alla classe : struttura bitmapfileinfo");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.create(100, 100,24,  255);
    LPBITMAPINFOHEADER v = s.getInfoHeader();
    CA_ASSERT(v != NULL);
    CA_ASSERT(v->biBitCount == 24);
    CA_ASSERT(v->biHeight == 100);
    CA_ASSERT(v->biWidth == 100);
    draw(&s);
}
Пример #19
0
void test_bmpImage_class::test11(void)
{
    _START();
    _INFO("verifica interrna alla classe:metodo portrait");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    bmpImage s;
    s.create(100, 50,24,  255);
    CA_ASSERT((int)s.getWidth()==100);
    CA_ASSERT((int)s.getHeight()== 50);
    draw(&s);
    s.portrait(false);
    CA_ASSERT((int)s.getWidth()==50);
    CA_ASSERT((int)s.getHeight()==100);
    draw(&s);

}
Пример #20
0
void test_bmpImage_class::test5(void)
{
    _START();
    _INFO("verifica interrna alla classe : metodi copytofile and copyfromfile");
    _AUTHOR("Coppi Angelo bmpImage library ");
    _STOP();
    remove("./whiteImage.bmp");
    bmpImage s;
    s.create(100, 100,32,  255);
    s.frameRect(10,10,90,90,255,0,0,0xffffffff);
    draw(&s);
    bool res = s.copyToFile(X("./whiteImage.bmp"));
    CA_ASSERT(res==true);
    bmpImage t;
    t.copyFromFile(X("./whiteImage.bmp"));
    CA_ASSERT((LPBITMAPFILEHEADER)s!=NULL);
    CA_ASSERT((LPBITMAPFILEHEADER)t!=NULL);
    int res1 = memcmp((LPBITMAPFILEHEADER)s, (LPBITMAPFILEHEADER)t, ((LPBITMAPFILEHEADER)(s))->bfSize);
    CA_ASSERT(res1==0);
    draw(&t);
    //remove("./whiteImage.bmp");
}