Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. #include "sns_irTransceive.h"
  3.  
  4. #ifdef sns_irTransceive_USEEEPROM
  5. #include "sns_irTransceive_eeprom.h"
  6. struct eeprom_sns_irTransceive EEMEM eeprom_sns_irTransceive =
  7. {
  8.     {
  9.         /* Define initialization values on the EEPROM variables here.
  10.         This will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips.
  11.         Write the values in the exact same order as the struct is defined in the *.h file. */
  12.         CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO,
  13.         0,
  14.         CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO,
  15.         0,
  16.         CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO,
  17.         0,
  18.     },
  19.     0   /* crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts */
  20. };
  21. #endif
  22.  
  23. #if IR_RX_ENABLE==1
  24. struct {
  25.     uint8_t             state;
  26.     uint8_t             modfreq;
  27.     uint16_t            *rxbuf;
  28.     uint8_t             rxlen;
  29.     uint8_t             timerNum;
  30.     Ir_Protocol_Data_t  proto;
  31.     uint8_t             newData;
  32. } irRxChannel[IR_SUPPORTED_NUM_CHANNELS];
  33. #endif
  34.  
  35. #if IR_TX_ENABLE==1
  36. struct {
  37.     uint8_t             state;
  38.     uint8_t             modfreq;
  39.     uint16_t            *txbuf;
  40.     uint8_t             txlen;
  41.     uint8_t             timerNum;
  42.     uint8_t             repeatCount;
  43.     Ir_Protocol_Data_t  proto;
  44.     uint8_t             stopSend;
  45.     uint8_t             sendComplete;
  46.     // pronto params
  47.     uint8_t             onceSeqLen;
  48.     uint8_t             repSeqLen;
  49.     uint8_t             numberOfRepeats;
  50. } irTxChannel[IR_SUPPORTED_NUM_CHANNELS];
  51. #endif
  52.  
  53. uint16_t    buf[IR_SUPPORTED_NUM_CHANNELS][MAX_NR_TIMES];
  54.  
  55. StdCan_Msg_t        irTxMsg;
  56.  
  57. #if (sns_irTransceive_SEND_DEBUG==1)
  58. void send_debug(uint16_t *buffer, uint8_t len) {
  59.     StdCan_Msg_t dbgIrTxMsg;
  60.     /* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */
  61.  
  62.     StdCan_Set_class(dbgIrTxMsg.Header, CAN_MODULE_CLASS_SNS);
  63.     StdCan_Set_direction(dbgIrTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  64.     dbgIrTxMsg.Length = 8;
  65.     dbgIrTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  66.     dbgIrTxMsg.Header.ModuleId = sns_irTransceive_ID;
  67.     dbgIrTxMsg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRRAW;
  68.     for (uint8_t i = 0; i < len>>2; i++) {
  69.         uint8_t index = i<<2;
  70.  
  71.         dbgIrTxMsg.Data[0] = (buffer[index]>>8)&0xff;
  72.         dbgIrTxMsg.Data[1] = (buffer[index]>>0)&0xff;
  73.         dbgIrTxMsg.Data[2] = (buffer[index+1]>>8)&0xff;
  74.         dbgIrTxMsg.Data[3] = (buffer[index+1]>>0)&0xff;
  75.         dbgIrTxMsg.Data[4] = (buffer[index+2]>>8)&0xff;
  76.         dbgIrTxMsg.Data[5] = (buffer[index+2]>>0)&0xff;
  77.         dbgIrTxMsg.Data[6] = (buffer[index+3]>>8)&0xff;
  78.         dbgIrTxMsg.Data[7] = (buffer[index+3]>>0)&0xff;
  79.                
  80.         /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
  81.         while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {}
  82.         _delay_ms(1);
  83.     }
  84.    
  85.     uint8_t lastpacketcnt = len&0x03;
  86.     if (lastpacketcnt > 0) {
  87.         dbgIrTxMsg.Length = lastpacketcnt<<1;
  88.         for (uint8_t i = 0; i < lastpacketcnt; i++) {
  89.             dbgIrTxMsg.Data[i<<1] = (buffer[(len&0xfc)|i]>>8)&0xff;
  90.             dbgIrTxMsg.Data[(i<<1)+1] = (buffer[(len&0xfc)|i]>>0)&0xff;
  91.         }
  92.         /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
  93.         while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {}
  94.         _delay_ms(1);
  95.     }
  96.  
  97. }
  98. #endif
  99.  
  100. #define sns_irTransceive_BaseFrq (4145146ULL)
  101.  
  102. #ifndef sns_irTransceive_PRONTO_SUPPORT
  103. #define sns_irTransceive_PRONTO_SUPPORT 1
  104. #endif
  105.  
  106. #if sns_irTransceive_PRONTO_SUPPORT==1
  107. volatile uint32_t sns_irTransceive_LastPronto=0;
  108. static uint8_t activeChannel = 0;
  109. #define sns_irTransceive_MAXTIMING (16*1000)
  110.  
  111. void send_pronto(uint16_t *buffer, uint8_t len, uint8_t channel, uint8_t modfreq) {
  112.     StdCan_Msg_t msg;
  113.  
  114.     StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS);
  115.     StdCan_Set_direction(msg.Header, DIRECTIONFLAG_FROM_OWNER);
  116.     msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  117.     msg.Header.ModuleId = sns_irTransceive_ID;
  118.    
  119.     /* Send timing command */
  120.     msg.Length = 5;
  121.     msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOTIMING;
  122.     uint32_t currentTime=Timer_GetTicks();
  123.     if ((currentTime < sns_irTransceive_LastPronto+sns_irTransceive_MAXTIMING) && (sns_irTransceive_LastPronto != 0))
  124.     {
  125.         msg.Data[0] = 0xff;
  126.         msg.Data[1] = 0x10;
  127.         msg.Data[2] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>16)&0xff;
  128.         msg.Data[3] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>8)&0xff;
  129.         msg.Data[4] = ((currentTime-sns_irTransceive_LastPronto)*1000)&0xff;
  130.         while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  131.         _delay_ms(1);
  132.     }
  133.     sns_irTransceive_LastPronto=currentTime;
  134.  
  135.     /* Send pronto start */
  136.     msg.Length = 8;
  137.     msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTART;
  138.  
  139.     msg.Data[0] = ((channel<<4)|0x0);   /* Channel and Prontoformat 0x000 */
  140.     msg.Data[1] = 0x00;
  141.     msg.Data[2] = 0x00; /* Freq divider */
  142.     msg.Data[3] = modfreq;
  143.     msg.Data[4] = 0x00; /* Once seq length, first byte always 0 */
  144.     msg.Data[5] = len/2;
  145.     msg.Data[6] = 0x00; /* Repeat seq length, always 0 for ir receive */
  146.     msg.Data[7] = 0x00;
  147.    
  148.     while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  149.     _delay_ms(1);
  150.  
  151.     /* Send pronto data */
  152.     uint16_t divider = ((1000000ULL*modfreq)/sns_irTransceive_BaseFrq);
  153.     msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1;
  154.     /* Counter for buffer */
  155.     uint8_t i = 0;
  156.     /* Counter for filling can frame data */
  157.     uint8_t j = 0;
  158.     /* Remember byte if data does not fit 8 bit */
  159.     uint8_t mem = 0;
  160.     while (i < len)
  161.     {
  162.         if (mem > 0)
  163.         {
  164.             /* If byte was memorized then buffer it */
  165.             msg.Data[j] = mem;
  166.             /* Clear memory */
  167.             mem = 0;
  168.         }
  169.         else
  170.         {
  171.             uint16_t data = buffer[i]/divider;
  172.             if (data >= 256)
  173.             {
  174.                 /* If data does not fit into 8 bit, then split, memorize low byte */
  175.                 mem = data&0xff;
  176.                 /* Buffer high byte */
  177.                 msg.Data[j] = (data>>8)&0xff;
  178.                 j++;
  179.                 if (j==8)
  180.                 {
  181.                     /* If send buffer is full, send frame */
  182.                     /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */
  183.                     while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  184.                     _delay_ms(1);
  185.                     j=0;
  186.                     msg.Header.Command++;
  187.                 }
  188.                 /* Set complementary burst pair to 0 to indicate 16bit transmission */
  189.                 msg.Data[j] = 0;
  190.             }
  191.             else
  192.             {
  193.                 msg.Data[j] = data&0xff;
  194.             }
  195.            
  196.             i++;
  197.         }
  198.        
  199.         j++;
  200.         if (j==8)
  201.         {
  202.             /* If send buffer is full, send frame */
  203.             /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */
  204.             while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  205.             _delay_ms(1);
  206.             j=0;
  207.             msg.Header.Command++;
  208.         }
  209.     }
  210.    
  211.     /* End with 25ms, TODO fix uglyness */
  212.     msg.Data[j] = ((IR_MAX_PULSE_WIDTH/divider)>>8)&0xff;
  213.     j++;
  214.     if (j==8)
  215.     {
  216.         /* If send buffer is full, send frame */
  217.         /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */
  218.         while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  219.         _delay_ms(1);
  220.         j=0;
  221.         msg.Header.Command++;
  222.     }
  223.     msg.Data[j] = 0;
  224.     j++;
  225.     msg.Data[j] = (IR_MAX_PULSE_WIDTH/divider)&0xff;
  226.     j++;
  227.     if (j==8)
  228.     {
  229.         /* If send buffer is full, send frame */
  230.         /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */
  231.         while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  232.         _delay_ms(1);
  233.         j=0;
  234.         msg.Header.Command++;
  235.     }
  236.    
  237.     /* Msg command kept from for loop, but increase 16 to send ProntoEnd */
  238.     msg.Header.Command+=16;
  239.     msg.Length = j;
  240.     /* data kept from loop, if any */
  241.     /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
  242.     while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  243.     _delay_ms(1);
  244. }
  245. #endif
  246.  
  247.  
  248. #if IR_RX_ENABLE==1
  249. void sns_irTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len)
  250. {
  251.     if (channel < IR_SUPPORTED_NUM_CHANNELS)
  252.     {
  253.         irRxChannel[channel].newData = TRUE;
  254.         irRxChannel[channel].rxlen = len;
  255.     }
  256. }
  257. #endif
  258.  
  259.  
  260. #if IR_TX_ENABLE==1
  261. void sns_irTransceive_TX_done_callback(uint8_t channel)
  262. {
  263.     if (channel < IR_SUPPORTED_NUM_CHANNELS)
  264.     {
  265.         irTxChannel[channel].sendComplete = TRUE;
  266.     }
  267. }
  268. #endif
  269.  
  270.  
  271. void sns_irTransceive_setConfig(uint8_t channel, uint8_t config, uint8_t power, uint8_t modfreq)
  272. {
  273.     if (channel < IR_SUPPORTED_NUM_CHANNELS && config <= CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_RECEIVE && power < 4)
  274.     {
  275. #if IR_RX_ENABLE==1
  276.         if (config == CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_RECEIVE)
  277.         {
  278. #if IR_TX_ENABLE==1
  279.             irTxChannel[channel].state = sns_irTransceive_STATE_DISABLED;
  280. #endif
  281.             irRxChannel[channel].modfreq = modfreq;
  282.             irRxChannel[channel].rxbuf = buf[channel];
  283.             switch (channel)
  284.             {
  285.                 case 0:
  286.                     gpio_clr_pin(sns_irTransceive_VCC_EN0_PIN);
  287.                     IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
  288.                     break;
  289.                 case 1:
  290.                     gpio_clr_pin(sns_irTransceive_VCC_EN1_PIN);
  291.                     IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN);
  292.                     break;
  293.                 case 2:
  294.                     gpio_clr_pin(sns_irTransceive_VCC_EN2_PIN);
  295.                     IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN);
  296.                     break;
  297.             }
  298.             irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING;
  299.         }
  300. #endif
  301.  
  302. #if IR_TX_ENABLE==1
  303.         if (config == CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_TRANSMIT)
  304.         {
  305. #if IR_RX_ENABLE==1
  306.             irRxChannel[channel].state = sns_irTransceive_STATE_DISABLED;
  307. #endif
  308.             irTxChannel[channel].modfreq = modfreq;
  309.             irTxChannel[channel].txbuf = buf[channel];
  310.             switch (channel)
  311.             {
  312.                 case 0:
  313. #if IR_RX_ENABLE==1
  314.                     gpio_set_pin(sns_irTransceive_VCC_EN0_PIN);
  315.                     IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
  316. #endif
  317.                     IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX0_PIN);
  318.  
  319. #if sns_irTransceive_ENABLE_PCA95xx==1
  320.                     Pca95xx_set_out(sns_irTransceive_TX0_PWRl);
  321.                     Pca95xx_set_out(sns_irTransceive_TX0_PWRh);
  322.                     if (power&0x1)
  323.                     {
  324.                         Pca95xx_set_in(sns_irTransceive_TX0_PWRl);
  325.                     }
  326.                     if (power&0x2)
  327.                     {
  328.                         Pca95xx_set_in(sns_irTransceive_TX0_PWRh);
  329.                     }
  330. #endif
  331.                     break;
  332.                 case 1:
  333. #if IR_RX_ENABLE==1
  334.                     gpio_set_pin(sns_irTransceive_VCC_EN1_PIN);
  335.                     IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN);
  336. #endif
  337.                     IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX1_PIN);
  338.                    
  339. #if sns_irTransceive_ENABLE_PCA95xx==1
  340.                     Pca95xx_set_out(sns_irTransceive_TX1_PWRl);
  341.                     Pca95xx_set_out(sns_irTransceive_TX1_PWRh);
  342.                     if (power&0x1)
  343.                     {
  344.                         Pca95xx_set_in(sns_irTransceive_TX1_PWRl);
  345.                     }
  346.                     if (power&0x2)
  347.                     {
  348.                         Pca95xx_set_in(sns_irTransceive_TX1_PWRh);
  349.                     }
  350. #endif
  351.                     break;
  352.                 case 2:
  353. #if IR_RX_ENABLE==1
  354.                     gpio_set_pin(sns_irTransceive_VCC_EN2_PIN);
  355.                     IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN);
  356. #endif
  357.                     IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX2_PIN);
  358.                    
  359. #if sns_irTransceive_ENABLE_PCA95xx==1
  360.                     Pca95xx_set_out(sns_irTransceive_TX2_PWRl);
  361.                     Pca95xx_set_out(sns_irTransceive_TX2_PWRh);
  362.                     if (power&0x1)
  363.                     {
  364.                         Pca95xx_set_in(sns_irTransceive_TX2_PWRl);
  365.                     }
  366.                     if (power&0x2)
  367.                     {
  368.                         Pca95xx_set_in(sns_irTransceive_TX2_PWRh);
  369.                     }
  370. #endif
  371.                     break;
  372.             }
  373.             irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  374.         }
  375. #endif
  376.     }
  377. }
  378.  
  379.  
  380. void sns_irTransceive_Init(void)
  381. {
  382.     StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS);
  383.     StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  384.     irTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  385.     irTxMsg.Header.ModuleId = sns_irTransceive_ID;
  386.     irTxMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_IR;
  387.     irTxMsg.Length = 6;
  388.  
  389.     for (uint8_t i = 0; i < IR_SUPPORTED_NUM_CHANNELS; i++)
  390.     {
  391. #if IR_RX_ENABLE==1
  392.         irRxChannel[i].state = sns_irTransceive_STATE_DISABLED;
  393.         irRxChannel[i].newData = FALSE;
  394.         irRxChannel[i].rxlen = 0;
  395.         irRxChannel[i].proto.timeout=0;
  396.         irRxChannel[i].proto.data=0;
  397.         irRxChannel[i].proto.repeats=0;
  398.         irRxChannel[i].proto.protocol=0;
  399. #endif
  400.  
  401. #if IR_TX_ENABLE==1
  402.         irTxChannel[i].state = sns_irTransceive_STATE_DISABLED;
  403.         irTxChannel[i].sendComplete = FALSE;
  404.         irTxChannel[i].repeatCount = 0;
  405.         irTxChannel[i].txlen = 0;
  406.         irTxChannel[i].proto.data=0;
  407.         irTxChannel[i].proto.repeats=0;
  408.         irTxChannel[i].proto.framecnt=0;
  409.         irTxChannel[i].proto.protocol=0;
  410. #endif
  411.     }
  412.    
  413. #if IR_RX_ENABLE==1
  414.     // TODO: hardcoded to 3 channels?? /jm
  415.     irRxChannel[0].timerNum=sns_irTransceive_RX0_REPEATE_TIMER;
  416.     irRxChannel[1].timerNum=sns_irTransceive_RX1_REPEATE_TIMER;
  417.     irRxChannel[2].timerNum=sns_irTransceive_RX2_REPEATE_TIMER;
  418. #endif
  419.  
  420. #if IR_TX_ENABLE==1
  421.     // TODO: hardcoded to 3 channels?? /jm
  422.     irTxChannel[0].timerNum=sns_irTransceive_TX0_REPEATE_TIMER;
  423.     irTxChannel[1].timerNum=sns_irTransceive_TX1_REPEATE_TIMER;
  424.     irTxChannel[2].timerNum=sns_irTransceive_TX2_REPEATE_TIMER;
  425. #endif
  426.    
  427.     IrTransceiver_Init();
  428.     /* Configure all TX VCC pins as outputs and disable them */
  429.     gpio_set_out(sns_irTransceive_VCC_EN0_PIN);
  430.     gpio_set_out(sns_irTransceive_VCC_EN1_PIN);
  431.     gpio_set_out(sns_irTransceive_VCC_EN2_PIN);
  432.     gpio_set_pin(sns_irTransceive_VCC_EN0_PIN);
  433.     gpio_set_pin(sns_irTransceive_VCC_EN1_PIN);
  434.     gpio_set_pin(sns_irTransceive_VCC_EN2_PIN);
  435.  
  436. #if IR_TX_ENABLE==1
  437.     gpio_set_out(sns_irTransceive_MOD_PIN);
  438.     gpio_set_out(sns_irTransceive_TX0_PIN);
  439.     gpio_set_out(sns_irTransceive_TX1_PIN);
  440.     gpio_set_out(sns_irTransceive_TX2_PIN);
  441. #if IR_TX_ACTIVE_LOW==1
  442.     gpio_set_pin(sns_irTransceive_TX0_PIN);
  443.     gpio_set_pin(sns_irTransceive_TX1_PIN);
  444.     gpio_set_pin(sns_irTransceive_TX2_PIN);
  445. #endif
  446. #endif
  447.    
  448.     /* IR tx power pins on PCA95xx */
  449. #if sns_irTransceive_ENABLE_PCA95xx==1
  450.     Pca95xx_Init(0);
  451.  
  452.     Pca95xx_clr_pin(sns_irTransceive_TX0_PWRl);
  453.     Pca95xx_set_out(sns_irTransceive_TX0_PWRl);
  454.     Pca95xx_clr_pin(sns_irTransceive_TX0_PWRh);
  455.     Pca95xx_set_out(sns_irTransceive_TX0_PWRh);
  456.    
  457.     Pca95xx_clr_pin(sns_irTransceive_TX1_PWRl);
  458.     Pca95xx_set_out(sns_irTransceive_TX1_PWRl);
  459.     Pca95xx_clr_pin(sns_irTransceive_TX1_PWRh);
  460.     Pca95xx_set_out(sns_irTransceive_TX1_PWRh);
  461.    
  462.     Pca95xx_clr_pin(sns_irTransceive_TX2_PWRl);
  463.     Pca95xx_set_out(sns_irTransceive_TX2_PWRl);
  464.     Pca95xx_clr_pin(sns_irTransceive_TX2_PWRh);
  465.     Pca95xx_set_out(sns_irTransceive_TX2_PWRh);
  466. #endif
  467.  
  468. #ifdef sns_irTransceive_USEEEPROM
  469.     if (EEDATA_OK)
  470.     {
  471.       /* Use stored data to set initial values for the module */
  472.         sns_irTransceive_setConfig(0, eeprom_read_byte(EEDATA.ch0_config), eeprom_read_byte(EEDATA.ch0_txpower), eeprom_read_byte(EEDATA.ch0_modfreq));
  473.         sns_irTransceive_setConfig(1, eeprom_read_byte(EEDATA.ch1_config), eeprom_read_byte(EEDATA.ch1_txpower), eeprom_read_byte(EEDATA.ch1_modfreq));
  474.         sns_irTransceive_setConfig(2, eeprom_read_byte(EEDATA.ch2_config), eeprom_read_byte(EEDATA.ch2_txpower), eeprom_read_byte(EEDATA.ch2_modfreq));
  475.     }
  476.     else
  477.     {  
  478.     /* The CRC of the EEPROM is not correct, store default values and update CRC */
  479.         eeprom_write_byte_crc(EEDATA.ch0_config, CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO, WITHOUT_CRC);
  480.         eeprom_write_byte_crc(EEDATA.ch0_txpower, 0, WITHOUT_CRC);
  481.         eeprom_write_byte_crc(EEDATA.ch0_modfreq, sns_irTransceive_BaseFrq/38000, WITHOUT_CRC);
  482.         eeprom_write_byte_crc(EEDATA.ch1_config, CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO, WITHOUT_CRC);
  483.         eeprom_write_byte_crc(EEDATA.ch1_txpower, 0, WITHOUT_CRC);
  484.         eeprom_write_byte_crc(EEDATA.ch1_modfreq, sns_irTransceive_BaseFrq/38000, WITHOUT_CRC);
  485.         eeprom_write_byte_crc(EEDATA.ch2_config, CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO, WITHOUT_CRC);
  486.         eeprom_write_byte_crc(EEDATA.ch2_txpower, 0, WITHOUT_CRC);
  487.         eeprom_write_byte_crc(EEDATA.ch2_modfreq, sns_irTransceive_BaseFrq/38000, WITHOUT_CRC);
  488.         EEDATA_UPDATE_CRC;
  489.     }
  490. #endif 
  491. }
  492.  
  493. void sns_irTransceive_Process(void)
  494. {
  495.     for (uint8_t channel=0; channel < IR_SUPPORTED_NUM_CHANNELS; channel++)
  496.     {
  497.  
  498. #if IR_RX_ENABLE==1
  499.         switch (irRxChannel[channel].state)
  500.         {
  501.         case sns_irTransceive_STATE_IDLE:
  502.             irRxChannel[channel].state = sns_irTransceive_STATE_START_RECEIVE;
  503.             break;
  504.  
  505.         case sns_irTransceive_STATE_START_RECEIVE:
  506.             IrTransceiver_ResetRx(channel);
  507.             cli();
  508.             irRxChannel[channel].newData = FALSE;
  509.             sei();
  510.             irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING;
  511.             break;
  512.        
  513.         case sns_irTransceive_STATE_RECEIVING:
  514.             if (irRxChannel[channel].newData == TRUE) {
  515.                 //TODO: move this line to the RX callback
  516.                 IrTransceiver_DisableRx(channel);
  517.                 cli();
  518.                 irRxChannel[channel].newData = FALSE;
  519.                 sei();
  520.  
  521.                 /* Let protocol driver parse and then send on CAN */
  522.                 uint8_t res2 = parseProtocol(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen, &irRxChannel[channel].proto);
  523.                 if (res2 == IR_OK && irRxChannel[channel].proto.protocol != IR_PROTO_UNKNOWN) {
  524.                     irTxMsg.Data[0] = 0xf&CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED;
  525.                     irTxMsg.Data[0] |= channel<<4;
  526.                     irTxMsg.Data[1] = irRxChannel[channel].proto.protocol;
  527.                     irTxMsg.Data[2] = (irRxChannel[channel].proto.data>>24)&0xff;
  528.                     irTxMsg.Data[3] = (irRxChannel[channel].proto.data>>16)&0xff;
  529.                     irTxMsg.Data[4] = (irRxChannel[channel].proto.data>>8)&0xff;
  530.                     irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff;
  531.  
  532.                     StdCan_Put(&irTxMsg);
  533.                 }
  534.                 else if (irRxChannel[channel].proto.protocol == IR_PROTO_UNKNOWN)
  535.                 {
  536. #if (sns_irTransceive_SEND_DEBUG==1)
  537.                     send_debug(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen);
  538.                     irRxChannel[channel].proto.timeout=300;
  539. #elif sns_irTransceive_PRONTO_SUPPORT==1
  540.                     send_pronto(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen, channel, irRxChannel[channel].modfreq);
  541.                     irRxChannel[channel].proto.timeout=1;
  542. #endif
  543.                 }
  544.  
  545.                 /* Enable the receiver again */
  546.                 IrTransceiver_EnableRx(channel);
  547.  
  548.                 irRxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
  549.             }
  550.             break;
  551.  
  552.         case sns_irTransceive_STATE_START_PAUSE:
  553.             /* set a timer so we can send release button event when no new IR is arriving */
  554.             Timer_SetTimeout(irRxChannel[channel].timerNum, irRxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  555.             irRxChannel[channel].state = sns_irTransceive_STATE_PAUSING;
  556.             break;
  557.  
  558.         case sns_irTransceive_STATE_PAUSING:
  559.             /* reset timer if new IR arrived */
  560.             if (irRxChannel[channel].newData == TRUE || IrTransceiver_GetStoreEnableRx(channel) == TRUE) {
  561.                 cli();
  562.                 irRxChannel[channel].newData = FALSE;
  563.                 sei();
  564.                 Timer_SetTimeout(irRxChannel[channel].timerNum, irRxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  565.             }
  566.        
  567.             if (Timer_Expired(irRxChannel[channel].timerNum)) {
  568.                 irRxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  569.             }
  570.             break;
  571.  
  572.         case sns_irTransceive_STATE_START_IDLE:
  573.             if (irRxChannel[channel].proto.protocol != IR_PROTO_UNKNOWN) {
  574.                 /* Send button release command on CAN */
  575.                 irTxMsg.Data[0] = 0xf&CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED;
  576.                 irTxMsg.Data[0] |= channel<<4;
  577.                 irTxMsg.Data[1] = irRxChannel[channel].proto.protocol;
  578.                 irTxMsg.Data[2] = (irRxChannel[channel].proto.data>>24)&0xff;
  579.                 irTxMsg.Data[3] = (irRxChannel[channel].proto.data>>16)&0xff;
  580.                 irTxMsg.Data[4] = (irRxChannel[channel].proto.data>>8)&0xff;
  581.                 irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff;
  582.  
  583.                 StdCan_Put(&irTxMsg);
  584.             }
  585.             irRxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  586.             break;
  587.  
  588.         default:
  589.             break;
  590.         }
  591. #endif
  592.  
  593. #if IR_TX_ENABLE==1
  594.         switch (irTxChannel[channel].state)
  595.         {
  596.         case sns_irTransceive_STATE_IDLE:
  597.             /* transmission is started when a command is received on can */
  598.             break;
  599.  
  600.         case sns_irTransceive_STATE_START_TRANSMIT:
  601.             if (expandProtocol(irTxChannel[channel].txbuf, &irTxChannel[channel].txlen, &irTxChannel[channel].proto) == IR_OK)
  602.             {
  603.                 IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen);
  604.                 irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING;
  605.             }
  606.             else
  607.             {
  608.                 irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  609.             }
  610.             break;
  611.  
  612.         case sns_irTransceive_STATE_TRANSMITTING:
  613.             if (irTxChannel[channel].sendComplete == TRUE)
  614.             {
  615.                 cli();
  616.                 irTxChannel[channel].sendComplete = FALSE;
  617.                 sei();
  618.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
  619.             }
  620.             break;
  621.  
  622.         case sns_irTransceive_STATE_START_PAUSE:
  623.             if (irTxChannel[channel].repeatCount < irTxChannel[channel].proto.repeats)
  624.             {
  625.                 irTxChannel[channel].repeatCount++;
  626.             }
  627.            
  628.             Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  629.  
  630.             if (irTxChannel[channel].proto.framecnt != 255)
  631.             {
  632.                 irTxChannel[channel].proto.framecnt++;
  633.             }
  634.            
  635.             irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING;
  636.             break;
  637.  
  638.         case sns_irTransceive_STATE_PAUSING:
  639.             if (Timer_Expired(irTxChannel[channel].timerNum))
  640.             {
  641.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
  642.             }
  643.            
  644.             /* transmission is stopped when such command is recevied on can */
  645.             if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats)
  646.             {
  647.                 //TODO maybe send message on can for status? to confirm stopped sending, ready for new command
  648.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  649.             }
  650.             break;
  651.  
  652.         case sns_irTransceive_STATE_START_IDLE:
  653.             irTxChannel[channel].stopSend = FALSE;
  654.             irTxChannel[channel].repeatCount = 0;
  655.             irTxChannel[channel].proto.framecnt = 0;
  656.            
  657.             irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  658.             break;
  659.  
  660.         default:
  661.             break;
  662.         }
  663. #endif
  664.  
  665.     }
  666. }
  667.  
  668.  
  669. /* Handle incoming CAN data */
  670. void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg)
  671. {
  672.     if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
  673.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
  674.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_IRTRANSCEIVE &&
  675.         rxMsg->Header.ModuleId == sns_irTransceive_ID)
  676.     {
  677.         //printf("CMD= %u", rxMsg->Header.Command);
  678.         switch (rxMsg->Header.Command)
  679.         {
  680. #if IR_TX_ENABLE==1
  681.         case CAN_MODULE_CMD_PHYSICAL_IR: {
  682.             uint8_t channel = rxMsg->Data[0]>>4;
  683.             if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED && channel < IR_SUPPORTED_NUM_CHANNELS)
  684.             {
  685.                 if (irTxChannel[channel].state == sns_irTransceive_STATE_IDLE)
  686.                 {
  687.                     irTxChannel[channel].proto.protocol = rxMsg->Data[1];
  688.  
  689.                     irTxChannel[channel].proto.data = rxMsg->Data[2];
  690.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  691.                     irTxChannel[channel].proto.data |= rxMsg->Data[3];
  692.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  693.                     irTxChannel[channel].proto.data |= rxMsg->Data[4];
  694.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  695.                     irTxChannel[channel].proto.data |= rxMsg->Data[5];
  696.  
  697.                     irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
  698.                 }
  699.             }
  700.             else if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED && channel < IR_SUPPORTED_NUM_CHANNELS)
  701.             {
  702.                 if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE)
  703.                 {
  704.                     irTxChannel[channel].stopSend = TRUE;
  705.                 }
  706.             }
  707.             break;
  708.         }
  709.        
  710.         /* TODO: add struct which stores pronto info:
  711.         channel, pronto receive state, buffer length of once burst pairs, buffer length of repeat burst pairs */
  712.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTART: {
  713.  
  714.             uint8_t channel = rxMsg->Data[0]>>4;
  715.             if (channel >= IR_SUPPORTED_NUM_CHANNELS) {
  716.                 // invalid channel
  717.                 break;
  718.             }
  719.  
  720.             if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) {
  721.                 // busy
  722.                 break;
  723.             }
  724.  
  725.             /* TODO: check pronto state, response is different if already sending data */
  726.             uint16_t format = (uint16_t)(rxMsg->Data[0] & 0x0F) << 8 | (uint16_t)(rxMsg->Data[1]);
  727.             if (format != 0) {
  728.                 // unsupported format
  729.                 break;
  730.             }
  731.  
  732.             irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMIT_PREPARING_PRONTO;
  733.  
  734.             //irTxChannel[channel].modfreq = rxMsg->Data[2];
  735.             irTxChannel[channel].modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1); // for testing
  736.             irTxChannel[channel].proto.modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1);
  737.             irTxChannel[channel].proto.timeout = 40;
  738.             irTxChannel[channel].proto.repeats = 1;
  739.  
  740.             irTxChannel[channel].onceSeqLen = rxMsg->Data[3];
  741.             irTxChannel[channel].repSeqLen = rxMsg->Data[4];
  742.  
  743.             activeChannel = channel;
  744.  
  745.             /* TODO: Send response frame */
  746.             break;
  747.         }
  748.  
  749.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTOP:
  750.             /* TODO: stop sending IR */
  751.            
  752.             /* TODO: Send response frame */
  753.             break;
  754.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOCONTINUE:
  755.             /* TODO: reset timeout to continue sending repeat sequences */
  756.            
  757.             /* TODO: Send response frame */
  758.             break;
  759.  
  760.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1:  /* Fall through */
  761.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA2:  /* Fall through */
  762.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA3:  /* Fall through */
  763.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA4:  /* Fall through */
  764.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA5:  /* Fall through */
  765.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA6:  /* Fall through */
  766.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA7:  /* Fall through */
  767.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA8:  /* Fall through */
  768.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA9:  /* Fall through */
  769.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA10: /* Fall through */
  770.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA11: /* Fall through */
  771.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA12: /* Fall through */
  772.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA13: /* Fall through */
  773.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA14: /* Fall through */
  774.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA15: /* Fall through */
  775.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA16: {
  776.             if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) {
  777.                 break;
  778.             }
  779.             if (irTxChannel[activeChannel].state!=sns_irTransceive_STATE_TRANSMIT_PREPARING_PRONTO) {
  780.                 // invalid state
  781.                 break;
  782.             }
  783.             if ((uint16_t)irTxChannel[activeChannel].txlen+(uint16_t)rxMsg->Length >= MAX_NR_TIMES) {
  784.                 // too long
  785.                 break;
  786.             }
  787.             for (uint8_t i=0; i<rxMsg->Length; i++) {
  788.                 // TODO: (109 * 1) / (4.145146 MHz) = 27, fix formula with modfreq
  789.                 irTxChannel[activeChannel].txbuf[irTxChannel[activeChannel].txlen++] = 27*rxMsg->Data[i];
  790.             }
  791.             break;
  792.         }
  793.  
  794.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND1:   /* Fall through */
  795.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND2:   /* Fall through */
  796.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND3:   /* Fall through */
  797.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND4:   /* Fall through */
  798.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND5:   /* Fall through */
  799.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND6:   /* Fall through */
  800.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND7:   /* Fall through */
  801.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND8:   /* Fall through */
  802.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND9:   /* Fall through */
  803.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND10:  /* Fall through */
  804.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND11:  /* Fall through */
  805.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND12:  /* Fall through */
  806.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND13:  /* Fall through */
  807.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND14:  /* Fall through */
  808.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND15:  /* Fall through */
  809.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND16:  /* Fall through */
  810.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND17: {
  811.             if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) {
  812.                 break;
  813.             }
  814.             if (irTxChannel[activeChannel].state!=sns_irTransceive_STATE_TRANSMIT_PREPARING_PRONTO) {
  815.                 // invalid state
  816.                 break;
  817.             }
  818.             if ((uint16_t)irTxChannel[activeChannel].txlen + (uint16_t)(rxMsg->Length-1) >= MAX_NR_TIMES) {
  819.                 // too long
  820.                 break;
  821.             }
  822.             // end packet does not always contain data, last byte is reserved
  823.             for (uint8_t i=0; i<rxMsg->Length-1; i++) {
  824.                 // TODO: (109 * 1) / (4.145146 MHz) = 27, fix formula with modfreq
  825.                 irTxChannel[activeChannel].txbuf[irTxChannel[activeChannel].txlen++] = 27*rxMsg->Data[i];
  826.             }
  827.             // last byte tells what to do with IR data (nr of repeats)
  828.             irTxChannel[activeChannel].numberOfRepeats = rxMsg->Data[rxMsg->Length-1];
  829.  
  830.             // send
  831.             IrTransceiver_Transmit(activeChannel, irTxChannel[activeChannel].txbuf, 0, irTxChannel[activeChannel].txlen);
  832.             irTxChannel[activeChannel].state = sns_irTransceive_STATE_TRANSMITTING;
  833.  
  834.             printf("SEND:%03u", irTxChannel[activeChannel].txlen);
  835.  
  836.             /* TODO: Send response frame */
  837.  
  838.             break;
  839.         }
  840.  
  841. /* TODO: In IR state machine add sending a response frame when ir stops sending, also implement pronto repeat */
  842. #endif
  843.        
  844.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRCONFIG: {
  845.             uint8_t channel = rxMsg->Data[0]>>4;
  846.             uint8_t config = rxMsg->Data[0] & 0x0f;
  847.             uint8_t power = rxMsg->Data[1]>>6;
  848.             uint8_t modfreq = rxMsg->Data[2];
  849.            
  850.             sns_irTransceive_setConfig(channel, config, power, modfreq);
  851.  
  852. #ifdef sns_irTransceive_USEEEPROM
  853.             if (channel < IR_SUPPORTED_NUM_CHANNELS && config <= CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_RECEIVE && power < 4)
  854.             {
  855.                 switch (channel)
  856.                 {
  857.                     case 0:
  858.                         eeprom_write_byte_crc(EEDATA.ch0_config, config, WITHOUT_CRC);
  859.                         eeprom_write_byte_crc(EEDATA.ch0_txpower, power, WITHOUT_CRC);
  860.                         eeprom_write_byte_crc(EEDATA.ch0_modfreq, modfreq, WITHOUT_CRC);
  861.                         break;
  862.                     case 1:
  863.                         eeprom_write_byte_crc(EEDATA.ch1_config, config, WITHOUT_CRC);
  864.                         eeprom_write_byte_crc(EEDATA.ch1_txpower, power, WITHOUT_CRC);
  865.                         eeprom_write_byte_crc(EEDATA.ch1_modfreq, modfreq, WITHOUT_CRC);
  866.                         break;
  867.                     case 2:
  868.                         eeprom_write_byte_crc(EEDATA.ch2_config, config, WITHOUT_CRC);
  869.                         eeprom_write_byte_crc(EEDATA.ch2_txpower, power, WITHOUT_CRC);
  870.                         eeprom_write_byte_crc(EEDATA.ch2_modfreq, modfreq, WITHOUT_CRC);
  871.                         break;
  872.                     default:
  873.                         break;
  874.                 }
  875.                 EEDATA_UPDATE_CRC;
  876.             }
  877. #endif 
  878.             break;
  879.         }
  880.            
  881.         default:
  882.             break;
  883.            
  884.         }
  885.     }
  886. }
  887.  
  888. void sns_irTransceive_List(uint8_t ModuleSequenceNumber)
  889. {
  890.     StdCan_Msg_t txMsg;
  891.    
  892.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  893.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  894.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  895.  
  896.     txMsg.Header.ModuleId = sns_irTransceive_ID;
  897.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  898.     txMsg.Length = 6;
  899.  
  900.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  901.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  902.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  903.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  904.    
  905.     txMsg.Data[4] = NUMBER_OF_MODULES;
  906.     txMsg.Data[5] = ModuleSequenceNumber;
  907.    
  908.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  909. }
  910.