case 0xA7:
//设置组地址
printf("A7 coming\r\n");
if(Authentication_list())
{
printf("0xA7\r\n");
memcpy(&(Groupaddr_nums), rev_buf + num + 1, 1);
//保存组地址个数:一字节,本包数据中共有组地址个数(≤8个)。
if(Groupaddr_nums <= 8)
{
for( i = 0; i < Groupaddr_nums; i++)
{
memcpy(Group_addr[i].addr_ID, rev_buf + num + 2 +(i*8), 3);//保存用户机ID
memcpy(Group_addr[i].addr_unit, rev_buf + num + 5 +(i*8), 4); //保存用户机ID对应组地址和组内地址
memcpy(&(Group_addr[i].addr_set), rev_buf + num + 9 + (i*8), 1); //保存用户机ID对应增删字段
}
printf("groupaddr_nums\r\n");
}
for(j = 0; j < Groupaddr_nums; j++)
//双层循环,较长的循环放在内层效率要高。但如果循环次数相当,那谁放内谁放外,再说吧?
{
//int memcmp(const void *buf1, const void *buf2, unsigned int count);
if(0 == memcmp(Group_addr[j].addr_ID, ICXX.localID, 3)) //如果传来的用户机ID是本机ID
{
I2C_Read(I2C1, ADDR_24C02N, 65, &group_list_nums, 1);
//从EEPROM里读取组地址列表中存的组地址个数
printf("first for\r\n");
for(k = 0; k < group_list_nums; k++)
{
I2C_Read(I2C1, ADDR_24C02N, 65, &group_list_nums, 1);
//从EEPROM里读取组地址列表中存的组地址个数
I2C_Read(I2C1, ADDR_24C02N, 66, group_list, (group_list_nums * 4));
//从EEPROM里读取组地址列表
printf("twice for\r\n");
if(0 == memcmp(Group_addr[j].addr_unit, (group_list + 4*k), 4)) //如果EEPROm里存在本次传来的组地址
{
if(Group_addr[j].addr_set == 1)//删除
{
memcpy(group_list_temp, group_list + 4*k + 4, (group_list_nums - k - 1)*4);
//保存EEPROm后续组地址
I2C_Write(I2C1, ADDR_24C02N, 66 + k*4, delete_group, (group_list_nums - k)*4 );
//先变成0再重新保存
I2C_Write(I2C1, ADDR_24C02N, 66 + k*4, group_list_temp, (group_list_nums - k - 1)*4); //将后续组地址从删除处填上
group_list_nums -= 1;
I2C_Write(I2C1, ADDR_24C02N, 65, &group_list_nums, 1);
printf("delete Group_addr\r\n");
}
else if(Group_addr[j].addr_set == 0) //增加
{
;//无需操作
}
exist_flag = 1; //传来的组地址在本地EEPROM组地址列表里是否存在的标志位
}
}
printf("twice for end\r\n");
if(exist_flag != 1)
//传来的组地址在本地EEPROM组地址列表里不存在
{
if(Group_addr[j].addr_set == 0)//增加
{
I2C_Read(I2C1, ADDR_24C02N, 65, &group_list_nums, 1);
I2C_Write(I2C1, ADDR_24C02N, 66 + group_list_nums*4, Group_addr[j].addr_unit, 4);
//保存组地址
group_list_nums += 1;
I2C_Write(I2C1, ADDR_24C02N, 65, &group_list_nums, 1);
//保存组地址个数
printf("add group_addr\r\n");
}
else if(Group_addr[j].addr_set == 1)//删除
{
;//无需操作
}
}
else if(exist_flag == 1)
{
exist_flag = 0;
//存在的话前面已经处理过了
}
}
}
//分包发送组地址
I2C_Read(I2C1, ADDR_24C02N, 65, &group_list_nums, 1);
package_nums = (group_list_nums / 16) + 1;
if(package_nums == 1)
//需要传送一包
{
I2C_Read(I2C1, ADDR_24C02N, 66, package_groupaddr1, group_list_nums * 4);
Group_Infor(txsq_context, txsqcontext_lens, package_groupaddr1, group_list_nums);
//响应:组地址信息B7
}
else if(package_nums == 2)
//需要传送二包
{
I2C_Read(I2C1, ADDR_24C02N, 130, package_groupaddr2, (group_list_nums - 16) * 4);
Group_Infor(txsq_context, txsqcontext_lens, package_groupaddr1, group_list_nums);
package_sendtwice = 1;
}
else if(package_nums == 3)
//需要传送三包
至多总共40组组地址
{
I2C_Read(I2C1, ADDR_24C02N, 194, package_groupaddr3, (group_list_nums - 32) * 4);
Group_Infor(txsq_context, txsqcontext_lens, package_groupaddr1, group_list_nums);
package_sendtriple = 1;
}
}
break;