예제 #1
0
/*-----------------------------------------------------------------------------
*  sio open and bus init
*/
static int InitBus(const char *comPort) {

    uint8_t ch;
    int     handle;

    SioInit();
    handle = SioOpen(comPort, eSioBaud9600, eSioDataBits8, eSioParityNo, eSioStopBits1, eSioModeHalfDuplex);
    if (handle == -1) {
        return -1;
    }
    while (SioGetNumRxChar(handle) > 0) {
        SioRead(handle, &ch, sizeof(ch));
    }
    BusInit(handle);

    return handle;
}
예제 #2
0
파일: bus.c 프로젝트: haslhoferm/homebus
/*-----------------------------------------------------------------------------
*  check for new received bus telegram
*  return codes:
*              BUS_NO_MSG     no telegram in progress
*              BUS_MSG_OK     telegram received completely
*              BUS_MSG_RXING  telegram receiving in progress
*              BUS_MSG_ERROR  errorous telegram received (checksum error)
*/
UINT8 BusCheck(void) {
                     
   static UINT8 ret = BUS_NO_MSG;
   UINT8        ch;
   UINT8        retTmp;
   UINT8        numRxChar;

   numRxChar = SioRead(&ch);
   if (numRxChar != 0) {
      ret = BusDecode(ch);
      if ((ret == BUS_MSG_ERROR) ||
          (ret == BUS_MSG_OK)) {
         retTmp = ret; 
         ret = BUS_NO_MSG;
         return retTmp;
      }
   }
   return ret;
}
예제 #3
0
파일: bus.c 프로젝트: busmaster/homebus
/*-----------------------------------------------------------------------------
*  check for new received bus telegram
*  return codes:
*              BUS_NO_MSG     no telegram in progress
*              BUS_MSG_OK     telegram received completely
*              BUS_MSG_RXING  telegram receiving in progress
*              BUS_MSG_ERROR  errorous telegram received (checksum error)
*/
uint8_t BusCheck(void) {

   static uint8_t ret = BUS_NO_MSG;
   uint8_t        ch;
   uint8_t        retTmp;
   uint8_t        numRxChar;

   numRxChar = SioRead(&ch);
   if (numRxChar != 0) {
      ret = BusDecode(ch);
      if ((ret == BUS_MSG_ERROR) ||
          (ret == BUS_MSG_OK)) {
         retTmp = ret;
         ret = BUS_NO_MSG;
         return retTmp;
      }
   }
   return ret;
}
예제 #4
0
파일: main.c 프로젝트: busmaster/homebus
/*-----------------------------------------------------------------------------
*  main
*/
int main(int argc, char *argv[]) {

    int  handle;
    int  i;
    char comPort[SIZE_COMPORT] = "";
    uint8_t len;
    uint8_t val8;

    /* get tty device */
    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-c") == 0) {
            if (argc > i) {
                strncpy(comPort, argv[i + 1], sizeof(comPort) - 1);
                comPort[sizeof(comPort) - 1] = 0;
            }
            break;
        }
    }
    if (strlen(comPort) == 0) {
        PrintUsage();
        return 0;
    }

    SioInit();
    handle = SioOpen(comPort, eSioBaud9600, eSioDataBits8, eSioParityNo, eSioStopBits1, eSioModeHalfDuplex);

    if (handle == -1) {
        printf("can't open %s\r\n", comPort);
        return 0;
    }

    // wait for sio input to settle and the flush
    usleep(100000);
    while ((len = SioGetNumRxChar(handle)) != 0) {
        SioRead(handle, &val8, sizeof(val8));
    }

    BusInit(handle);
#if 1
    BusVarInit(67, BusVarNv);

    {
    	uint8_t var1 = 1;
    	uint16_t var2 = 0x1234;

    	bool rc;
    	uint8_t len;

    	TBusVarHdl hdl1;
    	TBusVarHdl hdl2;
    	TBusTelegram *msg;

    	TBusVarResult result;
    	TBusVarState  state;


    	BusVarAdd(0, sizeof(var1), true);
    	BusVarAdd(1, sizeof(var2), false);

    	rc = BusVarWrite(1, &var2, sizeof(var2), &result);
    	rc = BusVarWrite(0, &var1, sizeof(var1), &result);

    	var1 = 0;
    	var2 = 0;

    	len = BusVarRead(1, &var2, sizeof(var2), &result);
    	printf("len %d var2 %x\n", len, var2);
    	len = BusVarRead(0, &var1, sizeof(var1), &result);
    	printf("len %d var1 %x\n", len, var1);

    	hdl2 = BusVarTransactionOpen(242, 1, &var2, sizeof(var2), eBusVarRead);
    	hdl1 = BusVarTransactionOpen(242, 0, &var1, sizeof(var1), eBusVarRead);

    	for (i = 0; i < 1000; i++) {
    		BusVarProcess();
    		usleep(10000);
   			if (BusCheck() == BUS_MSG_OK) {
  				msg = BusMsgBufGet();
   				if ((msg->type == eBusDevRespGetVar) &&
   					(msg->msg.devBus.receiverAddr == 67)) {
         	        BusVarRespGet(msg->senderAddr, &msg->msg.devBus.x.devResp.getVar);
   				}
  			}

   			if (hdl1 != BUSVAR_HDL_INVALID) {
   		        state = BusVarTransactionState(hdl1);
   		        if (state & BUSVAR_STATE_FINAL) {
   		            if (state == eBusVarState_Ready) {
   		            	printf("var1 %02x\n", var1);
   		            }
   		            BusVarTransactionClose(hdl1);
   		            hdl1 = BUSVAR_HDL_INVALID;
   		        }
   		    }
   			if (hdl2 != BUSVAR_HDL_INVALID) {
   		        state = BusVarTransactionState(hdl2);
   		        if (state & BUSVAR_STATE_FINAL) {
   		            if (state == eBusVarState_Ready) {
   		            	printf("var2 %04x\n", var2);
   		            }
   		            BusVarTransactionClose(hdl2);
   		            hdl2 = BUSVAR_HDL_INVALID;
   		        }
   		    }
    	}

    }
    return 0;
#endif

    if (Test() == 0) {
    	printf("OK\n");
    } else {
    	printf("ERROR\n");
    }

    if (handle != -1) {
        SioClose(handle);
    }

    return 0;
}