Commit de225a19e240530674f4fc3ff28b258dc43321b7

Authored by Stéphane Raimbault
1 parent 861e6a84

- Fix the server side of force_single_coil

- Add some tests for force_single_coil
modbus/modbus.c
... ... @@ -823,9 +823,10 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query,
823 823 if (data == 0xFF00 || data == 0x0) {
824 824 mb_mapping->tab_coil_status[address] = (data) ? ON : OFF;
825 825  
826   - memcpy(response, query, query_size);
  826 + /* In RTU mode, the CRC is computed
  827 + and added to the query by modbus_send */
  828 + memcpy(response, query, query_size - mb_param->checksum_size);
827 829 response_size = query_size;
828   - printf("FIXME works only in TCP mode (CRC)");
829 830 } else {
830 831 printf("Illegal data value %0X in force_single_coil request at address %0X\n",
831 832 data, address);
... ...
tests/unit-test-master.c
... ... @@ -156,7 +156,17 @@ int main(void)
156 156 }
157 157 printf("OK\n");
158 158  
159   -
  159 + /** WRITE FUNCTIONS **/
  160 + printf("\nTest write functions:\n");
  161 +
  162 + ret = force_single_coil(&mb_param, SLAVE, UT_COIL_STATUS_ADDRESS, ON);
  163 + printf("* force single coil: ");
  164 + if (ret == 1) {
  165 + printf("OK\n");
  166 + } else {
  167 + printf("FAILED\n");
  168 + }
  169 +
160 170 /** ILLEGAL DATA ADDRESS */
161 171 printf("\nTest illegal data address:");
162 172  
... ... @@ -195,6 +205,15 @@ int main(void)
195 205 else
196 206 printf("FAILED");
197 207  
  208 + ret = force_single_coil(&mb_param, SLAVE,
  209 + UT_COIL_STATUS_ADDRESS + UT_COIL_STATUS_NB_POINTS, ON);
  210 + printf("* force single coil: ");
  211 + if (ret == ILLEGAL_DATA_ADDRESS) {
  212 + printf("OK\n");
  213 + } else {
  214 + printf("FAILED\n");
  215 + }
  216 +
198 217 close:
199 218 /* Free the memory */
200 219 free(tab_rp_status);
... ...