Forráskód Böngészése

1、修复myname映射。2、添加关机、重启应用程序。3、修复钱箱连续打印两次o问题

qidong.liu 3 hete
szülő
commit
800783e75f
4 módosított fájl, 143 hozzáadás és 7 törlés
  1. 1 0
      Makefile
  2. 2 1
      cash_drawers.c
  3. 35 6
      myname.c
  4. 105 0
      test_app/system_ctl_app.c

+ 1 - 0
Makefile

@@ -19,6 +19,7 @@ all:
 	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/setss.c -DPROJECT=$(PROJECT_NAME) -o test_app/setss
 	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/test_beep.c -DPROJECT=$(PROJECT_NAME) -o test_app/beep
 	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/setled.c -DPROJECT=$(PROJECT_NAME) -o test_app/setled
+	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/system_ctl_app.c -DPROJECT=$(PROJECT_NAME) -o test_app/system_ctl_app
 	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/cash_app.c -DPROJECT=$(PROJECT_NAME) -o test_app/cash_app -lpthread
 
 clean:

+ 2 - 1
cash_drawers.c

@@ -245,7 +245,7 @@ static int __init cashd_init_device(struct cashd_device *dev, int minor)
     dev->buffer_size = BUFFER_SIZE;
     dev->dev_major = cashd_major;
     dev->dev_minor = minor;
-    dev->last_status = -1;
+    dev->status_changed = 0;
     
     init_waitqueue_head(&dev->read_wait);
     
@@ -327,6 +327,7 @@ int cashd_init(void)
             cashd_devices[i]->gpio_ctl_reg_base = ioremap(GPIO1_CTL, 4);
             cashd_devices[i]->gpio_status_reg_base = ioremap(GPIO1_STATUS, 4);            
         }
+        cashd_devices[i]->last_status = readl(cashd_devices[i]->gpio_status_reg_base) & 0x2;
         schedule_delayed_work(&cashd_devices[i]->delay_work2, msecs_to_jiffies(100));
         
         pr_info("cashd: Created /dev/cashd%d\n", i);

+ 35 - 6
myname.c

@@ -186,11 +186,11 @@ int get_board_id(void)
     board_id |= (myname_readl(SWITCH_ID4)&0x02) << 3;
     printk("board_id=%08x\n", board_id);
 
-    if(board_id > 15)
-    {
-        printk(KERN_ERR "myname: Invalid board_id\n");
-        return -EINVAL;
-    }
+    // if(board_id > 15)
+    // {
+    //     printk(KERN_ERR "myname: Invalid board_id\n");
+    //     return -EINVAL;
+    // }
     if(board_id == 0)
     {
         memcpy(dev->buffer, "ci (Ruby Ci)\n", strlen("ci (Ruby Ci)\n"));
@@ -206,11 +206,40 @@ int get_board_id(void)
         memcpy(dev->buffer, "selene\n", strlen("selene\n"));
         dev->size = strlen("selene\n");
     }
-    else if(board_id >= 12 && board_id <= 15)
+    else if(board_id >= 12 && board_id <= 13)
     {
         memcpy(dev->buffer, "cobra (Commander Ci)\n", strlen("cobra (Commander Ci)\n"));
         dev->size = strlen("cobra (Commander Ci)\n");
     }
+    else if(board_id == 14)
+    {
+        memcpy(dev->buffer, "admiral (Commander refresh)\n", strlen("admiral (Commander refresh)\n"));
+        dev->size = strlen("admiral (Commander refresh)\n");
+        
+    }
+    else if(board_id == 15)
+    {
+        memcpy(dev->buffer, "Commander\n", strlen("Commander\n"));
+        dev->size = strlen("Commander\n");
+        
+    }
+    else if(board_id == 16)
+    {
+        memcpy(dev->buffer, "C18+\n", strlen("C18+\n"));
+        dev->size = strlen("C18+\n");
+        
+    }
+    else if(board_id == 20)
+    {
+        memcpy(dev->buffer, "Commander Nx\n", strlen("Commander Nx\n"));
+        dev->size = strlen("Commander Nx\n");
+        
+    }
+    else
+    {
+        memcpy(dev->buffer, "Invalid\n", strlen("Invalid\n"));
+        dev->size = strlen("Invalid\n");
+    }
     // printk(KERN_ERR "myname: board_id = %d\n", board_id);
     return board_id;
 }

+ 105 - 0
test_app/system_ctl_app.c

@@ -0,0 +1,105 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/reboot.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#define DEV_PATH "/dev/power"
+#define BUFFER_SIZE 2
+
+void execute_command(const char *cmd) {
+    pid_t pid = fork();
+    if (pid == -1) {
+        perror("fork failed");
+        return;
+    }
+    
+    if (pid == 0) {
+        execl("/bin/sh", "sh", "-c", cmd, NULL);
+        perror("execl failed");
+        exit(EXIT_FAILURE);
+    } else {
+        int status;
+        waitpid(pid, &status, 0);
+    }
+}
+
+void reboot_system() {
+    printf("reboot command received, system rebooting...\n");
+    sync();
+    execute_command("reboot");
+}
+
+void shutdown_system() {
+    printf("shutdown command received, system shutting down...\n");
+    sync();
+    execute_command("shutdown -h now");
+}
+
+int main() {
+    int fd;
+    char buf[BUFFER_SIZE];
+    ssize_t nread;
+    
+    fd = open(DEV_PATH, O_RDONLY);
+    if (fd == -1) {
+        fprintf(stderr, "cannot open device node %s: %s\n", 
+                DEV_PATH, strerror(errno));
+        fprintf(stderr, "please ensure:\n");
+        fprintf(stderr, "1. device node /dev/power exists\n");
+        fprintf(stderr, "2. sufficient permissions to access\n");
+        fprintf(stderr, "3. kernel driver is loaded\n");
+        return EXIT_FAILURE;
+    }
+    
+    printf("monitoring %s, waiting for commands...\n", DEV_PATH);
+    printf("'r' -> reboot system\n");
+    printf("'p' -> graceful shutdown\n");
+    printf("press Ctrl+C to exit\n\n");
+    
+    while (1) {
+        nread = read(fd, buf, sizeof(buf) - 1);
+        
+        if (nread == -1) {
+            if (errno == EINTR) {
+                continue;
+            }
+            perror("read device node failed");
+            break;
+        } else if (nread == 0) {
+            printf("device node closed, exiting\n");
+            break;
+        }
+        
+        buf[nread] = '\0';
+        
+        for (int i = 0; i < nread; i++) {
+            char ch = buf[i];
+            
+            switch (ch) {
+                case 'r':
+                case 'R':
+                    printf("detected character '%c'\n", ch);
+                    reboot_system();
+                    break;
+                    
+                case 'p':
+                case 'P':
+                    printf("detected character '%c'\n", ch);
+                    shutdown_system();
+                    break;
+                    
+                default:
+                    printf("unknown character: '%c' (ASCII: %d)\n", ch, ch);
+                    break;
+            }
+        }
+    }
+    
+    close(fd);
+    return EXIT_SUCCESS;
+}