diff --git a/src/gpio.h b/src/gpio.h index 916856f..d0ce515 100644 --- a/src/gpio.h +++ b/src/gpio.h @@ -1,5 +1,3 @@ -#include "hal/macros.h" - #include #include #include @@ -16,6 +14,8 @@ #include #endif +#include "hal/macros.h" + void gpio_deinit(void); int gpio_init(void); int gpio_read(char pin, bool *value); diff --git a/src/hal/support.c b/src/hal/support.c index 44c6792..cee6196 100644 --- a/src/hal/support.c +++ b/src/hal/support.c @@ -6,7 +6,9 @@ void *vid_thread = NULL; char chnCount = 0; hal_chnstate *chnState = NULL; -char chipId[16] = "unknown"; + +char chip[16] = "unknown"; +char family[32] = {0}; hal_platform plat = HAL_PLATFORM_UNK; int series = 0; @@ -69,8 +71,9 @@ void hal_identify(void) { case 0xF1: // Pudding (6E) case 0xF2: // Ispahan (6B0) plat = HAL_PLATFORM_I6; - strcpy(chipId, series == 0xEF ? + strcpy(chip, series == 0xEF ? "SSC32x" : "SSC33x"); + strcpy(family, "infinity6(b/e0)"); chnCount = I6_VENC_CHN_NUM; chnState = (hal_chnstate*)i6_state; aud_thread = i6_audio_thread; @@ -78,7 +81,8 @@ void hal_identify(void) { return; case 0xF9: plat = HAL_PLATFORM_I6C; - strcpy(chipId, "SSC37x"); + strcpy(chip, "SSC37x"); + strcpy(family, "infinity6c"); chnCount = I6C_VENC_CHN_NUM; chnState = (hal_chnstate*)i6c_state; aud_thread = i6c_audio_thread; @@ -86,7 +90,8 @@ void hal_identify(void) { return; case 0xFB: plat = HAL_PLATFORM_I6F; - strcpy(chipId, "SSC37x"); + strcpy(chip, "SSC379G"); + strcpy(family, "infinity6f"); chnCount = I6F_VENC_CHN_NUM; chnState = (hal_chnstate*)i6f_state; aud_thread = i6f_audio_thread; @@ -96,10 +101,11 @@ void hal_identify(void) { if (!access("/dev/vpd", 0)) { plat = HAL_PLATFORM_GM; - strcpy(chipId, "GM813x"); + strcpy(chip, "GM813x"); + strcpy(family, "grainmedia"); if (file = fopen("/proc/pmu/chipver", "r")) { fgets(line, 200, file); - sscanf(line, "%4s", chipId + 2); + sscanf(line, "%4s", chip + 2); fclose(file); } chnCount = GM_VENC_CHN_NUM; @@ -120,16 +126,17 @@ void hal_identify(void) { case 0x31: plat = HAL_PLATFORM_T31; switch (type >> 16) { - case 0x2222: sprintf(chipId, "T31X"); break; - case 0x3333: sprintf(chipId, "T31L"); break; - case 0x4444: sprintf(chipId, "T31A"); break; - case 0x5555: sprintf(chipId, "T31ZL"); break; - case 0x6666: sprintf(chipId, "T31ZX"); break; - case 0xcccc: sprintf(chipId, "T31AL"); break; - case 0xdddd: sprintf(chipId, "T31ZC"); break; - case 0xeeee: sprintf(chipId, "T31LC"); break; - default: sprintf(chipId, "T31N"); break; + case 0x2222: sprintf(chip, "T31X"); break; + case 0x3333: sprintf(chip, "T31L"); break; + case 0x4444: sprintf(chip, "T31A"); break; + case 0x5555: sprintf(chip, "T31ZL"); break; + case 0x6666: sprintf(chip, "T31ZX"); break; + case 0xcccc: sprintf(chip, "T31AL"); break; + case 0xdddd: sprintf(chip, "T31ZC"); break; + case 0xeeee: sprintf(chip, "T31LC"); break; + default: sprintf(chip, "T31N"); break; } + strcpy(family, "ingenic t31"); break; chnCount = T31_VENC_CHN_NUM; chnState = (hal_chnstate*)t31_state; aud_thread = t31_audio_thread; @@ -174,20 +181,21 @@ void hal_identify(void) { out |= (SCSYSID[i] & 0xFF) << i * 8; } - sprintf(chipId, "%s%X", + sprintf(chip, "%s%X", ((out >> 28) == 0x7) ? "GK" : "Hi", out); - if (chipId[6] == '0') { - chipId[6] = 'V'; + if (chip[6] == '0') { + chip[6] = 'V'; } else { - chipId[8] = chipId[7]; - chipId[7] = 'V'; - chipId[9] = chipId[8]; - chipId[10] = chipId[9]; - chipId[11] = '\0'; + chip[8] = chip[7]; + chip[7] = 'V'; + chip[9] = chip[8]; + chip[10] = chip[9]; + chip[11] = '\0'; } if (out == 0x35180100) { plat = HAL_PLATFORM_V1; + strcpy(family, "hisi-gen1"); chnCount = V1_VENC_CHN_NUM; chnState = (hal_chnstate*)v1_state; aud_thread = v1_audio_thread; @@ -196,6 +204,7 @@ void hal_identify(void) { return; } else if (v2series) { plat = HAL_PLATFORM_V2; + strcpy(family, "hisi-gen2"); chnCount = V2_VENC_CHN_NUM; chnState = (hal_chnstate*)v2_state; aud_thread = v2_audio_thread; @@ -204,6 +213,7 @@ void hal_identify(void) { return; } else if (v3series) { plat = HAL_PLATFORM_V3; + strcpy(family, "hisi-gen3"); chnCount = V3_VENC_CHN_NUM; chnState = (hal_chnstate*)v3_state; aud_thread = v3_audio_thread; @@ -213,6 +223,7 @@ void hal_identify(void) { } plat = HAL_PLATFORM_V4; + strcpy(family, "hisi-gen4"); chnCount = V4_VENC_CHN_NUM; chnState = (hal_chnstate*)v4_state; aud_thread = v4_audio_thread; diff --git a/src/hal/support.h b/src/hal/support.h index 0e84091..070594b 100644 --- a/src/hal/support.h +++ b/src/hal/support.h @@ -41,7 +41,8 @@ extern void *vid_thread; extern char chnCount; extern hal_chnstate *chnState; -extern char chipId[16]; +extern char chip[16]; +extern char family[32]; extern hal_platform plat; extern int series; diff --git a/src/hal/types.h b/src/hal/types.h index 8fabb05..7223cfa 100644 --- a/src/hal/types.h +++ b/src/hal/types.h @@ -21,6 +21,7 @@ typedef enum { HAL_PLATFORM_UNK, HAL_PLATFORM_GM, + HAL_PLATFORM_I3, HAL_PLATFORM_I6, HAL_PLATFORM_I6C, HAL_PLATFORM_I6F, diff --git a/src/http_post.c b/src/http_post.c index b103b53..eb8bf69 100644 --- a/src/http_post.c +++ b/src/http_post.c @@ -1,5 +1,7 @@ #include "http_post.h" +pthread_t httpPostPid = 0; + int post_send(hal_jpegdata *jpeg) { char *host_addr = app_config.http_post_host; @@ -95,8 +97,6 @@ void *send_thread(void *vargp) { } void start_http_post_send() { - pthread_t http_post_thread_id = 0; - pthread_attr_t thread_attr; pthread_attr_init(&thread_attr); size_t stacksize; @@ -105,9 +105,13 @@ void start_http_post_send() { if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) HAL_DANGER("http_post", "Can't set stack size %zu\n", new_stacksize); if (pthread_create( - &http_post_thread_id, &thread_attr, send_thread, NULL)) + &httpPostPid, &thread_attr, send_thread, NULL)) HAL_DANGER("http_post", "Starting the HTTP poster thread failed!\n"); if (pthread_attr_setstacksize(&thread_attr, stacksize)) HAL_DANGER("http_post", "Can't set stack size %zu\n", stacksize); pthread_attr_destroy(&thread_attr); +} + +void stop_http_post_send() { + pthread_join(httpPostPid, NULL); } \ No newline at end of file diff --git a/src/http_post.h b/src/http_post.h index 8248842..d75774f 100644 --- a/src/http_post.h +++ b/src/http_post.h @@ -1,26 +1,19 @@ #pragma once -#include "hal/macros.h" -#include "hal/tools.h" -#include "jpeg.h" -#include "mp4/mp4.h" -#include "mp4/nal.h" - #include #include #include -#include +#include #include #include -#include #include #include - -#include -#include -#include #include +#include "hal/macros.h" +#include "jpeg.h" + extern char keepRunning; void start_http_post_send(); +void stop_http_post_send(); \ No newline at end of file diff --git a/src/main.c b/src/main.c index b164895..61bdbc1 100644 --- a/src/main.c +++ b/src/main.c @@ -21,38 +21,14 @@ char graceful = 0; int main(int argc, char *argv[]) { hal_identify(); - switch (plat) { -#if defined(__arm__) - case HAL_PLATFORM_GM: - fprintf(stderr, "Divinus for grainmedia\n"); break; - case HAL_PLATFORM_I6: - fprintf(stderr, "Divinus for infinity6(b0/e)\n"); break; - case HAL_PLATFORM_I6C: - fprintf(stderr, "Divinus for infinity6c\n"); break; - case HAL_PLATFORM_I6F: - fprintf(stderr, "Divinus for infinity6f\n"); break; - case HAL_PLATFORM_V1: - fprintf(stderr, "Divinus for hisi-gen1\n"); break; - case HAL_PLATFORM_V2: - fprintf(stderr, "Divinus for hisi-gen2\n"); break; - case HAL_PLATFORM_V3: - fprintf(stderr, "Divinus for hisi-gen3\n"); break; - case HAL_PLATFORM_V4: - fprintf(stderr, "Divinus for hisi-gen4\n"); break; -#elif defined(__mips__) - case HAL_PLATFORM_T31: - fprintf(stderr, "Divinus for ingenic t31\n"); break; -#endif - default: - fprintf(stderr, "Unsupported chip family! Quitting...\n"); - return EXIT_FAILURE; - } - fprintf(stderr, "Chip ID: %s\n", chipId); + if (!*family) + HAL_ERROR("hal", "Unsupported chip family! Quitting...\n"); - if (parse_app_config() != CONFIG_OK) { - fprintf(stderr, "Can't load app config 'divinus.yaml'\n"); - return EXIT_FAILURE; - } + fprintf(stderr, "Divinus for %s\n", family); + fprintf(stderr, "Chip ID: %s\n", chip); + + if (parse_app_config() != CONFIG_OK) + HAL_ERROR("hal", "Can't load app config 'divinus.yaml'\n"); if (app_config.mdns_enable) start_mdns(); @@ -61,11 +37,11 @@ int main(int argc, char *argv[]) { if (app_config.rtsp_enable) { rtspHandle = rtsp_create(RTSP_MAXIMUM_CONNECTIONS, 2); - fprintf(stderr, "RTSP server started, listening for clients...\n"); + HAL_INFO("rtsp", "Started listening for clients...\n"); } if (start_sdk()) - return EXIT_FAILURE; + HAL_ERROR("hal", "Failed to start SDK!\n"); if (app_config.night_mode_enable) start_monitor_light_sensor(); @@ -83,7 +59,7 @@ int main(int argc, char *argv[]) { if (app_config.rtsp_enable) { rtsp_finish(rtspHandle); - fprintf(stderr, "RTSP server has closed!\n"); + HAL_INFO("rtsp", "Server has closed!\n"); } if (app_config.osd_enable) diff --git a/src/media.h b/src/media.h index ef68594..39ccb1a 100644 --- a/src/media.h +++ b/src/media.h @@ -1,5 +1,13 @@ #pragma once +#include +#include +#include +#include +#include +#include +#include + #include "app_config.h" #include "error.h" #include "hal/types.h" @@ -9,14 +17,6 @@ #include "rtsp/rtsp_server.h" #include "server.h" -#include -#include -#include -#include -#include -#include -#include - extern rtsp_handle rtspHandle; int start_sdk(void); diff --git a/src/network.h b/src/network.h index c9dd86e..bd402df 100644 --- a/src/network.h +++ b/src/network.h @@ -1,8 +1,5 @@ #pragma once -#include "hal/support.h" -#include "lib/tinysvcmdns.h" - #include #include #include @@ -12,5 +9,8 @@ extern int asprintf(char **restrict strp, const char *restrict fmt, ...); #endif +#include "hal/support.h" +#include "lib/tinysvcmdns.h" + int start_mdns(); void stop_mdns(); \ No newline at end of file diff --git a/src/night.h b/src/night.h index 95b5bb5..22f80e0 100644 --- a/src/night.h +++ b/src/night.h @@ -1,10 +1,5 @@ #pragma once -#include "app_config.h" -#include "gpio.h" -#include "hal/macros.h" -#include "media.h" - #include #include #include @@ -12,6 +7,11 @@ #include #include +#include "app_config.h" +#include "gpio.h" +#include "hal/macros.h" +#include "media.h" + void set_night_mode(bool night); bool night_mode_is_enabled(); void *night_thread(); diff --git a/src/region.h b/src/region.h index 8674b4b..993facf 100644 --- a/src/region.h +++ b/src/region.h @@ -1,26 +1,12 @@ #pragma once -#include "app_config.h" -#include "hal/support.h" -#include "text.h" - -#define DEF_COLOR 0xFFFF -#define DEF_FONT "UbuntuMono-Regular" -#define DEF_OPAL 255 -#define DEF_POSX 16 -#define DEF_POSY 16 -#define DEF_SIZE 32.0f -#define DEF_TIMEFMT "%Y/%m/%d %H:%M:%S" -#define MAX_OSD 8 - -#include -#include -#include - #include #include #include #include +#include +#include +#include #include #ifdef __UCLIBC__ @@ -33,6 +19,19 @@ extern int asprintf(char **restrict strp, const char *restrict fmt, ...); #include #endif +#include "app_config.h" +#include "hal/support.h" +#include "text.h" + +#define DEF_COLOR 0xFFFF +#define DEF_FONT "UbuntuMono-Regular" +#define DEF_OPAL 255 +#define DEF_POSX 16 +#define DEF_POSY 16 +#define DEF_SIZE 32.0f +#define DEF_TIMEFMT "%Y/%m/%d %H:%M:%S" +#define MAX_OSD 8 + extern char keepRunning; extern int sysinfo (struct sysinfo *__info); diff --git a/src/server.c b/src/server.c index 171dbb0..654a314 100644 --- a/src/server.c +++ b/src/server.c @@ -1127,7 +1127,7 @@ void *server_thread(void *vargp) { "Connection: close\r\n" \ "\r\n" \ "{\"chip\":\"%s\",\"loadavg\":[%.2f,%.2f,%.2f],\"memory\":\"%s\",\"uptime\":\"%s\"}", - chipId, si.loads[0] / 65536.0, si.loads[1] / 65536.0, si.loads[2] / 65536.0, + chip, si.loads[0] / 65536.0, si.loads[1] / 65536.0, si.loads[2] / 65536.0, memory, uptime); send_and_close(client_fd, response, respLen); } else send_and_close(client_fd, (char*)error400, strlen(error400)); diff --git a/src/server.h b/src/server.h index 8d19f4f..8ed2f7c 100644 --- a/src/server.h +++ b/src/server.h @@ -16,6 +16,12 @@ #include #include +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) +#include +#else +#include +#endif + #include "app_config.h" #include "hal/types.h" #include "jpeg.h" @@ -25,12 +31,6 @@ #include "region.h" #include "watchdog.h" -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) -#include -#else -#include -#endif - #define IMPORT_BIN(sect, file, sym) asm (\ ".section " #sect "\n" /* Change section */\ ".balign 4\n" /* Word alignment */\ diff --git a/src/text.h b/src/text.h index 1014a43..74c5c54 100644 --- a/src/text.h +++ b/src/text.h @@ -1,8 +1,8 @@ #pragma once +#include + #include "hal/support.h" #include "lib/schrift.h" -#include - hal_bitmap text_create_rendered(const char *font, double size, const char *text, int color); \ No newline at end of file diff --git a/src/watchdog.h b/src/watchdog.h index ab04586..8f8118d 100644 --- a/src/watchdog.h +++ b/src/watchdog.h @@ -1,7 +1,5 @@ #pragma once -#include "hal/macros.h" - #include #include #include @@ -9,6 +7,8 @@ #include #include +#include "hal/macros.h" + void watchdog_reset(void); int watchdog_start(int timeout); void watchdog_stop(void); \ No newline at end of file