Subversion Repositories HomeAutomation

Rev

Rev 1498 | Rev 1744 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. #include "sns_irTransceive.h"
  3.  
  4. #if IR_RX_ENABLE==1
  5. struct {
  6.     uint8_t             state;
  7.     uint8_t             newData;
  8.     uint16_t            *rxbuf;
  9.     uint8_t             rxlen;
  10.     uint8_t             timerNum;
  11.     Ir_Protocol_Data_t  proto;
  12. } irRxChannel[IR_SUPPORTED_NUM_CHANNELS];
  13. #endif
  14.  
  15. #if IR_TX_ENABLE==1
  16. struct {
  17.     uint8_t             state;
  18.     uint8_t             sendComplete;
  19.     uint16_t            *txbuf;
  20.     uint8_t             txlen;
  21.     uint8_t             timerNum;
  22.     uint8_t             repeatCount;
  23.     uint8_t             stopSend;
  24.     Ir_Protocol_Data_t  proto;
  25. } irTxChannel[IR_SUPPORTED_NUM_CHANNELS];
  26. #endif
  27.  
  28. uint16_t    buf[3][MAX_NR_TIMES];
  29.  
  30. StdCan_Msg_t        irTxMsg;
  31.  
  32. #if (sns_irTransceive_SEND_DEBUG==1)
  33. void send_debug(uint16_t *buffer, uint8_t len) {
  34.     StdCan_Msg_t dbgIrTxMsg;
  35.     /* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */
  36.  
  37.     StdCan_Set_class(dbgIrTxMsg.Header, CAN_MODULE_CLASS_SNS);
  38.     StdCan_Set_direction(dbgIrTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  39.     dbgIrTxMsg.Length = 8;
  40.     dbgIrTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  41.     dbgIrTxMsg.Header.ModuleId = sns_irTransceive_ID;
  42.     dbgIrTxMsg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRRAW;
  43.     for (uint8_t i = 0; i < len>>2; i++) {
  44.         uint8_t index = i<<2;
  45.  
  46.         dbgIrTxMsg.Data[0] = (buffer[index]>>8)&0xff;
  47.         dbgIrTxMsg.Data[1] = (buffer[index]>>0)&0xff;
  48.         dbgIrTxMsg.Data[2] = (buffer[index+1]>>8)&0xff;
  49.         dbgIrTxMsg.Data[3] = (buffer[index+1]>>0)&0xff;
  50.         dbgIrTxMsg.Data[4] = (buffer[index+2]>>8)&0xff;
  51.         dbgIrTxMsg.Data[5] = (buffer[index+2]>>0)&0xff;
  52.         dbgIrTxMsg.Data[6] = (buffer[index+3]>>8)&0xff;
  53.         dbgIrTxMsg.Data[7] = (buffer[index+3]>>0)&0xff;
  54.                
  55.         /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
  56.         while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {}
  57.         _delay_ms(1);
  58.     }
  59.    
  60.     uint8_t lastpacketcnt = len&0x03;
  61.     if (lastpacketcnt > 0) {
  62.         dbgIrTxMsg.Length = lastpacketcnt<<1;
  63.         for (uint8_t i = 0; i < lastpacketcnt; i++) {
  64.             dbgIrTxMsg.Data[i<<1] = (buffer[(len&0xfc)|i]>>8)&0xff;
  65.             dbgIrTxMsg.Data[(i<<1)+1] = (buffer[(len&0xfc)|i]>>0)&0xff;
  66.         }
  67.         /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
  68.         while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {}
  69.         _delay_ms(1);
  70.     }
  71.  
  72. }
  73. #endif
  74.  
  75. #if IR_RX_ENABLE==1
  76. void sns_irTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len)
  77. {
  78.     if (channel < IR_SUPPORTED_NUM_CHANNELS)
  79.     {
  80.         irRxChannel[channel].newData = TRUE;
  81.         irRxChannel[channel].rxlen = len;
  82.     }
  83. }
  84. #endif
  85.  
  86. void sns_irTransceive_TX_done_callback(uint8_t channel)
  87. {
  88.     if (channel < IR_SUPPORTED_NUM_CHANNELS)
  89.     {
  90.         irTxChannel[channel].sendComplete = TRUE;
  91.     }
  92. }
  93.  
  94. void sns_irTransceive_Init(void)
  95. {
  96. /* Debug IO, PB7 */
  97. gpio_set_out(EXP_A);
  98. gpio_set_pin(EXP_A);
  99.  
  100.     StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS);
  101.     StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  102.     irTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  103.     irTxMsg.Header.ModuleId = sns_irTransceive_ID;
  104.     irTxMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_IR;
  105.     irTxMsg.Length = 6;
  106.  
  107.     for (uint8_t i = 0; i < IR_SUPPORTED_NUM_CHANNELS; i++)
  108.     {
  109. #if IR_RX_ENABLE==1
  110.         irRxChannel[i].state = sns_irTransceive_STATE_RECEIVING;
  111.         irRxChannel[i].newData = FALSE;
  112.         irRxChannel[i].rxlen = 0;
  113.         irRxChannel[i].proto.timeout=0;
  114.         irRxChannel[i].proto.data=0;
  115.         irRxChannel[i].proto.repeats=0;
  116.         irRxChannel[i].proto.protocol=0;
  117. #endif
  118.  
  119. #if IR_TX_ENABLE==1
  120.         irTxChannel[i].state = sns_irTransceive_STATE_IDLE;
  121.         irTxChannel[i].sendComplete = FALSE;
  122.         irTxChannel[i].repeatCount = 0;
  123.         irTxChannel[i].txlen = 0;
  124.         irTxChannel[i].proto.data=0;
  125.         irTxChannel[i].proto.repeats=0;
  126.         irTxChannel[i].proto.framecnt=0;
  127.         irTxChannel[i].proto.protocol=0;
  128. #endif
  129.     }
  130.    
  131. #if IR_RX_ENABLE==1
  132.     irRxChannel[0].timerNum=sns_irTransceive_RX0_REPEATE_TIMER;
  133.     irRxChannel[1].timerNum=sns_irTransceive_RX1_REPEATE_TIMER;
  134.     irRxChannel[2].timerNum=sns_irTransceive_RX2_REPEATE_TIMER;
  135. #endif
  136.  
  137. #if IR_TX_ENABLE==1
  138.     irTxChannel[0].timerNum=sns_irTransceive_TX0_REPEATE_TIMER;
  139.     irTxChannel[1].timerNum=sns_irTransceive_TX1_REPEATE_TIMER;
  140.     irTxChannel[2].timerNum=sns_irTransceive_TX2_REPEATE_TIMER;
  141. #endif
  142.    
  143.     IrTransceiver_Init();
  144.     /* Configure all TX VCC pins as outputs and disable them */
  145.     gpio_set_out(sns_irTransceive_VCC_EN0_PIN);
  146.     gpio_set_out(sns_irTransceive_VCC_EN1_PIN);
  147.     gpio_set_out(sns_irTransceive_VCC_EN2_PIN);
  148.     gpio_set_pin(sns_irTransceive_VCC_EN0_PIN);
  149.     gpio_set_pin(sns_irTransceive_VCC_EN1_PIN);
  150.     gpio_set_pin(sns_irTransceive_VCC_EN2_PIN);
  151.  
  152. #if IR_TX_ENABLE==1
  153.     gpio_set_out(sns_irTransceive_MOD_PIN);
  154.     gpio_set_out(sns_irTransceive_TX0_PIN);
  155.     gpio_set_out(sns_irTransceive_TX1_PIN);
  156.     gpio_set_out(sns_irTransceive_TX2_PIN);
  157. #if IR_TX_ACTIVE_LOW==1
  158.     gpio_set_pin(sns_irTransceive_TX0_PIN);
  159.     gpio_set_pin(sns_irTransceive_TX1_PIN);
  160.     gpio_set_pin(sns_irTransceive_TX2_PIN);
  161. #endif
  162. #endif
  163.  
  164. }
  165.  
  166. void sns_irTransceive_Process(void)
  167. {
  168.     for (uint8_t channel=0; channel < IR_SUPPORTED_NUM_CHANNELS; channel++)
  169.     {
  170. //gpio_toggle_pin(EXP_A); /* Toggle debug output PB7 */
  171.  
  172. #if IR_RX_ENABLE==1
  173.         switch (irRxChannel[channel].state)
  174.         {
  175.         case sns_irTransceive_STATE_IDLE:
  176.             irRxChannel[channel].state = sns_irTransceive_STATE_START_RECEIVE;
  177.             break;
  178.  
  179.         case sns_irTransceive_STATE_START_RECEIVE:
  180.             IrTransceiver_ResetRx(channel);
  181.             cli();
  182.             irRxChannel[channel].newData = FALSE;
  183.             sei();
  184.             irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING;
  185.             break;
  186.        
  187.         case sns_irTransceive_STATE_RECEIVING:
  188.             if (irRxChannel[channel].newData == TRUE) {
  189.                 //TODO: move this line to the RX callback
  190.                 IrTransceiver_DisableRx(channel);
  191.                 cli();
  192.                 irRxChannel[channel].newData = FALSE;
  193.                 sei();
  194.  
  195.                 /* Let protocol driver parse and then send on CAN */
  196.                 uint8_t res2 = parseProtocol(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen, &irRxChannel[channel].proto);
  197.                 if (res2 == IR_OK && irRxChannel[channel].proto.protocol != IR_PROTO_UNKNOWN) {
  198.                     irTxMsg.Data[0] = 0xf&CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED;
  199.                     irTxMsg.Data[0] |= channel<<4;
  200.                     irTxMsg.Data[1] = irRxChannel[channel].proto.protocol;
  201.                     irTxMsg.Data[2] = (irRxChannel[channel].proto.data>>24)&0xff;
  202.                     irTxMsg.Data[3] = (irRxChannel[channel].proto.data>>16)&0xff;
  203.                     irTxMsg.Data[4] = (irRxChannel[channel].proto.data>>8)&0xff;
  204.                     irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff;
  205.  
  206.                     StdCan_Put(&irTxMsg);
  207.                 }
  208.                 else if (irRxChannel[channel].proto.protocol == IR_PROTO_UNKNOWN)
  209.                 {
  210. #if (sns_irTransceive_SEND_DEBUG==1)
  211.                     send_debug(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen);
  212.                     irRxChannel[channel].proto.timeout=300;
  213. #endif
  214.                 }
  215.                
  216.                 /* Enable the receiver again */
  217.                 IrTransceiver_EnableRx(channel);
  218.                
  219.                 irRxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
  220.             }
  221.             break;
  222.  
  223.         case sns_irTransceive_STATE_START_PAUSE:
  224.             /* set a timer so we can send release button event when no new IR is arriving */
  225.             Timer_SetTimeout(irRxChannel[channel].timerNum, irRxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  226.             irRxChannel[channel].state = sns_irTransceive_STATE_PAUSING;
  227.             break;
  228.  
  229.         case sns_irTransceive_STATE_PAUSING:
  230.             /* reset timer if new IR arrived */
  231.             if (irRxChannel[channel].newData == TRUE || IrTransceiver_GetStoreEnableRx(channel) == TRUE) {
  232.                 cli();
  233.                 irRxChannel[channel].newData = FALSE;
  234.                 sei();
  235.                 Timer_SetTimeout(irRxChannel[channel].timerNum, irRxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  236.             }
  237.        
  238.             if (Timer_Expired(irRxChannel[channel].timerNum)) {
  239.                 irRxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  240.             }
  241.             break;
  242.  
  243.         case sns_irTransceive_STATE_START_IDLE:
  244.             if (irRxChannel[channel].proto.protocol != IR_PROTO_UNKNOWN) {
  245.                 /* Send button release command on CAN */
  246.                 irTxMsg.Data[0] = 0xf&CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED;
  247.                 irTxMsg.Data[0] |= channel<<4;
  248.                 irTxMsg.Data[1] = irRxChannel[channel].proto.protocol;
  249.                 irTxMsg.Data[2] = (irRxChannel[channel].proto.data>>24)&0xff;
  250.                 irTxMsg.Data[3] = (irRxChannel[channel].proto.data>>16)&0xff;
  251.                 irTxMsg.Data[4] = (irRxChannel[channel].proto.data>>8)&0xff;
  252.                 irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff;
  253.  
  254.                 StdCan_Put(&irTxMsg);
  255.             }
  256.             irRxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  257.             break;
  258.         }
  259. #endif
  260.  
  261. #if IR_TX_ENABLE==1
  262.         switch (irTxChannel[channel].state)
  263.         {
  264.         case sns_irTransceive_STATE_IDLE:
  265.             /* transmission is started when a command is received on can */
  266.             break;
  267.  
  268.         case sns_irTransceive_STATE_START_TRANSMIT:
  269.             if (expandProtocol(irTxChannel[channel].txbuf, &irTxChannel[channel].txlen, &irTxChannel[channel].proto) == IR_OK)
  270.             {
  271.                 IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, irTxChannel[channel].txlen);
  272.                 irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING;
  273.             }
  274.             else
  275.             {
  276.                 irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  277.             }
  278.             break;
  279.        
  280.         case sns_irTransceive_STATE_TRANSMITTING:
  281.             if (irTxChannel[channel].sendComplete == TRUE)
  282.             {
  283.                 cli();
  284.                 irTxChannel[channel].sendComplete = FALSE;
  285.                 sei();
  286.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
  287.             }
  288.             break;
  289.  
  290.         case sns_irTransceive_STATE_START_PAUSE:
  291.             if (irTxChannel[channel].repeatCount < irTxChannel[channel].proto.repeats)
  292.             {
  293.                 irTxChannel[channel].repeatCount++;
  294.             }
  295.            
  296.             Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  297.  
  298.             if (irTxChannel[channel].proto.framecnt != 255)
  299.             {
  300.                 irTxChannel[channel].proto.framecnt++;
  301.             }
  302.            
  303.             irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING;
  304.             break;
  305.  
  306.         case sns_irTransceive_STATE_PAUSING:
  307.             if (Timer_Expired(irTxChannel[channel].timerNum))
  308.             {
  309.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
  310.             }
  311.            
  312.             /* transmission is stopped when such command is recevied on can */
  313.             if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats)
  314.             {
  315.                 //TODO maybe send message on can for status? to confirm stopped sending, ready for new command
  316.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  317.             }
  318.             break;
  319.  
  320.         case sns_irTransceive_STATE_START_IDLE:
  321.             irTxChannel[channel].stopSend = FALSE;
  322.             irTxChannel[channel].repeatCount = 0;
  323.             irTxChannel[channel].proto.framecnt = 0;
  324.            
  325.             irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  326.             break;
  327.         }
  328. #endif
  329.  
  330.     }
  331. }
  332.  
  333. /* Handle incoming CAN data */
  334. void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg)
  335. {
  336.     if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
  337.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
  338.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_IRTRANSCEIVE &&
  339.         rxMsg->Header.ModuleId == sns_irTransceive_ID)
  340.     {
  341.         uint8_t channel;
  342.         switch (rxMsg->Header.Command)
  343.         {
  344.         case CAN_MODULE_CMD_PHYSICAL_IR:
  345.             channel = rxMsg->Data[0]>>4;
  346.             if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED && channel < IR_SUPPORTED_NUM_CHANNELS)
  347.             {
  348.                 if (irTxChannel[channel].state == sns_irTransceive_STATE_IDLE)
  349.                 {
  350.                     irTxChannel[channel].proto.protocol = rxMsg->Data[1];
  351.  
  352.                     irTxChannel[channel].proto.data = rxMsg->Data[2];
  353.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  354.                     irTxChannel[channel].proto.data |= rxMsg->Data[3];
  355.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  356.                     irTxChannel[channel].proto.data |= rxMsg->Data[4];
  357.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  358.                     irTxChannel[channel].proto.data |= rxMsg->Data[5];
  359.  
  360.                     irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
  361.                 }
  362.             }
  363.             else if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED && channel < IR_SUPPORTED_NUM_CHANNELS)
  364.             {
  365.                 if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE)
  366.                 {
  367.                     irTxChannel[channel].stopSend = TRUE;
  368.                 }
  369.             }
  370.             break;
  371.        
  372.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRCONFIG:
  373.             channel = rxMsg->Data[0]>>4;
  374.             uint8_t config = rxMsg->Data[0] & 0x0f;
  375.             uint8_t power = rxMsg->Data[1]>>6;
  376.  
  377.             if (channel < IR_SUPPORTED_NUM_CHANNELS && config <= CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_RECEIVE && power < 4)
  378.             {
  379. #if IR_RX_ENABLE==1
  380.                 if (config == CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_RECEIVE)
  381.                 {
  382.                     irRxChannel[channel].rxbuf = buf[channel];
  383.                     switch (channel)
  384.                     {
  385.                         case 0:
  386.                             gpio_clr_pin(sns_irTransceive_VCC_EN0_PIN);
  387.                             IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
  388.                             break;
  389.                         case 1:
  390.                             gpio_clr_pin(sns_irTransceive_VCC_EN1_PIN);
  391.                             IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN);
  392.                             break;
  393.                         case 2:
  394.                             gpio_clr_pin(sns_irTransceive_VCC_EN2_PIN);
  395.                             IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN);
  396.                             break;
  397.                     }
  398.                 }
  399. #endif
  400.  
  401. #if IR_TX_ENABLE==1
  402.                 if (config == CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_TRANSMIT)
  403.                 {
  404.                     irTxChannel[channel].txbuf = buf[channel];
  405.                     switch (channel)
  406.                     {
  407.                         case 0:
  408. #if IR_RX_ENABLE==1
  409.                             gpio_set_pin(sns_irTransceive_VCC_EN0_PIN);
  410.                             IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
  411. #endif
  412.                             IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX0_PIN);
  413.                             break;
  414.                         case 1:
  415. #if IR_RX_ENABLE==1
  416.                             gpio_set_pin(sns_irTransceive_VCC_EN1_PIN);
  417.                             IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN);
  418. #endif
  419.                             IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX1_PIN);
  420.                             break;
  421.                         case 2:
  422. #if IR_RX_ENABLE==1
  423.                             gpio_set_pin(sns_irTransceive_VCC_EN2_PIN);
  424.                             IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN);
  425. #endif
  426.                             IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX2_PIN);
  427.                             break;
  428.                     }
  429.                 }
  430. #endif
  431.             }
  432.             break;
  433.         }
  434.     }
  435. }
  436.  
  437. void sns_irTransceive_List(uint8_t ModuleSequenceNumber)
  438. {
  439.     StdCan_Msg_t txMsg;
  440.    
  441.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  442.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  443.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  444.  
  445.     txMsg.Header.ModuleId = sns_irTransceive_ID;
  446.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  447.     txMsg.Length = 6;
  448.  
  449.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  450.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  451.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  452.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  453.    
  454.     txMsg.Data[4] = NUMBER_OF_MODULES;
  455.     txMsg.Data[5] = ModuleSequenceNumber;
  456.    
  457.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  458. }
  459.