Jelajahi Sumber

update demo & SConscript

redocCheng 5 tahun lalu
induk
melakukan
a089e8ce6e
5 mengubah file dengan 16 tambahan dan 168 penghapusan
  1. 11 0
      SConscript
  2. 5 5
      demo/drv_can_ymodem.c
  3. 0 0
      demo/drv_can_ymodem.h
  4. 0 143
      demo/topctrl_log_be.c
  5. 0 20
      demo/topctrl_log_be.h

+ 11 - 0
SConscript

@@ -0,0 +1,11 @@
+from building import *
+
+# get current directory
+cwd     = GetCurrentDir()
+# The set of source files associated with this SConscript file.
+
+src     = Glob('can_ymodem.c')
+path    = [cwd]
+group   = DefineGroup('DeviceDrivers', src, depend = ['PKG_USING_CAN_YMODEM'], CPPPATH = path)
+
+Return('group')

+ 5 - 5
driver/drv_can_ymodem.c → demo/drv_can_ymodem.c

@@ -20,7 +20,7 @@
 struct rt_can_ymodem_device can_ymodem_device;
 
 /*  fun of can send  */
-static int rt_hw_can_ymodem_topctrl_to_ctrlbox(struct rt_can_ymodem_device *can_ymodem,
+static int rt_hw_can_ymodem_tx(struct rt_can_ymodem_device *can_ymodem,
                                 const void       *buffer,
                                 rt_size_t         size)
 {
@@ -28,21 +28,21 @@ static int rt_hw_can_ymodem_topctrl_to_ctrlbox(struct rt_can_ymodem_device *can_
 }    
 
 /*  recv ymodem msg  */
-void drv_can_ymodem_ctrlbox_to_topctrl(const void  *buffer, rt_size_t size)
+void drv_can_ymodem_rx(const void  *buffer, rt_size_t size)
 {
     rt_can_ymodem_rx(&can_ymodem_device, buffer, size);
 }
 
-static const struct rt_can_ymodem_ops topctrl_can_ymodem_ops =
+static const struct rt_can_ymodem_ops _can_ymodem_ops =
 {
-    .puts = rt_hw_can_ymodem_topctrl_to_ctrlbox,
+    .puts = rt_hw_can_ymodem_tx,
 };
 
 int rt_hw_can_ymodem_init(void)
 {
     rt_err_t result = 0;
     
-    can_ymodem_device.ops = &topctrl_can_ymodem_ops;
+    can_ymodem_device.ops = &_can_ymodem_ops;
     
     result = rt_hw_can_ymodem_register(&can_ymodem_device, "can_ymodem", RT_DEVICE_FLAG_RDWR, RT_NULL);
     

+ 0 - 0
driver/drv_can_ymodem.h → demo/drv_can_ymodem.h


+ 0 - 143
demo/topctrl_log_be.c

@@ -1,143 +0,0 @@
-#include <rthw.h>
-#include <rtthread.h>
-#include <shell.h>
-#include <finsh.h>
-#include <ulog.h>
-#include <easyflash.h>
-#include <ymodem.h>
-#include <board.h>
-#include <dfs_posix.h>
-#include <sys/time.h>
-#include "thread_can.h"
-
-static char log_name_buf[32] = {0};
-static int fd;
-static uint8_t log_export_flag = false;
-static size_t log_file_total_size ,log_file_cur_size;
-
-static rt_err_t log_file_open(char *file_name)
-{
-    static time_t now;
-    static struct tm *tm, tm_tmp;
-    uint32_t size;
-    
-    rt_err_t result = RT_EOK;
-
-    now = time(NULL);
-    tm = gmtime_r(&now, &tm_tmp);
-    
-//  size = rt_snprintf(log_name_buf,32, "/topctrl_log_%04d%02d%02d.txt",tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
-    
-    size = rt_snprintf(log_name_buf,32, "/%s", file_name);
-    
-    rt_kprintf("%s\r\n",log_name_buf);
-    
-    fd = open(log_name_buf, O_WRONLY | O_CREAT);
-    
-    if (fd >= 0)
-    {
-        write(fd, log_name_buf, size);
-        write(fd, ":\r\n\r\n", sizeof(":\r\n\r\n"));
-        rt_kprintf("open done.\n");
-
-    }
-    else
-    {
-        result = -RT_ERROR;
-    }
-    
-    return result;
-}
-
-static void log_out_print(size_t size, size_t total_size)
-{
-    static uint8_t per_printf = 0;
-    
-    float per = size * 100 / total_size;
-    
-    if(per - per_printf >= 10)
-    {
-        per_printf = per;
-        rt_kprintf("log output %3d%\r\n",per_printf);
-    }
-}
-
-static enum rym_code ymodem_on_begin(struct rym_ctx *ctx, rt_uint8_t *buf, rt_size_t len) {
-    char *file_name, *file_size;
-
-    /* calculate and store file size */
-    file_name = (char *) &buf[0];
-    file_size = (char *) &buf[rt_strlen(file_name) + 1];
-    log_file_total_size = atol(file_size);
-    log_file_cur_size = 0;
-    
-    rt_kprintf("log name %s  size %dKB\r\n",file_name , log_file_total_size);
-    
-    /* erase backup section */
-    if (RT_EOK != log_file_open(file_name)) 
-    {
-        /* if erase fail then end session */
-        return RYM_CODE_CAN;
-    }
-
-    return RYM_CODE_ACK;
-}
-
-static enum rym_code ymodem_on_data(struct rym_ctx *ctx, rt_uint8_t *buf, rt_size_t len) {
-    
-    if (log_file_cur_size + len < log_file_total_size)
-    {
-        write(fd, buf, len);
-
-        log_file_cur_size += len;
-    }
-    else
-    {
-        write(fd, buf,log_file_total_size - log_file_cur_size);
-    }  
-    log_out_print(log_file_cur_size, log_file_total_size);
-
-    return RYM_CODE_ACK;
-}
-
-static enum rym_code ymodem_on_end(struct rym_ctx *ctx, rt_uint8_t *buf, rt_size_t len)
-{
-    close(fd);
-    rt_kprintf("topctrl log out succ!!\r\n");
-}
-
-void topctrl_log_be(uint8_t argc, char **argv) {
-    char new_char[2], c_file_size[11] = { 0 }, c_crc32_checksum[11] = { 0 };
-    struct rym_ctx rctx;
-    rt_device_t dev;
-    
-    dev = rt_device_find("can_ymodem");
-    
-    fd = -1;
-
-    rt_kprintf("Waring: This operator will not recovery. If you want, press 'Y'.\n");
-    new_char[0] = getchar();
-    rt_kprintf("%c", new_char[0]);
-    new_char[1] = getchar();
-    rt_kprintf("%c", new_char[1]);
-    if ((new_char[0] != 'y') && (new_char[0] != 'Y')) {
-        goto __exit;
-    }
-    rt_kprintf("Please select the application firmware file and use Ymodem to send.\n");
-
-
-    if (!rym_recv_on_device(&rctx, dev, RT_DEVICE_OFLAG_RDWR ,
-            ymodem_on_begin, ymodem_on_data, ymodem_on_end, RT_TICK_PER_SECOND)) {
-        /* wait some time for terminal response finish */
-        rt_kprintf("log out succ.\n");
-        
-    } else {
-        /* wait some time for terminal response finish */
-      
-        rt_kprintf("log out fail.\n");
-    }
-
-__exit:
- 
-}
-MSH_CMD_EXPORT(topctrl_log_be, Update user application firmware);

+ 0 - 20
demo/topctrl_log_be.h

@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2019, Anke Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date           Author       Notes
- * 2020-03-06     redoc        the first version
- */
-
-#ifndef __TOPCTRL_LOG_BE_H
-#define __TOPCTRL_LOG_BE_H
-#include <rtthread.h>
-#include <drv_common.h>
-#include "stdbool.h"
-
-
-void topctrl_log_be_export(void);
-
-#endif