瀏覽代碼

- Fix the server side of force_single_coil
- Add some tests for force_single_coil

Stéphane Raimbault 17 年之前
父節點
當前提交
de225a19e2
共有 2 個文件被更改,包括 23 次插入3 次删除
  1. 3 2
      modbus/modbus.c
  2. 20 1
      tests/unit-test-master.c

+ 3 - 2
modbus/modbus.c

@@ -823,9 +823,10 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query,
                         if (data == 0xFF00 || data == 0x0) {
                                 mb_mapping->tab_coil_status[address] = (data) ? ON : OFF;
 
-                                memcpy(response, query, query_size);
+                                /* In RTU mode, the CRC is computed
+                                   and added to the query by modbus_send */
+                                memcpy(response, query, query_size - mb_param->checksum_size);
                                 response_size = query_size;
-                                printf("FIXME works only in TCP mode (CRC)");
                         } else {
                                 printf("Illegal data value %0X in force_single_coil request at address %0X\n",
                                        data, address);

+ 20 - 1
tests/unit-test-master.c

@@ -156,7 +156,17 @@ int main(void)
         }
         printf("OK\n");
 
-
+        /** WRITE FUNCTIONS **/
+        printf("\nTest write functions:\n");
+        
+        ret = force_single_coil(&mb_param, SLAVE, UT_COIL_STATUS_ADDRESS, ON);
+        printf("* force single coil: ");
+        if (ret == 1) {
+                printf("OK\n");
+        } else {
+                printf("FAILED\n");
+        }
+        
         /** ILLEGAL DATA ADDRESS */
         printf("\nTest illegal data address:");
 
@@ -195,6 +205,15 @@ int main(void)
         else
                 printf("FAILED");
 
+        ret = force_single_coil(&mb_param, SLAVE,
+                                UT_COIL_STATUS_ADDRESS + UT_COIL_STATUS_NB_POINTS, ON);
+        printf("* force single coil: ");
+        if (ret == ILLEGAL_DATA_ADDRESS) {
+                printf("OK\n");
+        } else {
+                printf("FAILED\n");
+        }
+
 close:
         /* Free the memory */
         free(tab_rp_status);