Subversion Repositories HomeAutomation

Rev

Rev 1832 | Rev 1834 | 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 0
  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_TRANSMIT_START_TRANSMIT_PRONTO:
  613.             IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen);
  614.             irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING;
  615.             break;
  616.            
  617.         case sns_irTransceive_STATE_TRANSMITTING:
  618.             if (irTxChannel[channel].sendComplete == TRUE)
  619.             {
  620.                 cli();
  621.                 irTxChannel[channel].sendComplete = FALSE;
  622.                 sei();
  623.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
  624.             }
  625.             break;
  626.  
  627.         case sns_irTransceive_STATE_START_PAUSE:
  628.             if (irTxChannel[channel].repeatCount < irTxChannel[channel].proto.repeats)
  629.             {
  630.                 irTxChannel[channel].repeatCount++;
  631.             }
  632.            
  633.             Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  634.  
  635.             if (irTxChannel[channel].proto.framecnt != 255)
  636.             {
  637.                 irTxChannel[channel].proto.framecnt++;
  638.             }
  639.            
  640.             irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING;
  641.             break;
  642.  
  643.         case sns_irTransceive_STATE_PAUSING:
  644.             if (Timer_Expired(irTxChannel[channel].timerNum))
  645.             {
  646.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
  647.             }
  648.            
  649.             /* transmission is stopped when such command is recevied on can */
  650.             if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats)
  651.             {
  652.                 //TODO maybe send message on can for status? to confirm stopped sending, ready for new command
  653.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  654.             }
  655.             break;
  656.  
  657.         case sns_irTransceive_STATE_START_IDLE:
  658.             irTxChannel[channel].stopSend = FALSE;
  659.             irTxChannel[channel].repeatCount = 0;
  660.             irTxChannel[channel].proto.framecnt = 0;
  661.            
  662.             irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  663.             break;
  664.  
  665.         default:
  666.             break;
  667.         }
  668. #endif
  669.  
  670.     }
  671. }
  672.  
  673.  
  674. /* Handle incoming CAN data */
  675. void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg)
  676. {
  677.     if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
  678.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
  679.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_IRTRANSCEIVE &&
  680.         rxMsg->Header.ModuleId == sns_irTransceive_ID)
  681.     {
  682.         //printf("CMD= %u\n", rxMsg->Header.Command);
  683.         switch (rxMsg->Header.Command)
  684.         {
  685. #if IR_TX_ENABLE==1
  686.         case CAN_MODULE_CMD_PHYSICAL_IR: {
  687.             uint8_t channel = rxMsg->Data[0]>>4;
  688.             if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED && channel < IR_SUPPORTED_NUM_CHANNELS)
  689.             {
  690.                 if (irTxChannel[channel].state == sns_irTransceive_STATE_IDLE)
  691.                 {
  692.                     irTxChannel[channel].proto.protocol = rxMsg->Data[1];
  693.  
  694.                     irTxChannel[channel].proto.data = rxMsg->Data[2];
  695.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  696.                     irTxChannel[channel].proto.data |= rxMsg->Data[3];
  697.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  698.                     irTxChannel[channel].proto.data |= rxMsg->Data[4];
  699.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  700.                     irTxChannel[channel].proto.data |= rxMsg->Data[5];
  701.  
  702.                     irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
  703.                 }
  704.             }
  705.             else if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED && channel < IR_SUPPORTED_NUM_CHANNELS)
  706.             {
  707.                 if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE)
  708.                 {
  709.                     irTxChannel[channel].stopSend = TRUE;
  710.                 }
  711.             }
  712.             break;
  713.         }
  714.        
  715. #if sns_irTransceive_PRONTO_SUPPORT==1
  716.         /* TODO: add struct which stores pronto info:
  717.         channel, pronto receive state, buffer length of once burst pairs, buffer length of repeat burst pairs */
  718.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTART: {
  719.  
  720.             uint8_t channel = rxMsg->Data[0]>>4;
  721.             if (channel >= IR_SUPPORTED_NUM_CHANNELS) {
  722.                 // invalid channel
  723.                 break;
  724.             }
  725.  
  726.             if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) {
  727.                 // busy
  728.                 break;
  729.             }
  730.  
  731.             /* TODO: check pronto state, response is different if already sending data */
  732.             uint16_t format = (uint16_t)(rxMsg->Data[0] & 0x0F) << 8 | (uint16_t)(rxMsg->Data[1]);
  733.             if (format != 0) {
  734.                 // unsupported format
  735.                 break;
  736.             }
  737.  
  738.             irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMIT_PREPARING_PRONTO;
  739.             irTxChannel[channel].txlen = 0;
  740.            
  741.             //irTxChannel[channel].modfreq = rxMsg->Data[2];
  742.             irTxChannel[channel].modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1); // for testing
  743.             irTxChannel[channel].proto.modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1);
  744.             irTxChannel[channel].proto.timeout = 40;
  745.             irTxChannel[channel].proto.repeats = 1;
  746.  
  747.             irTxChannel[channel].onceSeqLen = rxMsg->Data[3];
  748.             irTxChannel[channel].repSeqLen = rxMsg->Data[4];
  749.  
  750.             activeChannel = channel;
  751.  
  752.             /* TODO: Send response frame */
  753.             break;
  754.         }
  755.  
  756.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTOP:
  757.             /* TODO: stop sending IR */
  758.            
  759.             /* TODO: Send response frame */
  760.             break;
  761.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOCONTINUE:
  762.             /* TODO: reset timeout to continue sending repeat sequences */
  763.            
  764.             /* TODO: Send response frame */
  765.             break;
  766.  
  767.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1:  /* Fall through */
  768.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA2:  /* Fall through */
  769.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA3:  /* Fall through */
  770.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA4:  /* Fall through */
  771.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA5:  /* Fall through */
  772.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA6:  /* Fall through */
  773.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA7:  /* Fall through */
  774.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA8:  /* Fall through */
  775.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA9:  /* Fall through */
  776.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA10: /* Fall through */
  777.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA11: /* Fall through */
  778.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA12: /* Fall through */
  779.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA13: /* Fall through */
  780.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA14: /* Fall through */
  781.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA15: /* Fall through */
  782.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA16: {
  783.             if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) {
  784.                 break;
  785.             }
  786.             if (irTxChannel[activeChannel].state!=sns_irTransceive_STATE_TRANSMIT_PREPARING_PRONTO) {
  787.                 // invalid state
  788.                 break;
  789.             }
  790.             if ((uint16_t)irTxChannel[activeChannel].txlen+(uint16_t)rxMsg->Length >= MAX_NR_TIMES) {
  791.                 // too long
  792.                 break;
  793.             }
  794.             for (uint8_t i=0; i<rxMsg->Length; i++) {
  795.                 // TODO: (109 * 1) / (4.145146 MHz) = 27, fix formula with modfreq
  796.                 irTxChannel[activeChannel].txbuf[irTxChannel[activeChannel].txlen++] = 27*rxMsg->Data[i];
  797.             }
  798.             break;
  799.         }
  800.  
  801.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND1:   /* Fall through */
  802.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND2:   /* Fall through */
  803.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND3:   /* Fall through */
  804.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND4:   /* Fall through */
  805.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND5:   /* Fall through */
  806.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND6:   /* Fall through */
  807.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND7:   /* Fall through */
  808.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND8:   /* Fall through */
  809.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND9:   /* Fall through */
  810.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND10:  /* Fall through */
  811.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND11:  /* Fall through */
  812.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND12:  /* Fall through */
  813.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND13:  /* Fall through */
  814.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND14:  /* Fall through */
  815.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND15:  /* Fall through */
  816.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND16:  /* Fall through */
  817.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND17: {
  818.             if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) {
  819.                 break;
  820.             }
  821.             if (irTxChannel[activeChannel].state!=sns_irTransceive_STATE_TRANSMIT_PREPARING_PRONTO) {
  822.                 // invalid state
  823.                 break;
  824.             }
  825.             if ((uint16_t)irTxChannel[activeChannel].txlen + (uint16_t)(rxMsg->Length-1) >= MAX_NR_TIMES) {
  826.                 // too long
  827.                 break;
  828.             }
  829.             // end packet does not always contain data, last byte is reserved
  830.             for (uint8_t i=0; i<rxMsg->Length-1; i++) {
  831.                 // TODO: (109 * 1) / (4.145146 MHz) = 27, fix formula with modfreq
  832.                 irTxChannel[activeChannel].txbuf[irTxChannel[activeChannel].txlen++] = 27*rxMsg->Data[i];
  833.             }
  834.             // last byte tells what to do with IR data (nr of repeats)
  835.             irTxChannel[activeChannel].numberOfRepeats = rxMsg->Data[rxMsg->Length-1];
  836.  
  837.             // send
  838.             //IrTransceiver_Transmit(activeChannel, irTxChannel[activeChannel].txbuf, 0, irTxChannel[activeChannel].txlen);
  839.             irTxChannel[activeChannel].state = sns_irTransceive_STATE_TRANSMIT_START_TRANSMIT_PRONTO;
  840.  
  841.             //printf("SEND:%03u\n", irTxChannel[activeChannel].txlen);
  842.  
  843.             /* TODO: Send response frame */
  844.  
  845.             break;
  846.         }
  847.  
  848. /* TODO: In IR state machine add sending a response frame when ir stops sending, also implement pronto repeat */
  849. #endif
  850. #endif
  851.        
  852.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRCONFIG: {
  853.             uint8_t channel = rxMsg->Data[0]>>4;
  854.             uint8_t config = rxMsg->Data[0] & 0x0f;
  855.             uint8_t power = rxMsg->Data[1]>>6;
  856.             uint8_t modfreq = rxMsg->Data[2];
  857.            
  858.             sns_irTransceive_setConfig(channel, config, power, modfreq);
  859.  
  860. #ifdef sns_irTransceive_USEEEPROM
  861.             if (channel < IR_SUPPORTED_NUM_CHANNELS && config <= CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_RECEIVE && power < 4)
  862.             {
  863.                 switch (channel)
  864.                 {
  865.                     case 0:
  866.                         eeprom_write_byte_crc(EEDATA.ch0_config, config, WITHOUT_CRC);
  867.                         eeprom_write_byte_crc(EEDATA.ch0_txpower, power, WITHOUT_CRC);
  868.                         eeprom_write_byte_crc(EEDATA.ch0_modfreq, modfreq, WITHOUT_CRC);
  869.                         break;
  870.                     case 1:
  871.                         eeprom_write_byte_crc(EEDATA.ch1_config, config, WITHOUT_CRC);
  872.                         eeprom_write_byte_crc(EEDATA.ch1_txpower, power, WITHOUT_CRC);
  873.                         eeprom_write_byte_crc(EEDATA.ch1_modfreq, modfreq, WITHOUT_CRC);
  874.                         break;
  875.                     case 2:
  876.                         eeprom_write_byte_crc(EEDATA.ch2_config, config, WITHOUT_CRC);
  877.                         eeprom_write_byte_crc(EEDATA.ch2_txpower, power, WITHOUT_CRC);
  878.                         eeprom_write_byte_crc(EEDATA.ch2_modfreq, modfreq, WITHOUT_CRC);
  879.                         break;
  880.                     default:
  881.                         break;
  882.                 }
  883.                 EEDATA_UPDATE_CRC;
  884.             }
  885. #endif 
  886.             break;
  887.         }
  888.            
  889.         default:
  890.             break;
  891.            
  892.         }
  893.     }
  894. }
  895.  
  896. void sns_irTransceive_List(uint8_t ModuleSequenceNumber)
  897. {
  898.     StdCan_Msg_t txMsg;
  899.    
  900.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  901.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  902.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  903.  
  904.     txMsg.Header.ModuleId = sns_irTransceive_ID;
  905.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  906.     txMsg.Length = 6;
  907.  
  908.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  909.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  910.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  911.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  912.    
  913.     txMsg.Data[4] = NUMBER_OF_MODULES;
  914.     txMsg.Data[5] = ModuleSequenceNumber;
  915.    
  916.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  917. }
  918.