static int modbus_after_write_table(struct modbus_instance *instance, enum modbus_table table, uint16_t address, uint16_t count) { if (table == MODBUS_TABLE_HOLDING_REGISTERS) { uint16_t offset = ELEMENT_OFFSET(common_values, now); if (ELEMENT_IN(0x0000, offset, address * 2, count * 2)) { // SYNC CLOCK DateTime dt(common_values.now.year, common_values.now.month, common_values.now.day, common_values.now.hours, common_values.now.minutes, common_values.now.seconds); OS::TSysTimerLocker lock; RTC_DS1307 rtc; rtc.begin(); rtc.adjust(dt); } offset = ELEMENT_OFFSET(common_values, modbus_address); if (ELEMENT_IN(0x0000, offset, address * 2, count * 2)) { config_lock(); config_set_address(common_values.modbus_address & 0xFF); config_unlock(); // instance->address = common_values.modbus_address; } } if (table == MODBUS_TABLE_COILS) { uint16_t offset = ELEMENT_OFFSET(controls, restart_programs); if (ELEMENT_IN(0x0000, offset, address, count)) { if (controls.restart_programs == 0x01) { controls.restart_programs = 0x00; controls.pause_flag = 0x00; program_reset(); config_set_pause_flag(controls.pause_flag); } } offset = ELEMENT_OFFSET(controls, pause_flag); if (ELEMENT_IN(0x0000, offset, address, count)) { config_set_pause_flag(controls.pause_flag); } } MODBUS_RETURN(instance, MODBUS_SUCCESS); }
int main(int argc, char const *argv[]) { int a[] = {1, 3232, 3 , 4343,5}; int tmp,i; int totalElm = ELEMENT_IN(a); printf("Before reverse\n"); for (i = 0; i < totalElm; ++i) { printf("%5d,", a[i]); } for(i=0; i< (int)(floor(totalElm/2)); i++) { tmp = a[i]; a[i] = a[totalElm-1-i]; a[totalElm-1-i] = tmp; } printf("\nBefore reverse\n"); for (i = 0; i < totalElm; ++i) { printf("%5d,", a[i]); } printf("\n"); return 0; }