Lsong's Blog

Lsong

Open Source Software & Hardware

  • China's Real Estate: Debt Crisis and Developer Challenges

    China’s Real Estate: Debt Crisis and Developer Challenges

    In past years, local governments, aiming for infrastructure development, struck deals with developers allowing them to obtain land at lower prices. The catch was that developers would help the local governments with infrastructure like building bridges, roads, schools, hospitals, and shopping centers. After completion, developers would also assist in attracting investment. For a time, this symbiotic relationship blossomed in a mutual honeymoon phase.

    However, as local economies began to improve, many local governments seemed to turn on their developer partners, suggesting they complete infrastructure projects before discussing land approvals. Unfortunately, after the developers fulfilled their end, land approvals were sometimes denied for various reasons, leaving many developers aggrieved but mostly silent.

    The construction industry inherently has a long capital turnover cycle, sometimes taking 5-6 years for full repayment. Meanwhile, expenses for labor, materials, and sales persist, creating significant financial pressure. A strategy devised by developers was to mortgage their constructed properties to banks. Once the property was sold, homeowners would repay the bank. Interestingly, many homeowners financed their purchases with bank loans, meaning the bank technically owned the property throughout the process.

    Developers realized under this scheme they didn’t have to worry about sales — they simply had to mortgage properties to gain funds. With house prices continuously rising, developers could keep building, ensuring a steady cash flow, and then invest these funds in high-return ventures.

    There were even incidents where developers hired actors to create a façade of booming sales at property sites, aiming to convince both potential buyers and banks of the property’s attractiveness.

    With house prices skyrocketing across China, even in third and fourth-tier cities, property prices often surpassed local incomes. The phenomenon of “locals can’t afford local homes” became widely discussed.

    The decree “Houses are for living in, not for speculation” signaled the start of real estate regulation, with various measures introduced to control property prices and loans. The market soon responded with a cooldown. Local governments tightened land approval processes, from a “villa restriction order” to an outright “villa ban”, followed by restrictions on high-rise plots, all aiming to curb the wild and chaotic expansion of real estate.

    Soon after, the central bank and the Ministry of Housing and Urban-Rural Development issued financing policies for developers, effective from January 1, 2021. These were the so-called “three red lines”:

    1. An asset-liability ratio greater than 70% after deducting advance receipts.
    2. A net debt ratio exceeding 100%.
    3. A cash-to-short-term debt ratio below 1.

    By mid-2023, the 12 pilot real estate companies had to meet all these “three red line” standards, with all companies expected to comply by the end of 2023.

    Evergrande hit all these red lines, making debt reduction its top priority. Various measures were taken, from asset sales, divestments in cultural sectors, debt-to-equity swaps, to other forms of financing. But these actions only exposed the colossal financial black hole, a shocking $300 billion debt, which alarmed the global community given its potential to trigger a worldwide financial crisis. Yet, there was an unusual consensus among foreign media and investors: “China can handle the Evergrande situation”.

    So far, there’s no clear sign of the state intervening. The message seems clear to corporate giants: “No company is too big to fail”. Controlling financial risks has become a lesson that Chinese enterprises must heed.

    The golden age for the real estate industry seems to be waning. The era where property developers leveraged financial gains for rapid growth no longer exists.

    Beyond the above, city investment bonds (often referred to as “城投债” or “City Investment Bonds”) have also become a topic of concern. These bonds, mainly issued by local government financing platforms (LGFVs), have played a pivotal role in fueling China’s urbanization drive over the past few decades.

    There’s a close relationship between developers like Country Garden and city investment platforms. For instance, Country Garden might buy land from these platforms or collaborate with them for development. This means that when these platforms face financial risks, developers like Country Garden are directly impacted.

    To combat these risks, many developers, including Country Garden, are searching for new partnership models and funding sources. But, clearly, this isn’t an issue that can be resolved overnight. This implies that China’s real estate market might face a prolonged period of adjustment and change.

    All the content above represents personal opinions. Some information is sourced from the internet. Please contact the author for any copyright or regulatory concerns.

    11 September 2023, 12:00 am
  • Talk About ChatGPT

    ChatGPT - OpenAI’s Powerful Language Model

    • What is ChatGPT?
    • The Origin of ChatGPT?

    ChatGPT is undoubtedly familiar to many. From research and development to education, from sales to even your local barber Tony, it’s a name known to all.

    In an era marked by rapid advancements in artificial intelligence, ChatGPT has provided numerous conveniences and innovations.

    Today, we delve deep into the definition of ChatGPT, its history and evolution, application scenarios, and future prospects, hoping to enlighten and aid our readers.

    What is ChatGPT?

    ChatGPT is an application of natural language processing based on AI technology. A technology rooted in deep learning neural networks, it utilizes vast text data for pre-training, enabling auto-generation and manipulation of text. Specifically, ChatGPT stands for “Generative Pre-trained Transformer.” Its capabilities span:

    • Text Generation: ChatGPT can generate various types of text, like articles, stories, poetry, etc.
    • Language Translation: ChatGPT can translate text between different languages.
    • Language Comprehension: ChatGPT can understand the meaning and semantics of human language, facilitating natural language processing and Q&A tasks.
    • Language Creation: ChatGPT can generate content that meets grammatical and semantic requirements by understanding context and dialogue.
    • Recommendation Systems: ChatGPT can analyze user text input and behaviors to provide personalized suggestions and content.

    The Origin of ChatGPT

    [Transformer] <- [GPT] <- [GPT 2] <- [GPT 3] <- [InstructGPT]

    In August 2017, Google released a blog titled Transformer: A Novel Neural Network Architecture for Language Understanding, introducing the Transformer neural network architecture for language understanding tasks. Transformers, with their self-attention mechanisms, replaced traditional RNNs and CNNs, effectively processing varying input sequence lengths, achieving optimal or near-optimal performance in translation, Q&A, and summary tasks.

    By June 2018, OpenAI introduced its first pre-trained language model, GPT-1, based on Transformer, pre-trained on over 800 billion words.

    In November 2019, the GPT-2 language model gained widespread attention for its ability to autonomously generate natural language text. Built atop the latest deep learning model with over 150 million parameters, GPT-2 can produce incredibly realistic and fluent text. It has been employed in text-generation applications, including chatbots, writing assistants, and smart customer service.

    GPT-3 further emphasizes representation capability and diversity. Upgraded versions consistently improve ChatGPT’s performance and efficiency, enabling it to tackle an increasing number of language tasks.

    InstructGPT was trained to follow commands in prompts and provide detailed responses. Converting the GPT-3 model to the InstructionGPT model required a three-step procedure devised by OpenAI. Firstly, the model is fine-tuned. Secondly, a reward model (RM) is established. Thirdly, supervised fine-tuning (SFT) is implemented, followed by further fine-tuning via reinforcement learning.

    InstructGPT has its upsides compared to GPT-3, better aligning with human preferences. However, this can also be its downside. Malicious users might exploit it to degrade model truthfulness and utility, possibly causing harm.

    Nonetheless, InstructGPT is not only superior to GPT-3 in following commands but also aligns better with human intent. The AI alignment issue is well-known in the industry. It pinpoints the challenge of designing AI systems that understand our values and beliefs without disrupting them.

    According to OpenAI, this is the first application of alignment, demonstrating that these techniques significantly enhance the alignment of general AI systems with human intent. The InstructGPT model is now deployed as the default language model on OpenAI’s API.

    In ChatGPT’s operation, context comprehension is crucial. Through prior dialogue, ChatGPT can better grasp the context of subsequent queries, generating more accurate responses. However, every API call will consume a certain number of tokens, linked to the input text’s length.

    The future prospects for ChatGPT are vast. As AI technology continues to evolve:

    • Intelligence: ChatGPT will refine its neural network structure, enhancing automated processing and generation.
    • Natural Interaction: It will strive for more fluent and natural language interactions.
    • Human-Centric: Efforts will be made for more humane and emotional interactions.
    • Broad Applications: ChatGPT will find applications in diverse fields like medicine, finance, and law.

    To harness ChatGPT effectively, users might need to provide “fact assumptions” or dialogue backgrounds. With the Fine-tuning technique, users can customize datasets and models, thereby achieving better performance and adaptability.

    In conclusion, ChatGPT is an excellent natural language processing model. Through Fine-tuning techniques, users can tailor datasets and models, resulting in superior performance and adaptability. ChatGPT will continue to expand its application areas, aiming for intelligent, natural, and human-centric language interactions.

    28 February 2023, 12:00 am
  • Container Strategies and Concerns of Internet Titans

    互联网巨头的容器战略及其焦虑

    随着科技的迅速进步,如今我们手机上的应用已经不再单一。许多应用现在都采用的是Hybird App的架构。这种模式结合了 Native 的基础功能和 Webview + JS Bridge 的快速变化的内容。在这种模式下,Webview 的渲染性能就显得尤为关键,因为它直接决定了用户的使用体验。

    看到这样的趋势,各大互联网公司都开始重视浏览器内核的研发和收购。例如,阿里收购了 UC 浏览器,并利用了 UC 的内核。腾讯则拥有 X5 内核,并且后续还收购了搜狗浏览器。字节跳动也不甘落后,他们也在积极布局开发自己的浏览器内核,基于 webkit 的技术。而美团虽然从商业角度支持了小程序的架构,但由于缺乏自己的浏览器内核,它一直面临着巨大的挑战。

    为了解决这个问题,美团开始了自己的浏览器内核研发工作。他们曾试图 fork webkit,但由于其庞大的 codebase,这个项目进展缓慢。后来,当React Native技术问世,美团决定投资 MRN 架构,期望通过这种方式优化移动端的渲染体验。但很快,由于社区对 React Native 技术性能的质疑,以及其无法解决的固有问题,美团逐渐转向 Flutter 架构。

    我的个人经历也与此相关。我最初专注于工程化方案的研究,但后来我被分配到小程序架构的团队,然后再到 Flutter 渲染引擎的项目中。我们的目标是基于 skia 来解析 DOM 和 CSS,从而实现一个高效的渲染引擎。这项工作仍在进行中。

    与此同时,React Native 的原生绑定模式对许多开发者来说也是一个挑战。很多前端开发者在尝试学习React Native时发现,由于其底层是基于 Native 的实现,导致许多功能需要先在 Native 中实现,React Native 才能调用。这也使得 React Native 无法真正实现“多端一致性”的目标。

    而 Flutter,是 Google 提出的一个解决方案。不同于 React Native,Flutter 直接使用 skia(基于 OpenGL)从头构建渲染引擎,避免了操作系统层面的交互。这种做法使得Flutter能够真正实现一套代码在多端运行。

    综上,从架构的特点和前景来看,Flutter 显然更具投资价值。但这并不意味着它现在就是完美的。例如,“闲鱼”App,尽管是基于 Flutter 开发的,但在实际使用中,其稳定性和性能仍有待提高。

    总的来说,随着技术的发展,各大互联网公司在容器技术方面的布局和策略也在不断调整。未来还有很长的路要走,但这也充满了机会和挑战。

    4 November 2021, 12:00 am
  • The Future Of Web Development

    我眼中的前端技术发展方向

    一、React 没有未来

    React 解决了什么问题?

    • 组件化的问题
    • 引入了虚拟 DOM 优化渲染

    组件化的问题 Web Component 已经在路上了,终将有一个标准化的实现。

    我们知道,VirtualDOM 可以一定程度上优化 DOM 渲染性能,但是在浏览器层面上 DOM 渲染性能本身就已经在优化了,React 中使用 VirtualDOM 来优化性能问题,这个问题很大程度上是 React 自己造成的。浏览器本身 DOM 性能已经很高了。当然我们也要知道 React VirtualDOM 不只是为了解决渲染问题,也为了能够实现渲染层抽象,适配更多的渲染引擎。

    二、Webpack 没有未来

    我们之所以使用 Webpack 来打包主要是解决两个问题:

    • 模块化
    • 合并文件以降低创建网络链接对页面加载性能的影响

    随着 HTTP/2/3/QUIC 的发展,连接复用技术已经可以实现,即使在页面上写多个相同域的多个 script 标签也只会创建一个 TCP 链接,而且支持交叉数据传递,对网络加载性能影响很小。

    目前很多 CDN 厂商都已经部署了 HTTP/2(\w QUIC)协议,毕竟对他们来说也是一个节省开销的好事情。

    其次,浏览器对于 ES Module 已经支持的很好了,而且从社区支持来看越来越多的 Library 都输出了符合 ESM 规范的打包格式。而且 ESM 相比于其他打包格式还有一些诸如减少JS VM 虚拟机计算量等额外优势,没有理由不支持。

    没有了 Webpack TypeScript 怎么办?

    如果没有了 Webpack,那么 TypeScript 可以通过 WebAssembly 在浏览器端解析和执行,无需预编译执行。

    三、小程序没有未来

    虽然目前小程序已经很流行,但是 Service Worker 和 Offline App 的广泛应用是迟早的事情。

    小程序总是想着向 Native 的方向努力,最终很可能会变成 Native 开发的一种方式,而非 Web 的未来。

    虽然小程序为开发者提供了一种简单、快速的开发方式,但它并没有实现重大创新。

    我眼中的未来是什么?

    回归标准:我在讲某个东西没有未来并不是说否定它存在的意义,在特定的时期下它们的存在是非常重要的,它们加速了 Web 发展进程功不可没,但是缺乏标准化总是在解决一个问题的同时带来了非常多衍生的其他问题,这就是工程化实践标准化实践的区别。

    大道至简:想想看,我们现在要开始做一个 Web 应用要做那些事情?安装一大堆的框架、工具库、工具链、打包编译工具,每修改一个文件都要等待漫长的编译,每次发布都要经过复杂的工作流程来确保与开发时的预期一致。我认为未来不是这样,就应该是开箱即用,唾手可得,且性能优异。

    28 October 2021, 12:00 am
  • The Meteoric Rise of Clubhouse: Dissecting its Popularity

    Clubhouse: An audio-driven social haven

    At its core, Clubhouse is an audio-centric social platform. Its users can be broadly classified as:

    • Moderators: The drivers of conversations
    • Speakers: The participants voicing their opinions
    • Listeners: The silent majority who absorb the discourse

    In terms of its product structure, Clubhouse resonates with traditional radio broadcasts, contemporary Podcasts, and teleconferences. However, it sets itself apart by allowing users to engage in real-time discussions on a plethora of topics or none at all.

    Interestingly, once a moderator ends a conversation and exits the room, it’s as if the discussion never happened; no recordings, no screen captures—a ‘snap-and-disappear’ essence. This ephemeral nature fosters open and burden-free communication.

    Insight One: Clubhouse is not a technological marvel

    Technologically speaking, Clubhouse wasn’t a pioneer in audio-social platforms. Platforms like Talkbox and YY had tread this path almost a decade ago. What’s more, indie developers even managed to recreate similar platforms on Twitter in a mere 60 hours! This suggests that Clubhouse’s popularity isn’t necessarily rooted in technological advancement.

    Insight Two: Its lack of niche is its niche

    The true essence of Clubhouse’s success lies in the ambiance it creates. Some equate it to a local tea house or a communal gathering under an old village tree. What makes it unique? In truth, not much. However, this absence of a specific niche, unlike platforms like YY or Twitch, makes it versatile for an array of topics.

    Currently exclusive to the iOS ecosystem and absent from the Chinese App Store due to content regulations, Clubhouse employs an invite-only model. This fosters a tight-knit community. The app’s core attributes reveal:

    • Rooms: Crafted around friendships or specific topics, rooms are algorithmically recommended to acquaintances or familiar faces, ensuring discussions remain intact without unexpected interruptions.

    • Voice-Centric Approach: Unlike text, voice feels warmer; unlike video, it rids the stress of appearance. The absence of recordings generates a laid-back, equal-footed, and spontaneous discussion environment.

    Insight Three: Why did Clubhouse resonate in China?

    Despite the barriers to entry (acquiring an App Store US account, purchasing invites), the app has managed to carve a niche as an “elite community” in China. Most users wouldn’t expend so much effort for a mere social app. But, Clubhouse, catering to a global audience, offers a window to the world—a tantalizing proposition for a curious Chinese populace.

    Recently, rooms discussing cross-strait relations have surged. Given the long-standing information gap and misconceptions fueled by media on both sides, direct voice dialogues offer a more reasoned and respectful medium of engagement.

    In a nutshell, Clubhouse’s rise can be attributed to:

    • Origins: Meeting basic human needs; gathering and conversing are essential emotional outlets.

    • Circumstance: The pandemic inhibited physical gatherings, amplifying this need.

    • Trigger: Elon Musk’s live session on Clubhouse spurred a monumental traffic surge.

    • User Experience: A clear and intuitive interface centered around its core function.

    • Ambiance: Its initial traction within venture capital, product, and crypto circles cultivated an elite community vibe.

    These insights represent personal opinions and are open for discussion. Engage away! 👏

    7 February 2021, 12:00 am
  • You Should Use Right Side USB-C Port

    搬了新工位让我的 MacBook Pro 发烫变慢

    最近我发现我的 MacBook Pro 运行一会儿就会风扇狂转,摸了一下机器感觉很烫。

    我寻思是不是我的开发任务太繁重了,以至于我的 Laptop 不堪重负,向我发出求救信号🆘

    经验告诉我应该打开 macOS 系统的 「Activity Monitor」 来看下进程使用情况,看看到底是那个小机灵鬼在捣蛋。😜

    image.png

    一般来说我们找到占用最高的进程,杀掉这个进程,就可以释放 CPU 和内存的占用了,但是这一次,事情并没有按我们设定的剧情发展。我们看到占用最高的是一个叫做 「kernel_task」的进程,凭我多年 搞基 搞机的经验来判断,事情没有辣么简单。

    我们需要先了解一下这个「kernel_task」是什么,其实这个进程有点类似 Windows 中的 「Idle Process」,就是说,在 CPU 运行过程中实际上是在时钟频率的周期下不断读取内存中的指令到内核中进行运算,为了保证系统中其他进程也能够分配到 CPU 时间,不至于撑的撑死饿的饿死,导致进程无响应,操作系统会使用时间分片来统一调度。同时为了保证任务空闲时 CPU 不至于满载运行,系统中通常会设计一个 「Idle Process」 来让 CPU 空跑。这个进程在 macOS 里面叫做 「kernel_task」。

    那么为什么「kernel_task」占用有这么高呢,凭什么把 CPU 时间都给了它却不分配给明明很忙的我们呢?🤔

    经过我持续几天的观察,我发现有的时候会出现这个情况,有的时候就不会出现。具体来说就是:电池电量剩余充足的情况下很少出现,通常在快没电了充电的时候就会比较卡。但是很奇怪的是,我以前也有过快没电了充电的经历,为啥之前没发现呢🤔

    在排查各种变量的过程中突然想到:最近搬了新工位! share.jpg

    你可能会惊讶,这TM有啥关系!

    你还别说,真的有关系,听我来分析一哈!

    (音响老师,音乐起🎵)

    image.png

    👇大家注意看这里👇

    image.png

    我在之前的工位,充电时一直用的是右侧的 USB-C 接口,搬到新工位的地方,由于桌面布局发生了改变,我插了左侧的接口充电和显示器。

    也就是这个差别导致了我的 MacBook Pro 发热严重,系统使用 kernel_task 让 CPU 降低负荷,以减缓发热问题。但是也正因为这个动作让我们的系统变得卡顿了。

    按着这个猜想我简单搜索了一下:

    image.png

    发现类似的问题也有人提出过,但是由于复现条件实在过于苛刻隐蔽,没能引起大规模讨论。

    原来是因为 MacBook Pro 因为设计问题导致左侧的 USB-C 口的电源芯片和 HDMI 芯片发热,导致 CPU 的温度传感器感知热量为了保证 CPU 稳定运行才让 kernel_task 插入一些空任务来降低其他任务的优先级。不光是充电,使用不合适的显示器设备也会导致这个问题。

    由此,问题原因终于找到了,这不禁让我想起两个类似的故事,这里和大家分享一下。

    對香草口味過敏的車

    有一天美国通用汽车公司的庞帝雅克(Pontiac)部门收到一封客户抱怨信,上面是这样写的∶“这是我为了同一件事第二次写信给你,我不会怪你们为什么没有回信给我,因为我也觉得这样别人会认为我疯了,但这的确是一个事实。”   “我们家有一个传统的习惯,就是我们每天在吃完晚餐后,都会以冰淇淋来当我们的饭后甜点。由于冰淇淋的口味很多,所以我们家每天在饭后才投票决定要吃哪一种口味,等大家决定后我就会开车去买。”   “但自从最近我买了一部新的庞帝雅克后,在我去买冰淇淋的这段路程问题就发生了。”   “你知道吗?每当我买的冰淇淋是香草口味时,我从店里出来车子就发不动。但如果我买的是其它的口味,车子发动就顺得很。我要让你知道,我对这件事情是非常认真的,尽管这个问题听起来很猪头。为什么这部庞帝雅克当我买了香草冰淇淋它就发不动,而我不管什么时候买其它口味的冰淇淋,它就一尾活龙?为什么?为什么?”   事实上庞帝雅克的总经理对这封信还真的心存怀疑,但他还是派了一位工程师去查看究竟。当工程师去找这位仁兄时,很惊讶的发现这封信是出之于一位事业成功、乐观、且受了高等教育的人。   工程师安排与这位仁兄的见面时间刚好是在用完晚餐的时间,两人于是一个箭步跃上车,往冰淇淋店开去。那个晚上投票结果是香草口味,当买好香草冰淇淋回到车上后,车子又发不动了。   这位工程师之后又依约来了三个晚上。   第一晚,巧克力冰淇淋,车子没事。   第二晚,草莓冰淇淋,车子也没事。   第三晚,香草冰淇淋,车子发不动。   这位思考有逻辑的工程师,到目前还是死不相信这位仁兄的车子对香草过敏。因此,他仍然不放弃继续安排相同的行程,希望能够将这个问题解决。工程师开始记下从头到现在所发生的种种详细资料,如时间、车子使用油的种类、车子开出及开回的时间……,根据资料显示他有了一个结论,这位仁兄买香草冰淇淋所花的时间比其它口味的要少。   为什么呢?原因是出在这家冰淇淋店的内部设置的问题。因为,香草冰淇淋是所有冰淇淋口味中最畅销的口味,店家为了让顾客每次都能很快的取拿,将香草口味特别分开陈列在单独的冰柜,并将冰柜放置在店的前端;至于其它口味则放置在距离收银台较远的后端。   现在,工程师所要知道的疑问是,为什么这部车会因为从熄火到重新激活的时间较短时就会发不动?原因很清楚,绝对不是因为香草冰淇淋的关系,工程师很快地由心中浮现出,答案应该是“蒸气锁”。因为当这位仁兄买其它口味时,由于时间较久,引擎有足够的时间散热,重新发动时就没有太大的问题。但是买香草口味时,由于花的时间较短,引擎太热以至于还无法让“蒸气琐”有足够的散热时间。

    第二个故事:

    image.png

    https://github.com/fastai/fastai/issues/751#issuecomment-419319808

    有时候问题的真正原因往往让你感到以外,就像一盒巧克力,你永远不知道下一颗是什么味道 …(bushi 就像上面的三个例子,看似不相关的行为背后竟有着千丝万缕的联系。而这些联系正无时无刻影响着我们的生活。

    很多时候,很多问题并不是没有偶然、随机发生的,只是我们看不透而已。(上帝视角

    最后,建议大家尽量使用右侧的 USB-C 口充电和连接显示器避免机器过热降频,祝大家工作愉快🎉

    4 December 2020, 12:00 am
  • Flash Chip of a Phicomm K2 Router With a Programmer

    斐讯 K2 PSG1218 是一款 1200M AC 双频无线路由器,支持 2.4G 和 5G 频率的信号发射。

    同事在给 K2 刷 LEDE (OpenWRT) 后 Reboot 长时间没有反应就强行断电重启导致固件数据损坏无法开机了。

    下面我们一起来看下如何修复它 😊

    TTL Debug

    拿到路由后用撬棒打开外壳,找到主板 TTL Pin 的位置,连接好 TTL Adapter 然后插上电源观察 SerialPort 输出:

    但是很遗憾没有任何反应,说明 ROM 中的固件完全损坏,无法正确引导。

    Flash Chip of Router

    既然没办法用 TTL 调试刷机,那么我们只好拆掉 EEPROM 强行烧录固件了。

    Unmount EEPROM flash chip

    找到 Flash 芯片的位置,用锡纸覆盖主板,在 Flash 芯片的位置开孔,用热风枪加热直至针脚的焊锡全部融化,使用芯片拔取器小心取下。

    用锡纸覆盖是为了避免热风枪 400摄氏度 的高温和风力将其他元器件吹跑…

    Programmer 编程器

    将取下的 Flash 放置到 Programmer 中的对应位置:

    读取后发现原来 ROM 中后面的数据损坏全部为 0x00 了,先备份一下以备之后使用 (因为里面有 WiFi 的 MAC 地址和网络驱动配置信息)

    Breed Firmware

    breed firmware 是一个 u-boot 固件,它允许我们引导不同的系统。

    下载对应版本 https://breed.hackpascal.net/breed-mt7620-phicomm-psg1208.bin 并写入到 EEPROM:

    Remount flash chip

    清理主板 Flash 芯片的焊接位置并放好,用热风枪加热焊盘确保所有针脚接触良好。

    连接 TTL Adapter 上电开机 breed 固件系统进入 boot 流程,并输出信息:

    看到这个提示信息说明 Router 中的 Breed firmware 已经正确引导,下面我们只需要正常刷机即可。

    Install Padavan firmware

    Padavan 固件具体我就不详细介绍了,大家可以到论坛查看 http://www.right.com.cn/forum/thread-161324-1-1.html

    固件下载地址:http://opt.cn2qq.com/padavan/

    收工

    通过一系列工作我成功地将一个变成板砖的路由器修复成原来的模样

    事实上,路由器是一个完整的计算机设备,软件的操作一般来说并不会导致硬件设备的永久性损坏。

    只要我们了解它的工作原理,并配合工具完全可以修复。

    原谅我混乱的桌面,祝大家玩得开心~

    29 September 2018, 12:00 am
  • 5 minutes 30 seconds
    Episode 1: Audio readme file

    This episode contains an example file with instructions on how to use this Jekyll template.

    Enjoy.

    10 July 2018, 12:00 am
  • Linux Low-level Input Event Reading

    在 PC 上看视频和听音乐时,如果距离比较远想去控制音量、播放进度、暂停继续等操作就比较麻烦

    我就在想,如果 PC 也能支持遥控器就好了

    遥控器每个人家里都有很多,空调、电视、电视盒子 基本都是红外发射器(IR)

    刚好手里还有个之前买的 CubieBoard 它上面是有 IR Receiver 接收器的

    https://wiki.lsong.org/cubietruck

    Linux 中设备以文件形式存在, 当插入一个「可提供输入的设备」时, Kernel 会在 /dev/input/ 目录下产生一个 char 类型文件。

    ➜ ~ ls -l /dev/input/ total 0 drwxr-xr-x 2 root root 60 Feb 10 13:03 by-path crw-r----- 1 root root 13, 64 Feb 10 13:03 event0 crw-r----- 1 root root 13, 65 Feb 10 13:03 event1 crw-r----- 1 root root 13, 63 Feb 10 13:03 mice

    通过 cat 命令可以读取该设备输入的数据流, 为了使数据流可读我们可以使用 hexdump 命令将数据流以 hex 形式显示。

    ➜ ~ cat /dev/input/event0 | hexdump

    当我按下(并松开)一个按键时, 我的到了下面的输出:

    ➜ ~ cat /dev/input/event0 | hexdump 0000000 5d77 56bd eb98 0005 0001 0007 0001 0000 0000010 5d77 56bd eba3 0005 0000 0000 0000 0000 0000020 5d77 56bd bc16 0009 0001 0007 0000 0000 0000030 5d77 56bd bc1e 0009 0000 0000 0000 0000

    不同的按键会产生不同的输出, 我们来看看 Kernel 中对 Input 的数据结构定义:

    struct input_event { struct timeval time; unsigned short type; unsigned short code; unsigned int value; }; struct timeval { __time_t tv_sec; __suseconds_t tv_usec; };
    • time: 时间戳, 表明事件发生的时间
    • type: 事件类型, eg: EV_KEY
    • code: 事件编码 eg: KEY_BACKSPACE
    • value: 事件值 eg: 1(keypress)
    <Buffer a4 3e 5b 51 ab cf 03 00 04 00 04 00 2c 00 07 00> | tv_sec | tv_usec |type |code | value |

    有了这个数据结构之后我们就可以以数据流的形式读取它们,并转换为相应的结构。

    解析流程比较复杂,可以看下代码:

    // source from: https://github.com/song940/input-event/blob/master/lib/index.js#L51-L76 process(buf) { var ev; /** * Sometimes (modern Linux), multiple key events will be in the triggered at once for the same timestamp. * The first 4 bytes will be repeated for every event, so we use that knowledge to actually split it. * We assume event structures of 3 bytes, 8 bytes, 16 bytes or 24 bytes. */ if (buf.length > 8) { var t = buf.readUInt32LE(0); var lastPos = 0; for (var i = 8, n = buf.length; i < n; i += 8) { if (buf.readUInt32LE(i) === t) { var part = buf.slice(lastPos, i); ev = this.parse(part); if (ev) this.emit('data', ev, part); lastPos = i; } } var part = buf.slice(lastPos, i); ev = this.parse(part); if (ev) this.emit('data', ev, part); } else { ev = this.parse(buf); if (ev) this.emit('data', ev, buf); } }

    我把这个解析逻辑封装成 npm package 发布在 http://npmjs.org/input-event 了

    经过社区开发者的贡献,我们现在已经支持对 键盘、鼠标、遥控器、游戏控制器和编码旋钮的支持了。

    接下来就是把从遥控器接收并解析出来的按键信息发送给 PC 再转换成按键

    const dgram = require('dgram'); const InputEvent = require('input-event'); var remote = new InputEvent.Keyboard('/dev/input/event0'); var udp = dgram.createSocket('udp4'); remote.on('keypress', function(ev){ console.log(ev.code); var buf = new Buffer('code:' + ev.code); udp.send(buf, 0, buf.length, 1989, '255.255.255.255'); });

    我们实现了红外接收遥控器按键,将按键 code 封装成 UDP 数据包广播到局域网中所有的设备上,这样就不用事先配置接收端的 IP 地址了。

    using System; using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Text; namespace RemoteControlServer { class RemoteServer { const int VOLUME_UP = 175; const int VOLUME_DOWN = 174; static void Main(string[] args) { var endpoint = new IPEndPoint(IPAddress.Any, 1989); UdpClient server = new UdpClient(endpoint); Console.WriteLine("Remote Server is running at 1989 ."); while (true) { var sender = new IPEndPoint(IPAddress.Any, 0); var data = server.Receive(ref sender); string message = Encoding.ASCII.GetString(data, 0, data.Length); Console.WriteLine("{0}: {1}", sender, message); switch (message) { case "code:7": for(var i = 0; i < 10; i++) keybd_event((byte)VOLUME_DOWN, 0, 0, 0); break; case "code:9": for (var i = 0; i < 10; i++) keybd_event((byte)VOLUME_UP, 0, 0, 0); break; case "code:69": Process.Start("shutdown", "/s /t 0"); break; } } } [DllImport("user32.dll")] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); } }

    在接收端我们监听 1989 端口上的 UDP 报文,根据按键的 code 执行对应的动作,模拟按键用到了 win32 API, 上面的例子主要实现了调整音量和关机操作,想要实现更多功能也比较简单,这里就不再详述了,大家可以根据自己的需求来调整。

    12 February 2016, 12:00 am
  • More Episodes? Get the App
© MoonFM 2024. All rights reserved.